Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
refactor gitlab connection fns to use getNavigationClient
adilsonaea9019f860a
diff --git a/backend/src/services/app-connection/gitlab/gitlab-connection-fns.ts b/backend/src/services/app-connection/gitlab/gitlab-connection-fns.tsindex d26fc167fe..2b655b2d79 100644--- a/backend/src/services/app-connection/gitlab/gitlab-connection-fns.ts+++ b/backend/src/services/app-connection/gitlab/gitlab-connection-fns.ts@@ -146,6 +146,39 @@ export const refreshGitLabToken = async (}};+const getNavigationClient = async ({ appConnection, appConnectionDAL, kmsService }: TNavigationParams) => {+ let { accessToken } = appConnection.credentials;++ if (+ appConnection.method === GitLabConnectionMethod.AccessToken &&+ appConnection.credentials.accessTokenType === GitLabAccessTokenType.Project+ ) {+ return null;+ }++ if (+ appConnection.method === GitLabConnectionMethod.OAuth &&+ appConnection.credentials.refreshToken &&+ new Date(appConnection.credentials.expiresAt) < new Date()+ ) {+ accessToken = await refreshGitLabToken(+ appConnection.credentials.refreshToken,+ appConnection.id,+ appConnection.orgId,+ appConnection.projectId,+ appConnectionDAL,+ kmsService,+ appConnection.credentials.instanceUrl+ );+ }++ return getGitLabClient(+ accessToken,+ appConnection.credentials.instanceUrl,+ appConnection.method === GitLabConnectionMethod.OAuth+ );+};+export const exchangeGitLabOAuthCode = async (code: string,instanceUrl?: string@@ -358,38 +391,10 @@ export const listGitLabGroups = async ({appConnectionDAL: Pick<TAppConnectionDALFactory, "updateById">;kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;}): Promise<TGitLabGroup[]> => {- let { accessToken } = appConnection.credentials;-- if (- appConnection.method === GitLabConnectionMethod.AccessToken &&- appConnection.credentials.accessTokenType === GitLabAccessTokenType.Project- ) {- return [];- }-- if (- appConnection.method === GitLabConnectionMethod.OAuth &&- appConnection.credentials.refreshToken &&- new Date(appConnection.credentials.expiresAt) < new Date()- ) {- accessToken = await refreshGitLabToken(- appConnection.credentials.refreshToken,- appConnection.id,- appConnection.orgId,- appConnection.projectId,- appConnectionDAL,- kmsService,- appConnection.credentials.instanceUrl- );- }+ const client = await getNavigationClient({ appConnection, appConnectionDAL, kmsService });+ if (!client) return [];try {- const client = await getGitLabClient(- accessToken,- appConnection.credentials.instanceUrl,- appConnection.method === GitLabConnectionMethod.OAuth- );-const groups = await client.Groups.all({orderBy: "name",sort: "asc",@@ -417,39 +422,6 @@ export const listGitLabGroups = async ({}};-const getNavigationClient = async ({ appConnection, appConnectionDAL, kmsService }: TNavigationParams) => {- let { accessToken } = appConnection.credentials;-- if (- appConnection.method === GitLabConnectionMethod.AccessToken &&- appConnection.credentials.accessTokenType === GitLabAccessTokenType.Project- ) {- return null;- }-- if (- appConnection.method === GitLabConnectionMethod.OAuth &&- appConnection.credentials.refreshToken &&- new Date(appConnection.credentials.expiresAt) < new Date()- ) {- accessToken = await refreshGitLabToken(- appConnection.credentials.refreshToken,- appConnection.id,- appConnection.orgId,- appConnection.projectId,- appConnectionDAL,- kmsService,- appConnection.credentials.instanceUrl- );- }-- return getGitLabClient(- accessToken,- appConnection.credentials.instanceUrl,- appConnection.method === GitLabConnectionMethod.OAuth- );-};-export const listGitLabRootGroups = async (params: TNavigationParams): Promise<TGitLabGroupTreeItem[]> => {const client = await getNavigationClient(params);if (!client) return [];diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GitLabProjectPicker.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GitLabProjectPicker.tsxindex 87ea111533..04273e2bed 100644--- a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GitLabProjectPicker.tsx+++ b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GitLabProjectPicker.tsx@@ -18,8 +18,8 @@ import {useGitLabConnectionListProjects,useGitLabConnectionListRootGroups,useGitLabConnectionListSubgroups,- useGitLabConnectionSearchGroupsAndProjects,- useGitLabConnectionSearchGroups+ useGitLabConnectionSearchGroups,+ useGitLabConnectionSearchGroupsAndProjects} from "@app/hooks/api/appConnections/gitlab";import { useDebounce } from "@app/hooks/useDebounce";@@ -650,19 +650,6 @@ export const GitLabProjectPicker = ({</div>)}</div>-- {/* <div className="flex flex-wrap items-center justify-between gap-2 text-xs text-muted">- <span className="inline-flex items-center gap-1.5">- {tab === "yours"- ? "Projects owned directly by your GitLab user."- : "Browse groups, then pick a project."}- </span>- {selectedProjectId && selectedProjectName && (- <Badge variant="project" className="font-mono">- <span className="truncate">{selectedProjectName}</span>- </Badge>- )}- </div> */}</div>);};