Skip to content

Commit

Permalink
Fix create message
Browse files Browse the repository at this point in the history
  • Loading branch information
nturinski committed Jul 22, 2024
1 parent 8e4e2e2 commit 8bd0f0a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion azure/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
11 changes: 8 additions & 3 deletions azure/src/wizard/RoleAssignmentExecuteStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends types.IResourceGroupWizardContext> extends AzureWizardExecuteStep<T> {
Expand All @@ -24,19 +24,24 @@ export class RoleAssignmentExecuteStep<T extends types.IResourceGroupWizardConte
this._roleDefinitionId = roleDefinitionId;
}

public async execute(wizardContext: T, _progress: Progress<{ message?: string; increment?: number }>): Promise<void> {
public async execute(wizardContext: T, progress: Progress<{ message?: string; increment?: number }>): Promise<void> {
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);
}

Expand Down

0 comments on commit 8bd0f0a

Please sign in to comment.