Beispiel #1
0
        public async Task <string> UpdateAscContributorRoleOnSubscription(string subscriptionId, dynamic role)
        {
            var roleId = role.name;

            role.properties.assignableScopes.Add($"/subscriptions/{subscriptionId}");

            var requestBody = role.ToString();
            var requestUrl  = $"{Config.AzureResourceManagerUrl}/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/{roleId}?api-version={apiVersion}";

            var response = await ArmHttpClient.Put(requestUrl, requestBody);

            return(response);
        }
Beispiel #2
0
        public async Task <string> CreateAscContributorRoleOnResourceGroup(string subscriptionId, string resourceGroup)
        {
            var newRoleId  = Guid.NewGuid().ToString();
            var requestUrl = $"{Config.AzureResourceManagerUrl}/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Authorization/roleDefinitions/{newRoleId}?api-version={apiVersion}";// 2016-02-01";

            // Modify the "assignableScopes" in the base template
            var     ascContributorJson = File.ReadAllText(HttpContext.Current.Server.MapPath("~/json/asc-contributor.json"));
            dynamic role = JObject.Parse(ascContributorJson);

            role.properties.assignableScopes = new JArray() as dynamic;
            role.properties.assignableScopes.Add($"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}");
            var requestBody = role.ToString();

            var response = await ArmHttpClient.Put(requestUrl, requestBody);

            return(response);
        }
Beispiel #3
0
        public async Task <string> GrantRoleOnResourceGroup(string subscriptionId, string resourceGroup, string roleId, string objectId)
        {
            var newRoleAssignmentId = Guid.NewGuid().ToString();
            var requestUrl          = $"{Config.AzureResourceManagerUrl}/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/microsoft.authorization/roleassignments/{newRoleAssignmentId}?api-version={Config.ARMAuthorizationRoleAssignmentsAPIVersion}";
            var requestBody         = new
            {
                properties = new
                {
                    roleDefinitionId = roleId,
                    principalId      = objectId
                }
            };
            var requestJson = JsonConvert.SerializeObject(requestBody);
            var json        = await ArmHttpClient.Put(requestUrl, requestJson);

            return(json);
        }
Beispiel #4
0
        public async Task <string> SavePolicyAssignment(string subscriptionId, string policyAssignmentName, object policy)
        {
            var requestUrl = $"{Config.AzureResourceManagerUrl}/subscriptions/{subscriptionId}/providers/Microsoft.authorization/policyassignments/{policyAssignmentName}?api-version={policyApiVersion}";

            return(await ArmHttpClient.Put(requestUrl, policy));
        }