From 8bd0f0a6ad75aa0b8cd1138cc424f024f9713d21 Mon Sep 17 00:00:00 2001 From: Nathan Turinski Date: Mon, 22 Jul 2024 16:43:23 -0700 Subject: [PATCH] Fix create message --- azure/index.d.ts | 2 +- azure/src/wizard/RoleAssignmentExecuteStep.ts | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/azure/index.d.ts b/azure/index.d.ts index 5eecd4ea44..c0f5c3e61d 100644 --- a/azure/index.d.ts +++ b/azure/index.d.ts @@ -491,5 +491,5 @@ export function setupAzureLogger(logOutputChannel: LogOutputChannel): Disposable export function addBasicAuthenticationCredentialsToClient(client: ServiceClient, userName: string, password: string): void; export declare enum RoleDefinitionId { - StorageBlobDataContributor = '/providers/Microsoft.Authorization/roleDefinitions/ba92f5b4-2d11-453d-a403-e96b0029c9fe' + 'Storage Blob Data Contributor' = '/providers/Microsoft.Authorization/roleDefinitions/ba92f5b4-2d11-453d-a403-e96b0029c9fe' } diff --git a/azure/src/wizard/RoleAssignmentExecuteStep.ts b/azure/src/wizard/RoleAssignmentExecuteStep.ts index 9a93f3e8eb..cc0bac0f34 100644 --- a/azure/src/wizard/RoleAssignmentExecuteStep.ts +++ b/azure/src/wizard/RoleAssignmentExecuteStep.ts @@ -11,7 +11,7 @@ import { createAuthorizationManagementClient } from '../clients'; import { ext } from '../extensionVariables'; export enum RoleDefinitionId { - StorageBlobDataContributor = '/providers/Microsoft.Authorization/roleDefinitions/ba92f5b4-2d11-453d-a403-e96b0029c9fe' + 'Storage Blob Data Contributor' = '/providers/Microsoft.Authorization/roleDefinitions/ba92f5b4-2d11-453d-a403-e96b0029c9fe' } export class RoleAssignmentExecuteStep extends AzureWizardExecuteStep { @@ -24,19 +24,24 @@ export class RoleAssignmentExecuteStep): Promise { + public async execute(wizardContext: T, progress: Progress<{ message?: string; increment?: number }>): Promise { const amClient = await createAuthorizationManagementClient(wizardContext) const scope = this.getScopeId(); if (!scope) { throw new Error(l10n.t('No scope was provided for the role assignment.')); } + const scopeSplit = scope.split('/'); + const resourceName = scopeSplit[scopeSplit.length - 1] ?? ''; + const resourceType = scopeSplit[scopeSplit.length - 2] ?? ''; const guid = randomUUID(); + const roleDefinitionDisplayName = Object.keys(RoleDefinitionId)[Object.values(RoleDefinitionId).indexOf(this._roleDefinitionId)]; const roleDefinitionId = this._roleDefinitionId as unknown as string; const principalId = nonNullValueAndProp(wizardContext.managedIdentity, 'principalId'); await amClient.roleAssignments.create(scope, guid, { roleDefinitionId, principalId }); - const roleAssignmentCreated = l10n.t('Role assignment "{1}" created with resource "{0}".', scope, roleDefinitionDisplayName); + const roleAssignmentCreated = l10n.t('Role assignment "{0}" created for resource "{1}" with provider "{2}".', roleDefinitionDisplayName, resourceName, resourceType); + progress.report({ message: roleAssignmentCreated }); ext.outputChannel.appendLog(roleAssignmentCreated); }