Skip to content

Commit

Permalink
Move some of dialog to log rather than prompt to unbold (#6950)
Browse files Browse the repository at this point in the history
  • Loading branch information
inlined authored Apr 2, 2024
1 parent fbbffd7 commit 4743344
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
13 changes: 8 additions & 5 deletions src/apphosting/secrets/dialogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,17 @@ export async function selectBackendServiceAccounts(
const metadata: BackendMetadata[] = toMetadata(projectNumber, listBackends.backends);

if (metadata.every(matchesServiceAccounts(metadata[0]))) {
utils.logLabeledBullet(
"apphosting",
"To use this secret, your backend's service account must have secret accessor permission. All of your backends use " +
(sameServiceAccount(metadata[0]) ? "service account " : "service accounts ") +
serviceAccountDisplay(metadata[0]) +
". Granting access to one backend will grant access to all backends.",
);
const grant = await prompt.confirm({
nonInteractive: options.nonInteractive,
default: true,
message:
"To use this secret, your backend's service account must have secret accessor permission. All of your backends use " +
(sameServiceAccount(metadata[0]) ? "service account " : "service accounts ") +
serviceAccountDisplay(metadata[0]) +
". Granting access to one backend will grant access to all backends. Would you like to grant it now?",
message: "Would you like to grant it now?",
});
if (grant) {
return selectFromMetadata(metadata, [
Expand Down
48 changes: 30 additions & 18 deletions src/test/apphosting/secrets/dialogs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,18 @@ describe("dialogs", () => {
dialogs.selectBackendServiceAccounts("number", "id", {}),
).to.eventually.deep.equal(secrets.toMulti(accounts));

expect(utils.logLabeledBullet).to.have.been.calledWith(
"apphosting",
"To use this secret, your backend's service account must have secret accessor permission. " +
`All of your backends use service accounts ${dialogs.serviceAccountDisplay(accounts)}. ` +
"Granting access to one backend will grant access to all backends.",
);
expect(prompt.confirm).to.have.been.calledWith({
nonInteractive: undefined,
default: true,
message:
"To use this secret, your backend's service account must have secret accessor permission. " +
`All of your backends use service accounts ${dialogs.serviceAccountDisplay(accounts)}. ` +
"Granting access to one backend will grant access to all backends. Would you like to grant it now?",
message: "Would you like to grant it now?",
});
expect(utils.logLabeledBullet).to.not.have.been.called;
expect(utils.logLabeledBullet).to.have.been.calledOnce;
});

it("handles multiple backends with the same (multiple) SAs (opt no)", async () => {
Expand All @@ -258,13 +261,16 @@ describe("dialogs", () => {
dialogs.selectBackendServiceAccounts("number", "id", {}),
).to.eventually.deep.equal(emptyMulti);

expect(utils.logLabeledBullet).to.have.been.calledWith(
"apphosting",
"To use this secret, your backend's service account must have secret accessor permission. " +
`All of your backends use service accounts ${dialogs.serviceAccountDisplay(legacyAccounts)}. ` +
"Granting access to one backend will grant access to all backends.",
);
expect(prompt.confirm).to.have.been.calledWith({
nonInteractive: undefined,
default: true,
message:
"To use this secret, your backend's service account must have secret accessor permission. " +
`All of your backends use service accounts ${dialogs.serviceAccountDisplay(legacyAccounts)}. ` +
"Granting access to one backend will grant access to all backends. Would you like to grant it now?",
message: "Would you like to grant it now?",
});
expect(utils.logLabeledBullet).to.have.been.calledWith(
"apphosting",
Expand All @@ -286,15 +292,18 @@ describe("dialogs", () => {
runServiceAccounts: [],
});

expect(utils.logLabeledBullet).to.have.been.calledWith(
"apphosting",
"To use this secret, your backend's service account must have secret accessor permission. " +
"All of your backends use service account a. Granting access to one backend will grant access " +
"to all backends.",
);
expect(prompt.confirm).to.have.been.calledWith({
nonInteractive: undefined,
default: true,
message:
"To use this secret, your backend's service account must have secret accessor permission. " +
"All of your backends use service account a. Granting access to one backend will grant access " +
"to all backends. Would you like to grant it now?",
message: "Would you like to grant it now?",
});
expect(utils.logLabeledBullet).to.not.have.been.called;
expect(utils.logLabeledBullet).to.have.been.calledOnce;
});

it("handles multiple backends with the same (single) SA (opt no)", async () => {
Expand All @@ -308,13 +317,16 @@ describe("dialogs", () => {
dialogs.selectBackendServiceAccounts("number", "id", {}),
).to.eventually.deep.equal(emptyMulti);

expect(utils.logLabeledBullet).to.have.been.calledWith(
"apphosting",
"To use this secret, your backend's service account must have secret accessor permission. " +
"All of your backends use service account a. Granting access to one backend will grant access " +
"to all backends.",
);
expect(prompt.confirm).to.have.been.calledWith({
nonInteractive: undefined,
default: true,
message:
"To use this secret, your backend's service account must have secret accessor permission. " +
"All of your backends use service account a. Granting access to one backend will grant access " +
"to all backends. Would you like to grant it now?",
message: "Would you like to grant it now?",
});
expect(utils.logLabeledBullet).to.have.been.calledWith(
"apphosting",
Expand Down

0 comments on commit 4743344

Please sign in to comment.