public static async ValueTask <RoleAssignmentDetails> CreateResource(RoleAssignmentsClient assignmentsClient, RoleDefinitionsClient definitionsClient, SynapseTestEnvironment testEnvironment)
            {
                string scope = "workspaces/" + testEnvironment.WorkspaceName;

                Guid?  roleID           = (await definitionsClient.ListRoleDefinitionsAsync()).Value.First(x => x.Name == "Synapse Administrator").Id;
                Guid   principalId      = Guid.NewGuid();
                string roleAssignmentId = Guid.NewGuid().ToString();

                return(await assignmentsClient.CreateRoleAssignmentAsync(roleAssignmentId, roleID.Value, principalId, scope));
            }
Ejemplo n.º 2
0
            public static async ValueTask <Response> CreateResource(RoleAssignmentsClient assignmentsClient, RoleDefinitionsClient definitionsClient, SynapseTestEnvironment testEnvironment)
            {
                Response listResponse = await definitionsClient.GetRoleDefinitionsAsync(new());

                var listContent = listResponse.Content;

                using var roleDefinitionsJson = JsonDocument.Parse(listContent.ToMemory());

                var    count            = roleDefinitionsJson.RootElement.GetArrayLength();
                var    roleId           = roleDefinitionsJson.RootElement.EnumerateArray().First(roleDefinitionJson => roleDefinitionJson.GetProperty("name").ToString() == "Synapse Administrator").GetProperty("id").ToString();
                string roleAssignmentId = Guid.NewGuid().ToString();

                var roleAssignmentDetails = new
                {
                    roleId      = roleId,
                    principalId = Guid.NewGuid(),
                    scope       = "workspaces/" + testEnvironment.WorkspaceName
                };

                return(await assignmentsClient.CreateRoleAssignmentAsync(roleAssignmentId, RequestContent.Create(roleAssignmentDetails)));
            }