Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Checkly group level sync support

Andrew Atimapre279958d54cd6
diff --git a/backend/src/integrations/sync.ts b/backend/src/integrations/sync.ts
index 5f7d533454..f4a0763203 100644
--- a/backend/src/integrations/sync.ts
+++ b/backend/src/integrations/sync.ts
@@ -2121,94 +2121,178 @@ const syncSecretsCheckly = async ({
accessToken: string;
appendices?: { prefix: string; suffix: string };
}) => {
- let getSecretsRes = (
- await standardRequest.get(`${INTEGRATION_CHECKLY_API_URL}/v1/variables`, {
- headers: {
- Authorization: `Bearer ${accessToken}`,
- "Accept-Encoding": "application/json",
- "X-Checkly-Account": integration.appId
- }
- })
- ).data.reduce(
- (obj: any, secret: any) => ({
- ...obj,
- [secret.key]: secret.value
- }),
- {}
- );
- getSecretsRes = Object.keys(getSecretsRes).reduce(
- (
- result: {
- [key: string]: string;
- },
- key
- ) => {
- if (
- (appendices?.prefix !== undefined ? key.startsWith(appendices?.prefix) : true) &&
- (appendices?.suffix !== undefined ? key.endsWith(appendices?.suffix) : true)
- ) {
- result[key] = getSecretsRes[key];
- }
- return result;
- },
- {}
- );
+ if (integration.targetServiceId) {
+ let getGroupSecretsRes = (
+ await standardRequest.get(`${INTEGRATION_CHECKLY_API_URL}/v1/check-groups/${integration.targetServiceId}`, {
+ headers: {
+ Authorization: `Bearer ${accessToken}`,
+ Accept: "application/json",
+ "X-Checkly-Account": integration.appId
+ }
+ })
+ ).data.environmentVariables.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 checkly
- // -> add secret
- await standardRequest.post(
- `${INTEGRATION_CHECKLY_API_URL}/v1/variables`,
- {
- key,
- value: secrets[key].value
+ getGroupSecretsRes = Object.keys(getGroupSecretsRes).reduce(
+ (
+ result: {
+ [key: string]: string;
},
- {
- headers: {
- Authorization: `Bearer ${accessToken}`,
- Accept: "application/json",
- "Content-Type": "application/json",
- "X-Checkly-Account": integration.appId
- }
+ key
+ ) => {
+ if (
+ (appendices?.prefix !== undefined ? key.startsWith(appendices?.prefix) : true) &&
+ (appendices?.suffix !== undefined ? key.endsWith(appendices?.suffix) : true)
+ ) {
+ result[key] = getGroupSecretsRes[key];
}
- );
- } else {
- // case: secret exists in checkly
- // -> update/set secret
+ return result;
+ },
+ {}
+ );
+
+ const groupEnvironmentVariables = Object.keys(secrets).map(key => ({
+ key,
+ value: secrets[key].value
+ }));
+
+ // add secrets
+ for await (const key of Object.keys(secrets)) {
+
+ if (!(key in getGroupSecretsRes)) {
+ // case: secret does not exist in checkly group
+ // -> add secret
- if (secrets[key] !== getSecretsRes[key]) {
await standardRequest.put(
- `${INTEGRATION_CHECKLY_API_URL}/v1/variables/${key}`,
+ `${INTEGRATION_CHECKLY_API_URL}/v1/check-groups/${integration.targetServiceId}`,
{
- value: secrets[key].value
+ environmentVariables: groupEnvironmentVariables
},
{
headers: {
Authorization: `Bearer ${accessToken}`,
- "Content-Type": "application/json",
Accept: "application/json",
"X-Checkly-Account": integration.appId
}
}
);
+ } else {
+ // case: secret exists in checkly group
+ // -> update/set secret
+
+ if (secrets[key] !== getGroupSecretsRes[key]) {
+ await standardRequest.put(
+ `${INTEGRATION_CHECKLY_API_URL}/v1/check-groups/${integration.targetServiceId}`,
+ {
+ environmentVariables: groupEnvironmentVariables
+ },
+ {
+ headers: {
+ Authorization: `Bearer ${accessToken}`,
+ Accept: "application/json",
+ "X-Checkly-Account": integration.appId
+ }
+ }
+ );
+ }
}
}
- }
-
- for await (const key of Object.keys(getSecretsRes)) {
- if (!(key in secrets)) {
- // delete secret
- await standardRequest.delete(`${INTEGRATION_CHECKLY_API_URL}/v1/variables/${key}`, {
+ } else {
+ let getSecretsRes = (
+ await standardRequest.get(`${INTEGRATION_CHECKLY_API_URL}/v1/variables`, {
headers: {
Authorization: `Bearer ${accessToken}`,
- Accept: "application/json",
+ "Accept-Encoding": "application/json",
"X-Checkly-Account": integration.appId
}
- });
+ })
+ ).data.reduce(
+ (obj: any, secret: any) => ({
+ ...obj,
+ [secret.key]: secret.value
+ }),
+ {}
+ );
+
+ getSecretsRes = Object.keys(getSecretsRes).reduce(
+ (
+ result: {
+ [key: string]: string;
+ },
+ key
+ ) => {
+ if (
+ (appendices?.prefix !== undefined ? key.startsWith(appendices?.prefix) : true) &&
+ (appendices?.suffix !== undefined ? key.endsWith(appendices?.suffix) : true)
+ ) {
+ result[key] = getSecretsRes[key];
+ }
+ return result;
+ },
+ {}
+ );
+
+ // add secrets
+ for await (const key of Object.keys(secrets)) {
+ 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].value
+ },
+ {
+ headers: {
+ Authorization: `Bearer ${accessToken}`,
+ Accept: "application/json",
+ "Content-Type": "application/json",
+ "X-Checkly-Account": integration.appId
+ }
+ }
+ );
+ } else {
+ // case: secret exists in checkly
+ // -> update/set secret
+
+ if (secrets[key] !== getSecretsRes[key]) {
+ await standardRequest.put(
+ `${INTEGRATION_CHECKLY_API_URL}/v1/variables/${key}`,
+ {
+ value: secrets[key].value
+ },
+ {
+ headers: {
+ Authorization: `Bearer ${accessToken}`,
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ "X-Checkly-Account": integration.appId
+ }
+ }
+ );
+ }
+ }
}
+
+ for await (const key of Object.keys(getSecretsRes)) {
+ if (!(key in secrets)) {
+ // delete secret
+ await standardRequest.delete(`${INTEGRATION_CHECKLY_API_URL}/v1/variables/${key}`, {
+ headers: {
+ Authorization: `Bearer ${accessToken}`,
+ Accept: "application/json",
+ "X-Checkly-Account": integration.appId
+ }
+ });
+ }
+ }
}
};
diff --git a/frontend/src/pages/integrations/checkly/create.tsx b/frontend/src/pages/integrations/checkly/create.tsx
index 9c203bb4ce..41122548b4 100644
--- a/frontend/src/pages/integrations/checkly/create.tsx
+++ b/frontend/src/pages/integrations/checkly/create.tsx
@@ -84,6 +84,16 @@ export default function ChecklyCreateIntegrationPage() {
}
}, [integrationAuthApps]);
+ const handleValueChange = (val) => {
+ const selectedGroup = integrationAuthGroups.find(group => group.name === val);
+ if (selectedGroup) {
+ setTargetGroupId(selectedGroup.groupId);
+ } else {
+ setTargetGroupId("");
+ }
+ setTargetGroup(val);
+ }
+
const handleButtonClick = async () => {
try {
if (!integrationAuth?._id) return;
@@ -96,6 +106,8 @@ export default function ChecklyCreateIntegrationPage() {
app: targetApp,
appId: targetAppId,
sourceEnvironment: selectedSourceEnvironment,
+ targetService: targetGroup,
+ targetServiceId: targetGroupId.toString(),
secretPath,
metadata: {
secretSuffix
@@ -188,7 +200,7 @@ export default function ChecklyCreateIntegrationPage() {
<FormControl label="Checkly Group">
<Select
value={targetGroup}
- onValueChange={(val) => setTargetGroup(val)}
+ onValueChange={handleValueChange}
className="w-full border border-mineshaft-500"
>
<SelectItem value="">