Example #1
0
            public static async ValueTask <DisposableClientRole> Create(RoleAssignmentsClient assignmentsClient, RoleDefinitionsClient definitionsClient, SynapseTestEnvironment testEnvironment)
            {
                var clientRole = new DisposableClientRole(assignmentsClient, definitionsClient, await CreateResource(assignmentsClient, definitionsClient, testEnvironment));

                return(clientRole);
            }
Example #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)));
            }
            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));
            }