Added DNS Records for Zone actions

This commit is contained in:
2024-11-11 10:23:19 +01:00
parent e561ad8ee7
commit 815c9e3e9d
38 changed files with 5581 additions and 69 deletions

View File

@@ -0,0 +1,34 @@
using System.Collections.Generic;
namespace AMWD.Net.Api.Cloudflare.Zones
{
/// <summary>
/// The DNS batch execution response.
/// </summary>
public class BatchDnsRecordsResult
{
/// <summary>
/// The deleted records.
/// </summary>
[JsonProperty("deletes")]
public IList<DnsRecord>? DeletedRecords { get; set; }
/// <summary>
/// The updated records.
/// </summary>
[JsonProperty("patches")]
public IList<DnsRecord>? UpdatedRecords { get; set; }
/// <summary>
/// The overwritten records.
/// </summary>
[JsonProperty("puts")]
public IList<DnsRecord>? OverwrittenRecords { get; set; }
/// <summary>
/// The created records.
/// </summary>
[JsonProperty("posts")]
public IList<DnsRecord>? CreatedRecords { get; set; }
}
}

View File

@@ -0,0 +1,618 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Newtonsoft.Json.Serialization;
namespace AMWD.Net.Api.Cloudflare.Zones
{
/// <summary>
/// DNS record.
/// </summary>
public class DnsRecord
{
/// <summary>
/// Identifier.
/// </summary>
[JsonProperty("id")]
public string? Id { get; set; }
/// <summary>
/// Identifier of the zone.
/// </summary>
[JsonProperty("zone_id")]
public string? ZoneId { get; set; }
/// <summary>
/// Name of the zone.
/// </summary>
[JsonProperty("zone_name")]
public string? ZoneName { get; set; }
/// <summary>
/// DNS record name (or @ for the zone apex) in Punycode.
/// </summary>
[JsonProperty("name")]
public string? Name { get; set; }
/// <summary>
/// Record type.
/// </summary>
[JsonProperty("type")]
public DnsRecordType Type { get; set; }
/// <summary>
/// A valid record content.
/// </summary>
[JsonProperty("content")]
public string? Content { get; set; }
/// <summary>
/// Components associated with the record.
/// </summary>
[JsonProperty("data")]
public object? Data { get; set; }
/// <summary>
/// Whether the record can be proxied by Cloudflare or not.
/// </summary>
[JsonProperty("proxiable")]
public bool Proxiable { get; set; }
/// <summary>
/// Whether the record is receiving the performance and security benefits of Cloudflare.
/// </summary>
[JsonProperty("proxied")]
public bool Proxied { get; set; }
/// <summary>
/// Time To Live (TTL) of the DNS record in seconds. Setting to 1 means 'automatic'.
/// Value must be between 60 and 86400, <em>with the minimum reduced to 30 for Enterprise zones</em>.
/// </summary>
/// <value>Unit: seconds. Range: <c>60 &lt;=</c> X <c>&lt;= 86400</c></value>
[JsonProperty("ttl")]
public int Ttl { get; set; }
/// <summary>
/// Settings for the DNS record.
/// </summary>
[JsonProperty("settings")]
public object? Settings { get; set; }
/// <summary>
/// Extra Cloudflare-specific information about the record.
/// </summary>
[JsonProperty("meta")]
public DnsRecordMeta? Meta { get; set; }
/// <summary>
/// Comments or notes about the DNS record. This field has no effect on DNS responses.
/// </summary>
[JsonProperty("comment")]
public string? Comment { get; set; }
/// <summary>
/// Custom tags for the DNS record. This field has no effect on DNS responses.
/// </summary>
[JsonProperty("tags")]
public IList<string>? Tags { get; set; }
/// <summary>
/// When the record was created.
/// </summary>
[JsonProperty("created_on")]
public DateTime CreatedOn { get; set; }
/// <summary>
/// When the record was last modified.
/// </summary>
[JsonProperty("modified_on")]
public DateTime ModifiedOn { get; set; }
/// <summary>
/// When the record comment was last modified. Omitted if there is no comment.
/// </summary>
[JsonProperty("comment_modified_on")]
public DateTime? CommentModifiedOn { get; set; }
/// <summary>
/// When the record tags were last modified. Omitted if there are no tags.
/// </summary>
[JsonProperty("tags_modified_on")]
public DateTime? TagsModifiedOn { get; set; }
#region Type definitions for data fields
/// <summary>
/// Components of a CAA record.
/// </summary>
public class CaaData(byte flags, string tag, string value)
{
/// <summary>
/// Flags for the CAA record
/// </summary>
/// <value>Range: <c>0 &lt;=</c> X <c>&lt;= 255</c></value>
[JsonProperty("flags")]
public byte Flags { get; set; } = flags;
/// <summary>
/// Name of the property controlled by this record (e.g.: issue, issuewild, iodef).
/// </summary>
[JsonProperty("tag")]
public string Tag { get; set; } = tag;
/// <summary>
/// Value of the record. This field's semantics depend on the chosen tag.
/// </summary>
[JsonProperty("value")]
public string Value { get; set; } = value;
}
/// <summary>
/// Components of a CERT record.
/// </summary>
public class CertData(byte algorithm, string certificate, ushort keyTag, ushort type)
{
/// <summary>
/// Algorithm of the certificate
/// </summary>
[JsonProperty("algorithm")]
public byte Algorithm { get; set; } = algorithm;
/// <summary>
/// Base64 encoded certificate.
/// </summary>
[JsonProperty("certificate")]
public string Certificate { get; set; } = certificate;
/// <summary>
/// Key tag.
/// </summary>
[JsonProperty("key_tag")]
public ushort KeyTag { get; set; } = keyTag;
/// <summary>
/// Type.
/// </summary>
[JsonProperty("type")]
public ushort Type { get; set; } = type;
}
/// <summary>
/// Components of a DNSKEY record.
/// </summary>
public class DnsKeyData(byte algorithm, ushort flags, byte protocol, string publicKey)
{
/// <summary>
/// Algorithm of the certificate
/// </summary>
[JsonProperty("algorithm")]
public byte Algorithm { get; set; } = algorithm;
/// <summary>
/// Algorithm of the certificate
/// </summary>
[JsonProperty("flags")]
public ushort Flags { get; set; } = flags;
/// <summary>
/// Algorithm of the certificate
/// </summary>
[JsonProperty("protocol")]
public byte Protocol { get; set; } = protocol;
/// <summary>
/// Public key.
/// </summary>
[JsonProperty("public_key")]
public string PublicKey { get; set; } = publicKey;
}
/// <summary>
/// Components of a DS record.
/// </summary>
public class DsData(byte algorithm, string digest, byte digestType, ushort keyTag)
{
/// <summary>
/// Algorithm of the certificate
/// </summary>
[JsonProperty("algorithm")]
public byte Algorithm { get; set; } = algorithm;
/// <summary>
/// Digest.
/// </summary>
[JsonProperty("digest")]
public string Digest { get; set; } = digest;
/// <summary>
/// Digest type.
/// </summary>
[JsonProperty("digest_type")]
public byte DigestType { get; set; } = digestType;
/// <summary>
/// Key tag.
/// </summary>
[JsonProperty("key_tag")]
public ushort KeyTag { get; set; } = keyTag;
}
/// <summary>
/// Components of an HTTPS record.
/// </summary>
public class HttpsData(ushort priority, string target, string value)
{
/// <summary>
/// Priority.
/// </summary>
[JsonProperty("priority")]
public ushort Priority { get; set; } = priority;
/// <summary>
/// Target.
/// </summary>
[JsonProperty("target")]
public string Target { get; set; } = target;
/// <summary>
/// Value.
/// </summary>
[JsonProperty("Value")]
public string Value { get; set; } = value;
}
/// <summary>
/// Components of a LOC record.
/// </summary>
public class LocData(int latitudeDegrees, int latitudeMinutes, double latitudeSeconds, LatitudeDirection latitudeDirection,
int longitudeDegrees, int longitudeMinutes, double longitudeSeconds, LongitudeDirection longitudeDirection,
double altitude, int size, int precisionHorizontal, int precisionVertical)
{
/// <summary>
/// Degrees of latitude.
/// </summary>
/// <value>Unit: degree. Range: <c>0 &lt;= X &lt;= 90</c></value>
[JsonProperty("lat_degrees")]
public int LatitudeDegrees { get; set; } = latitudeDegrees;
/// <summary>
/// Minutes of latitude.
/// </summary>
/// <value>Unit: minute. Range: <c>0 &lt;= X &lt;= 59</c></value>
[JsonProperty("lat_minutes")]
public int LatitudeMinutes { get; set; } = latitudeMinutes;
/// <summary>
/// Seconds of latitude.
/// </summary>
/// <value>Unit: second. Range: <c>0 &lt;= X &lt;= 59.999</c></value>
[JsonProperty("lat_seconds")]
public double LatitudeSeconds { get; set; } = latitudeSeconds;
/// <summary>
/// Latitude direction.
/// </summary>
[JsonProperty("lat_direction")]
public LatitudeDirection LatitudeDirection { get; set; } = latitudeDirection;
/// <summary>
/// Degrees of longitude.
/// </summary>
/// <value>Unit: degree. Range: <c>0 &lt;= X &lt;= 180</c></value>
[JsonProperty("long_degrees")]
public int LongitudeDegrees { get; set; } = longitudeDegrees;
/// <summary>
/// Minutes of longitude.
/// </summary>
/// <value>Unit: minute. Range: <c>0 &lt;= X &lt;= 59</c></value>
[JsonProperty("long_minutes")]
public int LongitudeMinutes { get; set; } = longitudeMinutes;
/// <summary>
/// Seconds of longitude.
/// </summary>
/// <value>Unit: second. Range: <c>0 &lt;= X &lt;= 59.999</c></value>
[JsonProperty("long_seconds")]
public double LongitudeSeconds { get; set; } = longitudeSeconds;
/// <summary>
/// Longitude direction.
/// </summary>
[JsonProperty("long_direction")]
public LongitudeDirection LongitudeDirection { get; set; } = longitudeDirection;
/// <summary>
/// Altitude of location in meters.
/// </summary>
/// <value>Unit: meter. Range: <c>-100_000.00 &lt;= X &lt;= 42_849_672.95</c></value>
[JsonProperty("altitude")]
public double Altitude { get; set; } = altitude;
/// <summary>
/// Size of location in meters.
/// </summary>
/// <value>Unit: meter. Range: <c>0 &lt;= X &lt;= 90_000_000</c></value>
[JsonProperty("size")]
public int Size { get; set; } = size;
/// <summary>
/// Horizontal precision of location.
/// </summary>
/// <value>Unit: meter. Range: <c>0 &lt;= X &lt;= 90_000_000</c></value>
[JsonProperty("precision_horz")]
public int PrecisionHorizontal { get; set; } = precisionHorizontal;
/// <summary>
/// Vertical precision of location.
/// </summary>
/// <value>Unit: meter. Range: <c>0 &lt;= X &lt;= 90_000_000</c></value>
[JsonProperty("precision_vert")]
public int PrecisionVertical { get; set; } = precisionVertical;
}
/// <summary>
/// Components of a NAPTR record.
/// </summary>
public class NaPtrData(string flags, ushort order, ushort preference, string regex, string replacement, string service)
{
/// <summary>
/// Flags.
/// </summary>
[JsonProperty("flags")]
public string Flags { get; set; } = flags;
/// <summary>
/// Order.
/// </summary>
[JsonProperty("order")]
public ushort Order { get; set; } = order;
/// <summary>
/// Preference.
/// </summary>
[JsonProperty("preference")]
public ushort Preference { get; set; } = preference;
/// <summary>
/// Service.
/// </summary>
[JsonProperty("regex")]
public string Regex { get; set; } = regex;
/// <summary>
/// Replacement.
/// </summary>
[JsonProperty("replacement")]
public string Replacement { get; set; } = replacement;
/// <summary>
/// Service.
/// </summary>
[JsonProperty("service")]
public string Service { get; set; } = service;
}
/// <summary>
/// Components of a SMIMEA record.
/// </summary>
public class SMimeAData(string certificate, byte matchingType, byte selector, byte usage)
{
/// <summary>
/// Certificate.
/// </summary>
[JsonProperty("certificate")]
public string Certificate { get; set; } = certificate;
/// <summary>
/// Matching type.
/// </summary>
[JsonProperty("matching_type")]
public byte MatchingType { get; set; } = matchingType;
/// <summary>
/// Selector.
/// </summary>
[JsonProperty("selector")]
public byte Selector { get; set; } = selector;
/// <summary>
/// Usage.
/// </summary>
[JsonProperty("usage")]
public byte Usage { get; set; } = usage;
}
/// <summary>
/// Components of a SRV record.
/// </summary>
public class SrvData(ushort port, ushort priority, string target, ushort weight)
{
/// <summary>
/// The port of the service.
/// </summary>
[JsonProperty("port")]
public ushort Port { get; set; } = port;
/// <summary>
/// The priority of the service.
/// </summary>
/// <remarks>
/// Required for <see cref="DnsRecordType.Mx"/>, <see cref="DnsRecordType.Srv"/> and <see cref="DnsRecordType.Uri"/> records; unused by other record types.
/// Records with lower priorities are preferred.
/// </remarks>
[JsonProperty("priority")]
public ushort Priority { get; set; } = priority;
/// <summary>
/// A valid hostname.
/// </summary>
[JsonProperty("target")]
public string Target { get; set; } = target;
/// <summary>
/// The weight of the record.
/// </summary>
[JsonProperty("weight")]
public ushort Weight { get; set; } = weight;
}
/// <summary>
/// Components of a SSHFP record.
/// </summary>
public class SshFpData(byte algorithm, string fingerprint, byte type)
{
/// <summary>
/// Algorithm.
/// </summary>
[JsonProperty("algorithm")]
public byte Algorithm { get; set; } = algorithm;
/// <summary>
/// Fingerprint.
/// </summary>
[JsonProperty("fingerprint")]
public string Fingerprint { get; set; } = fingerprint;
/// <summary>
/// Type.
/// </summary>
[JsonProperty("type")]
public byte Type { get; set; } = type;
}
/// <summary>
/// Components of a SVCB record.
/// </summary>
public class SvcBData(ushort priority, string target, string value)
{
/// <summary>
/// The priority of the service binding.
/// </summary>
[JsonProperty("priority")]
public ushort Priority { get; set; } = priority;
/// <summary>
/// A valid target.
/// </summary>
[JsonProperty("target")]
public string Target { get; set; } = target;
/// <summary>
/// The value of the service binding.
/// </summary>
/// <remarks>
/// e.g. <c>alpn="h3,h2" ipv4hint="127.0.0.1" ipv6hint="::1"</c>
/// </remarks>
[JsonProperty("value")]
public string Value { get; set; } = value;
}
/// <summary>
/// Components of a TLSA record.
/// </summary>
public class TlsAData(string certificate, byte matchingType, byte selector, byte usage)
{
/// <summary>
/// Certificate.
/// </summary>
[JsonProperty("certificate")]
public string Certificate { get; set; } = certificate;
/// <summary>
/// Matching type.
/// </summary>
[JsonProperty("matching_type")]
public byte MatchingType { get; set; } = matchingType;
/// <summary>
/// Selector.
/// </summary>
[JsonProperty("selector")]
public byte Selector { get; set; } = selector;
/// <summary>
/// Usage.
/// </summary>
[JsonProperty("usage")]
public byte Usage { get; set; } = usage;
}
/// <summary>
/// Components of a URI record.
/// </summary>
public class UriData(string target, ushort weight)
{
/// <summary>
/// A valid target.
/// </summary>
[JsonProperty("target")]
public string Target { get; set; } = target;
/// <summary>
/// The weight of the record.
/// </summary>
[JsonProperty("weight")]
public ushort Weight { get; set; } = weight;
}
#region Enums for data fields
/// <summary>
/// Directions for latitude.
/// </summary>
public enum LatitudeDirection
{
/// <summary>
/// North.
/// </summary>
[EnumMember(Value = "N")]
North = 1,
/// <summary>
/// South.
/// </summary>
[EnumMember(Value = "S")]
South = 2
}
/// <summary>
/// Directions for longitude.
/// </summary>
public enum LongitudeDirection
{
/// <summary>
/// East.
/// </summary>
[EnumMember(Value = "E")]
East = 1,
/// <summary>
/// West.
/// </summary>
[EnumMember(Value = "W")]
West = 2
}
#endregion Enums for data fields
#endregion Type definitions for data fields
#region Type definitions for settings fields
/// <summary>
/// Settings for the DNS record.
/// </summary>
public class CnameSettings(bool flattenCname)
{
/// <summary>
/// If enabled, causes the CNAME record to be resolved externally and the resulting address records (e.g., A and AAAA) to be returned instead of the CNAME record itself.
/// This setting has no effect on proxied records, which are always flattened.
/// </summary>
[JsonProperty("flatten_cname")]
public bool FlattenCname { get; set; } = flattenCname;
}
#endregion Type definitions for settings fields
}
}

