Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

refactor: pagination

adilson5e62375a92fd
diff --git a/backend/src/services/app-connection/cloud-66/cloud-66-connection-fns.ts b/backend/src/services/app-connection/cloud-66/cloud-66-connection-fns.ts
index 187a2aac45..74cd43b53d 100644
--- a/backend/src/services/app-connection/cloud-66/cloud-66-connection-fns.ts
+++ b/backend/src/services/app-connection/cloud-66/cloud-66-connection-fns.ts
@@ -1,3 +1,5 @@
+import { AxiosError, AxiosResponse } from "axios";
+
import { request } from "@app/lib/config/request";
import { UnauthorizedError } from "@app/lib/errors";
import { logger } from "@app/lib/logger";
@@ -8,11 +10,61 @@ import { TCloud66Connection, TCloud66ConnectionConfig, TCloud66Stack } from "./c
export const CLOUD_66_API_BASE_URL = "https://app.cloud66.com/api";
+const PER_PAGE_ITEMS = 30;
+const MAX_CLOUD_66_RETRIES = 5;
+const CLOUD_66_RATE_LIMIT_DELAY_MS = 60_000;
+
export const getCloud66Headers = (accessToken: string) => ({
Authorization: `Bearer ${accessToken}`,
Accept: "application/json"
});
+const sleep = (ms: number) =>
+ new Promise((resolve) => {
+ setTimeout(resolve, ms);
+ });
+
+// Cloud 66 rate-limits requests (HTTP 429); retry after a delay before giving up.
+const cloud66GetWithRetry = async (url: string, accessToken: string, attempt = 0): Promise<AxiosResponse> => {
+ try {
+ return await request.get(url, { headers: getCloud66Headers(accessToken) });
+ } catch (error) {
+ if (error instanceof AxiosError && error.response?.status === 429 && attempt < MAX_CLOUD_66_RETRIES) {
+ await sleep(CLOUD_66_RATE_LIMIT_DELAY_MS);
+ return cloud66GetWithRetry(url, accessToken, attempt + 1);
+ }
+
+ throw error;
+ }
+};
+
+// Walks Cloud 66's `page`/`pagination.next` cursor, retrying rate-limited pages, and returns every item.
+export const paginateCloud66 = async <T>(accessToken: string, path: string): Promise<T[]> => {
+ const items: T[] = [];
+ let page: number | null = 1;
+
+ while (page) {
+ const currentPage = page;
+
+ // eslint-disable-next-line no-await-in-loop
+ const res = await cloud66GetWithRetry(
+ `${CLOUD_66_API_BASE_URL}${path}?page=${currentPage}&per_page=${PER_PAGE_ITEMS}`,
+ accessToken
+ );
+
+ const { response, pagination } = res.data as {
+ response: T[];
+ pagination?: { next: number | null };
+ };
+
+ items.push(...response);
+
+ page = pagination?.next ?? null;
+ }
+
+ return items;
+};
+
export const getCloud66ConnectionListItem = () => {
return {
name: "Cloud 66" as const,
@@ -43,24 +95,7 @@ export const validateCloud66ConnectionCredentials = async (config: TCloud66Conne
export const listCloud66Stacks = async (appConnection: TCloud66Connection): Promise<TCloud66Stack[]> => {
const { accessToken } = appConnection.credentials;
- const stacks: TCloud66Stack[] = [];
- let page: number | null = 1;
-
- while (page) {
- // eslint-disable-next-line no-await-in-loop
- const res = await request.get(`${CLOUD_66_API_BASE_URL}/3/stacks?page=${page}&per_page=30`, {
- headers: getCloud66Headers(accessToken)
- });
-
- const { response, pagination } = res.data as {
- response: { uid: string; name: string }[];
- pagination?: { next: number | null };
- };
-
- stacks.push(...response.map((stack) => ({ id: stack.uid, name: stack.name })));
-
- page = pagination?.next ?? null;
- }
+ const stacks = await paginateCloud66<{ uid: string; name: string }>(accessToken, "/3/stacks");
- return stacks;
+ return stacks.map((stack) => ({ id: stack.uid, name: stack.name }));
};
diff --git a/backend/src/services/secret-sync/cloud66/cloud66-sync-fns.ts b/backend/src/services/secret-sync/cloud66/cloud66-sync-fns.ts
index 20f1d4fff1..27ca9f5077 100644
--- a/backend/src/services/secret-sync/cloud66/cloud66-sync-fns.ts
+++ b/backend/src/services/secret-sync/cloud66/cloud66-sync-fns.ts
@@ -1,7 +1,8 @@
import { request } from "@app/lib/config/request";
import {
CLOUD_66_API_BASE_URL,
- getCloud66Headers
+ getCloud66Headers,
+ paginateCloud66
} from "@app/services/app-connection/cloud-66/cloud-66-connection-fns";
import { SecretSyncError } from "@app/services/secret-sync/secret-sync-errors";
import { matchesSchema } from "@app/services/secret-sync/secret-sync-fns";
@@ -12,31 +13,8 @@ import { TCloud66EnvVar, TCloud66SyncWithCredentials } from "./cloud66-sync-type
// Cloud 66 system-managed variables (readonly / generated) cannot be modified or deleted via the API.
const isModifiable = (envVar: TCloud66EnvVar) => !envVar.readonly && !envVar.is_generated;
-const listCloud66EnvVars = async (accessToken: string, stackId: string): Promise<TCloud66EnvVar[]> => {
- const envVars: TCloud66EnvVar[] = [];
- let page: number | null = 1;
-
- while (page) {
- // eslint-disable-next-line no-await-in-loop
- const res = await request.get(
- `${CLOUD_66_API_BASE_URL}/3/stacks/${stackId}/environments?page=${page}&per_page=30`,
- {
- headers: getCloud66Headers(accessToken)
- }
- );
-
- const { response, pagination } = res.data as {
- response: TCloud66EnvVar[];
- pagination?: { next: number | null };
- };
-
- envVars.push(...response);
-
- page = pagination?.next ?? null;
- }
-
- return envVars;
-};
+const listCloud66EnvVars = (accessToken: string, stackId: string): Promise<TCloud66EnvVar[]> =>
+ paginateCloud66<TCloud66EnvVar>(accessToken, `/3/stacks/${stackId}/environments`);
const createCloud66EnvVar = (accessToken: string, stackId: string, key: string, value: string) =>
request.post(
diff --git a/docs/images/secret-syncs/cloud66/step-4.png b/docs/images/secret-syncs/cloud66/step-4.png
index f23903b9e1..1a509d004a 100644
Binary files a/docs/images/secret-syncs/cloud66/step-4.png and b/docs/images/secret-syncs/cloud66/step-4.png differ
diff --git a/docs/integrations/secret-syncs/cloud-66.mdx b/docs/integrations/secret-syncs/cloud-66.mdx
index 2ac09859c7..91d13c42a4 100644
--- a/docs/integrations/secret-syncs/cloud-66.mdx
+++ b/docs/integrations/secret-syncs/cloud-66.mdx
@@ -16,9 +16,6 @@ description: "Learn how to configure a Cloud 66 Sync for Infisical."
</Note>
-<Note>
- Secrets with hyphens are not allowed by Cloud 66, so they are skipped from the sync process.
-</Note>
<Tabs>
<Tab title="Infisical UI">
@@ -44,6 +41,10 @@ description: "Learn how to configure a Cloud 66 Sync for Infisical."
- **Cloud 66 Connection**: The Cloud 66 Connection to authenticate with.
- **Stack**: The Cloud 66 stack (application) to sync secrets to.
+ <Note>
+ Secrets with hyphens are not allowed by Cloud 66, so they are skipped from the sync process.
+ </Note>
+
5. Configure the **Initial Sync Behavior** to determine how Infisical should resolve the first sync, then click **Continue**.
![Configure Initial Sync Behavior](/images/secret-syncs/cloud66/step-5.png)
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/Cloud66SyncFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/Cloud66SyncFields.tsx
index 5e5768dde8..af9b4e801d 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/Cloud66SyncFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/Cloud66SyncFields.tsx
@@ -1,8 +1,12 @@
import { Controller, useFormContext, useWatch } from "react-hook-form";
import { SingleValue } from "react-select";
+import { TriangleAlert } from "lucide-react";
import { SecretSyncConnectionField } from "@app/components/secret-syncs/forms/SecretSyncConnectionField";
import {
+ Alert,
+ AlertDescription,
+ AlertTitle,
Field,
FieldContent,
FieldError,
@@ -65,6 +69,15 @@ export const Cloud66SyncFields = () => {
</Field>
)}
/>
+
+ <Alert variant="warning">
+ <TriangleAlert />
+ <AlertTitle>Hyphens are not supported in keys</AlertTitle>
+ <AlertDescription>
+ Cloud 66 does not allow environment variable names containing hyphens (-). Secrets whose
+ keys contain a hyphen will be skipped during sync.
+ </AlertDescription>
+ </Alert>
</FieldGroup>
);
};