public void UpdateSoaRecord(string zoneName, string host, string primaryNsServer, string primaryPerson) { //Null checking if (string.IsNullOrWhiteSpace(zoneName)) { throw new ArgumentNullException(nameof(zoneName)); } if (string.IsNullOrWhiteSpace(primaryNsServer)) { throw new ArgumentNullException(nameof(primaryNsServer)); } if (string.IsNullOrWhiteSpace(primaryPerson)) { throw new ArgumentNullException(nameof(primaryPerson)); } //Define the endpoint since it is used multiple times var endpoint = $"zones/{zoneName}/records"; //Get all the existing records //We need to get all the records according to the new API specification, as the PUT request updates the entire zones records - not just a single one //New API will automatically implement SOA serial number so we can pass a 0 on in its place var records = ZoneRecordsResponse.FromJson(ApiGet(endpoint)); //Get the SOA record and edit it. Can disable ReSharper warning as there is always a SOA record //ReSharper disable once PossibleNullReferenceException records.FirstOrDefault(record => record.Type == "SOA").Data = $"{Utilities.CorrectSOARecord(zoneName, primaryNsServer)} {Utilities.CorrectSOARecord(zoneName, primaryPerson)} 0 {RefreshInterval} {RetryDelay} {ExpireLimit} {MinimumTTL}"; //PUT the records back to the API ApiPut(endpoint, records.ToJson()); }
public DnsRecord[] GetZoneRecords(string zoneName) { //Null checking if (string.IsNullOrWhiteSpace(zoneName)) { throw new ArgumentNullException(nameof(zoneName)); } //Get all the records for the specific zone var records = ZoneRecordsResponse.FromJson(ApiGet($"zones/{zoneName}/records")); //Return the resulting array without SOA and DNSSEC records List <string> dnsTypes = new List <string> { "A", "AAAA", "CAA", "MX", "NS", "TXT", "CNAME", "SRV" }; List <ZoneRecordsResponse> recordlist = new List <ZoneRecordsResponse>(); foreach (ZoneRecordsResponse rec in records) { if (dnsTypes.Contains(rec.Type)) { recordlist.Add(rec); } } return(recordlist.ToDnsRecordArray()); }
public DnsRecord[] GetZoneRecords(string zoneName) { //Null checking if (string.IsNullOrWhiteSpace(zoneName)) { throw new ArgumentNullException(nameof(zoneName)); } //Get all the records for the specific zone var records = ZoneRecordsResponse.FromJson(ApiGet($"zones/{zoneName}/records")); //Return the resulting array return(records.ToDnsRecordArray()); }