mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-04 17:26:19 +00:00
Merge pull request #2566 from Infisical/feat/github-integration-app-auth
feat: github integration with Github app auth
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
UpdateSecretCommand
|
||||
} from "@aws-sdk/client-secrets-manager";
|
||||
import { AssumeRoleCommand, STSClient } from "@aws-sdk/client-sts";
|
||||
import { createAppAuth } from "@octokit/auth-app";
|
||||
import { Octokit } from "@octokit/rest";
|
||||
import AWS, { AWSError } from "aws-sdk";
|
||||
import { AxiosError } from "axios";
|
||||
@@ -36,6 +37,7 @@ import { TCreateManySecretsRawFn, TUpdateManySecretsRawFn } from "@app/services/
|
||||
|
||||
import { TIntegrationDALFactory } from "../integration/integration-dal";
|
||||
import { IntegrationMetadataSchema } from "../integration/integration-schema";
|
||||
import { IntegrationAuthMetadataSchema } from "./integration-auth-schema";
|
||||
import { TIntegrationsWithEnvironment } from "./integration-auth-types";
|
||||
import {
|
||||
IntegrationInitialSyncBehavior,
|
||||
@@ -1542,11 +1544,13 @@ const syncSecretsNetlify = async ({
|
||||
*/
|
||||
const syncSecretsGitHub = async ({
|
||||
integration,
|
||||
integrationAuth,
|
||||
secrets,
|
||||
accessToken,
|
||||
appendices
|
||||
}: {
|
||||
integration: TIntegrations;
|
||||
integrationAuth: TIntegrationAuths;
|
||||
secrets: Record<string, { value: string; comment?: string }>;
|
||||
accessToken: string;
|
||||
appendices?: { prefix: string; suffix: string };
|
||||
@@ -1568,9 +1572,24 @@ const syncSecretsGitHub = async ({
|
||||
selected_repositories_url?: string | undefined;
|
||||
}
|
||||
|
||||
const octokit = new Octokit({
|
||||
auth: accessToken
|
||||
});
|
||||
const authMetadata = IntegrationAuthMetadataSchema.parse(integrationAuth.metadata || {});
|
||||
let octokit: Octokit;
|
||||
const appCfg = getConfig();
|
||||
|
||||
if (authMetadata.installationId) {
|
||||
octokit = new Octokit({
|
||||
authStrategy: createAppAuth,
|
||||
auth: {
|
||||
appId: appCfg.CLIENT_APP_ID_GITHUB_APP,
|
||||
privateKey: appCfg.CLIENT_PRIVATE_KEY_GITHUB_APP,
|
||||
installationId: authMetadata.installationId
|
||||
}
|
||||
});
|
||||
} else {
|
||||
octokit = new Octokit({
|
||||
auth: accessToken
|
||||
});
|
||||
}
|
||||
|
||||
enum GithubScope {
|
||||
Repo = "github-repo",
|
||||
@@ -4069,6 +4088,7 @@ export const syncIntegrationSecrets = async ({
|
||||
case Integrations.GITHUB:
|
||||
await syncSecretsGitHub({
|
||||
integration,
|
||||
integrationAuth,
|
||||
secrets,
|
||||
accessToken,
|
||||
appendices
|
||||
|
||||
Reference in New Issue
Block a user