public ListResourceRecordSetsResponse listRecordSets(string hostedZoneId, string startRecordIdentifier)
 {
     logger.Info("Calling ListResourceRecordSets");
     return(client.ListResourceRecordSets(new ListResourceRecordSetsRequest()
                                          .WithHostedZoneId(hostedZoneId)
                                          .WithStartRecordIdentifier(startRecordIdentifier)));
 }
        public ListResourceRecordSetsResponse listRecordSets(string hostedZoneId,
                                                             string startRecordIdentifier, string startRecordName, string startRecordType)
        {
            logger.Info("Calling ListResourceRecordSets");
            ListResourceRecordSetsRequest request = new ListResourceRecordSetsRequest()
            {
                HostedZoneId          = hostedZoneId,
                StartRecordIdentifier = startRecordIdentifier,
                StartRecordName       = startRecordName,
                StartRecordType       = startRecordType
            };

            return(client.ListResourceRecordSets(request));
        }
Esempio n. 3
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);
        }