From 381806d84b53eec1e9d18efef33058a58ab187c8 Mon Sep 17 00:00:00 2001 From: Stijn-Kuijper Date: Thu, 15 Jun 2023 09:46:09 +0200 Subject: [PATCH] feat: initial getApps for Cloudflare Pages --- backend/src/integrations/apps.ts | 44 ++++++++++++++++++- backend/src/models/integrationAuth.ts | 6 ++- backend/src/variables/integration.ts | 5 ++- frontend/public/data/frequentConstants.ts | 3 +- .../cloudflare-pages/authorize.tsx | 4 +- 5 files changed, 54 insertions(+), 8 deletions(-) diff --git a/backend/src/integrations/apps.ts b/backend/src/integrations/apps.ts index f8ed77277..e7f745974 100644 --- a/backend/src/integrations/apps.ts +++ b/backend/src/integrations/apps.ts @@ -17,6 +17,7 @@ import { INTEGRATION_TRAVISCI, INTEGRATION_SUPABASE, INTEGRATION_CHECKLY, + INTEGRATION_CLOUDFLARE_PAGES, INTEGRATION_HEROKU_API_URL, INTEGRATION_GITLAB_API_URL, INTEGRATION_VERCEL_API_URL, @@ -27,7 +28,8 @@ import { INTEGRATION_CIRCLECI_API_URL, INTEGRATION_TRAVISCI_API_URL, INTEGRATION_SUPABASE_API_URL, - INTEGRATION_CHECKLY_API_URL + INTEGRATION_CHECKLY_API_URL, + INTEGRATION_CLOUDFLARE_PAGES_API_URL } from "../variables"; interface App { @@ -127,6 +129,12 @@ const getApps = async ({ accessToken, }); break; + case INTEGRATION_CLOUDFLARE_PAGES: + apps = await getAppsCloudflarePages({ + accessToken, + accountId: '' + }) + break; } return apps; @@ -636,4 +644,38 @@ const getAppsCheckly = async ({ accessToken }: { accessToken: string }) => { return apps; }; +/** + * Return list of projects for the Cloudflare Pages integration + * @param {Object} obj + * @param {String} obj.accessToken - api key for the Cloudflare API + * @returns {Object[]} apps - Cloudflare Pages projects + * @returns {String} apps.name - name of Cloudflare Pages project + */ +const getAppsCloudflarePages = async ({ + accessToken, + accountId +}: { + accessToken: string; + accountId?: string; +}) => { + const { data } = await standardRequest.get( + `${INTEGRATION_CLOUDFLARE_PAGES_API_URL}/client/v4/accounts/${accountId}/pages/projects`, + { + headers: { + Authorization: `Bearer ${accessToken}`, + "Accept": "application/json", + }, + } + ); + + const apps = data.map((a: any) => { + return { + name: a["project_name"], + appId: a.id, + }; + }); + + return apps; +} + export { getApps }; diff --git a/backend/src/models/integrationAuth.ts b/backend/src/models/integrationAuth.ts index cc28c9fd6..9e2cb0c19 100644 --- a/backend/src/models/integrationAuth.ts +++ b/backend/src/models/integrationAuth.ts @@ -15,6 +15,7 @@ import { INTEGRATION_TRAVISCI, INTEGRATION_SUPABASE, INTEGRATION_HASHICORP_VAULT, + INTEGRATION_CLOUDFLARE_PAGES, ALGORITHM_AES_256_GCM, ENCODING_SCHEME_UTF8, ENCODING_SCHEME_BASE64 @@ -23,7 +24,7 @@ import { export interface IIntegrationAuth extends Document { _id: Types.ObjectId; workspace: Types.ObjectId; - integration: 'heroku' | 'vercel' | 'netlify' | 'github' | 'gitlab' | 'render' | 'railway' | 'flyio' | 'azure-key-vault' | 'circleci' | 'travisci' | 'supabase' | 'aws-parameter-store' | 'aws-secret-manager' | 'checkly'; + integration: 'heroku' | 'vercel' | 'netlify' | 'github' | 'gitlab' | 'render' | 'railway' | 'flyio' | 'azure-key-vault' | 'circleci' | 'travisci' | 'supabase' | 'aws-parameter-store' | 'aws-secret-manager' | 'checkly' | 'cloudflare-pages'; teamId: string; accountId: string; url: string; @@ -66,7 +67,8 @@ const integrationAuthSchema = new Schema( INTEGRATION_CIRCLECI, INTEGRATION_TRAVISCI, INTEGRATION_SUPABASE, - INTEGRATION_HASHICORP_VAULT + INTEGRATION_HASHICORP_VAULT, + INTEGRATION_CLOUDFLARE_PAGES, ], required: true, }, diff --git a/backend/src/variables/integration.ts b/backend/src/variables/integration.ts index 8935e7b49..06bd74fdf 100644 --- a/backend/src/variables/integration.ts +++ b/backend/src/variables/integration.ts @@ -23,8 +23,8 @@ export const INTEGRATION_CIRCLECI = "circleci"; export const INTEGRATION_TRAVISCI = "travisci"; export const INTEGRATION_SUPABASE = 'supabase'; export const INTEGRATION_CHECKLY = 'checkly'; -export const INTEGRATION_CLOUDFLARE_PAGES = 'cloudflare-pages'; export const INTEGRATION_HASHICORP_VAULT = 'hashicorp-vault'; +export const INTEGRATION_CLOUDFLARE_PAGES = 'cloudflare-pages'; export const INTEGRATION_SET = new Set([ INTEGRATION_AZURE_KEY_VAULT, INTEGRATION_HEROKU, @@ -38,7 +38,8 @@ export const INTEGRATION_SET = new Set([ INTEGRATION_TRAVISCI, INTEGRATION_SUPABASE, INTEGRATION_CHECKLY, - INTEGRATION_HASHICORP_VAULT + INTEGRATION_HASHICORP_VAULT, + INTEGRATION_CLOUDFLARE_PAGES ]); // integration types diff --git a/frontend/public/data/frequentConstants.ts b/frontend/public/data/frequentConstants.ts index e873f1a72..480061e1a 100644 --- a/frontend/public/data/frequentConstants.ts +++ b/frontend/public/data/frequentConstants.ts @@ -18,7 +18,8 @@ const integrationSlugNameMapping: Mapping = { 'travisci': 'TravisCI', 'supabase': 'Supabase', 'checkly': 'Checkly', - 'hashicorp-vault': 'Vault' + 'hashicorp-vault': 'Vault', + 'cloudflare-pages': 'Cloudflare Pages' } const envMapping: Mapping = { diff --git a/frontend/src/pages/integrations/cloudflare-pages/authorize.tsx b/frontend/src/pages/integrations/cloudflare-pages/authorize.tsx index 71b6059e8..cbd20f018 100644 --- a/frontend/src/pages/integrations/cloudflare-pages/authorize.tsx +++ b/frontend/src/pages/integrations/cloudflare-pages/authorize.tsx @@ -26,8 +26,8 @@ export default function CloudflarePagesIntegrationPage() { const integrationAuth = await saveIntegrationAccessToken({ workspaceId: localStorage.getItem('projectData.id'), integration: 'cloudflare-pages', - accessId: accessKey, - accessToken: accountId, + accessId: accountId, + accessToken: accessKey, url: null, namespace: null });