From 2920ba5195a586e3f950ee6cd9ae9011f3e77a03 Mon Sep 17 00:00:00 2001 From: Tuan Dang Date: Thu, 8 Jun 2023 11:18:23 +0100 Subject: [PATCH] Update Checkly envars only if changed --- backend/src/integrations/sync.ts | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/backend/src/integrations/sync.ts b/backend/src/integrations/sync.ts index ef14ca561..3b655e2fd 100644 --- a/backend/src/integrations/sync.ts +++ b/backend/src/integrations/sync.ts @@ -1706,11 +1706,12 @@ const syncSecretsCheckly = async ({ if (!(key in getSecretsRes)) { // case: secret does not exist in checkly // -> add secret + await standardRequest.post( `${INTEGRATION_CHECKLY_API_URL}/v1/variables`, { key, - value: secrets[key] ? secrets[key] : 'EMPTY' + value: secrets[key] }, { headers: { @@ -1724,20 +1725,23 @@ const syncSecretsCheckly = async ({ } else { // case: secret exists in checkly // -> update/set secret - await standardRequest.put( - `${INTEGRATION_CHECKLY_API_URL}/v1/variables/${key}`, - { - value: secrets[key] ? secrets[key] : 'EMPTY' - }, - { - headers: { - "Authorization": `Bearer ${accessToken}`, - "Content-Type": "application/json", - "Accept": "application/json", - "X-Checkly-Account": integration.appId + + if (secrets[key] !== getSecretsRes[key]) { + await standardRequest.put( + `${INTEGRATION_CHECKLY_API_URL}/v1/variables/${key}`, + { + value: secrets[key] }, - } - ); + { + headers: { + "Authorization": `Bearer ${accessToken}`, + "Content-Type": "application/json", + "Accept": "application/json", + "X-Checkly-Account": integration.appId + }, + } + ); + } } }