Skip to content

Commit

Permalink
only ensureSecretManagerAdminGrant when creating an oauth token
Browse files Browse the repository at this point in the history
  • Loading branch information
mathu97 committed Mar 25, 2024
1 parent 4e096b5 commit 4baff20
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/init/features/apphosting/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export async function linkGitHubRepository(
): Promise<gcb.Repository> {
utils.logBullet(clc.bold(`${clc.yellow("===")} Set up a GitHub connection`));
// Fetch the sentinel Oauth connection first which is needed to create further GitHub connections.
await ensureSecretManagerAdminGrant(projectId);
const oauthConn = await getOrCreateOauthConnection(projectId, location);
const existingConns = await listAppHostingConnections(projectId);

Expand Down Expand Up @@ -174,7 +173,20 @@ async function getOrCreateOauthConnection(
projectId: string,
location: string,
): Promise<gcb.Connection> {
let conn = await getOrCreateConnection(projectId, location, APPHOSTING_OAUTH_CONN_NAME);
let conn: gcb.Connection;
try {
conn = await gcb.getConnection(projectId, location, APPHOSTING_OAUTH_CONN_NAME);
} catch (err: unknown) {
if ((err as any).status === 404) {

Check warning on line 180 in src/init/features/apphosting/repo.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .status on an `any` value

Check warning on line 180 in src/init/features/apphosting/repo.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
// Cloud build P4SA requires the secret manager admin role.
// This is only required when creating an Oauth connection.
await ensureSecretManagerAdminGrant(projectId);
conn = await createConnection(projectId, location, APPHOSTING_OAUTH_CONN_NAME);
} else {
throw err;
}
}

while (conn.installationState.stage === "PENDING_USER_OAUTH") {
utils.logBullet("You must authorize the Cloud Build GitHub app.");
utils.logBullet("Sign in to GitHub and authorize Cloud Build GitHub app:");
Expand Down

0 comments on commit 4baff20

Please sign in to comment.