Skip to content

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

add pagination into list datadog service accounts

adilsonab8cb9a3b48f
diff --git a/backend/src/ee/services/secret-rotation-v2/datadog-application-key-secret/datadog-application-key-secret-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/datadog-application-key-secret/datadog-application-key-secret-rotation-fns.ts
index 40a0400c0f..e427b27c44 100644
--- a/backend/src/ee/services/secret-rotation-v2/datadog-application-key-secret/datadog-application-key-secret-rotation-fns.ts
+++ b/backend/src/ee/services/secret-rotation-v2/datadog-application-key-secret/datadog-application-key-secret-rotation-fns.ts
@@ -100,7 +100,7 @@ export const datadogApplicationKeySecretRotationFactory: TRotationFactory<
try {
const baseUrl = await getDatadogBaseUrl(connection);
- await request.get(`${baseUrl}/api/v1/validate`, {
+ await request.get(`${baseUrl}/api/v2/permissions`, {
headers: { "DD-API-KEY": connection.credentials.apiKey, "DD-APPLICATION-KEY": created.applicationKey }
});
} catch (error) {
diff --git a/backend/src/services/app-connection/datadog/datadog-connection-fns.ts b/backend/src/services/app-connection/datadog/datadog-connection-fns.ts
index 244b585cde..76e840ec09 100644
--- a/backend/src/services/app-connection/datadog/datadog-connection-fns.ts
+++ b/backend/src/services/app-connection/datadog/datadog-connection-fns.ts
@@ -78,40 +78,62 @@ export const validateDatadogConnectionCredentials = async (config: TDatadogConne
return config.credentials;
};
+type TDatadogServiceAccountEntry = {
+ id: string;
+ type: string;
+ attributes?: {
+ name?: string | null;
+ email?: string | null;
+ handle?: string | null;
+ disabled?: boolean;
+ };
+};
+
type TDatadogServiceAccountResponse = {
- data: Array<{
- id: string;
- type: string;
- attributes?: {
- name?: string | null;
- email?: string | null;
- handle?: string | null;
- disabled?: boolean;
+ data: TDatadogServiceAccountEntry[];
+ meta?: {
+ page?: {
+ total_count?: number;
};
- }>;
+ };
};
export const listDatadogServiceAccounts = async (connection: TDatadogConnection): Promise<TDatadogServiceAccount[]> => {
const baseUrl = await getDatadogBaseUrl(connection);
+ const PAGE_SIZE = 100;
+ const MAX_PAGES = 50;
- try {
- const { data } = await request.get<TDatadogServiceAccountResponse>(`${baseUrl}/api/v2/users`, {
- params: {
- "filter[service_account]": "true",
- "page[size]": 100
- },
- headers: getDatadogAuthHeaders(connection.credentials)
- });
+ const rawEntries: TDatadogServiceAccountEntry[] = [];
- return (data.data ?? [])
- .filter((entry) => !entry.attributes?.disabled)
- .map((entry) => ({
- id: entry.id,
- name: entry.attributes?.name || entry.attributes?.email || entry.attributes?.handle || entry.id
- }));
+ try {
+ for (let pageNumber = 0; pageNumber < MAX_PAGES; pageNumber += 1) {
+ // eslint-disable-next-line no-await-in-loop
+ const { data } = await request.get<TDatadogServiceAccountResponse>(`${baseUrl}/api/v2/users`, {
+ params: {
+ "filter[service_account]": "true",
+ "page[size]": PAGE_SIZE,
+ "page[number]": pageNumber
+ },
+ headers: getDatadogAuthHeaders(connection.credentials)
+ });
+
+ const pageEntries = data.data ?? [];
+ rawEntries.push(...pageEntries);
+
+ const totalCount = data.meta?.page?.total_count;
+ if (pageEntries.length < PAGE_SIZE) break;
+ if (typeof totalCount === "number" && rawEntries.length >= totalCount) break;
+ }
} catch (error: unknown) {
throw new BadRequestError({
message: `Failed to list Datadog service accounts: ${getDatadogErrorMessage(error)}`
});
}
+
+ return rawEntries
+ .filter((entry) => !entry.attributes?.disabled)
+ .map((entry) => ({
+ id: entry.id,
+ name: entry.attributes?.name || entry.attributes?.email || entry.attributes?.handle || entry.id
+ }));
};
diff --git a/docs/documentation/platform/secret-rotation/datadog-application-key-secret.mdx b/docs/documentation/platform/secret-rotation/datadog-application-key-secret.mdx
index 6497ca67a9..37e1a15653 100644
--- a/docs/documentation/platform/secret-rotation/datadog-application-key-secret.mdx
+++ b/docs/documentation/platform/secret-rotation/datadog-application-key-secret.mdx
@@ -16,7 +16,6 @@ description: "Learn how to automatically rotate Datadog Service Account Applicat
you need to set `user_app_keys` under **API and Application Keys** and `service_account_writer`, `user_access_manage` and `user_access_read` under **Access Management**
-
## Create a Datadog Application Key Rotation in Infisical
<Tabs>
@@ -44,6 +43,11 @@ you need to set `user_app_keys` under **API and Application Keys** and `service_
- **Service Account** - the Datadog Service Account that will own the rotated Application Keys. Only non-disabled Service Accounts visible to the connection are listed.
+
+ <Note>
+ **Service account role:** The Datadog Service Account whose Application Keys are rotated must have at least the **Datadog Standard Role** assigned.
+ </Note>
+
5. Specify the secret names that the rotated credentials should be mapped to. Then click **Next**.
![Rotation Secrets Mapping](/images/secret-rotations-v2/datadog/datadog-mappings.png)
@@ -63,6 +67,8 @@ you need to set `user_app_keys` under **API and Application Keys** and `service_
![Rotation Review](/images/secret-rotations-v2/datadog/datadog-review.png)
8. Your **Datadog Application Key** credentials are now available for use via the mapped secrets.
+
+ ![Datadog Credentials](/images/secret-rotations-v2/datadog/datadog-credentials.png)
</Tab>
<Tab title="API">
To create a Datadog Application Key Rotation, make an API request to the [Create Datadog Application Key Rotation](/api-reference/endpoints/secret-rotations/datadog-application-key-secret/create) API endpoint.
diff --git a/docs/images/secret-rotations-v2/datadog/datadog-credentials.png b/docs/images/secret-rotations-v2/datadog/datadog-credentials.png
new file mode 100644
index 0000000000..e59425066c
Binary files /dev/null and b/docs/images/secret-rotations-v2/datadog/datadog-credentials.png differ