This commit is contained in:
x032205
2025-07-11 13:38:17 -04:00
parent 782b6fce4a
commit 16c89c6dbd
8 changed files with 12 additions and 6 deletions

View File

@@ -1,4 +1,6 @@
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 { matchesSchema } from "@app/services/secret-sync/secret-sync-fns";
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 { TCloudflareWorkersSyncWithCredentials } from "./cloudflare-workers-types";
const getProjectEnvironmentSecretNames = async (
secretSync: TCloudflareWorkersSyncWithCredentials
): Promise<string[]> => {
const getSecretKeys = async (secretSync: TCloudflareWorkersSyncWithCredentials): Promise<string[]> => {
const {
destinationConfig,
connection: {
@@ -40,10 +40,11 @@ export const CloudflareWorkersSyncFns = {
destinationConfig: { scriptId }
} = secretSync;
const existingSecretNames = await getProjectEnvironmentSecretNames(secretSync);
const existingSecretNames = await getSecretKeys(secretSync);
const secretMapKeys = new Set(Object.keys(secretMap));
const secretsToCreateOrUpdatePromises = Object.entries(secretMap).map(async ([key, val]) => {
await delayMs(Math.max(0, applyJitter(100, 200)));
await request.put(
`${IntegrationUrls.CLOUDFLARE_WORKERS_API_URL}/client/v4/accounts/${accountId}/workers/scripts/${scriptId}/secrets`,
{ name: key, text: val.value, type: "secret_text" },
@@ -69,6 +70,7 @@ export const CloudflareWorkersSyncFns = {
return !isInNewSecretMap && isManagedBySchema;
})
.map(async (key) => {
await delayMs(Math.max(0, applyJitter(100, 200)));
await request.delete(
`${IntegrationUrls.CLOUDFLARE_WORKERS_API_URL}/client/v4/accounts/${accountId}/workers/scripts/${scriptId}/secrets/${key}`,
{
@@ -94,7 +96,7 @@ export const CloudflareWorkersSyncFns = {
destinationConfig: { scriptId }
} = secretSync;
const existingSecretNames = await getProjectEnvironmentSecretNames(secretSync);
const existingSecretNames = await getSecretKeys(secretSync);
const secretMapToRemoveKeys = new Set(Object.keys(secretMap));
const deletePromises = existingSecretNames.map(async (existingKey) => {
@@ -106,6 +108,7 @@ export const CloudflareWorkersSyncFns = {
const isInSecretMapToRemove = secretMapToRemoveKeys.has(existingKey);
if (isInSecretMapToRemove && isManagedBySchema) {
await delayMs(Math.max(0, applyJitter(100, 200)));
await request.delete(
`${IntegrationUrls.CLOUDFLARE_WORKERS_API_URL}/client/v4/accounts/${accountId}/workers/scripts/${scriptId}/secrets/${existingKey}`,
{

View File

@@ -16,7 +16,10 @@ const CloudflareWorkersSyncDestinationConfigSchema = z.object({
.string()
.min(1, "Script ID is required")
.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)
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 105 KiB

After

Width:  |  Height:  |  Size: 578 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 108 KiB

After

Width:  |  Height:  |  Size: 575 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 160 KiB

After

Width:  |  Height:  |  Size: 624 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 136 KiB

After

Width:  |  Height:  |  Size: 598 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 558 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 182 KiB

After

Width:  |  Height:  |  Size: 637 KiB