Пример #1
0
        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
        }
Пример #2
0
        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);
        }
Пример #3
0
        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
        }