feat: add user prompts for declarative security changes (PR 4)#10735
feat: add user prompts for declarative security changes (PR 4)#10735inlined wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the promptForSecurityChanges function in src/deploy/functions/prompts.ts along with comprehensive unit tests in src/deploy/functions/prompts.spec.ts to prompt operators for codebase-wide declarative security changes. The review feedback points out a TypeScript compilation error caused by typing the plan parameter with DeploymentPlan, which lacks the required security properties; defining a custom CodebasePlan interface is recommended to resolve this. Additionally, the feedback suggests conditionally formatting the prompt message when rolesToAdd is empty to prevent displaying an empty list of roles.
| import * as artifacts from "../../functions/artifacts"; | ||
| import { Options } from "../../options"; | ||
| import { EndpointUpdate } from "./release/planner"; | ||
| import { EndpointUpdate, DeploymentPlan } from "./release/planner"; |
There was a problem hiding this comment.
The DeploymentPlan type imported from ./release/planner is defined as Record<string, Changeset>, where Changeset does not contain the security-related properties (like serviceAccountToCreate, rolesToAdd, etc.) accessed in promptForSecurityChanges. This causes a TypeScript compilation error.
We should remove DeploymentPlan from this import and define a specific CodebasePlan interface to type the plan parameter correctly.
| import { EndpointUpdate, DeploymentPlan } from "./release/planner"; | |
| import { EndpointUpdate } from "./release/planner"; |
| export async function promptForSecurityChanges( | ||
| plan: DeploymentPlan, | ||
| options: Options, | ||
| ): Promise<void> { |
There was a problem hiding this comment.
Define a proper CodebasePlan interface and use it to type the plan parameter. This resolves the TypeScript compilation error caused by the mismatch with DeploymentPlan (which is Record<string, Changeset>).
export interface CodebasePlan {
serviceAccountToDelete?: string;
serviceAccountToCreate?: string;
managedServiceAccount?: string;
rolesToAdd?: string[];
rolesToRemove?: string[];
}
/**
* Prompts operators for codebase-wide declarative security changes.
*/
export async function promptForSecurityChanges(
plan: Record<string, CodebasePlan>,
options: Options,
): Promise<void> {| const msg = `This codebase uses declarative security. It will use the following role(s):\n${roleNames | ||
| .map((r) => `* ${r}`) | ||
| .join("\n")}\nContinue?`; |
There was a problem hiding this comment.
If rolesToAdd is empty or undefined, the prompt will print an empty list of roles, which looks awkward (e.g., It will use the following role(s):\n\nContinue?). We should conditionally format the message to only list roles if there are any.
| const msg = `This codebase uses declarative security. It will use the following role(s):\n${roleNames | |
| .map((r) => `* ${r}`) | |
| .join("\n")}\nContinue?`; | |
| let msg = `This codebase uses declarative security.`; | |
| if (roleNames.length > 0) { | |
| msg += ` It will use the following role(s):\n${roleNames.map((r) => `* ${r}`).join("\n")}\n`; | |
| } else { | |
| msg += "\n"; | |
| } | |
| msg += "Continue?"; |
86e2632 to
ef1d12f
Compare
31fc515 to
7d9cc2f
Compare
ef1d12f to
1eb74ff
Compare
### Description This is PR 4 in the requiresRole PR chain. It implements prompts asking the operator for confirmation when: 1. Enabling declarative security (enrolling). 2. Modifying roles on the managed service account. 3. Opting out of declarative security (unenrolling and deleting the SA). Includes options.nonInteractive checks to safely throw errors in headless environments. ### Scenarios Tested - Run unit tests: npx mocha src/deploy/functions/prompts.spec.ts - Run npm run build & npm run lint ### Sample Commands N/A
7d9cc2f to
ae9eaaa
Compare
Description
This is PR 4 in the requiresRole PR chain.
It implements prompts asking the operator for confirmation when:
Includes
options.nonInteractivechecks to safely throw errors in headless environments.Scenarios Tested
npx mocha src/deploy/functions/prompts.spec.tsSample Commands
N/A