mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00: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 ({
|
const syncSecretsCloudflarePages = async ({
|
||||||
integration,
|
integration,
|
||||||
secrets,
|
secrets,
|
||||||
@@ -1854,65 +1861,56 @@ const syncSecretsCloudflarePages = async ({
|
|||||||
accessId: string | null;
|
accessId: string | null;
|
||||||
accessToken: string;
|
accessToken: string;
|
||||||
}) => {
|
}) => {
|
||||||
const targetEnvironment = integration.targetEnvironment;
|
|
||||||
|
|
||||||
// get secrets from cloudflare pages
|
// get secrets from cloudflare pages
|
||||||
const getSecretsRes = (
|
const getSecretsRes = (
|
||||||
await standardRequest.get(
|
await standardRequest.get(
|
||||||
`${INTEGRATION_CLOUDFLARE_PAGES_API_URL}/client/v4/accounts/${accessId}/pages/projects/${integration.app}`,
|
`${INTEGRATION_CLOUDFLARE_PAGES_API_URL}/client/v4/accounts/${accessId}/pages/projects/${integration.app}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${accessToken}`,
|
Authorization: `Bearer ${accessToken}`,
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.data.result['deployment_configs'][targetEnvironment]['env_vars'];
|
.data.result['deployment_configs'][integration.targetEnvironment]['env_vars'];
|
||||||
|
|
||||||
// copy the secrets object, so we can set deleted keys to null
|
// copy the secrets object, so we can set deleted keys to null
|
||||||
const secretsObj: any = {...secrets};
|
const secretsObj: any = {...secrets};
|
||||||
|
|
||||||
for (const [key, val] of Object.entries(secretsObj)) {
|
for (const [key, val] of Object.entries(secretsObj)) {
|
||||||
secretsObj[key] = { type: "secret_text", value: val };
|
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
|
await standardRequest.patch(
|
||||||
for await (const key of Object.keys(getSecretsRes)) {
|
`${INTEGRATION_CLOUDFLARE_PAGES_API_URL}/client/v4/accounts/${accessId}/pages/projects/${integration.app}`,
|
||||||
if (!(key in secrets)) {
|
data,
|
||||||
// case: secret does not exist in infisical
|
{
|
||||||
// -> delete secret from cloudflare pages
|
headers: {
|
||||||
secretsObj[key] = null;
|
Authorization: `Bearer ${accessToken}`,
|
||||||
}
|
"Accept": "application/json",
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
);
|
||||||
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",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export { syncSecrets };
|
export { syncSecrets };
|
||||||
|
|||||||
@@ -288,7 +288,7 @@ export default function Integrations() {
|
|||||||
link = `${window.location.origin}/integrations/hashicorp-vault/create?integrationAuthId=${integrationAuth._id}`;
|
link = `${window.location.origin}/integrations/hashicorp-vault/create?integrationAuthId=${integrationAuth._id}`;
|
||||||
break;
|
break;
|
||||||
case 'cloudflare-pages':
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from "react";
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from "next/router";
|
||||||
import { Card, CardTitle, FormControl, Input, Button } from '../../../components/v2';
|
import { Card, CardTitle, FormControl, Input, Button } from "../../../components/v2";
|
||||||
import saveIntegrationAccessToken from '~/pages/api/integrations/saveIntegrationAccessToken';
|
import saveIntegrationAccessToken from "~/pages/api/integrations/saveIntegrationAccessToken";
|
||||||
|
|
||||||
export default function CloudflarePagesIntegrationPage() {
|
export default function CloudflarePagesIntegrationPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -16,7 +16,7 @@ export default function CloudflarePagesIntegrationPage() {
|
|||||||
setAccessKeyErrorText('');
|
setAccessKeyErrorText('');
|
||||||
setAccountIdErrorText('');
|
setAccountIdErrorText('');
|
||||||
if (accessKey.length === 0 || accountId.length === 0) {
|
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!');
|
if (accountId.length === 0) setAccountIdErrorText('Account ID cannot be blank!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from "react";
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from "next/router";
|
||||||
import { useGetWorkspaceById } from '~/hooks/api';
|
import { useGetWorkspaceById } from "~/hooks/api";
|
||||||
import queryString from 'query-string';
|
import queryString from "query-string";
|
||||||
import { useGetIntegrationAuthApps, useGetIntegrationAuthById } from '~/hooks/api/integrationAuth';
|
import { useGetIntegrationAuthApps, useGetIntegrationAuthById } from "~/hooks/api/integrationAuth";
|
||||||
import createIntegration from '~/pages/api/integrations/createIntegration';
|
import createIntegration from "~/pages/api/integrations/createIntegration";
|
||||||
import { Button, Card, CardTitle, FormControl, Select, SelectItem } from '~/components/v2';
|
import { Button, Card, CardTitle, FormControl, Select, SelectItem } from "~/components/v2";
|
||||||
|
|
||||||
const cloudflareEnvironments = [
|
const cloudflareEnvironments = [
|
||||||
{ name: 'Production', slug: 'production' },
|
{ name: 'Production', slug: 'production' },
|
||||||
|
|||||||
Reference in New Issue
Block a user