From 8a33f1a5912814c3ac5aba524485b0944367c32b Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Mon, 16 Sep 2024 15:36:41 +0400 Subject: [PATCH 1/3] feat(integrations): aws secrets manager prefix support --- .../integration-sync-secret.ts | 20 +++++++++++++++++-- .../aws-secret-manager/create.tsx | 18 +++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/backend/src/services/integration-auth/integration-sync-secret.ts b/backend/src/services/integration-auth/integration-sync-secret.ts index 5085d42532..ad8aad5a39 100644 --- a/backend/src/services/integration-auth/integration-sync-secret.ts +++ b/backend/src/services/integration-auth/integration-sync-secret.ts @@ -1006,12 +1006,28 @@ const syncSecretsAWSSecretManager = async ({ } }; + let secretsToProcess: Record = {}; + if (metadata && metadata.secretPrefix) { + const { secretPrefix } = metadata; + + // Update each secret to have the secret prefix + Object.keys(secrets).forEach((key) => { + if (key.startsWith(secretPrefix)) { + secretsToProcess[key] = secrets[key]; + } else { + secretsToProcess[`${secretPrefix}${key}`] = secrets[key]; + } + }); + } else { + secretsToProcess = secrets; + } + if (metadata.mappingBehavior === IntegrationMappingBehavior.ONE_TO_ONE) { - for await (const [key, value] of Object.entries(secrets)) { + for await (const [key, value] of Object.entries(secretsToProcess)) { await processAwsSecret(key, value.value); } } else { - await processAwsSecret(integration.app as string, getSecretKeyValuePair(secrets)); + await processAwsSecret(integration.app as string, getSecretKeyValuePair(secretsToProcess)); } }; diff --git a/frontend/src/pages/integrations/aws-secret-manager/create.tsx b/frontend/src/pages/integrations/aws-secret-manager/create.tsx index 10bf190ed0..d183797897 100644 --- a/frontend/src/pages/integrations/aws-secret-manager/create.tsx +++ b/frontend/src/pages/integrations/aws-secret-manager/create.tsx @@ -104,6 +104,7 @@ export default function AWSSecretManagerCreateIntegrationPage() { const [tagKey, setTagKey] = useState(""); const [tagValue, setTagValue] = useState(""); const [kmsKeyId, setKmsKeyId] = useState(""); + const [secretPrefix, setSecretPrefix] = useState(""); // const [path, setPath] = useState(''); // const [pathErrorText, setPathErrorText] = useState(''); @@ -165,6 +166,7 @@ export default function AWSSecretManagerCreateIntegrationPage() { ] } : {}), + ...(secretPrefix && { secretPrefix }), ...(kmsKeyId && { kmsKeyId }), mappingBehavior: selectedMappingBehavior } @@ -325,7 +327,7 @@ export default function AWSSecretManagerCreateIntegrationPage() { {shouldTag && ( -
+
)} + + + setSecretPrefix(e.target.value)} + placeholder="INFISICAL_" + /> + + From 4eea0dc5448c5e655a33806084bf065cd4a05091 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Mon, 16 Sep 2024 15:37:44 +0400 Subject: [PATCH 2/3] fix(integrations): improved github repos fetching --- .../integration-auth/integration-app-list.ts | 35 +++---------------- 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/backend/src/services/integration-auth/integration-app-list.ts b/backend/src/services/integration-auth/integration-app-list.ts index d6930c5943..95dac6800e 100644 --- a/backend/src/services/integration-auth/integration-app-list.ts +++ b/backend/src/services/integration-auth/integration-app-list.ts @@ -242,37 +242,12 @@ const getAppsGithub = async ({ accessToken }: { accessToken: string }) => { }; } - const octokit = new Octokit({ + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + const repos = (await new Octokit({ auth: accessToken - }); - - const getAllRepos = async () => { - let repos: GitHubApp[] = []; - let page = 1; - const perPage = 100; - let hasMore = true; - - while (hasMore) { - const response = await octokit.request( - "GET /user/repos{?visibility,affiliation,type,sort,direction,per_page,page,since,before}", - { - per_page: perPage, - page - } - ); - - if ((response.data as GitHubApp[]).length > 0) { - repos = repos.concat(response.data as GitHubApp[]); - page += 1; - } else { - hasMore = false; - } - } - - return repos; - }; - - const repos = await getAllRepos(); + }).paginate("GET /user/repos{?visibility,affiliation,type,sort,direction,per_page,page,since,before}", { + per_page: 100 + })) as GitHubApp[]; const apps = repos .filter((a: GitHubApp) => a.permissions.admin === true) From 6fc17a4964b9b4580397d54d7bdb6f0ff75e3cc2 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Mon, 16 Sep 2024 18:15:35 +0400 Subject: [PATCH 3/3] Update license-fns.ts --- .../integration-sync-secret.ts | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/backend/src/services/integration-auth/integration-sync-secret.ts b/backend/src/services/integration-auth/integration-sync-secret.ts index ad8aad5a39..5085d42532 100644 --- a/backend/src/services/integration-auth/integration-sync-secret.ts +++ b/backend/src/services/integration-auth/integration-sync-secret.ts @@ -1006,28 +1006,12 @@ const syncSecretsAWSSecretManager = async ({ } }; - let secretsToProcess: Record = {}; - if (metadata && metadata.secretPrefix) { - const { secretPrefix } = metadata; - - // Update each secret to have the secret prefix - Object.keys(secrets).forEach((key) => { - if (key.startsWith(secretPrefix)) { - secretsToProcess[key] = secrets[key]; - } else { - secretsToProcess[`${secretPrefix}${key}`] = secrets[key]; - } - }); - } else { - secretsToProcess = secrets; - } - if (metadata.mappingBehavior === IntegrationMappingBehavior.ONE_TO_ONE) { - for await (const [key, value] of Object.entries(secretsToProcess)) { + for await (const [key, value] of Object.entries(secrets)) { await processAwsSecret(key, value.value); } } else { - await processAwsSecret(integration.app as string, getSecretKeyValuePair(secretsToProcess)); + await processAwsSecret(integration.app as string, getSecretKeyValuePair(secrets)); } };