From 85de9853216e59ce56a1357ac12f28157af71b8a Mon Sep 17 00:00:00 2001 From: Shreyas Singh Date: Sat, 11 Nov 2023 00:43:13 +0530 Subject: [PATCH] Add apps list for cloudflare workers integration --- backend/src/integrations/apps.ts | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/backend/src/integrations/apps.ts b/backend/src/integrations/apps.ts index e67136275..00196b3d0 100644 --- a/backend/src/integrations/apps.ts +++ b/backend/src/integrations/apps.ts @@ -10,6 +10,8 @@ import { INTEGRATION_CIRCLECI_API_URL, INTEGRATION_CLOUDFLARE_PAGES, INTEGRATION_CLOUDFLARE_PAGES_API_URL, + INTEGRATION_CLOUDFLARE_WORKERS, + INTEGRATION_CLOUDFLARE_WORKERS_API_URL, INTEGRATION_CLOUD_66, INTEGRATION_CLOUD_66_API_URL, INTEGRATION_CODEFRESH, @@ -186,6 +188,12 @@ const getApps = async ({ accountId: accessId }); break; + case INTEGRATION_CLOUDFLARE_WORKERS: + apps = await getAppsCloudflareWorkers({ + accessToken, + accountId: accessId + }); + break; case INTEGRATION_NORTHFLANK: apps = await getAppsNorthflank({ accessToken @@ -968,6 +976,40 @@ const getAppsCloudflarePages = async ({ return apps; }; +/** + * Return list of projects for the Cloudflare Workers integration + * @param {Object} obj + * @param {String} obj.accessToken - api key for the Cloudflare API + * @returns {Object[]} apps - Cloudflare Workers projects + * @returns {String} apps.id - Id of Cloudflare Workers project + * @returns {String} apps.name - Id of Cloudflare Workers project (Cloudflare workers API does not return the name) + */ +const getAppsCloudflareWorkers = async ({ + accessToken, + accountId +}: { + accessToken: string; + accountId?: string; +}) => { + const { data } = await standardRequest.get( + `${INTEGRATION_CLOUDFLARE_WORKERS_API_URL}/client/v4/accounts/${accountId}/workers/services`, + { + headers: { + Authorization: `Bearer ${accessToken}`, + Accept: "application/json" + } + } + ); + + const apps = data.result.map((a: any) => { + return { + name: a.id, + appId: a.id + }; + }); + return apps; +}; + /** * Return list of repositories for the BitBucket integration based on provided BitBucket workspace * @param {Object} obj