public void RoleAssignmentSample() { #region Snippet:CreateAccessControlClient // Replace the string below with your actual endpoint url. string endpoint = "<my-endpoint-url>"; /*@@*/ endpoint = TestEnvironment.EndpointUrl; AccessControlClient client = new AccessControlClient(endpoint: new Uri(endpoint), credential: new DefaultAzureCredential()); #endregion string principalId = TestEnvironment.PrincipalId; #region Snippet:CreateRoleAssignment Pageable <SynapseRole> roles = client.GetRoleDefinitions(); SynapseRole sqlAdminRole = roles.Single(role => role.Name == "Sql Admin"); RoleAssignmentOptions options = new RoleAssignmentOptions(sqlAdminRole.Id, principalId); RoleAssignmentDetails createdRoleAssignment = client.CreateRoleAssignment(options); #endregion #region Snippet:RetrieveRoleAssignment RoleAssignmentDetails retrievedRoleAssignment = client.GetRoleAssignmentById(createdRoleAssignment.Id); #endregion #region Snippet:ListRoleAssignments IReadOnlyList <RoleAssignmentDetails> roleAssignments = client.GetRoleAssignments().Value; foreach (RoleAssignmentDetails roleAssignment in roleAssignments) { Console.WriteLine(roleAssignment.Id); } #endregion #region Snippet:DeleteRoleAssignment client.DeleteRoleAssignmentById(retrievedRoleAssignment.Id); #endregion }
public void AddAndRemoveRoleAssignmentSync() { // Environment variable with the Synapse workspace endpoint. string endpoint = TestEnvironment.EndpointUrl; AccessControlClient client = new AccessControlClient(new Uri(endpoint), new DefaultAzureCredential()); Pageable <SynapseRole> roles = client.GetRoleDefinitions(); SynapseRole role = roles.Single(role => role.Name == "Workspace Admin"); string principalId = Guid.NewGuid().ToString(); RoleAssignmentOptions request = new RoleAssignmentOptions(role.Id, principalId); Response <RoleAssignmentDetails> response = client.CreateRoleAssignment(request); RoleAssignmentDetails roleAssignmentAdded = response.Value; RoleAssignmentDetails roleAssignment = client.GetRoleAssignmentById(roleAssignmentAdded.Id); Debug.WriteLine($"Role {roleAssignment.RoleId} is assigned to {roleAssignment.PrincipalId}. Role assignment id: {roleAssignment.Id}"); IReadOnlyList <RoleAssignmentDetails> roleAssignments = client.GetRoleAssignments().Value; foreach (RoleAssignmentDetails assignment in roleAssignments) { Console.WriteLine(assignment.Id); } client.DeleteRoleAssignmentById(roleAssignment.Id); }
public void CreateRoleAssignment() { string principalId = TestEnvironment.PrincipalId; string sqlAdminRoleId = client.GetRoleDefinitions().AsEnumerable().Single(role => role.Name == "Sql Admin").Id; #region Snippet:CreateRoleAssignment RoleAssignmentOptions options = new RoleAssignmentOptions(sqlAdminRoleId, principalId); RoleAssignmentDetails roleAssignment = client.CreateRoleAssignment(options); #endregion }
public virtual Response <RoleAssignmentDetails> CreateRoleAssignment(RoleAssignmentOptions createRoleAssignmentOptions, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("AccessControlClient.CreateRoleAssignment"); scope.Start(); try { return(RestClient.CreateRoleAssignment(createRoleAssignmentOptions, cancellationToken)); } catch (Exception e) { scope.Failed(e); throw; } }
internal HttpMessage CreateCreateRoleAssignmentRequest(RoleAssignmentOptions createRoleAssignmentOptions) { var message = _pipeline.CreateMessage(); var request = message.Request; request.Method = RequestMethod.Post; var uri = new RawRequestUriBuilder(); uri.AppendRaw(endpoint, false); uri.AppendPath("/rbac/roleAssignments", false); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; request.Headers.Add("Content-Type", "application/json"); var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(createRoleAssignmentOptions); request.Content = content; return(message); }
public void AddAndRemoveRoleAssignmentSync() { #region Snippet:CreateAccessControlClient // Replace the string below with your actual endpoint url. string endpoint = "<my-endpoint-url>"; /*@@*/ endpoint = TestEnvironment.EndpointUrl; AccessControlClient client = new AccessControlClient(new Uri(endpoint), new DefaultAzureCredential()); #endregion #region Snippet:PrepCreateRoleAssignment Pageable <SynapseRole> roles = client.GetRoleDefinitions(); SynapseRole role = roles.Single(role => role.Name == "Workspace Admin"); string roleID = role.Id; // Replace the string below with the ID you'd like to assign the role. string principalId = "<my-principal-id>"; /*@@*/ principalId = Guid.NewGuid().ToString(); #endregion #region Snippet:CreateRoleAssignment RoleAssignmentOptions request = new RoleAssignmentOptions(roleID, principalId); Response <RoleAssignmentDetails> response = client.CreateRoleAssignment(request); RoleAssignmentDetails roleAssignmentAdded = response.Value; #endregion #region Snippet:RetrieveRoleAssignment RoleAssignmentDetails roleAssignment = client.GetRoleAssignmentById(roleAssignmentAdded.Id); Console.WriteLine($"Role {roleAssignment.RoleId} is assigned to {roleAssignment.PrincipalId}."); #endregion #region Snippet:ListRoleAssignments Response <IReadOnlyList <RoleAssignmentDetails> > roleAssignments = client.GetRoleAssignments(); foreach (RoleAssignmentDetails assignment in roleAssignments.Value) { Console.WriteLine(assignment.Id); } #endregion #region Snippet:DeleteRoleAssignment client.DeleteRoleAssignmentById(roleAssignment.Id); #endregion }
public void SubmitSparkJobSync() { // Environment variable with the Synapse workspace endpoint. string workspaceUrl = TestEnvironment.WorkspaceUrl; #region Snippet:AccessControlSample1AccessControlClient AccessControlClient client = new AccessControlClient(new Uri(workspaceUrl), new DefaultAzureCredential()); #endregion #region Snippet:AccessControlSample1GetWorkspaceAdminRole SynapseRole role = client.GetRoleDefinitions().Single(role => role.Name == "Workspace Admin"); #endregion #region Snippet:AccessControlSample1AddRoleAssignment string principalId = Guid.NewGuid().ToString(); RoleAssignmentOptions request = new RoleAssignmentOptions(roleId: role.Id, principalId: principalId); RoleAssignmentDetails roleAssignmentAdded = client.CreateRoleAssignment(request); #endregion #region Snippet:AccessControlSample1GetRoleAssignment RoleAssignmentDetails roleAssignment = client.GetRoleAssignmentById(principalId); Debug.WriteLine($"Role {roleAssignment.RoleId} is assigned to {roleAssignment.PrincipalId}. Role assignment id: {roleAssignment.Id}"); #endregion #region Snippet:AccessControlSample1ListRoleAssignments IReadOnlyList <RoleAssignmentDetails> roleAssignments = client.GetRoleAssignments().Value; foreach (RoleAssignmentDetails assignment in roleAssignments) { Console.WriteLine(assignment.Id); } #endregion #region Snippet:AccessControlSample1RemoveRoleAssignment client.DeleteRoleAssignmentById(roleAssignment.Id); #endregion }
public async Task <Response <RoleAssignmentDetails> > CreateRoleAssignmentAsync(RoleAssignmentOptions createRoleAssignmentOptions, CancellationToken cancellationToken = default) { if (createRoleAssignmentOptions == null) { throw new ArgumentNullException(nameof(createRoleAssignmentOptions)); } using var message = CreateCreateRoleAssignmentRequest(createRoleAssignmentOptions); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: { RoleAssignmentDetails value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); if (document.RootElement.ValueKind == JsonValueKind.Null) { value = null; } else { value = RoleAssignmentDetails.DeserializeRoleAssignmentDetails(document.RootElement); } return(Response.FromValue(value, message.Response)); }
public RoleAssignmentDetails CreateRoleAssignment(string roleDefinitionId, string objectId) { RoleAssignmentOptions roleAssignmentOptions = new RoleAssignmentOptions(roleDefinitionId, objectId); return(_accessControlClient.CreateRoleAssignment(roleAssignmentOptions).Value); }
public virtual async Task <Response <RoleAssignmentDetails> > CreateRoleAssignmentAsync(RoleAssignmentOptions createRoleAssignmentOptions, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("AccessControlClient.CreateRoleAssignment"); scope.Start(); try { return(await RestClient.CreateRoleAssignmentAsync(createRoleAssignmentOptions, cancellationToken).ConfigureAwait(false)); } catch (Exception e) { scope.Failed(e); throw; } }