Created
July 22, 2023 02:18
-
-
Save xximjasonxx/03427d9467c82d30b9117f96346e8b4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Task AssignRoleToServicePrincipal(Guid objectId, string roleName, string scopePath) | |
{ | |
var tcs = new TaskCompletionSource(); | |
Task.Run(() => | |
{ | |
try | |
{ | |
var roleAssignmentResourceId = RoleAssignmentResource.CreateResourceIdentifier(scopePath, roleName); | |
var roleAssignmentResource = _armClient.GetRoleAssignmentResource(roleAssignmentResourceId); | |
var operationContent = new RoleAssignmentCreateOrUpdateContent(roleAssignmentResource.Id, objectId) | |
{ | |
PrincipalType = RoleManagementPrincipalType.ServicePrincipal | |
}; | |
var operationOutcome = roleAssignmentResource.Update(Azure.WaitUntil.Completed, operationContent); | |
tcs.TrySetResult(); | |
} | |
catch (Exception ex) | |
{ | |
tcs.TrySetException(ex); | |
} | |
}); | |
return tcs.Task; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment