Skip to content

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

Update Bitbucket sync function

Tuan Dangd9f6c27e4d7b
diff --git a/backend/.eslintrc b/backend/.eslintrc
index 2e5f5f719a..172e72d4b7 100644
--- a/backend/.eslintrc
+++ b/backend/.eslintrc
@@ -25,7 +25,6 @@
],
"@typescript-eslint/no-unused-vars": "off",
"unused-imports/no-unused-imports": "error",
- "@typescript-eslint/no-empty-function": "off",
"unused-imports/no-unused-vars": [
"warn",
{
diff --git a/backend/src/controllers/v1/integrationAuthController.ts b/backend/src/controllers/v1/integrationAuthController.ts
index 9072f459b9..88968a2727 100644
--- a/backend/src/controllers/v1/integrationAuthController.ts
+++ b/backend/src/controllers/v1/integrationAuthController.ts
@@ -386,7 +386,7 @@ export const getIntegrationAuthRailwayServices = async (req: Request, res: Respo
};
/**
- * Return list of workspaces allowed for integration with integration authorization id [integrationAuthId]
+ * Return list of workspaces allowed for Bitbucket integration
* @param req
* @param res
* @returns
diff --git a/backend/src/integrations/sync.ts b/backend/src/integrations/sync.ts
index 7b7456b86f..a1815fe7e7 100644
--- a/backend/src/integrations/sync.ts
+++ b/backend/src/integrations/sync.ts
@@ -678,8 +678,6 @@ const syncSecretsVercel = async ({
return true;
});
- // return secret.target.includes(integration.targetEnvironment);
-
const res: { [key: string]: VercelSecret } = {};
for await (const vercelSecret of vercelSecrets) {
@@ -1963,16 +1961,17 @@ const syncSecretsBitBucket = async ({
secrets: any;
accessToken: string;
}) => {
+
interface VariablesResponse {
size: number;
page: number;
pageLen: number;
next: string;
previous: string;
- values: Array<Variable>;
+ values: Array<BitbucketVariable>;
}
- interface Variable {
+ interface BitbucketVariable {
type: string;
uuid: string;
key: string;
@@ -1980,13 +1979,11 @@ const syncSecretsBitBucket = async ({
secured: boolean;
}
- const existingSecrets: Variable[] = [];
- const workspaceSlug = integration.targetEnvironmentId
- const repoSlug = integration.appId
+ const res: { [key: string]: BitbucketVariable } = {};
+
let hasNextPage = true;
- let variablesUrl = `${INTEGRATION_BITBUCKET_API_URL}/2.0/repositories/${workspaceSlug}/${repoSlug}/pipelines_config/variables`
+ let variablesUrl = `${INTEGRATION_BITBUCKET_API_URL}/2.0/repositories/${integration.targetEnvironmentId}/${integration.appId}/pipelines_config/variables`
- // Fetch all repository variables
while (hasNextPage) {
const { data }: { data: VariablesResponse } = await standardRequest.get(
variablesUrl,
@@ -2000,8 +1997,8 @@ const syncSecretsBitBucket = async ({
if (data?.values.length > 0) {
data.values.forEach((variable) => {
- existingSecrets.push(variable)
- })
+ res[variable.key] = variable;
+ });
}
if (data.next) {
@@ -2011,12 +2008,11 @@ const syncSecretsBitBucket = async ({
}
}
- Object.keys(secrets).forEach(async (key) => {
- const existingSecret = existingSecrets.find((secret) => secret.key.toUpperCase() === key.toUpperCase());
- if (existingSecret) {
- // Update existing secrets
+ for await (const key of Object.keys(secrets)) {
+ if (key in res) {
+ // update existing secret
await standardRequest.put(
- `${variablesUrl}/${existingSecret.uuid}`,
+ `${variablesUrl}/${res[key].uuid}`,
{
key,
value: secrets[key],
@@ -2030,7 +2026,7 @@ const syncSecretsBitBucket = async ({
}
);
} else {
- // Create new secrets
+ // create new secret
await standardRequest.post(
variablesUrl,
{
@@ -2046,22 +2042,22 @@ const syncSecretsBitBucket = async ({
}
);
}
- })
+ }
- // Delete secrets
- existingSecrets.forEach(async (existingSecret) => {
- if (!(existingSecret.key in secrets) && existingSecret.secured) {
+ for await (const key of Object.keys(res)) {
+ if (!(key in secrets)) {
+ // delete secret
await standardRequest.delete(
- `${variablesUrl}/${existingSecret.uuid}`,
+ `${variablesUrl}/${res[key].uuid}`,
{
headers: {
Authorization: `Bearer ${accessToken}`,
"Accept": "application/json",
- },
+ }
}
- );
+ );
}
- })
+ }
}
export { syncSecrets };
diff --git a/backend/src/routes/v1/integrationAuth.ts b/backend/src/routes/v1/integrationAuth.ts
index 5e5f1e6d17..673d269d28 100644
--- a/backend/src/routes/v1/integrationAuth.ts
+++ b/backend/src/routes/v1/integrationAuth.ts
@@ -150,7 +150,7 @@ router.get(
requireIntegrationAuthorizationAuth({
acceptedRoles: [ADMIN, MEMBER],
}),
- param("integrationAuthId"),
+ param("integrationAuthId").exists().isString(),
validateRequest,
integrationAuthController.getIntegrationAuthBitBucketWorkspaces
);
diff --git a/backend/src/variables/integration.ts b/backend/src/variables/integration.ts
index fc4397871b..041d1d1095 100644
--- a/backend/src/variables/integration.ts
+++ b/backend/src/variables/integration.ts
@@ -75,7 +75,7 @@ export const INTEGRATION_SUPABASE_API_URL = "https://api.supabase.com";
export const INTEGRATION_LARAVELFORGE_API_URL = "https://forge.laravel.com";
export const INTEGRATION_CHECKLY_API_URL = "https://api.checklyhq.com";
export const INTEGRATION_CLOUDFLARE_PAGES_API_URL = "https://api.cloudflare.com";
-export const INTEGRATION_BITBUCKET_API_URL = "https://api.bitbucket.org/";
+export const INTEGRATION_BITBUCKET_API_URL = "https://api.bitbucket.org";
export const getIntegrationOptions = async () => {
const INTEGRATION_OPTIONS = [
diff --git a/frontend/src/hooks/api/integrationAuth/queries.tsx b/frontend/src/hooks/api/integrationAuth/queries.tsx
index 841c1a52b0..10083432ad 100644
--- a/frontend/src/hooks/api/integrationAuth/queries.tsx
+++ b/frontend/src/hooks/api/integrationAuth/queries.tsx
@@ -34,7 +34,7 @@ const integrationAuthKeys = {
appId: string;
}) => [{ integrationAuthId, appId }, "integrationAuthRailwayServices"] as const,
getIntegrationAuthBitBucketWorkspaces: (integrationAuthId: string) =>
- [{ integrationAuthId }, "integrationAuthTeams"] as const,
+ [{ integrationAuthId }, "integrationAuthBitbucketWorkspaces"] as const,
};
const fetchIntegrationAuthById = async (integrationAuthId: string) => {