Added ZoneTransfer implementation
This commit is contained in:
77
src/Extensions/Cloudflare.Dns/Requests/CreateACLRequest.cs
Normal file
77
src/Extensions/Cloudflare.Dns/Requests/CreateACLRequest.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace AMWD.Net.Api.Cloudflare.Dns
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a request to create a DNS zone transfer access control list (ACL).
|
||||
/// </summary>
|
||||
public class CreateACLRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CreateACLRequest"/> class.
|
||||
/// </summary>
|
||||
/// <param name="accountId">The account identifier.</param>
|
||||
/// <param name="ipRange">Allowed IPv4/IPv6 address range of primary or secondary nameservers (CIDR).</param>
|
||||
/// <param name="name">The name of the ACL.</param>
|
||||
public CreateACLRequest(string accountId, string ipRange, string name)
|
||||
{
|
||||
IpRangeBaseAddress = IPAddress.None;
|
||||
IpRangeSubnet = 0;
|
||||
|
||||
AccountId = accountId;
|
||||
IpRange = ipRange;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The account identifier.
|
||||
/// </summary>
|
||||
public string AccountId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Allowed IPv4/IPv6 address range of primary or secondary nameservers.
|
||||
/// This will be applied for the entire account.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The IP range is used to allow additional NOTIFY IPs for secondary zones and IPs Cloudflare allows AXFR/IXFR requests from for primary zones.
|
||||
/// CIDRs are limited to a maximum of /24 for IPv4 and /64 for IPv6 respectively.
|
||||
/// </remarks>
|
||||
public string IpRange
|
||||
{
|
||||
get => $"{IpRangeBaseAddress}/{IpRangeSubnet}";
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
throw new ArgumentNullException(nameof(value), $"{nameof(IpRange)} cannot be null or empty.");
|
||||
|
||||
string[] parts = value.Split('/');
|
||||
if (parts.Length != 2)
|
||||
throw new FormatException("Invalid IP range format.");
|
||||
|
||||
var prefix = IPAddress.Parse(parts[0]);
|
||||
|
||||
if (!int.TryParse(parts[1], out int prefixLength))
|
||||
throw new FormatException("Invalid IP range subnet format.");
|
||||
|
||||
if (prefix.AddressFamily == AddressFamily.InterNetwork && (prefixLength < 0 || 32 < prefixLength))
|
||||
throw new FormatException("Invalid subnet length for IPv4.");
|
||||
|
||||
if (prefix.AddressFamily == AddressFamily.InterNetworkV6 && (prefixLength < 0 || 128 < prefixLength))
|
||||
throw new FormatException("Invalid subnet length for IPv6.");
|
||||
|
||||
IpRangeBaseAddress = prefix;
|
||||
IpRangeSubnet = prefixLength;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The name of the ACL.
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
internal IPAddress IpRangeBaseAddress { get; set; }
|
||||
|
||||
internal int IpRangeSubnet { get; set; }
|
||||
}
|
||||
}
|
||||
29
src/Extensions/Cloudflare.Dns/Requests/CreatePeerRequest.cs
Normal file
29
src/Extensions/Cloudflare.Dns/Requests/CreatePeerRequest.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
namespace AMWD.Net.Api.Cloudflare.Dns
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a request to create a new peer within a specific account.
|
||||
/// </summary>
|
||||
public class CreatePeerRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CreatePeerRequest"/> class.
|
||||
/// </summary>
|
||||
/// <param name="accountId">The account identifier.</param>
|
||||
/// <param name="name">The name of the peer.</param>
|
||||
public CreatePeerRequest(string accountId, string name)
|
||||
{
|
||||
AccountId = accountId;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The account identifier.
|
||||
/// </summary>
|
||||
public string AccountId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the peer.
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
43
src/Extensions/Cloudflare.Dns/Requests/CreateTSIGRequest.cs
Normal file
43
src/Extensions/Cloudflare.Dns/Requests/CreateTSIGRequest.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
namespace AMWD.Net.Api.Cloudflare.Dns
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a request to create a TSIG (Transaction Signature) key for DNS operations.
|
||||
/// </summary>
|
||||
public class CreateTSIGRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CreateTSIGRequest"/> class.
|
||||
/// </summary>
|
||||
/// <param name="accountId">The account identifier.</param>
|
||||
/// <param name="name">TSIG key name.</param>
|
||||
/// <param name="secret">TSIG secret.</param>
|
||||
public CreateTSIGRequest(string accountId, string name, string secret)
|
||||
{
|
||||
Algorithm = TSigAlgorithm.HMAC_SHA256;
|
||||
|
||||
AccountId = accountId;
|
||||
Name = name;
|
||||
Secret = secret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The account identifier.
|
||||
/// </summary>
|
||||
public string AccountId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// TSIG algorithm.
|
||||
/// </summary>
|
||||
public TSigAlgorithm Algorithm { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// TSIG key name.
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// TSIG secret.
|
||||
/// </summary>
|
||||
public string Secret { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace AMWD.Net.Api.Cloudflare.Dns
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a request to create a primary zone configuration.
|
||||
/// </summary>
|
||||
public class PrimaryZoneConfigurationRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PrimaryZoneConfigurationRequest"/> class.
|
||||
/// </summary>
|
||||
/// <param name="zoneId">The zone identifier.</param>
|
||||
/// <param name="name">The zone name.</param>
|
||||
public PrimaryZoneConfigurationRequest(string zoneId, string name)
|
||||
{
|
||||
ZoneId = zoneId;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The zone identifier.
|
||||
/// </summary>
|
||||
public string ZoneId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The zone name.
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A list of peer tags.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<string> Peers { get; set; } = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
namespace AMWD.Net.Api.Cloudflare.Dns
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a request to create a secondary zone configuration.
|
||||
/// </summary>
|
||||
public class SecondaryZoneConfigurationRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SecondaryZoneConfigurationRequest"/> class.
|
||||
/// </summary>
|
||||
/// <param name="zoneId">The zone identifier.</param>
|
||||
/// <param name="name">The zone name.</param>
|
||||
public SecondaryZoneConfigurationRequest(string zoneId, string name)
|
||||
{
|
||||
ZoneId = zoneId;
|
||||
Name = name;
|
||||
|
||||
Peers = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The zone identifier.
|
||||
/// </summary>
|
||||
public string ZoneId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Zone name.
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// How often should a secondary zone auto refresh regardless of DNS NOTIFY. Not applicable for primary zones.
|
||||
/// </summary>
|
||||
public int AutoRefreshSeconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A list of peer tags.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<string> Peers { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace AMWD.Net.Api.Cloudflare.Dns
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a request to update an existing DNS zone transfer access control list (ACL).
|
||||
/// </summary>
|
||||
public class UpdateDnsZoneTransferAclRequest : CreateACLRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateDnsZoneTransferAclRequest"/> class.
|
||||
/// </summary>
|
||||
/// <param name="accountId">The account identifier.</param>
|
||||
/// <param name="aclId">The access control list identifier.</param>
|
||||
/// <param name="ipRange">Allowed IPv4/IPv6 address range of primary or secondary nameservers (CIDR).</param>
|
||||
/// <param name="name">The name of the ACL.</param>
|
||||
public UpdateDnsZoneTransferAclRequest(string accountId, string aclId, string ipRange, string name)
|
||||
: base(accountId, ipRange, name)
|
||||
{
|
||||
AclId = aclId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The access control list identifier.
|
||||
/// </summary>
|
||||
public string AclId { get; set; }
|
||||
}
|
||||
}
|
||||
49
src/Extensions/Cloudflare.Dns/Requests/UpdatePeerRequest.cs
Normal file
49
src/Extensions/Cloudflare.Dns/Requests/UpdatePeerRequest.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
namespace AMWD.Net.Api.Cloudflare.Dns
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a request to update an existing peer with new configuration details.
|
||||
/// </summary>
|
||||
public class UpdatePeerRequest : CreatePeerRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdatePeerRequest"/> class.
|
||||
/// </summary>
|
||||
/// <param name="accountId">The account identifier.</param>
|
||||
/// <param name="peerId">The peer identifier.</param>
|
||||
/// <param name="name">The name of the peer</param>
|
||||
public UpdatePeerRequest(string accountId, string peerId, string name)
|
||||
: base(accountId, name)
|
||||
{
|
||||
PeerId = peerId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The peer identifier.
|
||||
/// </summary>
|
||||
public string PeerId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// IPv4/IPv6 address of primary or secondary nameserver, depending on what zone this peer is linked to.
|
||||
/// <list type="bullet">
|
||||
/// <item>For primary zones this IP defines the IP of the secondary nameserver Cloudflare will NOTIFY upon zone changes.</item>
|
||||
/// <item>For secondary zones this IP defines the IP of the primary nameserver Cloudflare will send AXFR/IXFR requests to.</item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public string? IpAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Enable IXFR transfer protocol, default is AXFR. Only applicable to secondary zones.
|
||||
/// </summary>
|
||||
public bool? IXFREnable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// DNS port of primary or secondary nameserver, depending on what zone this peer is linked to.
|
||||
/// </summary>
|
||||
public int? Port { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// TSIG authentication will be used for zone transfer if configured.
|
||||
/// </summary>
|
||||
public string? TSIGId { get; set; }
|
||||
}
|
||||
}
|
||||
26
src/Extensions/Cloudflare.Dns/Requests/UpdateTSIGRequest.cs
Normal file
26
src/Extensions/Cloudflare.Dns/Requests/UpdateTSIGRequest.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
namespace AMWD.Net.Api.Cloudflare.Dns
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a request to update an existing TSIG (Transaction Signature) key.
|
||||
/// </summary>
|
||||
public class UpdateTSIGRequest : CreateTSIGRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateTSIGRequest"/> class.
|
||||
/// </summary>
|
||||
/// <param name="accountId">The account identifier.</param>
|
||||
/// <param name="tsigId">The TSIG identifier.</param>
|
||||
/// <param name="name">TSIG key name.</param>
|
||||
/// <param name="secret">TSIG secret.</param>
|
||||
public UpdateTSIGRequest(string accountId, string tsigId, string name, string secret)
|
||||
: base(accountId, name, secret)
|
||||
{
|
||||
TSigId = tsigId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The TSIG identifier.
|
||||
/// </summary>
|
||||
public string TSigId { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user