コード例 #1
0
        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());
        }
コード例 #2
0
        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());
        }
コード例 #3
0
 public ZoneRecordsDeleteRequest(ZoneRecordsResponse baseResponse)
 {
     Name    = baseResponse.Name;
     Type    = baseResponse.Type;
     Ttl     = baseResponse.Ttl;
     Data    = baseResponse.Data;
     Comment = baseResponse.Comment;
     Remove  = true;
 }
コード例 #4
0
        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());
        }
コード例 #5
0
 public static string ToJson(this ZoneRecordsResponse self) =>
 JsonConvert.SerializeObject(self, Converter.Settings);
コード例 #6
0
        public void ZoneRecordsResponse()
        {
            var response = new ZoneRecordsResponse(_jToken);

            Assert.AreEqual(5, response.Data.Records.Count);
        }