From e4e83fcff05289b1b789323fcadc3f19ac0527e2 Mon Sep 17 00:00:00 2001 From: Daniel Young Lee Date: Wed, 6 Dec 2023 13:14:23 +0900 Subject: [PATCH 1/4] Update use of log to be consistent in framework init. --- src/init/features/frameworks/index.ts | 24 +++++++++--------------- src/init/features/frameworks/repo.ts | 9 +++++---- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/init/features/frameworks/index.ts b/src/init/features/frameworks/index.ts index c3749671b31..21ae156425a 100644 --- a/src/init/features/frameworks/index.ts +++ b/src/init/features/frameworks/index.ts @@ -1,14 +1,13 @@ import * as clc from "colorette"; -import * as utils from "../../../utils"; import * as repo from "./repo"; import * as poller from "../../../operation-poller"; import * as gcp from "../../../gcp/frameworks"; +import { logBullet, logSuccess } from "../../../utils"; import { frameworksOrigin } from "../../../api"; import { Backend, BackendOutputOnlyFields } from "../../../gcp/frameworks"; import { Repository } from "../../../gcp/cloudbuild"; import { API_VERSION } from "../../../gcp/frameworks"; import { FirebaseError } from "../../../error"; -import { logger } from "../../../logger"; import { promptOnce } from "../../../prompt"; import { DEFAULT_REGION, ALLOWED_REGIONS } from "./constants"; @@ -25,7 +24,7 @@ const frameworksPollerOptions: Omit { setup.frameworks = {}; - utils.logBullet("First we need a few details to create your backend."); + logBullet("First we need a few details to create your backend."); await promptOnce( { @@ -50,20 +49,16 @@ export async function doSetup(setup: any, projectId: string): Promise { setup.frameworks ); - utils.logSuccess(`Region set to ${setup.frameworks.region}.`); + logSuccess(`Region set to ${setup.frameworks.region}.\n`); const backend: Backend | undefined = await getOrCreateBackend(projectId, setup); if (backend) { - logger.info(); - utils.logSuccess(`Successfully created backend:\n ${backend.name}`); - logger.info(); - utils.logSuccess(`Your site is being deployed at:\n https://${backend.uri}`); - logger.info(); - utils.logSuccess( - `View the rollout status by running:\n firebase backends:get --backend=${backend.name}` + logSuccess(`Successfully created backend:\n ${backend.name}`); + logSuccess(`Your site is being deployed at:\n https://${backend.uri}\n`); + logSuccess( + `View the rollout status by running:\n firebase backends:get --backend=${backend.name}\n` ); - logger.info(); } } @@ -91,7 +86,6 @@ export async function getOrCreateBackend( } catch (err: unknown) { if ((err as FirebaseError).status === 404) { const cloudBuildConnRepo = await repo.linkGitHubRepository(projectId, location); - logger.info(); await promptOnce( { name: "branchName", @@ -102,7 +96,7 @@ export async function getOrCreateBackend( setup.frameworks ); const backendDetails = toBackend(cloudBuildConnRepo); - logger.info(clc.bold(`\n${clc.white("===")} Creating your backend`)); + logBullet(clc.bold(`${clc.white("===")} Creating your backend`)); return await createBackend(projectId, location, backendDetails, setup.frameworks.serviceName); } else { throw new FirebaseError( @@ -133,7 +127,7 @@ async function getExistingBackend( setup.frameworks ); if (setup.frameworks.existingBackend) { - logger.info("Using the existing backend."); + logBullet("Using the existing backend."); return backend; } await promptOnce( diff --git a/src/init/features/frameworks/repo.ts b/src/init/features/frameworks/repo.ts index 288dcd05b37..1db075bcc62 100644 --- a/src/init/features/frameworks/repo.ts +++ b/src/init/features/frameworks/repo.ts @@ -80,7 +80,7 @@ export async function linkGitHubRepository( projectId: string, location: string ): Promise { - logger.info(clc.bold(`\n${clc.yellow("===")} Connect a GitHub repository`)); + utils.logBullet(clc.bold(`${clc.yellow("===")} Connect a GitHub repository`)); const existingConns = await listFrameworksConnections(projectId); if (existingConns.length < 1) { const grantSuccess = await promptSecretManagerAdminGrant(projectId); @@ -165,7 +165,7 @@ async function promptRepositoryUri( async function promptSecretManagerAdminGrant(projectId: string): Promise { const projectNumber = await getProjectNumber({ projectId }); const cbsaEmail = gcb.serviceAgentEmail(projectNumber); - logger.info( + utils.logBullet( "To create a new GitHub connection, Secret Manager Admin role (roles/secretmanager.admin) is required on the Cloud Build Service Agent." ); const grant = await promptOnce({ @@ -173,8 +173,9 @@ async function promptSecretManagerAdminGrant(projectId: string): Promise Date: Wed, 6 Dec 2023 17:22:43 +0900 Subject: [PATCH 2/4] More consitent use of logger. --- src/init/features/frameworks/repo.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/init/features/frameworks/repo.ts b/src/init/features/frameworks/repo.ts index 1db075bcc62..989337c58a8 100644 --- a/src/init/features/frameworks/repo.ts +++ b/src/init/features/frameworks/repo.ts @@ -6,7 +6,6 @@ import * as poller from "../../../operation-poller"; import * as utils from "../../../utils"; import { cloudbuildOrigin } from "../../../api"; import { FirebaseError } from "../../../error"; -import { logger } from "../../../logger"; import { promptOnce } from "../../../prompt"; import { getProjectNumber } from "../../../getProjectNumber"; @@ -124,7 +123,6 @@ export async function linkGitHubRepository( appInstallationId: connection.githubConfig?.appInstallationId, }); const repo = await getOrCreateRepository(projectId, location, connectionId, remoteUri); - logger.info(); utils.logSuccess(`Successfully linked GitHub repository at remote URI:\n ${remoteUri}`); return repo; } @@ -188,15 +186,13 @@ async function promptSecretManagerAdminGrant(projectId: string): Promise { - logger.info("You must authorize the Cloud Build GitHub app."); - logger.info(); - logger.info("Sign in to GitHub and authorize Cloud Build GitHub app:"); + utils.logBullet("You must authorize the Cloud Build GitHub app.\n"); + utils.logBullet("Sign in to GitHub and authorize Cloud Build GitHub app:"); const { url, cleanup } = await utils.openInBrowserPopup( conn.installationState.actionUri, "Authorize the GitHub app" ); - logger.info(`\t${url}`); - logger.info(); + utils.logBullet(`\t${url}\n`); await promptOnce({ type: "input", message: "Press Enter once you have authorized the app", @@ -207,9 +203,9 @@ async function promptConnectionAuth(conn: gcb.Connection): Promise { - logger.info("Now, install the Cloud Build GitHub app:"); + utils.logBullet("Now, install the Cloud Build GitHub app:"); const targetUri = conn.installationState.actionUri.replace("install_v2", "direct_install_v2"); - logger.info(targetUri); + utils.logBullet(targetUri); await utils.openInBrowser(targetUri); await promptOnce({ type: "input", From cd5bd608fa3d3afa46c181bdbb36996e7e788ed2 Mon Sep 17 00:00:00 2001 From: Daniel Young Lee Date: Wed, 6 Dec 2023 17:30:35 +0900 Subject: [PATCH 3/4] Missed a spot. --- src/init/features/frameworks/repo.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/init/features/frameworks/repo.ts b/src/init/features/frameworks/repo.ts index 989337c58a8..c792a6e1793 100644 --- a/src/init/features/frameworks/repo.ts +++ b/src/init/features/frameworks/repo.ts @@ -163,6 +163,17 @@ async function promptRepositoryUri( async function promptSecretManagerAdminGrant(projectId: string): Promise { const projectNumber = await getProjectNumber({ projectId }); const cbsaEmail = gcb.serviceAgentEmail(projectNumber); + + const alreadyGranted = await rm.serviceAccountHasRoles( + projectId, + cbsaEmail, + ["roles/secretmanager.admin"], + true + ); + if (alreadyGranted) { + return true; + } + utils.logBullet( "To create a new GitHub connection, Secret Manager Admin role (roles/secretmanager.admin) is required on the Cloud Build Service Agent." ); @@ -205,7 +216,7 @@ async function promptConnectionAuth(conn: gcb.Connection): Promise { utils.logBullet("Now, install the Cloud Build GitHub app:"); const targetUri = conn.installationState.actionUri.replace("install_v2", "direct_install_v2"); - utils.logBullet(targetUri); + utils.logBullet(`\t${targetUri}`); await utils.openInBrowser(targetUri); await promptOnce({ type: "input", From eeccd95bb10fb18357e6cce0de7845395fa23c5e Mon Sep 17 00:00:00 2001 From: Daniel Young Lee Date: Wed, 6 Dec 2023 17:42:10 +0900 Subject: [PATCH 4/4] Finishing touches on the logged messages. --- src/init/features/frameworks/index.ts | 7 +++---- src/init/features/frameworks/repo.ts | 13 +++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/init/features/frameworks/index.ts b/src/init/features/frameworks/index.ts index 21ae156425a..1a42ae475d0 100644 --- a/src/init/features/frameworks/index.ts +++ b/src/init/features/frameworks/index.ts @@ -54,10 +54,10 @@ export async function doSetup(setup: any, projectId: string): Promise { const backend: Backend | undefined = await getOrCreateBackend(projectId, setup); if (backend) { - logSuccess(`Successfully created backend:\n ${backend.name}`); - logSuccess(`Your site is being deployed at:\n https://${backend.uri}\n`); + logSuccess(`Successfully created backend:\n\t${backend.name}`); + logSuccess(`Your site is being deployed at:\n\thttps://${backend.uri}`); logSuccess( - `View the rollout status by running:\n firebase backends:get --backend=${backend.name}\n` + `View the rollout status by running:\n\tfirebase backends:get --backend=${backend.name}` ); } } @@ -96,7 +96,6 @@ export async function getOrCreateBackend( setup.frameworks ); const backendDetails = toBackend(cloudBuildConnRepo); - logBullet(clc.bold(`${clc.white("===")} Creating your backend`)); return await createBackend(projectId, location, backendDetails, setup.frameworks.serviceName); } else { throw new FirebaseError( diff --git a/src/init/features/frameworks/repo.ts b/src/init/features/frameworks/repo.ts index c792a6e1793..8cc346c418c 100644 --- a/src/init/features/frameworks/repo.ts +++ b/src/init/features/frameworks/repo.ts @@ -79,7 +79,7 @@ export async function linkGitHubRepository( projectId: string, location: string ): Promise { - utils.logBullet(clc.bold(`${clc.yellow("===")} Connect a GitHub repository`)); + utils.logBullet(clc.bold(`${clc.yellow("===")} Set up a GitHub connection`)); const existingConns = await listFrameworksConnections(projectId); if (existingConns.length < 1) { const grantSuccess = await promptSecretManagerAdminGrant(projectId); @@ -123,7 +123,8 @@ export async function linkGitHubRepository( appInstallationId: connection.githubConfig?.appInstallationId, }); const repo = await getOrCreateRepository(projectId, location, connectionId, remoteUri); - utils.logSuccess(`Successfully linked GitHub repository at remote URI:\n ${remoteUri}`); + utils.logSuccess(`Successfully linked GitHub repository at remote URI`); + utils.logSuccess(`\t${remoteUri}`); return repo; } @@ -197,13 +198,13 @@ async function promptSecretManagerAdminGrant(projectId: string): Promise { - utils.logBullet("You must authorize the Cloud Build GitHub app.\n"); + utils.logBullet("You must authorize the Cloud Build GitHub app."); utils.logBullet("Sign in to GitHub and authorize Cloud Build GitHub app:"); const { url, cleanup } = await utils.openInBrowserPopup( conn.installationState.actionUri, "Authorize the GitHub app" ); - utils.logBullet(`\t${url}\n`); + utils.logBullet(`\t${url}`); await promptOnce({ type: "input", message: "Press Enter once you have authorized the app", @@ -214,9 +215,9 @@ async function promptConnectionAuth(conn: gcb.Connection): Promise { - utils.logBullet("Now, install the Cloud Build GitHub app:"); + utils.logBullet("Install the Cloud Build GitHub app to enable access to GitHub repositories"); const targetUri = conn.installationState.actionUri.replace("install_v2", "direct_install_v2"); - utils.logBullet(`\t${targetUri}`); + utils.logBullet(targetUri); await utils.openInBrowser(targetUri); await promptOnce({ type: "input",