コード例 #1
0
 public PSSynapseRole(SynapseRoleDefinition synapseRole)
 {
     this.Id                 = synapseRole.Id?.ToString();
     this.Name               = synapseRole.Name;
     this.IsBuiltIn          = synapseRole.IsBuiltIn.Value;
     this.Description        = synapseRole.Description;
     this.AvailabilityStatus = synapseRole.AvailabilityStatus;
     this.Permissions        = synapseRole.Permissions;
     this.Scopes             = synapseRole.Scopes;
 }
コード例 #2
0
        public void AddAndRemoveRoleAssignmentSync()
        {
            #region Snippet:CreateAccessControlClient
            // Replace the string below with your actual endpoint url.
            string endpoint = "<my-endpoint-url>";
            /*@@*/ endpoint = TestEnvironment.EndpointUrl;

            RoleAssignmentsClient roleAssignmentsClient = new RoleAssignmentsClient(endpoint, new DefaultAzureCredential());
            RoleDefinitionsClient definitionsClient     = new RoleDefinitionsClient(endpoint, new DefaultAzureCredential());
            #endregion

            #region Snippet:PrepCreateRoleAssignment
            Response <IReadOnlyList <SynapseRoleDefinition> > roles = definitionsClient.ListRoleDefinitions();
            SynapseRoleDefinition role = roles.Value.Single(role => role.Name == "Synapse Administrator");
            Guid roleId = role.Id.Value;

            string assignedScope = "workspaces/<my-workspace-name>";
            /*@@*/ assignedScope = "workspaces/" + TestEnvironment.WorkspaceName;

            // Replace the string below with the ID you'd like to assign the role.
            Guid principalId = /*<my-principal-id>"*/ Guid.NewGuid();

            // Replace the string below with the ID of the assignment you'd like to use.
            string assignmentId = "<my-assignment-id>";
            /*@@*/ assignmentId = Guid.NewGuid().ToString();
            #endregion

            #region Snippet:CreateRoleAssignment
            Response <RoleAssignmentDetails> response            = roleAssignmentsClient.CreateRoleAssignment(assignmentId, roleId, principalId, assignedScope);
            RoleAssignmentDetails            roleAssignmentAdded = response.Value;
            #endregion

            #region Snippet:RetrieveRoleAssignment
            RoleAssignmentDetails roleAssignment = roleAssignmentsClient.GetRoleAssignmentById(roleAssignmentAdded.Id);
            Console.WriteLine($"Role {roleAssignment.RoleDefinitionId} is assigned to {roleAssignment.PrincipalId}.");
            #endregion

            #region Snippet:ListRoleAssignments
            Response <IReadOnlyList <SynapseRoleDefinition> > roleAssignments = definitionsClient.ListRoleDefinitions();
            foreach (SynapseRoleDefinition assignment in roleAssignments.Value)
            {
                Console.WriteLine(assignment.Id);
            }
            #endregion

            #region Snippet:DeleteRoleAssignment
            roleAssignmentsClient.DeleteRoleAssignmentById(roleAssignment.Id);
            #endregion
        }
コード例 #3
0
        public async Task ListRoleAssignments()
        {
            RoleAssignmentsClient assignmentsClient = CreateAssignmentClient();
            RoleDefinitionsClient definitionsClient = CreateDefinitionsClient();

            await using DisposableClientRole role = await DisposableClientRole.Create(assignmentsClient, definitionsClient, TestEnvironment);

            Response <IReadOnlyList <SynapseRoleDefinition> > roleAssignments = await definitionsClient.ListRoleDefinitionsAsync();

            foreach (SynapseRoleDefinition expected in roleAssignments.Value)
            {
                SynapseRoleDefinition actual = await definitionsClient.GetRoleDefinitionByIdAsync(expected.Id.ToString());

                Assert.AreEqual(expected.Id, actual.Id);
                Assert.AreEqual(expected.Name, actual.Name);
            }
            Assert.GreaterOrEqual(roleAssignments.Value.Count, 1);
        }
コード例 #4
0
        public async Task <Response <IReadOnlyList <SynapseRoleDefinition> > > ListRoleDefinitionsAsync(bool?isBuiltIn = null, string scope = null, CancellationToken cancellationToken = default)
        {
            using var message = CreateListRoleDefinitionsRequest(isBuiltIn, scope);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            switch (message.Response.Status)
            {
            case 200:
            {
                IReadOnlyList <SynapseRoleDefinition> value = default;
                using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);

                List <SynapseRoleDefinition> array = new List <SynapseRoleDefinition>();
                foreach (var item in document.RootElement.EnumerateArray())
                {
                    array.Add(SynapseRoleDefinition.DeserializeSynapseRoleDefinition(item));
                }
                value = array;
                return(Response.FromValue(value, message.Response));
            }