Skip to content

Commit

Permalink
Update use of log to be consistent in framework init.
Browse files Browse the repository at this point in the history
  • Loading branch information
taeold committed Dec 6, 2023
1 parent ebea9c3 commit 471e32c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
24 changes: 9 additions & 15 deletions src/init/features/frameworks/index.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -25,7 +24,7 @@ const frameworksPollerOptions: Omit<poller.OperationPollerOptions, "operationRes
export async function doSetup(setup: any, projectId: string): Promise<void> {

Check warning on line 24 in src/init/features/frameworks/index.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unexpected any. Specify a different type
setup.frameworks = {};

Check warning on line 25 in src/init/features/frameworks/index.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .frameworks on an `any` value

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(
{
Expand All @@ -50,20 +49,16 @@ export async function doSetup(setup: any, projectId: string): Promise<void> {
setup.frameworks

Check warning on line 49 in src/init/features/frameworks/index.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe argument of type `any` assigned to a parameter of type `Options | undefined`

Check warning on line 49 in src/init/features/frameworks/index.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .frameworks on an `any` value
);

utils.logSuccess(`Region set to ${setup.frameworks.region}.`);
logSuccess(`Region set to ${setup.frameworks.region}.\n`);

Check warning on line 52 in src/init/features/frameworks/index.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Invalid type "any" of template literal expression

Check warning on line 52 in src/init/features/frameworks/index.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .frameworks on an `any` value

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();
}
}

Expand All @@ -90,7 +85,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",
Expand All @@ -101,7 +95,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(
Expand Down Expand Up @@ -132,7 +126,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(
Expand Down
9 changes: 5 additions & 4 deletions src/init/features/frameworks/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function linkGitHubRepository(
projectId: string,
location: string
): Promise<gcb.Repository> {
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);
Expand Down Expand Up @@ -165,24 +165,25 @@ async function promptRepositoryUri(
async function promptSecretManagerAdminGrant(projectId: string): Promise<Boolean> {
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({
type: "confirm",
message: "Grant the required role to the Cloud Build Service Agent?",
});
if (!grant) {
logger.info(
utils.logBullet(
"You, or your project administrator, should run the following command to grant the required role:\n\n" +
"You, or your project adminstrator, can run the following command to grant the required role manually:\n\n" +
`\tgcloud projects add-iam-policy-binding ${projectId} \\\n` +
`\t --member="serviceAccount:${cbsaEmail} \\\n` +
`\t --role="roles/secretmanager.admin\n`
);
return false;
}
await rm.addServiceAccountToRoles(projectId, cbsaEmail, ["roles/secretmanager.admin"], true);
logger.info("Successfully granted the required role to the Cloud Build Service Agent!");
utils.logSuccess("Successfully granted the required role to the Cloud Build Service Agent!");
return true;
}

Expand Down

0 comments on commit 471e32c

Please sign in to comment.