public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems) { AmazonRoute53Config config = new AmazonRoute53Config(); config.RegionEndpoint = region; ConfigureClient(config); AmazonRoute53Client client = new AmazonRoute53Client(creds, config); ListHostedZonesResponse resp = new ListHostedZonesResponse(); do { ListHostedZonesRequest req = new ListHostedZonesRequest { Marker = resp.NextMarker , MaxItems = maxItems.ToString() }; resp = client.ListHostedZones(req); CheckError(resp.HttpStatusCode, "200"); foreach (var obj in resp.HostedZones) { AddObject(obj); } }while (!string.IsNullOrEmpty(resp.NextMarker)); }
private List <HostedZone> GetHostedZones() { try { var zonesResponse = client.ListHostedZones(); var zones = zonesResponse.ListHostedZonesResult.HostedZones; return(zones); } catch (Exception ex) { logger.Error(ex); return(null); } }
private string GetHostedZoneId(string recordName) { var domainName = _dnsClientProvider.DomainParser.Get(recordName); var response = _route53Client.ListHostedZones(); var hostedZone = response.HostedZones.SingleOrDefault(_ => string.Equals(_.Name.TrimEnd('.'), domainName.RegistrableDomain, StringComparison.InvariantCultureIgnoreCase)); if (hostedZone != null) { return(hostedZone.Id); } _log.Error($"Can't find hosted zone for domain {domainName.RegistrableDomain}"); return(null); }
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); }