From e8fdaf571c5bb46120f31ba3da08df4704a26f86 Mon Sep 17 00:00:00 2001 From: Tuan Dang Date: Wed, 19 Jul 2023 23:17:59 +0700 Subject: [PATCH] Make sync function for Codefresh --- backend/src/integrations/sync.ts | 107 +++--------------- backend/src/variables/integration.ts | 1 - .../integrations/codefresh/authorize.tsx | 2 +- .../IntegrationsSection.tsx | 2 - 4 files changed, 18 insertions(+), 94 deletions(-) diff --git a/backend/src/integrations/sync.ts b/backend/src/integrations/sync.ts index 93eaf22be..26c447056 100644 --- a/backend/src/integrations/sync.ts +++ b/backend/src/integrations/sync.ts @@ -225,7 +225,6 @@ const syncSecrets = async ({ case INTEGRATION_CODEFRESH: await syncSecretsCodefresh({ integration, - // integrationAuth, secrets, accessToken, }); @@ -1923,17 +1922,13 @@ const syncSecretsCloudflarePages = async ({ ); } - /** - * Sync/push [secrets] to codefresh with name [integration.app] + * Sync/push [secrets] to Codefresh with name [integration.app] * @param {Object} obj * @param {IIntegration} obj.integration - integration details * @param {Object} obj.secrets - secrets to push to integration (object where keys are secret keys and values are secret values) - * @param {String} obj.accessToken - access token for Supabase integration + * @param {String} obj.accessToken - access token for Codefresh integration */ - - - const syncSecretsCodefresh = async ({ integration, secrets, @@ -1943,89 +1938,21 @@ const syncSecretsCodefresh = async ({ secrets: any; accessToken: string; }) => { - // get variables from codefresh. - - // there is no endpoint to get secrets from codefresh - // const getSecretsRes = ( - // await standardRequest.get( - // `${INTEGRATION_CODEFRESH_API_URL}/api/pipelines/utils/extractVariables`, - // { - // headers: { - // "Authorization": `Bearer ${accessToken}`, - // "Accept-Encoding": "application/json", - // }, - // } - // ) - // ) - // .data - // .reduce((obj: any, secret: any) => ({ - // ...obj, - // [secret.key]: secret.value, - // }), {}); - - // add secrets - // for await (const key of Object.keys(secrets)) { - // if (!(key in getSecretsRes)) { - // // case: secret does not exist in codefresh - // // -> add secret - - // await standardRequest.post( - // `${INTEGRATION_CODEFRESH_API_URL}/api/pipelines`, - // { - // spec: { - // variables: [ - // { - // key, - // value: secrets[key], - // } - // ] - - // }, - // }, - // { - // headers: { - // "Authorization": `Bearer ${accessToken}`, - // "Accept": "application/json", - // "Content-Type": "application/json", - // }, - // } - // ); - // } else { - // // case: secret exists in checkly - // // -> update/set secret - - // if (secrets[key] !== getSecretsRes[key]) { - // await standardRequest.put( - // `${INTEGRATION_CODEFRESH_API_URL}/v1/variables/${key}`, - // { - // value: secrets[key], - // }, - // { - // headers: { - // "Authorization": `Bearer ${accessToken}`, - // "Content-Type": "application/json", - // "Accept": "application/json", - // }, - // } - // ); - // } - // } - // } - - // for await (const key of Object.keys(getSecretsRes)) { - // if (!(key in secrets)) { - // // delete secret - // await standardRequest.delete( - // `${INTEGRATION_CODEFRESH_API_URL}/v1/variables/${key}`, - // { - // headers: { - // "Authorization": `Bearer ${accessToken}`, - // "Accept": "application/json", - // }, - // } - // ); - // } - // } + await standardRequest.patch( + `${INTEGRATION_CODEFRESH_API_URL}/projects/${integration.appId}`, + { + variables: Object.keys(secrets).map((key) => ({ + key, + value: secrets[key] + })) + }, + { + headers: { + Authorization: `Bearer ${accessToken}`, + "Accept": "application/json", + }, + } + ); }; export { syncSecrets }; diff --git a/backend/src/variables/integration.ts b/backend/src/variables/integration.ts index 5eb50b583..13e89a324 100644 --- a/backend/src/variables/integration.ts +++ b/backend/src/variables/integration.ts @@ -25,7 +25,6 @@ export const INTEGRATION_SUPABASE = 'supabase'; export const INTEGRATION_CHECKLY = 'checkly'; export const INTEGRATION_HASHICORP_VAULT = 'hashicorp-vault'; export const INTEGRATION_CLOUDFLARE_PAGES = 'cloudflare-pages'; -// chisom export const INTEGRATION_CODEFRESH = 'codefresh'; export const INTEGRATION_SET = new Set([ diff --git a/frontend/src/pages/integrations/codefresh/authorize.tsx b/frontend/src/pages/integrations/codefresh/authorize.tsx index aebfd2139..17416ffab 100644 --- a/frontend/src/pages/integrations/codefresh/authorize.tsx +++ b/frontend/src/pages/integrations/codefresh/authorize.tsx @@ -23,8 +23,8 @@ export default function CodefreshCreateIntegrationPage() { const integrationAuth = await saveIntegrationAccessToken({ workspaceId: localStorage.getItem("projectData.id"), integration: "codefresh", - accessToken: apiKey, accessId: null, + accessToken: apiKey, url: null, namespace: null }); diff --git a/frontend/src/views/IntegrationsPage/components/IntegrationsSection/IntegrationsSection.tsx b/frontend/src/views/IntegrationsPage/components/IntegrationsSection/IntegrationsSection.tsx index 65d1dc1ca..1fe734c96 100644 --- a/frontend/src/views/IntegrationsPage/components/IntegrationsSection/IntegrationsSection.tsx +++ b/frontend/src/views/IntegrationsPage/components/IntegrationsSection/IntegrationsSection.tsx @@ -32,8 +32,6 @@ export const IntegrationsSection = ({ const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([ "deleteConfirmation" ] as const); - - console.log(integrationSlugNameMapping, integrations, '>>>chisom') return (