Beispiel #1
0
 private Amazon.CertificateManager.Model.DeleteCertificateResponse CallAWSServiceOperation(IAmazonCertificateManager client, Amazon.CertificateManager.Model.DeleteCertificateRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Certificate Manager", "DeleteCertificate");
     try
     {
         #if DESKTOP
         return(client.DeleteCertificate(request));
         #elif CORECLR
         return(client.DeleteCertificateAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }
        public async Task <Response> Delete()
        {
            var props = Request.ResourceProperties;
            IAmazonCertificateManager acmClient = await acmFactory.Create(props.CreationRoleArn);

            IAmazonRoute53 route53Client = await route53Factory.Create(props.ValidationRoleArn);

            var describeResponse = await acmClient.DescribeCertificateAsync(new DescribeCertificateRequest
            {
                CertificateArn = Request.PhysicalResourceId,
            });

            Console.WriteLine($"Got describe certificate response: {JsonSerializer.Serialize(describeResponse)}");

            var names   = new HashSet <string>();
            var changes = new List <Change>();

            foreach (var option in describeResponse.Certificate.DomainValidationOptions)
            {
                var query = from name in names where name == option.ResourceRecord.Name select name;

                if (query.Count() != 0)
                {
                    continue;
                }

                names.Add(option.ResourceRecord.Name);
                changes.Add(new Change
                {
                    Action            = ChangeAction.DELETE,
                    ResourceRecordSet = new ResourceRecordSet
                    {
                        Name            = option.ResourceRecord.Name,
                        Type            = new RRType(option.ResourceRecord.Type.Value),
                        SetIdentifier   = Request.PhysicalResourceId,
                        Weight          = 1,
                        TTL             = 60,
                        ResourceRecords = new List <ResourceRecord> {
                            new ResourceRecord {
                                Value = option.ResourceRecord.Value
                            }
                        }
                    }
                });
            }

            if (changes.Count() != 0)
            {
                try
                {
                    var roleArn = Request.ResourceProperties.ValidationRoleArn;
                    var changeRecordsResponse = await route53Client.ChangeResourceRecordSetsAsync(new ChangeResourceRecordSetsRequest
                    {
                        HostedZoneId = Request.ResourceProperties.HostedZoneId,
                        ChangeBatch  = new ChangeBatch
                        {
                            Changes = changes
                        }
                    });

                    Console.WriteLine($"Got delete record response: {JsonSerializer.Serialize(changeRecordsResponse)}");
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Error deleting old resource records: {e.Message} {e.StackTrace}");
                }
            }

            var deleteResponse = await acmClient.DeleteCertificateAsync(new DeleteCertificateRequest
            {
                CertificateArn = Request.PhysicalResourceId,
            });

            Console.WriteLine($"Received delete certificate response: {JsonSerializer.Serialize(deleteResponse)}");

            return(new Response
            {
                PhysicalResourceId = Request.PhysicalResourceId
            });
        }