App connection updates

This commit is contained in:
x032205
2025-07-03 00:00:50 -04:00
parent 62ad82f7b1
commit ae35a863bc
10 changed files with 127 additions and 22 deletions
+3
View File
@@ -2632,6 +2632,9 @@ export const SecretScanningDataSources = {
CONFIG: {
GITHUB: {
includeRepos: 'The repositories to include when scanning. Defaults to all repositories (["*"]).'
},
BITBUCKET: {
includeRepos: 'The repositories to include when scanning. Defaults to all repositories (["*"]).'
}
}
};
@@ -1,9 +1,14 @@
import { z } from "zod";
import { readLimit } from "@app/server/config/rateLimiter";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
import {
CreateBitBucketConnectionSchema,
SanitizedBitBucketConnectionSchema,
UpdateBitBucketConnectionSchema
} from "@app/services/app-connection/bitbucket";
import { AuthMode } from "@app/services/auth/auth-type";
import { registerAppConnectionEndpoints } from "./app-connection-endpoints";
@@ -15,4 +20,32 @@ export const registerBitBucketConnectionRouter = async (server: FastifyZodProvid
createSchema: CreateBitBucketConnectionSchema,
updateSchema: UpdateBitBucketConnectionSchema
});
// The below endpoints are not exposed and for Infisical App use
server.route({
method: "GET",
url: `/:connectionId/repositories`,
config: {
rateLimit: readLimit
},
schema: {
params: z.object({
connectionId: z.string().uuid()
}),
response: {
200: z.object({
repositories: z.object({ id: z.string(), name: z.string() }).array()
})
}
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
const { connectionId } = req.params;
const repositories = await server.services.appConnection.bitbucket.listRepositories(connectionId, req.permission);
return { repositories };
}
});
};
@@ -3,9 +3,10 @@ import { AxiosError } from "axios";
import { request } from "@app/lib/config/request";
import { BadRequestError } from "@app/lib/errors";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
import { IntegrationUrls } from "@app/services/integration-auth/integration-list";
import { BitBucketConnectionMethod } from "./bitbucket-connection-enums";
import { TBitBucketConnectionConfig } from "./bitbucket-connection-types";
import { TBitBucketConnection, TBitBucketConnectionConfig, TBitBucketRepo } from "./bitbucket-connection-types";
export const getBitBucketConnectionListItem = () => {
return {
@@ -15,16 +16,16 @@ export const getBitBucketConnectionListItem = () => {
};
};
export const validateBitBucketConnectionCredentials = async (config: TBitBucketConnectionConfig) => {
const { email, apiToken } = config.credentials;
export const getBitBucketUser = async ({ email, apiToken }: { email: string; apiToken: string }) => {
try {
await request.get("https://api.bitbucket.org/2.0/user", {
const { data } = await request.get<{ username: string }>(`${IntegrationUrls.BITBUCKET_API_URL}/2.0/user`, {
headers: {
Authorization: `Basic ${Buffer.from(`${email}:${apiToken}`).toString("base64")}`,
Accept: "application/json"
}
});
return data;
} catch (error: unknown) {
if (error instanceof AxiosError) {
throw new BadRequestError({
@@ -35,6 +36,26 @@ export const validateBitBucketConnectionCredentials = async (config: TBitBucketC
message: "Unable to validate connection: verify credentials"
});
}
};
export const validateBitBucketConnectionCredentials = async (config: TBitBucketConnectionConfig) => {
await getBitBucketUser(config.credentials);
return config.credentials;
};
export const listBitBucketRepositories = async (appConnection: TBitBucketConnection) => {
const { email, apiToken } = appConnection.credentials;
// TODO(andrey): Support pagination for cases where a token has access to over 100 repos
const { data } = await request.get<{ values: TBitBucketRepo[] }>(
`${IntegrationUrls.BITBUCKET_API_URL}/2.0/repositories?role=member&pagelen=100`,
{
headers: {
Authorization: `Basic ${Buffer.from(`${email}:${apiToken}`).toString("base64")}`,
Accept: "application/json"
}
}
);
return data.values;
};
@@ -1,7 +1,7 @@
import { OrgServiceActor } from "@app/lib/types";
import { AppConnection } from "../app-connection-enums";
// import { listBitBucketVaults } from "./bitbucket-connection-fns";
import { listBitBucketRepositories } from "./bitbucket-connection-fns";
import { TBitBucketConnection } from "./bitbucket-connection-types";
type TGetAppConnectionFunc = (
@@ -10,6 +10,17 @@ type TGetAppConnectionFunc = (
actor: OrgServiceActor
) => Promise<TBitBucketConnection>;
export const bitBucketConnectionService = (_getAppConnection: TGetAppConnectionFunc) => {
return {};
export const bitBucketConnectionService = (getAppConnection: TGetAppConnectionFunc) => {
const listRepositories = async (connectionId: string, actor: OrgServiceActor) => {
const appConnection = await getAppConnection(AppConnection.BitBucket, connectionId, actor);
const repositories = await listBitBucketRepositories(appConnection);
// TODO(andrey): May need to change from slug to ID or something
return repositories.map((repo) => ({ id: repo.slug, name: repo.full_name }));
};
return {
listRepositories
};
};
@@ -24,15 +24,7 @@ export type TBitBucketConnectionConfig = DiscriminativePick<
orgId: string;
};
export type TBitBucketVault = {
id: string;
name: string;
type: string;
items: number;
attributeVersion: number;
contentVersion: number;
createdAt: string;
updatedAt: string;
export type TBitBucketRepo = {
full_name: string; // workspace-slug/repo-slug
slug: string;
};