Reviews
@@ -1,4 +1,6 @@
|
|||||||
import { request } from "@app/lib/config/request";
|
import { request } from "@app/lib/config/request";
|
||||||
|
import { applyJitter } from "@app/lib/dates";
|
||||||
|
import { delay as delayMs } from "@app/lib/delay";
|
||||||
import { IntegrationUrls } from "@app/services/integration-auth/integration-list";
|
import { IntegrationUrls } from "@app/services/integration-auth/integration-list";
|
||||||
import { matchesSchema } from "@app/services/secret-sync/secret-sync-fns";
|
import { matchesSchema } from "@app/services/secret-sync/secret-sync-fns";
|
||||||
import { TSecretMap } from "@app/services/secret-sync/secret-sync-types";
|
import { TSecretMap } from "@app/services/secret-sync/secret-sync-types";
|
||||||
@@ -6,9 +8,7 @@ import { TSecretMap } from "@app/services/secret-sync/secret-sync-types";
|
|||||||
import { SECRET_SYNC_NAME_MAP } from "../secret-sync-maps";
|
import { SECRET_SYNC_NAME_MAP } from "../secret-sync-maps";
|
||||||
import { TCloudflareWorkersSyncWithCredentials } from "./cloudflare-workers-types";
|
import { TCloudflareWorkersSyncWithCredentials } from "./cloudflare-workers-types";
|
||||||
|
|
||||||
const getProjectEnvironmentSecretNames = async (
|
const getSecretKeys = async (secretSync: TCloudflareWorkersSyncWithCredentials): Promise<string[]> => {
|
||||||
secretSync: TCloudflareWorkersSyncWithCredentials
|
|
||||||
): Promise<string[]> => {
|
|
||||||
const {
|
const {
|
||||||
destinationConfig,
|
destinationConfig,
|
||||||
connection: {
|
connection: {
|
||||||
@@ -40,10 +40,11 @@ export const CloudflareWorkersSyncFns = {
|
|||||||
destinationConfig: { scriptId }
|
destinationConfig: { scriptId }
|
||||||
} = secretSync;
|
} = secretSync;
|
||||||
|
|
||||||
const existingSecretNames = await getProjectEnvironmentSecretNames(secretSync);
|
const existingSecretNames = await getSecretKeys(secretSync);
|
||||||
const secretMapKeys = new Set(Object.keys(secretMap));
|
const secretMapKeys = new Set(Object.keys(secretMap));
|
||||||
|
|
||||||
const secretsToCreateOrUpdatePromises = Object.entries(secretMap).map(async ([key, val]) => {
|
const secretsToCreateOrUpdatePromises = Object.entries(secretMap).map(async ([key, val]) => {
|
||||||
|
await delayMs(Math.max(0, applyJitter(100, 200)));
|
||||||
await request.put(
|
await request.put(
|
||||||
`${IntegrationUrls.CLOUDFLARE_WORKERS_API_URL}/client/v4/accounts/${accountId}/workers/scripts/${scriptId}/secrets`,
|
`${IntegrationUrls.CLOUDFLARE_WORKERS_API_URL}/client/v4/accounts/${accountId}/workers/scripts/${scriptId}/secrets`,
|
||||||
{ name: key, text: val.value, type: "secret_text" },
|
{ name: key, text: val.value, type: "secret_text" },
|
||||||
@@ -69,6 +70,7 @@ export const CloudflareWorkersSyncFns = {
|
|||||||
return !isInNewSecretMap && isManagedBySchema;
|
return !isInNewSecretMap && isManagedBySchema;
|
||||||
})
|
})
|
||||||
.map(async (key) => {
|
.map(async (key) => {
|
||||||
|
await delayMs(Math.max(0, applyJitter(100, 200)));
|
||||||
await request.delete(
|
await request.delete(
|
||||||
`${IntegrationUrls.CLOUDFLARE_WORKERS_API_URL}/client/v4/accounts/${accountId}/workers/scripts/${scriptId}/secrets/${key}`,
|
`${IntegrationUrls.CLOUDFLARE_WORKERS_API_URL}/client/v4/accounts/${accountId}/workers/scripts/${scriptId}/secrets/${key}`,
|
||||||
{
|
{
|
||||||
@@ -94,7 +96,7 @@ export const CloudflareWorkersSyncFns = {
|
|||||||
destinationConfig: { scriptId }
|
destinationConfig: { scriptId }
|
||||||
} = secretSync;
|
} = secretSync;
|
||||||
|
|
||||||
const existingSecretNames = await getProjectEnvironmentSecretNames(secretSync);
|
const existingSecretNames = await getSecretKeys(secretSync);
|
||||||
const secretMapToRemoveKeys = new Set(Object.keys(secretMap));
|
const secretMapToRemoveKeys = new Set(Object.keys(secretMap));
|
||||||
|
|
||||||
const deletePromises = existingSecretNames.map(async (existingKey) => {
|
const deletePromises = existingSecretNames.map(async (existingKey) => {
|
||||||
@@ -106,6 +108,7 @@ export const CloudflareWorkersSyncFns = {
|
|||||||
const isInSecretMapToRemove = secretMapToRemoveKeys.has(existingKey);
|
const isInSecretMapToRemove = secretMapToRemoveKeys.has(existingKey);
|
||||||
|
|
||||||
if (isInSecretMapToRemove && isManagedBySchema) {
|
if (isInSecretMapToRemove && isManagedBySchema) {
|
||||||
|
await delayMs(Math.max(0, applyJitter(100, 200)));
|
||||||
await request.delete(
|
await request.delete(
|
||||||
`${IntegrationUrls.CLOUDFLARE_WORKERS_API_URL}/client/v4/accounts/${accountId}/workers/scripts/${scriptId}/secrets/${existingKey}`,
|
`${IntegrationUrls.CLOUDFLARE_WORKERS_API_URL}/client/v4/accounts/${accountId}/workers/scripts/${scriptId}/secrets/${existingKey}`,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,7 +16,10 @@ const CloudflareWorkersSyncDestinationConfigSchema = z.object({
|
|||||||
.string()
|
.string()
|
||||||
.min(1, "Script ID is required")
|
.min(1, "Script ID is required")
|
||||||
.max(64)
|
.max(64)
|
||||||
.regex(new RE2(/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/), "Invalid script ID format")
|
.refine((val) => {
|
||||||
|
const re2 = new RE2(/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/);
|
||||||
|
return re2.test(val);
|
||||||
|
}, "Invalid script ID format")
|
||||||
.describe(SecretSyncs.DESTINATION_CONFIG.CLOUDFLARE_WORKERS.scriptId)
|
.describe(SecretSyncs.DESTINATION_CONFIG.CLOUDFLARE_WORKERS.scriptId)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 578 KiB |
|
Before Width: | Height: | Size: 108 KiB After Width: | Height: | Size: 575 KiB |
|
Before Width: | Height: | Size: 160 KiB After Width: | Height: | Size: 624 KiB |
|
Before Width: | Height: | Size: 136 KiB After Width: | Height: | Size: 598 KiB |
|
Before Width: | Height: | Size: 88 KiB After Width: | Height: | Size: 558 KiB |
|
Before Width: | Height: | Size: 182 KiB After Width: | Height: | Size: 637 KiB |