Beispiel #1
0
        public void Route53GetHostedZone()
        {
            #region to-get-information-about-a-hosted-zone-1481752361124

            var client   = new AmazonRoute53Client();
            var response = client.GetHostedZone(new GetHostedZoneRequest
            {
                Id = "Z3M3LMPEXAMPLE"
            });

            DelegationSet delegationSet = response.DelegationSet;
            HostedZone    hostedZone    = response.HostedZone;

            #endregion
        }
Beispiel #2
0
        public bool PrepareChallengeForValidation(string dnsKeyName, string dnsKeyValue)
        {
            try
            {
                route53Client = new AmazonRoute53Client();
                HostedZone zone = null;
                if (zoneId != null)
                {
                    GetHostedZoneResponse zoneResp = route53Client.GetHostedZone(new Amazon.Route53.Model.GetHostedZoneRequest {
                        Id = zoneId
                    });
                    zone = zoneResp.HostedZone;
                }
                else
                {
                    ListHostedZonesResponse zones = route53Client.ListHostedZones();
                    string recordToZone           = dnsKeyName;
                    while (recordToZone.IndexOf('.') > 0)
                    {
                        recordToZone = recordToZone.Substring(recordToZone.IndexOf('.') + 1);
                        zone         = zones.HostedZones.Where(z => z.Name.Contains(recordToZone)).FirstOrDefault();
                        if (zone != null)
                        {
                            break;
                        }
                    }
                }
                if (zone == null)
                {
                    logger.Error("Could not find DNS zone");
                    return(false);
                }

                ListResourceRecordSetsResponse txtRecordsResponse = route53Client.ListResourceRecordSets(new ListResourceRecordSetsRequest
                {
                    StartRecordName = dnsKeyName,
                    StartRecordType = "TXT",
                    MaxItems        = "1",
                    HostedZoneId    = zone.Id
                });
                ResourceRecordSet txtRecord = txtRecordsResponse.ResourceRecordSets.FirstOrDefault(r => (r.Name == dnsKeyName || r.Name == dnsKeyName + ".") && r.Type.Value == "TXT");

                if (txtRecord != null)
                {
                    ApplyDnsChange(zone, txtRecord, ChangeAction.DELETE);
                }

                txtRecord = new ResourceRecordSet()
                {
                    Name            = dnsKeyName,
                    TTL             = 5,
                    Type            = RRType.TXT,
                    ResourceRecords = new List <ResourceRecord>
                    {
                        new ResourceRecord {
                            Value = "\"" + dnsKeyValue + "\""
                        }
                    }
                };

                ApplyDnsChange(zone, txtRecord, ChangeAction.UPSERT);
            }
            catch (AmazonRoute53Exception exp)
            {
                logger.Error($"Could not update AWS Route53 record: ", exp);
                return(false);
            }
            return(true);
        }