View File

@@ -0,0 +1,26 @@
namespace AMWD.Net.Api.Cloudflare.Zones
{
/// <summary>
/// Extra Cloudflare-specific information about the record.
/// </summary>
public class DnsRecordMeta
{
/// <summary>
/// Whether the record was automatically added.
/// </summary>
[JsonProperty("auto_added")]
public bool AutoAdded { get; set; }
/// <summary>
/// Whether the record is managed by apps.
/// </summary>
[JsonProperty("managed_by_apps")]
public bool ManagedByApps { get; set; }
/// <summary>
/// Whether the record is managed by argo tunnel.
/// </summary>
[JsonProperty("managed_by_argo_tunnel")]
public bool ManagedByArgoTunnel { get; set; }
}
}

View File

@@ -1,9 +1,9 @@
namespace AMWD.Net.Api.Cloudflare.Zones
{
/// <summary>
/// The deleted zone.
/// The deleted id.
/// </summary>
public class ZoneIdResponse
public class IdResponse
{
/// <summary>
/// Identifier.

View File

@@ -0,0 +1,20 @@
namespace AMWD.Net.Api.Cloudflare.Zones
{
/// <summary>
/// The DNS records import result.
/// </summary>
public class ImportDnsRecordsResult
{
/// <summary>
/// Number of DNS records added.
/// </summary>
[JsonProperty("recs_added")]
public int? RecordsAdded { get; set; }
/// <summary>
/// Total number of DNS records parsed.
/// </summary>
[JsonProperty("total_records_parsed")]
public int? TotalRecordsParsed { get; set; }
}
}

View File

@@ -9,7 +9,7 @@
/// The nameserver type.
/// </summary>
[JsonProperty("type")]
public virtual NameserverType Type { get; set; }
public NameserverType Type { get; set; }
// TODO: DEPRECATED? - not available on API request.
///// <summary>
@@ -17,6 +17,6 @@
///// </summary>
///// <value>Range: <c>1 &lt;=</c> X <c>&lt;= 5</c></value>
//[JsonProperty("ns_set")]
//public virtual int NameserverSet { get; set; }
//public int NameserverSet { get; set; }
}
}

