mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 19:28:16 +00:00
feat: option to choose target environment
This commit is contained in:
@@ -1854,6 +1854,8 @@ const syncSecretsCloudflarePages = async ({
|
||||
accessId: string | null;
|
||||
accessToken: string;
|
||||
}) => {
|
||||
const targetEnvironment = integration.targetEnvironment;
|
||||
|
||||
// get secrets from cloudflare pages
|
||||
const getSecretsRes = (
|
||||
await standardRequest.get(
|
||||
@@ -1866,7 +1868,7 @@ const syncSecretsCloudflarePages = async ({
|
||||
}
|
||||
)
|
||||
)
|
||||
.data.result['deployment_configs'].production['env_vars'];
|
||||
.data.result['deployment_configs'][targetEnvironment]['env_vars'];
|
||||
|
||||
// copy the secrets object, so we can set deleted keys to null
|
||||
const secretsObj: any = {...secrets};
|
||||
@@ -1878,22 +1880,32 @@ const syncSecretsCloudflarePages = async ({
|
||||
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 deos not exist in infisical
|
||||
// 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}`,
|
||||
{
|
||||
"deployment_configs": {
|
||||
"production": {
|
||||
"env_vars": secretsObj
|
||||
}
|
||||
}
|
||||
},
|
||||
data,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
|
||||
Reference in New Issue
Block a user