Wire Azure authorization request to init command#1376
Conversation
After workspace initialization, automatically request Azure authorization for each newly initialized cloud account by creating a PR on eng-azure-authorization to add the bootstrap identity to directory readers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🦋 Changeset detectedLatest commit: 24d8941 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
4f71ca7 to
40d001c
Compare
There was a problem hiding this comment.
Pull request overview
This PR wires the Azure authorization request flow into the dx init command so that, after initializing a workspace/environment, the CLI also opens PR(s) on eng-azure-authorization to add the bootstrap identity to directory readers for newly initialized cloud accounts.
Changes:
runDeploymentEnvironmentGeneratornow validates prompt answers with the generator schema and returns the parsed environment payload for downstream use.initcommand now callsauthorizeCloudAccountsafter environment initialization and GitHub repository setup, and prints authorization PR URLs in the summary (when available).- Adds unit tests for
authorizeCloudAccountsand a changeset for the CLI patch release.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| apps/cli/src/adapters/plop/index.ts | Returns the parsed environment payload from the environment generator so init can use initialization metadata. |
| apps/cli/src/adapters/commander/commands/init.ts | Introduces authorizeCloudAccounts, injects authorizationService, and integrates authorization PR creation into the init flow + summary output. |
| apps/cli/src/adapters/commander/commands/tests/init.test.ts | Adds unit tests covering the new authorizeCloudAccounts behavior. |
| .changeset/smart-planes-cheer.md | Declares a patch changeset for the CLI release. |
Comments suppressed due to low confidence (1)
apps/cli/src/adapters/commander/commands/init.ts:103
displaySummaryonly prints Azure authorization PR URLs inside theif (pr)branch. SincecreatePullRequestis explicitly allowed to fail (it returnsundefinedvia.orElse(() => okAsync(undefined))), this can hide successfully-created authorization PRs from the user when the main repo PR couldn’t be created. Consider renderingauthorizationPrswheneverauthorizationPrs.length > 0, independently of whetherprexists (and adjust the messaging accordingly).
if (pr) {
let step = 1;
console.log(chalk.green.bold("\nNext Steps:"));
console.log(
`${step++}. Review the Pull Request in the GitHub repository: ${chalk.underline(pr.url)}`,
);
if (authorizationPrs.length > 0) {
console.log(`${step++}. Review the Azure authorization Pull Request(s):`);
for (const authPr of authorizationPrs) {
console.log(` - ${chalk.underline(authPr.url)}`);
}
}
console.log(
`${step}. Visit ${chalk.underline("https://dx.pagopa.it/getting-started")} to deploy your first project\n`,
);
} else {
console.log(
chalk.yellow(`\n⚠️ There was an error during Pull Request creation.`),
);
console.log(
`Please, manually create a Pull Request in the GitHub repository to review the scaffolded code.\n`,
);
}
| const locShort = locationShort[account.defaultLocation]; | ||
| const input = requestAuthorizationInputSchema.safeParse({ | ||
| bootstrapIdentityId: `${prefix}-${envShort}-${locShort}-bootstrap-id-01`, | ||
| subscriptionName: account.displayName, | ||
| }); |
There was a problem hiding this comment.
subscriptionName is derived from account.displayName, but Azure subscription display names can contain spaces and other characters. This will often fail requestAuthorizationInputSchema (only allows letters/numbers/hyphens) and silently skip authorization. Since the authorization adapter uses subscriptionName as a path/branch segment, consider normalizing the display name into the expected repo folder slug (e.g., lowercased, whitespace to -, strip unsupported chars) or using a dedicated field that already matches the eng-azure-authorization directory naming.
| return ResultAsync.fromPromise(requestAll(), () => []).orElse(() => | ||
| okAsync([]), | ||
| ); |
There was a problem hiding this comment.
authorizeCloudAccounts converts any unexpected exception thrown by requestAll() into an ok([]) (via fromPromise(..., () => []) + .orElse(() => okAsync([]))), and the error is not logged. This makes genuine failures (e.g. network/auth issues) invisible to users and hard to troubleshoot. Consider logging the caught exception (and/or returning an Err), or at least mapping the error to something meaningful instead of an empty array literal.
| return ResultAsync.fromPromise(requestAll(), () => []).orElse(() => | |
| okAsync([]), | |
| ); | |
| return ResultAsync.fromPromise( | |
| requestAll(), | |
| (error: unknown) => | |
| error instanceof Error ? error : new Error(String(error)), | |
| ).orElse((error) => { | |
| logger.error("Failed to authorize cloud accounts", { error }); | |
| return okAsync([]); | |
| }); |
| }; | ||
|
|
||
| /** | ||
| * Authorize a Cloud Account (Azure Subscription, AWS Account, ...), creating a Pull Request for each account that requires authorization. |
There was a problem hiding this comment.
The docstring says this authorizes "Azure Subscription, AWS Account, ..." but the current CloudAccount model only supports csp: "azure" and the implementation only handles Azure locations. Consider narrowing the comment to Azure to avoid misleading readers, or expanding the implementation/types if multi-cloud is intended.
| * Authorize a Cloud Account (Azure Subscription, AWS Account, ...), creating a Pull Request for each account that requires authorization. | |
| * Authorize Azure subscriptions, creating a Pull Request for each subscription that requires authorization. |
| const account = { | ||
| csp: "azure" as const, | ||
| defaultLocation: "italynorth", | ||
| displayName: "DEV-FooBar", | ||
| id: "sub-123", | ||
| }; |
There was a problem hiding this comment.
The test data uses csp: "azure" as const repeatedly. This type assertion is unnecessary here (TS will infer the literal type in a const object) and reduces the test’s type-safety signal. Prefer removing the assertion or using satisfies with the appropriate CloudAccount type to keep tests strongly typed without assertions.
After workspace initialization, the
initcommand now automatically requests Azure authorization for each newly initialized cloud account by creating a PR oneng-azure-authorizationto add the bootstrap identity to directory readers.This wires the
requestAuthorizationuse case (introduced in #1256) into the init flow.Closes CES-1522