Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
add digital ocean enhancements
adilson9080fd862b3f
diff --git a/backend/src/services/app-connection/digital-ocean/digital-ocean-connection-public-client.ts b/backend/src/services/app-connection/digital-ocean/digital-ocean-connection-public-client.tsindex dcf3ed911b..4a5901e60d 100644--- a/backend/src/services/app-connection/digital-ocean/digital-ocean-connection-public-client.ts+++ b/backend/src/services/app-connection/digital-ocean/digital-ocean-connection-public-client.ts@@ -83,7 +83,7 @@ class DigitalOceanAppPlatformPublicClient {const response = await this.getApp(connection, appId);const existing = response.spec.envs || [];- const variables = existing.filter((v) => input.find((i) => i.key === v.key));+ const variables = existing.filter((v) => !input.some((i) => i.key === v.key));return this.client.put(`/apps/${appId}`,diff --git a/backend/src/services/app-connection/digital-ocean/digital-ocean-connection-types.ts b/backend/src/services/app-connection/digital-ocean/digital-ocean-connection-types.tsindex cc6b4c1eff..13c4cdced1 100644--- a/backend/src/services/app-connection/digital-ocean/digital-ocean-connection-types.ts+++ b/backend/src/services/app-connection/digital-ocean/digital-ocean-connection-types.ts@@ -39,4 +39,6 @@ export type TDigitalOceanApp = {}>;envs?: TDigitalOceanVariable[];};+ in_progress_deployment?: { id: string; phase?: string };+ pending_deployment?: { id: string };};diff --git a/backend/src/services/secret-sync/digital-ocean-app-platform/digital-ocean-app-platform-sync-fns.test.ts b/backend/src/services/secret-sync/digital-ocean-app-platform/digital-ocean-app-platform-sync-fns.test.tsnew file mode 100644index 0000000000..d633295c66--- /dev/null+++ b/backend/src/services/secret-sync/digital-ocean-app-platform/digital-ocean-app-platform-sync-fns.test.ts@@ -0,0 +1,97 @@+import { beforeEach, describe, expect, it, vi } from "vitest";++import { TDigitalOceanApp } from "@app/services/app-connection/digital-ocean";++import { SecretSyncError } from "../secret-sync-errors";+import { TSecretSyncPayload } from "../secret-sync-payload";+import { DigitalOceanAppPlatformSyncFns } from "./digital-ocean-app-platform-sync-fns";+import { TDigitalOceanAppPlatformSyncWithCredentials } from "./digital-ocean-app-platform-sync-types";++vi.mock("@app/lib/config/env", () => ({ getConfig: () => ({}) }));++const { get, put } = vi.hoisted(() => ({ get: vi.fn(), put: vi.fn() }));+vi.mock("@app/lib/config/request", () => ({ createRequestClient: () => ({ get, put }) }));++const sync = {+ destination: "digital-ocean-app-platform",+ destinationConfig: { appId: "app-id", appName: "my-app" },+ environment: { slug: "prod" },+ syncOptions: { disableSecretDeletion: false },+ connection: { method: "api-token", credentials: { apiToken: "token" } }+} as unknown as TDigitalOceanAppPlatformSyncWithCredentials;++const payloadOf = (keys: string[]) =>+ ({+ flatten: () => Object.fromEntries(keys.map((key) => [key, { value: `${key}-value` }]))+ }) as unknown as TSecretSyncPayload;++const appWith = (extra: Partial<TDigitalOceanApp> = {}): TDigitalOceanApp => ({+ id: "app-id",+ spec: {+ name: "my-app",+ services: [],+ envs: [+ { key: "MANAGED", value: "old", type: "SECRET" },+ { key: "UNMANAGED", value: "keep", type: "GENERAL" }+ ]+ },+ ...extra+});++const putEnvKeys = () => (put.mock.calls[0][1] as { spec: TDigitalOceanApp["spec"] }).spec.envs?.map((v) => v.key);++describe("DigitalOceanAppPlatformSyncFns", () => {+ beforeEach(() => {+ get.mockReset();+ put.mockReset();+ get.mockResolvedValue({ data: { app: appWith() } });+ put.mockResolvedValue({});+ });++ it("removeSecrets only removes the synced keys", async () => {+ await DigitalOceanAppPlatformSyncFns.removeSecrets(sync, payloadOf(["MANAGED"]));++ expect(put).toHaveBeenCalledTimes(1);+ expect(putEnvKeys()).toEqual(["UNMANAGED"]);+ });++ it.each([+ ["sync", "in progress", { in_progress_deployment: { id: "d1", phase: "BUILDING" } }],+ ["sync", "pending", { pending_deployment: { id: "d1" } }],+ ["remove", "in progress", { in_progress_deployment: { id: "d1", phase: "BUILDING" } }],+ ["remove", "pending", { pending_deployment: { id: "d1" } }]+ ])("%s fails with a retryable error when a deployment is %s", async (operation, _, extra) => {+ get.mockResolvedValue({ data: { app: appWith(extra) } });++ const payload = payloadOf(["MANAGED"]);+ const error = await (+ operation === "sync"+ ? DigitalOceanAppPlatformSyncFns.syncSecrets(sync, payload)+ : DigitalOceanAppPlatformSyncFns.removeSecrets(sync, payload)+ ).catch((err: unknown) => err);++ expect(error).toBeInstanceOf(SecretSyncError);+ expect((error as SecretSyncError).shouldRetry).toBe(true);+ expect((error as SecretSyncError).message).toContain("deployment is in progress");+ expect(put).not.toHaveBeenCalled();+ });++ it("fails without retry when a key contains a hyphen", async () => {+ const error = await DigitalOceanAppPlatformSyncFns.syncSecrets(sync, payloadOf(["OK_KEY", "MY-KEY"])).catch(+ (err: unknown) => err+ );++ expect(error).toBeInstanceOf(SecretSyncError);+ expect((error as SecretSyncError).shouldRetry).toBe(false);+ expect((error as SecretSyncError).secretKey).toBe("MY-KEY");+ expect((error as SecretSyncError).message).toContain("MY-KEY");+ expect(get).not.toHaveBeenCalled();+ expect(put).not.toHaveBeenCalled();+ });++ it("syncSecrets writes secrets when no deployment is running", async () => {+ await DigitalOceanAppPlatformSyncFns.syncSecrets(sync, payloadOf(["MANAGED"]));++ expect(putEnvKeys()).toEqual(["MANAGED"]);+ });+});diff --git a/backend/src/services/secret-sync/digital-ocean-app-platform/digital-ocean-app-platform-sync-fns.ts b/backend/src/services/secret-sync/digital-ocean-app-platform/digital-ocean-app-platform-sync-fns.tsindex c1e2637eb9..c94140f952 100644--- a/backend/src/services/secret-sync/digital-ocean-app-platform/digital-ocean-app-platform-sync-fns.ts+++ b/backend/src/services/secret-sync/digital-ocean-app-platform/digital-ocean-app-platform-sync-fns.ts@@ -2,15 +2,24 @@/* eslint-disable @typescript-eslint/no-unsafe-member-access *//* eslint-disable @typescript-eslint/no-unsafe-assignment */-import { TDigitalOceanVariable } from "@app/services/app-connection/digital-ocean";+import { TDigitalOceanApp, TDigitalOceanVariable } from "@app/services/app-connection/digital-ocean";import { DigitalOceanAppPlatformPublicAPI } from "@app/services/app-connection/digital-ocean/digital-ocean-connection-public-client";import { matchesSchema } from "@app/services/secret-sync/secret-sync-fns";import { SecretSyncError } from "../secret-sync-errors";import { SECRET_SYNC_NAME_MAP } from "../secret-sync-maps";import { TSecretSyncPayload } from "../secret-sync-payload";+import { DIGITAL_OCEAN_ENV_KEY_PATTERN, DIGITAL_OCEAN_ENV_KEY_RULE } from "./digital-ocean-app-platform-sync-schemas";import { TDigitalOceanAppPlatformSyncWithCredentials } from "./digital-ocean-app-platform-sync-types";+const assertNoDeploymentInProgress = (app: TDigitalOceanApp) => {+ if (app.in_progress_deployment || app.pending_deployment) {+ throw new SecretSyncError({+ message: `A deployment is in progress for DigitalOcean app '${app.spec.name}'. Wait for the deployment to finish, then sync again.`+ });+ }+};+export const DigitalOceanAppPlatformSyncFns = {async getSecrets(secretSync: TDigitalOceanAppPlatformSyncWithCredentials) {throw new Error(`${SECRET_SYNC_NAME_MAP[secretSync.destination]} does not support importing secrets.`);@@ -23,9 +32,23 @@ export const DigitalOceanAppPlatformSyncFns = {syncOptions: { disableSecretDeletion, keySchema }} = secretSync;+ const invalidKeys = Object.keys(secretMap).filter((key) => !DIGITAL_OCEAN_ENV_KEY_PATTERN.test(key));+ if (invalidKeys.length) {+ throw new SecretSyncError({+ secretKey: invalidKeys[0],+ shouldRetry: false,+ message: `${invalidKeys.length} secret ${+ invalidKeys.length === 1 ? "key is" : "keys are"+ } not a valid DigitalOcean environment variable name: ${invalidKeys.join(", ")}. ${DIGITAL_OCEAN_ENV_KEY_RULE}`+ });+ }+const config = secretSync.destinationConfig;- const existing = await DigitalOceanAppPlatformPublicAPI.getVariables(secretSync.connection, config.appId);+ const app = await DigitalOceanAppPlatformPublicAPI.getApp(secretSync.connection, config.appId);+ assertNoDeploymentInProgress(app);++ const existing = app.spec.envs ?? [];const variables: Record<string, TDigitalOceanVariable> = Object.fromEntries(existing.map((v) => [v.key, v]));@@ -61,22 +84,15 @@ export const DigitalOceanAppPlatformSyncFns = {const config = secretSync.destinationConfig;try {- const existingSecrets = await DigitalOceanAppPlatformPublicAPI.getVariables(secretSync.connection, config.appId);+ const app = await DigitalOceanAppPlatformPublicAPI.getApp(secretSync.connection, config.appId);+ assertNoDeploymentInProgress(app);- const vars = Object.entries(existingSecrets)- .map(([key, v]) => {- if (!(key in secretMap)) return;-- return {- key,- value: v.value,- type: "SECRET"- } as TDigitalOceanVariable;- })- .filter(Boolean) as TDigitalOceanVariable[];+ const vars = (app.spec.envs ?? []).filter((v) => v.key in secretMap);await DigitalOceanAppPlatformPublicAPI.deleteVariables(secretSync.connection, config.appId, ...vars);} catch (error) {+ if (error instanceof SecretSyncError) throw error;+throw new SecretSyncError({error});diff --git a/backend/src/services/secret-sync/digital-ocean-app-platform/digital-ocean-app-platform-sync-schemas.ts b/backend/src/services/secret-sync/digital-ocean-app-platform/digital-ocean-app-platform-sync-schemas.tsindex c8f09b26ec..a98b2effbe 100644--- a/backend/src/services/secret-sync/digital-ocean-app-platform/digital-ocean-app-platform-sync-schemas.ts+++ b/backend/src/services/secret-sync/digital-ocean-app-platform/digital-ocean-app-platform-sync-schemas.ts@@ -11,6 +11,10 @@ import { TSyncOptionsConfig } from "@app/services/secret-sync/secret-sync-types"import { SECRET_SYNC_NAME_MAP } from "../secret-sync-maps";+export const DIGITAL_OCEAN_ENV_KEY_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;+export const DIGITAL_OCEAN_ENV_KEY_RULE =+ "DigitalOcean environment variable names must start with a letter or underscore and contain only letters, digits and underscores (no hyphens).";+const DigitalOceanAppPlatformSyncDestinationConfigSchema = z.object({appId: z.string().min(1, "Account ID is required").max(255, "Account ID must be less than 255 characters"),appName: z.string().min(1, "Account Name is required").max(255, "Account Name must be less than 255 characters")diff --git a/docs/integrations/secret-syncs/digital-ocean-app-platform.mdx b/docs/integrations/secret-syncs/digital-ocean-app-platform.mdxindex 584ce3f2e5..8eb0d9e2ed 100644--- a/docs/integrations/secret-syncs/digital-ocean-app-platform.mdx+++ b/docs/integrations/secret-syncs/digital-ocean-app-platform.mdx@@ -53,7 +53,13 @@ description: "Learn how to configure a DigitalOcean App Platform Sync for Infisi<Note>We highly recommend using a Key Schema to ensure that Infisical only manages the specific keys you intend, keeping everything else untouched.</Note>+ <Note>+ DigitalOcean only accepts environment variable names that contain letters, digits, and underscores and don't start with a digit. Infisical checks each secret name after applying the Key Schema and if any name contains a hyphen or another character DigitalOcean rejects, the sync fails without changing the app and lists the invalid names. Rename those secrets or change the Key Schema, then sync again.+ </Note>- **Auto-Sync Enabled**: If enabled, secrets will automatically be synced from the source location when changes occur. Disable to enforce manual syncing only.+ <Note>+ If a deployment is running or pending for the app, the sync fails without changing the app. Wait for the deployment to finish, then sync again.+ </Note>- **Disable Secret Deletion**: If enabled, Infisical will not remove secrets from the sync destination. Enable this option if you intend to manage some secrets manually outside of Infisical.</Step><Step title="Configure details">@@ -76,7 +82,7 @@ description: "Learn how to configure a DigitalOcean App Platform Sync for Infisi</Step></Steps></Tab>-+<Tab title="API">To create a **DigitalOcean App Platform Sync**, make an API request to the [Create DigitalOcean Sync](/api-reference/endpoints/secret-syncs/digital-ocean-app-platform/create) API endpoint.@@ -153,4 +159,5 @@ description: "Learn how to configure a DigitalOcean App Platform Sync for Infisi}```</Tab>+</Tabs>diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncInitialSyncBehaviorFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncInitialSyncBehaviorFields.tsxindex 3815973b77..20161fbaf9 100644--- a/frontend/src/components/secret-syncs/forms/SecretSyncInitialSyncBehaviorFields.tsx+++ b/frontend/src/components/secret-syncs/forms/SecretSyncInitialSyncBehaviorFields.tsx@@ -33,7 +33,9 @@ const getGraphicVariant = (key: string): GraphicVariant => {return "prioritize-destination";};-const getShortDestinationName = (name: string) => name.split(" ")[0];+// "Digital Ocean" is a two-word vendor; the first word alone is not the name.+const getShortDestinationName = (name: string) =>+ name.startsWith("Digital Ocean") ? "Digital Ocean" : name.split(" ")[0];const getBehaviorCopy = (key: SecretSyncInitialSyncBehavior,