Skip to content

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

remove search endpoints and add search query parameter on list ones

adilson3b0c7b8d6c29
diff --git a/backend/src/server/routes/v1/app-connection-routers/gitlab-connection-router.ts b/backend/src/server/routes/v1/app-connection-routers/gitlab-connection-router.ts
index f7a6c10026..3190293162 100644
--- a/backend/src/server/routes/v1/app-connection-routers/gitlab-connection-router.ts
+++ b/backend/src/server/routes/v1/app-connection-routers/gitlab-connection-router.ts
@@ -36,6 +36,9 @@ export const registerGitLabConnectionRouter = async (server: FastifyZodProvider)
params: z.object({
connectionId: z.string().uuid()
}),
+ querystring: z.object({
+ search: z.string().trim().max(255).optional()
+ }),
response: {
200: z
.object({
@@ -48,10 +51,12 @@ export const registerGitLabConnectionRouter = async (server: FastifyZodProvider)
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
const { connectionId } = req.params;
+ const { search } = req.query;
const projects: TGitLabProject[] = await server.services.appConnection.gitlab.listProjects(
connectionId,
- req.permission
+ req.permission,
+ search
);
return projects;
@@ -69,47 +74,15 @@ export const registerGitLabConnectionRouter = async (server: FastifyZodProvider)
params: z.object({
connectionId: z.string().uuid()
}),
- response: {
- 200: z
- .object({
- id: z.string(),
- fullName: z.string()
- })
- .array()
- }
- },
- onRequest: verifyAuth([AuthMode.JWT]),
- handler: async (req) => {
- const { connectionId } = req.params;
-
- const groups: TGitLabGroup[] = await server.services.appConnection.gitlab.listGroups(
- connectionId,
- req.permission
- );
-
- return groups;
- }
- });
-
- server.route({
- method: "GET",
- url: `/:connectionId/search-groups`,
- config: {
- rateLimit: readLimit
- },
- schema: {
- operationId: "searchGitLabGroups",
- params: z.object({
- connectionId: z.string().uuid()
- }),
querystring: z.object({
- search: z.string().trim().min(1).max(255)
+ search: z.string().trim().max(255).optional()
}),
response: {
200: z
.object({
id: z.string(),
name: z.string(),
+ fullName: z.string(),
fullPath: z.string()
})
.array()
@@ -119,50 +92,14 @@ export const registerGitLabConnectionRouter = async (server: FastifyZodProvider)
handler: async (req) => {
const { connectionId } = req.params;
const { search } = req.query;
- const groups: TGitLabGroupTreeItem[] = await server.services.appConnection.gitlab.searchGroups(
- connectionId,
- search,
- req.permission
- );
- return groups;
- }
- });
- server.route({
- method: "GET",
- url: `/:connectionId/search-projects`,
- config: {
- rateLimit: readLimit
- },
- schema: {
- operationId: "searchGitLabProjects",
- params: z.object({
- connectionId: z.string().uuid()
- }),
- querystring: z.object({
- search: z.string().trim().min(1).max(255)
- }),
- response: {
- 200: z
- .object({
- id: z.string(),
- name: z.string(),
- fullPath: z.string()
- })
- .array()
- }
- },
- onRequest: verifyAuth([AuthMode.JWT]),
- handler: async (req) => {
- const { connectionId } = req.params;
- const { search } = req.query;
- const projects: TGitLabGroupTreeItem[] = await server.services.appConnection.gitlab.searchProjects(
+ const groups: TGitLabGroup[] = await server.services.appConnection.gitlab.listGroups(
connectionId,
- search,
- req.permission
+ req.permission,
+ search
);
- return projects;
+ return groups;
}
});
diff --git a/backend/src/services/app-connection/gitlab/gitlab-connection-fns.ts b/backend/src/services/app-connection/gitlab/gitlab-connection-fns.ts
index 63b2db4c72..83769e8c2c 100644
--- a/backend/src/services/app-connection/gitlab/gitlab-connection-fns.ts
+++ b/backend/src/services/app-connection/gitlab/gitlab-connection-fns.ts
@@ -323,11 +323,13 @@ export const getGitLabConnectionClient = async (
export const listGitLabProjects = async ({
appConnection,
appConnectionDAL,
- kmsService
+ kmsService,
+ search
}: {
appConnection: TGitLabConnection;
appConnectionDAL: Pick<TAppConnectionDALFactory, "updateById">;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
+ search?: string;
}): Promise<TGitLabProject[]> => {
let { accessToken } = appConnection.credentials;
@@ -354,6 +356,7 @@ export const listGitLabProjects = async ({
appConnection.method === GitLabConnectionMethod.OAuth
);
const projects = await client.Projects.all({
+ ...(search ? { search } : {}),
archived: false,
includePendingDelete: false,
membership: true,
@@ -385,11 +388,13 @@ export const listGitLabProjects = async ({
export const listGitLabGroups = async ({
appConnection,
appConnectionDAL,
- kmsService
+ kmsService,
+ search
}: {
appConnection: TGitLabConnection;
appConnectionDAL: Pick<TAppConnectionDALFactory, "updateById">;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
+ search?: string;
}): Promise<TGitLabGroup[]> => {
const client = await getNavigationClient({ appConnection, appConnectionDAL, kmsService });
if (!client) return [];
@@ -398,12 +403,15 @@ export const listGitLabGroups = async ({
const groups = await client.Groups.all({
orderBy: "name",
sort: "asc",
- minAccessLevel: 50
+ minAccessLevel: 50,
+ ...(search ? { search } : {})
});
return groups.map((group) => ({
id: group.id.toString(),
- fullName: group.fullName
+ name: group.name,
+ fullName: group.fullName,
+ fullPath: group.fullPath
}));
} catch (error: unknown) {
if (error instanceof GitbeakerRequestError) {
@@ -496,57 +504,3 @@ export const listGitLabGroupProjects = async (
throw new InternalServerError({ message: "Unable to fetch GitLab group projects" });
}
};
-
-export const searchGitLabGroups = async (
- search: string,
- params: TNavigationParams
-): Promise<TGitLabGroupTreeItem[]> => {
- const client = await getNavigationClient(params);
- if (!client) return [];
-
- try {
- const groups = await client.Groups.all({
- search,
- minAccessLevel: 20
- });
-
- return groups.map((g) => ({ id: g.id.toString(), name: g.name, fullPath: g.fullPath }));
- } catch (error: unknown) {
- if (error instanceof GitbeakerRequestError) {
- throw new BadRequestError({
- message: `Failed to search GitLab groups: ${error.message ?? "Unknown error"}${error.cause?.description && error.message !== "Unauthorized" ? `. Cause: ${error.cause.description}` : ""}`
- });
- }
- if (error instanceof InternalServerError) throw error;
- throw new InternalServerError({ message: "Unable to search GitLab groups" });
- }
-};
-
-export const searchGitLabProjects = async (
- search: string,
- params: TNavigationParams
-): Promise<TGitLabGroupTreeItem[]> => {
- const client = await getNavigationClient(params);
- if (!client) return [];
-
- try {
- const projects = await client.Projects.all({
- search,
- archived: false,
- includePendingDelete: false,
- membership: true,
- includeHidden: false,
- imported: false
- });
-
- return projects.map((p) => ({ id: p.id.toString(), name: p.name, fullPath: p.pathWithNamespace }));
- } catch (error: unknown) {
- if (error instanceof GitbeakerRequestError) {
- throw new BadRequestError({
- message: `Failed to search GitLab projects: ${error.message ?? "Unknown error"}${error.cause?.description && error.message !== "Unauthorized" ? `. Cause: ${error.cause.description}` : ""}`
- });
- }
- if (error instanceof InternalServerError) throw error;
- throw new InternalServerError({ message: "Unable to search GitLab projects" });
- }
-};
diff --git a/backend/src/services/app-connection/gitlab/gitlab-connection-service.ts b/backend/src/services/app-connection/gitlab/gitlab-connection-service.ts
index 7c184c4854..35254613c5 100644
--- a/backend/src/services/app-connection/gitlab/gitlab-connection-service.ts
+++ b/backend/src/services/app-connection/gitlab/gitlab-connection-service.ts
@@ -9,9 +9,7 @@ import {
listGitLabGroups,
listGitLabProjects,
listGitLabRootGroups,
- listGitLabSubgroups,
- searchGitLabGroups,
- searchGitLabProjects
+ listGitLabSubgroups
} from "./gitlab-connection-fns";
import { TGitLabConnection } from "./gitlab-connection-types";
@@ -26,10 +24,10 @@ export const gitlabConnectionService = (
appConnectionDAL: Pick<TAppConnectionDALFactory, "updateById">,
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">
) => {
- const listProjects = async (connectionId: string, actor: OrgServiceActor) => {
+ const listProjects = async (connectionId: string, actor: OrgServiceActor, search?: string) => {
try {
const appConnection = await getAppConnection(AppConnection.GitLab, connectionId, actor);
- const projects = await listGitLabProjects({ appConnection, appConnectionDAL, kmsService });
+ const projects = await listGitLabProjects({ appConnection, appConnectionDAL, kmsService, search });
return projects;
} catch (error) {
logger.error(error, `Failed to establish connection with GitLab for app ${connectionId}`);
@@ -37,10 +35,10 @@ export const gitlabConnectionService = (
}
};
- const listGroups = async (connectionId: string, actor: OrgServiceActor) => {
+ const listGroups = async (connectionId: string, actor: OrgServiceActor, search?: string) => {
try {
const appConnection = await getAppConnection(AppConnection.GitLab, connectionId, actor);
- const groups = await listGitLabGroups({ appConnection, appConnectionDAL, kmsService });
+ const groups = await listGitLabGroups({ appConnection, appConnectionDAL, kmsService, search });
return groups;
} catch (error) {
logger.error(error, `Failed to establish connection with GitLab for app ${connectionId}`);
@@ -58,16 +56,6 @@ export const gitlabConnectionService = (
}
};
- const searchGroups = async (connectionId: string, search: string, actor: OrgServiceActor) => {
- try {
- const appConnection = await getAppConnection(AppConnection.GitLab, connectionId, actor);
- return await searchGitLabGroups(search, { appConnection, appConnectionDAL, kmsService });
- } catch (error) {
- logger.error(error, `Failed to search groups for GitLab connection ${connectionId}`);
- return [];
- }
- };
-
const listSubgroups = async (connectionId: string, groupId: string, actor: OrgServiceActor) => {
try {
const appConnection = await getAppConnection(AppConnection.GitLab, connectionId, actor);
@@ -93,23 +81,11 @@ export const gitlabConnectionService = (
}
};
- const searchProjects = async (connectionId: string, search: string, actor: OrgServiceActor) => {
- try {
- const appConnection = await getAppConnection(AppConnection.GitLab, connectionId, actor);
- return await searchGitLabProjects(search, { appConnection, appConnectionDAL, kmsService });
- } catch (error) {
- logger.error(error, `Failed to search projects for GitLab connection ${connectionId}`);
- return [];
- }
- };
-
return {
listProjects,
listGroups,
listRootGroups,
listSubgroups,
- listGroupProjects,
- searchGroups,
- searchProjects
+ listGroupProjects
};
};
diff --git a/backend/src/services/app-connection/gitlab/gitlab-connection-types.ts b/backend/src/services/app-connection/gitlab/gitlab-connection-types.ts
index 62048cd510..10d6d8aa59 100644
--- a/backend/src/services/app-connection/gitlab/gitlab-connection-types.ts
+++ b/backend/src/services/app-connection/gitlab/gitlab-connection-types.ts
@@ -52,7 +52,9 @@ export type TGitLabRefreshTokenCredentials = {
export interface TGitLabGroup {
id: string;
+ name: string;
fullName: string;
+ fullPath: string;
}
export type TGitLabGroupTreeItem = {
diff --git a/frontend/src/components/secret-scanning/forms/SecretScanningDataSourceConfigFields/GitLabDataSourceConfigFields.tsx b/frontend/src/components/secret-scanning/forms/SecretScanningDataSourceConfigFields/GitLabDataSourceConfigFields.tsx
index 20c1c6f066..0943b5368f 100644
--- a/frontend/src/components/secret-scanning/forms/SecretScanningDataSourceConfigFields/GitLabDataSourceConfigFields.tsx
+++ b/frontend/src/components/secret-scanning/forms/SecretScanningDataSourceConfigFields/GitLabDataSourceConfigFields.tsx
@@ -38,12 +38,17 @@ export const GitLabDataSourceConfigFields = () => {
const { data: projects, isPending: isProjectsPending } = useGitLabConnectionListProjects(
connectionId,
+ undefined,
{ enabled: Boolean(connectionId) }
);
- const { data: groups, isPending: isGroupsPending } = useGitLabConnectionListGroups(connectionId, {
- enabled: Boolean(connectionId) && scope === GitLabDataSourceScope.Group
- });
+ const { data: groups, isPending: isGroupsPending } = useGitLabConnectionListGroups(
+ connectionId,
+ undefined,
+ {
+ enabled: Boolean(connectionId) && scope === GitLabDataSourceScope.Group
+ }
+ );
const scanMethod =
!includeProjects || includeProjects.includes("*")
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GitLabProjectPicker.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GitLabProjectPicker.tsx
index 1a7590f27c..95a7335452 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GitLabProjectPicker.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GitLabProjectPicker.tsx
@@ -17,11 +17,10 @@ import {
import { cn } from "@app/components/v3/utils";
import {
useGitLabConnectionListGroupProjects,
+ useGitLabConnectionListGroups,
useGitLabConnectionListProjects,
useGitLabConnectionListRootGroups,
- useGitLabConnectionListSubgroups,
- useGitLabConnectionSearchGroups,
- useGitLabConnectionSearchProjects
+ useGitLabConnectionListSubgroups
} from "@app/hooks/api/appConnections/gitlab";
import { useDebounce } from "@app/hooks/useDebounce";
@@ -215,15 +214,15 @@ export const GitLabProjectPicker = ({
enabled: hasConnection
});
- const personalProjectsQuery = useGitLabConnectionListProjects(connectionId, {
+ const personalProjectsQuery = useGitLabConnectionListProjects(connectionId, undefined, {
enabled: hasConnection
});
- const projectSearchQuery = useGitLabConnectionSearchProjects(connectionId, debouncedSearch, {
+ const projectSearchQuery = useGitLabConnectionListProjects(connectionId, debouncedSearch, {
enabled: hasConnection && tab === "groups" && isSearching
});
- const groupNameSearchQuery = useGitLabConnectionSearchGroups(connectionId, debouncedSearch, {
+ const groupNameSearchQuery = useGitLabConnectionListGroups(connectionId, debouncedSearch, {
enabled: hasConnection && tab === "groups" && isSearching
});
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GitLabSyncFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GitLabSyncFields.tsx
index eedd60ea63..6c257b9681 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GitLabSyncFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GitLabSyncFields.tsx
@@ -98,9 +98,13 @@ export const GitLabSyncFields = () => {
const scope = useWatch({ name: "destinationConfig.scope", control });
const shouldMaskSecrets = useWatch({ name: "destinationConfig.shouldMaskSecrets", control });
- const { data: groups, isLoading: isGroupsLoading } = useGitLabConnectionListGroups(connectionId, {
- enabled: Boolean(connectionId) && scope === GitLabSyncScope.Group
- });
+ const { data: groups, isLoading: isGroupsLoading } = useGitLabConnectionListGroups(
+ connectionId,
+ undefined,
+ {
+ enabled: Boolean(connectionId) && scope === GitLabSyncScope.Group
+ }
+ );
return (
<FieldGroup>
diff --git a/frontend/src/hooks/api/appConnections/gitlab/queries.tsx b/frontend/src/hooks/api/appConnections/gitlab/queries.tsx
index e16f7405b7..35217541ed 100644
--- a/frontend/src/hooks/api/appConnections/gitlab/queries.tsx
+++ b/frontend/src/hooks/api/appConnections/gitlab/queries.tsx
@@ -7,16 +7,12 @@ import { TGitLabGroup, TGitLabGroupTreeItem, TGitLabProject } from "./types";
const gitlabConnectionKeys = {
all: [...appConnectionKeys.all, "gitlab"] as const,
- listProjects: (connectionId: string) =>
- [...gitlabConnectionKeys.all, "projects", connectionId] as const,
- listGroups: (connectionId: string) =>
- [...gitlabConnectionKeys.all, "groups", connectionId] as const,
+ listProjects: (connectionId: string, search?: string) =>
+ [...gitlabConnectionKeys.all, "projects", connectionId, search ?? ""] as const,
+ listGroups: (connectionId: string, search?: string) =>
+ [...gitlabConnectionKeys.all, "groups", connectionId, search ?? ""] as const,
listRootGroups: (connectionId: string) =>
[...gitlabConnectionKeys.all, "groups", "root", connectionId] as const,
- searchGroups: (connectionId: string, search: string) =>
- [...gitlabConnectionKeys.all, "search-groups", connectionId, search] as const,
- searchProjects: (connectionId: string, search: string) =>
- [...gitlabConnectionKeys.all, "search-projects", connectionId, search] as const,
listSubgroups: (connectionId: string, groupId: string) =>
[...gitlabConnectionKeys.all, "subgroups", connectionId, groupId] as const,
listGroupProjects: (connectionId: string, groupId: string) =>
@@ -25,6 +21,7 @@ const gitlabConnectionKeys = {
export const useGitLabConnectionListProjects = (
connectionId: string,
+ search?: string,
options?: Omit<
UseQueryOptions<
TGitLabProject[],
@@ -36,10 +33,11 @@ export const useGitLabConnectionListProjects = (
>
) => {
return useQuery({
- queryKey: gitlabConnectionKeys.listProjects(connectionId),
+ queryKey: gitlabConnectionKeys.listProjects(connectionId, search),
queryFn: async () => {
const { data } = await apiRequest.get<TGitLabProject[]>(
- `/api/v1/app-connections/gitlab/${connectionId}/projects`
+ `/api/v1/app-connections/gitlab/${connectionId}/projects`,
+ { params: search ? { search } : undefined }
);
return data;
@@ -50,6 +48,7 @@ export const useGitLabConnectionListProjects = (
export const useGitLabConnectionListGroups = (
connectionId: string,
+ search?: string,
options?: Omit<
UseQueryOptions<
TGitLabGroup[],
@@ -61,10 +60,11 @@ export const useGitLabConnectionListGroups = (
>
) => {
return useQuery({
- queryKey: gitlabConnectionKeys.listGroups(connectionId),
+ queryKey: gitlabConnectionKeys.listGroups(connectionId, search),
queryFn: async () => {
const { data } = await apiRequest.get<TGitLabGroup[]>(
- `/api/v1/app-connections/gitlab/${connectionId}/groups`
+ `/api/v1/app-connections/gitlab/${connectionId}/groups`,
+ { params: search ? { search } : undefined }
);
return data;
@@ -98,58 +98,6 @@ export const useGitLabConnectionListRootGroups = (
});
};
-export const useGitLabConnectionSearchGroups = (
- connectionId: string,
- search: string,
- options?: Omit<
- UseQueryOptions<
- TGitLabGroupTreeItem[],
- unknown,
- TGitLabGroupTreeItem[],
- ReturnType<typeof gitlabConnectionKeys.searchGroups>
- >,
- "queryKey" | "queryFn"
- >
-) => {
- return useQuery({
- queryKey: gitlabConnectionKeys.searchGroups(connectionId, search),
- queryFn: async () => {
- const { data } = await apiRequest.get<TGitLabGroupTreeItem[]>(
- `/api/v1/app-connections/gitlab/${connectionId}/search-groups?search=${encodeURIComponent(search)}`
- );
-
- return data;
- },
- ...options
- });
-};
-
-export const useGitLabConnectionSearchProjects = (
- connectionId: string,
- search: string,
- options?: Omit<
- UseQueryOptions<
- TGitLabGroupTreeItem[],
- unknown,
- TGitLabGroupTreeItem[],
- ReturnType<typeof gitlabConnectionKeys.searchProjects>
- >,
- "queryKey" | "queryFn"
- >
-) => {
- return useQuery({
- queryKey: gitlabConnectionKeys.searchProjects(connectionId, search),
- queryFn: async () => {
- const { data } = await apiRequest.get<TGitLabGroupTreeItem[]>(
- `/api/v1/app-connections/gitlab/${connectionId}/search-projects?search=${encodeURIComponent(search)}`
- );
-
- return data;
- },
- ...options
- });
-};
-
export const useGitLabConnectionListSubgroups = (
connectionId: string,
groupId: string,
diff --git a/frontend/src/hooks/api/appConnections/gitlab/types.ts b/frontend/src/hooks/api/appConnections/gitlab/types.ts
index 25e6de00b1..e67fb2b93c 100644
--- a/frontend/src/hooks/api/appConnections/gitlab/types.ts
+++ b/frontend/src/hooks/api/appConnections/gitlab/types.ts
@@ -5,7 +5,9 @@ export type TGitLabProject = {
export type TGitLabGroup = {
id: string;
+ name: string;
fullName: string;
+ fullPath: string;
};
export type TGitLabGroupTreeItem = {