diff --git a/backend/src/services/app-connection/github/github-connection-fns.ts b/backend/src/services/app-connection/github/github-connection-fns.ts index 5f4057bd2..b86e2ed65 100644 --- a/backend/src/services/app-connection/github/github-connection-fns.ts +++ b/backend/src/services/app-connection/github/github-connection-fns.ts @@ -116,6 +116,18 @@ export const getGitHubAppAuthToken = async (appConnection: TGitHubConnection) => return token; }; +function extractNextPageUrl(linkHeader: string | undefined): string | null { + if (!linkHeader) return null; + + const links = linkHeader.split(","); + const nextLink = links.find((link) => link.includes('rel="next"')); + + if (!nextLink) return null; + + const match = new RE2(/<([^>]+)>/).exec(nextLink); + return match ? match[1] : null; +} + export const makePaginatedGitHubRequest = async ( appConnection: TGitHubConnection, gatewayService: Pick, @@ -128,8 +140,9 @@ export const makePaginatedGitHubRequest = async ( method === GitHubConnectionMethod.OAuth ? credentials.accessToken : await getGitHubAppAuthToken(appConnection); let url: string | null = `https://api.${credentials.host || "github.com"}${path}`; let results: T[] = []; + let i = 0; - while (url) { + while (url && i < 1000) { // eslint-disable-next-line no-await-in-loop const response: AxiosResponse = await requestWithGitHubGateway(appConnection, gatewayService, { url, @@ -144,14 +157,8 @@ export const makePaginatedGitHubRequest = async ( const items = dataMapper ? dataMapper(response.data) : (response.data as unknown as T[]); results = results.concat(items); - const linkHeader = response.headers.link as string | undefined; - const nextLink = - typeof linkHeader === "string" ? linkHeader.split(",").find((s) => s.includes('rel="next"')) : undefined; - if (nextLink) { - url = new RE2(/<(.+)>/).exec(nextLink)?.[1] || null; - } else { - url = null; - } + url = extractNextPageUrl(response.headers.link as string | undefined); + i += 1; } return results; diff --git a/backend/src/services/secret-sync/github/github-sync-fns.ts b/backend/src/services/secret-sync/github/github-sync-fns.ts index 580d77bca..022490da6 100644 --- a/backend/src/services/secret-sync/github/github-sync-fns.ts +++ b/backend/src/services/secret-sync/github/github-sync-fns.ts @@ -171,9 +171,11 @@ const putSecret = async ( export const GithubSyncFns = { syncSecrets: async ( secretSync: TGitHubSyncWithCredentials, - secretMap: TSecretMap, + ogSecretMap: TSecretMap, gatewayService: Pick ) => { + const secretMap = Object.fromEntries(Object.entries(ogSecretMap).map(([i, v]) => [i.toUpperCase(), v])); + switch (secretSync.destinationConfig.scope) { case GitHubSyncScope.Organization: if (Object.values(secretMap).length > 1000) { @@ -252,9 +254,11 @@ export const GithubSyncFns = { }, removeSecrets: async ( secretSync: TGitHubSyncWithCredentials, - secretMap: TSecretMap, + ogSecretMap: TSecretMap, gatewayService: Pick ) => { + const secretMap = Object.fromEntries(Object.entries(ogSecretMap).map(([i, v]) => [i.toUpperCase(), v])); + const { connection } = secretSync; const token = connection.method === GitHubConnectionMethod.OAuth diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx index 4f2cffd44..eb93993af 100644 --- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx +++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx @@ -20,6 +20,7 @@ import { SelectItem, Tooltip } from "@app/components/v2"; +import { useSubscription } from "@app/context"; import { OrgGatewayPermissionActions, OrgPermissionSubjects @@ -80,6 +81,7 @@ export const GitHubConnectionForm = ({ appConnection }: Props) => { formState: { isSubmitting, isDirty } } = form; + const { subscription } = useSubscription(); const { data: gateways, isPending: isGatewaysLoading } = useQuery(gatewaysQueryKeys.list()); const selectedMethod = watch("method"); @@ -173,80 +175,81 @@ export const GitHubConnectionForm = ({ appConnection }: Props) => { )} /> - - - -
GitHub Enterprise Options
-
- - - {(isAllowed) => ( - ( - - + + +
GitHub Enterprise Options
+
+ + + {(isAllowed) => ( + ( + -
- - Internet Gateway - - {gateways?.map((el) => ( - - {el.name} + onChange(undefined)} + > + Internet Gateway - ))} - -
-
-
- )} - /> - )} -
- ( - - - - )} - /> -
-
-
- + {gateways?.map((el) => ( + + {el.name} + + ))} + + + + + )} + /> + )} + + ( + + + + )} + /> + + + + )}
+ + + )} + /> + )} + + )} { formState: { isSubmitting, isDirty } } = form; + const { subscription } = useSubscription(); const isPlatformManagedCredentials = appConnection?.isPlatformManagedCredentials ?? false; const { data: gateways, isPending: isGatewaysLoading } = useQuery(gatewaysQueryKeys.list()); @@ -96,55 +98,57 @@ export const MySqlConnectionForm = ({ appConnection, onSubmit }: Props) => { }} > {!isUpdate && } - - {(isAllowed) => ( - ( - - + {(isAllowed) => ( + ( + -
- - Internet Gateway - - {gateways?.map((el) => ( - - {el.name} + onChange(undefined)} + > + Internet Gateway - ))} - -
-
-
- )} - /> - )} -
+ {gateways?.map((el) => ( + + {el.name} + + ))} + + + + + )} + /> + )} + + )} { formState: { isSubmitting, isDirty } } = form; + const { subscription } = useSubscription(); const isPlatformManagedCredentials = appConnection?.isPlatformManagedCredentials ?? false; const { data: gateways, isPending: isGatewaysLoading } = useQuery(gatewaysQueryKeys.list()); @@ -96,55 +98,57 @@ export const OracleDBConnectionForm = ({ appConnection, onSubmit }: Props) => { }} > {!isUpdate && } - - {(isAllowed) => ( - ( - - + {(isAllowed) => ( + ( + -
- - Internet Gateway - - {gateways?.map((el) => ( - - {el.name} + onChange(undefined)} + > + Internet Gateway - ))} - -
-
-
- )} - /> - )} -
+ {gateways?.map((el) => ( + + {el.name} + + ))} + + + + + )} + /> + )} + + )} { formState: { isSubmitting, isDirty } } = form; + const { subscription } = useSubscription(); const isPlatformManagedCredentials = appConnection?.isPlatformManagedCredentials ?? false; const { data: gateways, isPending: isGatewaysLoading } = useQuery(gatewaysQueryKeys.list()); @@ -96,55 +98,57 @@ export const PostgresConnectionForm = ({ appConnection, onSubmit }: Props) => { }} > {!isUpdate && } - - {(isAllowed) => ( - ( - - + {(isAllowed) => ( + ( + -
- - Internet Gateway - - {gateways?.map((el) => ( - - {el.name} + onChange(undefined)} + > + Internet Gateway - ))} - -
-
-
- )} - /> - )} -
+ {gateways?.map((el) => ( + + {el.name} + + ))} + + + + + )} + /> + )} + + )}