/// <summary>
        /// 删除资源分组
        /// </summary>
        public DeleteResourceGroupResponse DeleteResourceGroup(DeleteResourceGroupRequest deleteResourceGroupRequest)
        {
            Dictionary <string, string> urlParam = new Dictionary <string, string>();

            urlParam.Add("group_id", deleteResourceGroupRequest.GroupId.ToString());
            string              urlPath  = HttpUtils.AddUrlPath("/V1.0/{project_id}/resource-groups/{group_id}", urlParam);
            SdkRequest          request  = HttpUtils.InitSdkRequest(urlPath, "application/json", deleteResourceGroupRequest);
            HttpResponseMessage response = DoHttpRequestSync("DELETE", request);

            return(JsonUtils.DeSerializeNull <DeleteResourceGroupResponse>(response));
        }
Esempio n. 2
0
        /// <summary>
        /// 删除资源组
        /// </summary>
        /// <param name="req"><see cref="DeleteResourceGroupRequest"/></param>
        /// <returns><see cref="DeleteResourceGroupResponse"/></returns>
        public DeleteResourceGroupResponse DeleteResourceGroupSync(DeleteResourceGroupRequest req)
        {
            JsonResponseModel <DeleteResourceGroupResponse> rsp = null;

            try
            {
                var strResp = this.InternalRequestSync(req, "DeleteResourceGroup");
                rsp = JsonConvert.DeserializeObject <JsonResponseModel <DeleteResourceGroupResponse> >(strResp);
            }
            catch (JsonSerializationException e)
            {
                throw new TencentCloudSDKException(e.Message);
            }
            return(rsp.Response);
        }
        public void DeleteResourceGroup([ActivityTrigger] DeleteResourceGroupRequest request)
        {
            var azr = _authenticatedStub.WithSubscription(request.SubscriptionId);

            if (azr == null || azr.SubscriptionId != request.SubscriptionId)
            {
                _log.LogInformation($"Created a new instance of _azr for subscription {request.SubscriptionId}");
                azr = _authenticatedStub.WithSubscription(request.SubscriptionId);
            }

            _log.LogInformation($"Deleting resource group {request.ResourceGroupName}");
            _log.LogInformation($"Commit: {_options.Commit}");

            if (_options.Commit)
            {
                azr.ResourceGroups.BeginDeleteByName(request.ResourceGroupName);
            }
        }
        public async Task NotifyOnDelete([ActivityTrigger] DeleteResourceGroupRequest request, [Queue("%OutboxQueueName%", Connection = "OutboxQueueStorageAccount")] IAsyncCollector <MailInfo> outboundMail)
        {
            var azr           = _authenticatedStub.WithSubscription(request.SubscriptionId);
            var resourceGroup = azr.ResourceGroups.GetByName(request.ResourceGroupName);

            var targets = new List <string>();

            if (resourceGroup.Tags.ContainsKey("owner") && resourceGroup.Tags.TryGetValue("owner", out var ownerMail))
            {
                targets.Add(ownerMail);
            }

            // find the role definition first - using built in 'owner' for now
            var o = await _authenticatedStub.RoleDefinitions.GetByScopeAndRoleNameAsync(resourceGroup.Id, "Owner");

            // find assignments on the RG matching the owner definition
            var owners = _authenticatedStub.RoleAssignments.ListByScope(resourceGroup.Id).Where(x => x.RoleDefinitionId == o.Id);

            foreach (var a in owners)
            {
                var mail = GetMailForPrincipal(a.PrincipalId);
                if (!string.IsNullOrEmpty(mail))
                {
                    targets.Add(mail);
                }
            }

            // todo: templatize the mail, move it out entirely
            var mailMessage = new MailInfo()
            {
                Subject  = "The azman cometh...",
                To       = targets,
                MailBody = $"<h1>...and taketh away.</h1><h2>azman deletion pass at {DateTime.UtcNow.ToString("O")} deleted {request.ResourceGroupName} from subscription {request.SubscriptionId}.</h2><p>You're getting this notification as an owner of a child or parent resource.</p>"
            };

            await outboundMail.AddAsync(mailMessage);
        }
        public async Task <bool> ExportTemplate([ActivityTrigger] DeleteResourceGroupRequest request, Binder binder)
        {
            var azr          = _authenticatedStub.WithSubscription(request.SubscriptionId);
            var exportResult = await azr.ResourceGroups.GetByName(request.ResourceGroupName).ExportTemplateAsync(ResourceGroupExportTemplateOptions.IncludeBoth);

            if (exportResult.Error != null)
            {
                _log.LogError($"ExportTemplate error: {exportResult.Error.Code} {exportResult.Error.Message} at {exportResult.Error.Target}");
                return(false);
            }

            var attributes = new Attribute[]
            {
                new BlobAttribute($"{_options.PersistenceStorageContainer}/{DateTime.UtcNow.ToString("yyyy-MM-dd")}/{request.ResourceGroupName}.json"),
                new StorageAccountAttribute("ExportTemplateBlobStorageConnection")
            };

            using (var writer = await binder.BindAsync <TextWriter>(attributes).ConfigureAwait(false))
            {
                writer.Write(exportResult.TemplateJson);
            }

            return(true);
        }
        public static async Task QueueStart([QueueTrigger("%DeleteResourceGroupQueueName%", Connection = "DeleteQueueStorageAccount")] DeleteResourceGroupRequest deleteQueueItem, [OrchestrationClient] DurableOrchestrationClient starter, ILogger log)
        {
            string instanceId = await starter.StartNewAsync("DeletionOrchestrator", deleteQueueItem);

            log.LogInformation($"Started orchestration with ID = '{instanceId}'.");
        }