View File

@@ -31,34 +31,34 @@
/// </summary>
/// <value>Unit: seconds. Range: <c>86400 &lt;=</c> X <c>&lt;= 2419200</c></value>
[JsonProperty("expire")]
public virtual int Expire { get; set; }
public int Expire { get; set; }
/// <summary>
/// The time to live (TTL) for negative caching of records within the zone.
/// </summary>
/// <value>Unit: seconds. Range: <c>60 &lt;=</c> X <c>&lt;= 86400</c></value>
[JsonProperty("min_ttl")]
public virtual int MinimumTtl { get; set; }
public int MinimumTtl { get; set; }
/// <summary>
/// The primary nameserver, which may be used for outbound zone transfers.
/// </summary>
[JsonProperty("mname", NullValueHandling = NullValueHandling.Include)]
public virtual string PrimaryNameserver { get; set; }
public string PrimaryNameserver { get; set; }
/// <summary>
/// Time in seconds after which secondary servers should re-check the SOA record to see if the zone has been updated.
/// </summary>
/// <value>Unit: seconds. Range: <c>600 &lt;=</c> X <c>&lt;= 86400</c></value>
[JsonProperty("refresh")]
public virtual int Refresh { get; set; }
public int Refresh { get; set; }
/// <summary>
/// Time in seconds after which secondary servers should retry queries after the primary server was unresponsive.
/// </summary>
/// <value>Unit: seconds. Range: <c>600 &lt;=</c> X <c>&lt;= 86400</c></value>
[JsonProperty("retry")]
public virtual int Retry { get; set; }
public int Retry { get; set; }
/// <summary>
/// The email address of the zone administrator, with the first label representing the local part of the email address.
@@ -71,13 +71,13 @@
/// test\.user.example.org => test.user@example.org
/// </remarks>
[JsonProperty("rname", NullValueHandling = NullValueHandling.Include)]
public virtual string ZoneAdministrator { get; set; }
public string ZoneAdministrator { get; set; }
/// <summary>
/// The time to live (TTL) of the SOA record itself.
/// </summary>
/// <value>Unit: seconds. Range: <c>300 &lt;=</c> X <c>&lt;= 86400</c></value>
[JsonProperty("ttl")]
public virtual int Ttl { get; set; }
public int Ttl { get; set; }
}
}