mirror of
https://github.com/Infisical/infisical.git
synced 2026-05-02 03:02:03 -04:00
Optimize and patch minor issues for Cloudflare Pages integration
This commit is contained in:
@@ -1843,6 +1843,13 @@ const syncSecretsHashiCorpVault = async ({
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Sync/push [secrets] to Cloudflare Pages project with name [integration.app]
|
||||
* @param {Object} obj
|
||||
* @param {IIntegration} obj.integration - integration details
|
||||
* @param {Object} obj.secrets - secrets to push to integration (object where keys are secret keys and values are secret values)
|
||||
* @param {String} obj.accessToken - API token for Cloudflare
|
||||
*/
|
||||
const syncSecretsCloudflarePages = async ({
|
||||
integration,
|
||||
secrets,
|
||||
@@ -1854,65 +1861,56 @@ const syncSecretsCloudflarePages = async ({
|
||||
accessId: string | null;
|
||||
accessToken: string;
|
||||
}) => {
|
||||
const targetEnvironment = integration.targetEnvironment;
|
||||
|
||||
// get secrets from cloudflare pages
|
||||
const getSecretsRes = (
|
||||
await standardRequest.get(
|
||||
`${INTEGRATION_CLOUDFLARE_PAGES_API_URL}/client/v4/accounts/${accessId}/pages/projects/${integration.app}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
"Accept": "application/json",
|
||||
},
|
||||
}
|
||||
)
|
||||
)
|
||||
.data.result['deployment_configs'][targetEnvironment]['env_vars'];
|
||||
// get secrets from cloudflare pages
|
||||
const getSecretsRes = (
|
||||
await standardRequest.get(
|
||||
`${INTEGRATION_CLOUDFLARE_PAGES_API_URL}/client/v4/accounts/${accessId}/pages/projects/${integration.app}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
"Accept": "application/json",
|
||||
},
|
||||
}
|
||||
)
|
||||
)
|
||||
.data.result['deployment_configs'][integration.targetEnvironment]['env_vars'];
|
||||
|
||||
// copy the secrets object, so we can set deleted keys to null
|
||||
const secretsObj: any = {...secrets};
|
||||
// copy the secrets object, so we can set deleted keys to null
|
||||
const secretsObj: any = {...secrets};
|
||||
|
||||
for (const [key, val] of Object.entries(secretsObj)) {
|
||||
secretsObj[key] = { type: "secret_text", value: val };
|
||||
for (const [key, val] of Object.entries(secretsObj)) {
|
||||
secretsObj[key] = { type: "secret_text", value: val };
|
||||
}
|
||||
|
||||
if (getSecretsRes) {
|
||||
for await (const key of Object.keys(getSecretsRes)) {
|
||||
if (!(key in secrets)) {
|
||||
// case: secret does not exist in infisical
|
||||
// -> delete secret from cloudflare pages
|
||||
secretsObj[key] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const data = {
|
||||
"deployment_configs": {
|
||||
[integration.targetEnvironment]: {
|
||||
"env_vars": secretsObj
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (getSecretsRes) { // if there are no env vars set in cloudflare pages, none have to be deleted either
|
||||
for await (const key of Object.keys(getSecretsRes)) {
|
||||
if (!(key in secrets)) {
|
||||
// case: secret does not exist in infisical
|
||||
// -> delete secret from cloudflare pages
|
||||
secretsObj[key] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const data = targetEnvironment === 'production'
|
||||
? {
|
||||
"deployment_configs": {
|
||||
"production" : {
|
||||
"env_vars": secretsObj
|
||||
}
|
||||
}
|
||||
}
|
||||
: {
|
||||
"deployment_configs": {
|
||||
"preview": {
|
||||
"env_vars": secretsObj
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const result = await standardRequest.patch(
|
||||
`${INTEGRATION_CLOUDFLARE_PAGES_API_URL}/client/v4/accounts/${accessId}/pages/projects/${integration.app}`,
|
||||
data,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
"Accept": "application/json",
|
||||
},
|
||||
}
|
||||
)
|
||||
await standardRequest.patch(
|
||||
`${INTEGRATION_CLOUDFLARE_PAGES_API_URL}/client/v4/accounts/${accessId}/pages/projects/${integration.app}`,
|
||||
data,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
"Accept": "application/json",
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export { syncSecrets };
|
||||
|
||||
@@ -288,7 +288,7 @@ export default function Integrations() {
|
||||
link = `${window.location.origin}/integrations/hashicorp-vault/create?integrationAuthId=${integrationAuth._id}`;
|
||||
break;
|
||||
case 'cloudflare-pages':
|
||||
link = `${window.location.origin}/integrations/cloudflare-pages/create?integrationAutHId=${integrationAuth._id}`;
|
||||
link = `${window.location.origin}/integrations/cloudflare-pages/create?integrationAuthId=${integrationAuth._id}`;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useState } from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
import { Card, CardTitle, FormControl, Input, Button } from '../../../components/v2';
|
||||
import saveIntegrationAccessToken from '~/pages/api/integrations/saveIntegrationAccessToken';
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import { Card, CardTitle, FormControl, Input, Button } from "../../../components/v2";
|
||||
import saveIntegrationAccessToken from "~/pages/api/integrations/saveIntegrationAccessToken";
|
||||
|
||||
export default function CloudflarePagesIntegrationPage() {
|
||||
const router = useRouter();
|
||||
@@ -16,7 +16,7 @@ export default function CloudflarePagesIntegrationPage() {
|
||||
setAccessKeyErrorText('');
|
||||
setAccountIdErrorText('');
|
||||
if (accessKey.length === 0 || accountId.length === 0) {
|
||||
if (accessKey.length === 0) setAccessKeyErrorText('Access key cannot be blank!');
|
||||
if (accessKey.length === 0) setAccessKeyErrorText('API token cannot be blank!');
|
||||
if (accountId.length === 0) setAccountIdErrorText('Account ID cannot be blank!');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
import { useGetWorkspaceById } from '~/hooks/api';
|
||||
import queryString from 'query-string';
|
||||
import { useGetIntegrationAuthApps, useGetIntegrationAuthById } from '~/hooks/api/integrationAuth';
|
||||
import createIntegration from '~/pages/api/integrations/createIntegration';
|
||||
import { Button, Card, CardTitle, FormControl, Select, SelectItem } from '~/components/v2';
|
||||
import { useState, useEffect } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import { useGetWorkspaceById } from "~/hooks/api";
|
||||
import queryString from "query-string";
|
||||
import { useGetIntegrationAuthApps, useGetIntegrationAuthById } from "~/hooks/api/integrationAuth";
|
||||
import createIntegration from "~/pages/api/integrations/createIntegration";
|
||||
import { Button, Card, CardTitle, FormControl, Select, SelectItem } from "~/components/v2";
|
||||
|
||||
const cloudflareEnvironments = [
|
||||
{ name: 'Production', slug: 'production' },
|
||||
|
||||
Reference in New Issue
Block a user