Skip to content

Commit 9d92a31

Browse files
(coding-agent) Update some text, include MI portal link and prep for release (#5924)
- Remove the dependency on being in an 'azd' project. - Adding in some more visual demarcation for the "NOTE:" at the end of the console output - PR body description has more text, and a link to the created managed identity - Updating release materials to 0.3.0 Fixes #5914
1 parent a228c05 commit 9d92a31

File tree

4 files changed

+60
-24
lines changed

4 files changed

+60
-24
lines changed

cli/azd/extensions/azure.coding-agent/extension.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ language: go
77
namespace: coding-agent
88
usage: azd coding-agent <command> [options]
99
# NOTE: Make sure version.txt is in sync with this version.
10-
version: 0.2.0
10+
version: 0.3.0

cli/azd/extensions/azure.coding-agent/internal/cmd/coding_agent_config.go

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ var prBodyMD string
5151
const copilotEnv = "copilot"
5252

5353
type flagValues struct {
54-
Debug bool
55-
RepoSlug string
56-
RoleNames []string
57-
BranchName string
58-
GitHubHostName string
54+
Debug bool
55+
ManagedIdentityName string
56+
RepoSlug string
57+
RoleNames []string
58+
BranchName string
59+
GitHubHostName string
5960
}
6061

6162
func setupFlags(commandFlags *pflag.FlagSet) *flagValues {
@@ -84,6 +85,13 @@ func setupFlags(commandFlags *pflag.FlagSet) *flagValues {
8485
"The branch name to use when pushing changes to the copilot-setup-steps.yml",
8586
)
8687

88+
commandFlags.StringVar(
89+
&flagValues.ManagedIdentityName,
90+
"managed-identity-name",
91+
"mi-copilot-coding-agent",
92+
"The name to use for the managed identity, if created.",
93+
)
94+
8795
commandFlags.StringVar(
8896
&flagValues.GitHubHostName,
8997
"github-host-name",
@@ -129,13 +137,6 @@ func newConfigCommand() *cobra.Command {
129137

130138
promptClient := azdClient.Prompt()
131139

132-
// Get the azd project to retrieve the project path
133-
getProjectResponse, err := azdClient.Project().Get(ctx, &azdext.EmptyRequest{})
134-
135-
if err != nil {
136-
return fmt.Errorf("failed to get azd project: %w", err)
137-
}
138-
139140
if err := loginToGitHubIfNeeded(ctx, flagValues.GitHubHostName, newCommandRunner, newGitHubCLI); err != nil {
140141
return fmt.Errorf("failed to log in to GitHub. Login manually using `gh auth login`: %w", err)
141142
}
@@ -177,7 +178,7 @@ func newConfigCommand() *cobra.Command {
177178
}
178179

179180
gitCLI := newInternalGitCLI(defaultCommandRunner)
180-
gitRepoRoot, err := gitCLI.GetRepoRoot(ctx, getProjectResponse.Project.Path)
181+
gitRepoRoot, err := gitCLI.GetRepoRoot(ctx, ".")
181182

182183
if err != nil {
183184
return fmt.Errorf("failed to get git repository root: %w", err)
@@ -194,7 +195,7 @@ func newConfigCommand() *cobra.Command {
194195
&msiService,
195196
entraIDService,
196197
rgClient,
197-
getProjectResponse.Project.Name, subscriptionID, flagValues.RoleNames)
198+
flagValues.ManagedIdentityName, subscriptionID, flagValues.RoleNames)
198199

199200
if err != nil {
200201
return err
@@ -228,10 +229,16 @@ func newConfigCommand() *cobra.Command {
228229
repoSlug,
229230
)
230231

232+
managedIdentityPortalURL := formatPortalLinkForManagedIdentity(tenantID, subscriptionID, authConfig.ResourceGroup, authConfig.Name)
233+
231234
fmt.Println("")
235+
fmt.Println(output.WithHighLightFormat("(!)"))
232236
fmt.Println(output.WithHighLightFormat("(!) NOTE: Some tasks must still be completed, manually:"))
237+
fmt.Println(output.WithHighLightFormat("(!)"))
238+
fmt.Println("")
233239
fmt.Printf("1. The branch created at %s/%s must be merged to %s/main\n", remote, flagValues.BranchName, repoSlug)
234-
fmt.Printf("2. Visit '%s' and update the \"MCP configuration\" field with this JSON:\n\n", codingAgentURL)
240+
fmt.Printf("2. Configure Copilot coding agent's managed identity roles in the Azure portal: %s\n", managedIdentityPortalURL)
241+
fmt.Printf("3. Visit '%s' and update the \"MCP configuration\" field with this JSON:\n\n", codingAgentURL)
235242

236243
fmt.Println(mcpJson)
237244

@@ -246,8 +253,10 @@ func newConfigCommand() *cobra.Command {
246253
}
247254

248255
func openBrowserWindows(ctx context.Context,
249-
prompter azdext.PromptServiceClient, githubCLI *azd_tools_github.Cli,
250-
codingAgentURL string, gitRepoRoot string) error {
256+
prompter azdext.PromptServiceClient,
257+
githubCLI *azd_tools_github.Cli,
258+
codingAgentURL string,
259+
gitRepoRoot string) error {
251260
resp, err := prompter.Confirm(ctx, &azdext.ConfirmRequest{
252261
Options: &azdext.ConfirmOptions{
253262
Message: "Open browser window to create a pull request?",
@@ -324,7 +333,7 @@ func promptForRepoSlug(ctx context.Context,
324333

325334
resp, err := promptClient.Select(ctx, &azdext.SelectRequest{
326335
Options: &azdext.SelectOptions{
327-
Message: "Which git repository will use the Copilot coding agent?",
336+
Message: "Which GitHub repository will use the Copilot coding agent?",
328337
Choices: choices,
329338
},
330339
})
@@ -476,7 +485,7 @@ func pickOrCreateMSI(ctx context.Context,
476485
msiService azdMSIService,
477486
entraIDService entraid.EntraIdService,
478487
resourceService resourceService,
479-
projectName string, subscriptionId string, roleNames []string) (*authConfiguration, error) {
488+
identityName string, subscriptionId string, roleNames []string) (*authConfiguration, error) {
480489

481490
// ************************** Pick or create a new MSI **************************
482491

@@ -548,8 +557,6 @@ func pickOrCreateMSI(ctx context.Context,
548557
resourceGroupName = rgName
549558
}
550559

551-
identityName := "msi-copilot-" + projectName
552-
553560
taskList.AddTask(ux.TaskOptions{
554561
Title: fmt.Sprintf("Creating User Managed Identity (MSI) '%s'", identityName),
555562
Action: func(spf ux.SetProgressFunc) (ux.TaskState, error) {
@@ -593,7 +600,7 @@ func pickOrCreateMSI(ctx context.Context,
593600

594601
selectedOption, err := prompter.Select(ctx, &azdext.SelectRequest{
595602
Options: &azdext.SelectOptions{
596-
Message: "Select an existing User Managed Identity (MSI) to use:",
603+
Message: "Select an existing User Managed Identity (MSI) to use",
597604
Choices: choices,
598605
},
599606
})
@@ -644,6 +651,8 @@ func pickOrCreateMSI(ctx context.Context,
644651
}
645652

646653
return &authConfiguration{
654+
Name: *managedIdentity.Name,
655+
ResourceGroup: parsedID.ResourceGroupName,
647656
TenantId: *managedIdentity.Properties.TenantID,
648657
SubscriptionId: subscriptionId,
649658
ResourceID: *managedIdentity.ID,
@@ -689,6 +698,8 @@ func promptForResourceGroup(ctx context.Context,
689698
}
690699

691700
type authConfiguration struct {
701+
Name string
702+
ResourceGroup string
692703
ClientId string
693704
SubscriptionId string
694705
TenantId string
@@ -889,3 +900,12 @@ func (cli *internalGitCLI) ListRemotes(ctx context.Context, gitRepoRoot string)
889900
remotes := strings.Split(strings.TrimSpace(runResult.Stdout), "\n")
890901
return remotes, nil
891902
}
903+
904+
// formatPortalLinkForManagedIdentity takes you to the Azure portal blade, for your managed identity, that lets you see its role assignments.
905+
func formatPortalLinkForManagedIdentity(tenantID string, subscriptionID string, resourceGroupName string, managedIdentityName string) string {
906+
return fmt.Sprintf("https://portal.azure.com/#@%s/resource/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ManagedIdentity/userAssignedIdentities/%s/azure_resources",
907+
tenantID,
908+
subscriptionID,
909+
resourceGroupName,
910+
managedIdentityName)
911+
}

cli/azd/extensions/azure.coding-agent/internal/cmd/templates/pr-body.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Update copilot-setup-steps.yml to use a federated credential to access Azure resources.
22

3+
## Final steps
4+
35
**NOTE: one final step, and you're ready to use the Copilot coding agent with Azure!**
46

57
After this pull request merges, you'll need to update the Copilot coding agent's MCP settings [(link)](%s) with
@@ -8,3 +10,17 @@ the following JSON to activate the Azure MCP server:
810
```json
911
%s
1012
```
13+
14+
## Extending the managed identity's roles and scopes
15+
16+
By default, the identity is configured with the Reader role, on the resource group you created/selected. You can expand the role and scope for the identity, to fit better with your needs:
17+
18+
Some further instructions on how to assign roles:
19+
20+
- [Using the Azure portal to assign roles](https://learn.microsoft.com/azure/role-based-access-control/role-assignments-portal-managed-identity)
21+
- [Using the Azure CLI to assign roles](https://learn.microsoft.com/azure/role-based-access-control/role-assignments-cli)
22+
- [Azure built-in roles](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles)
23+
24+
## Resources
25+
26+
- `coding-agent` readme: ([link](https://github.com/Azure/azure-dev/blob/main/cli/azd/extensions/azure.coding-agent/README.md#troubleshooting))
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.0
1+
0.3.0

0 commit comments

Comments
 (0)