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 async Task TestGetRoleDefinition() { List <SynapseRole> roles = await AccessControlClient.GetRoleDefinitionsAsync().ToEnumerableAsync(); CollectionAssert.IsNotEmpty(roles); foreach (SynapseRole expectedRole in roles) { SynapseRole actualRole = await AccessControlClient.GetRoleDefinitionByIdAsync(expectedRole.Id.ToString()); Assert.AreEqual(expectedRole.Name, actualRole.Name); Assert.AreEqual(expectedRole.Id, actualRole.Id); Assert.AreEqual(expectedRole.IsBuiltIn, actualRole.IsBuiltIn); } }
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 PSSynapseRole(SynapseRole synapseRole) { this.Id = synapseRole.Id; this.Name = synapseRole.Name; this.IsBuiltIn = synapseRole.IsBuiltIn; }