-
Notifications
You must be signed in to change notification settings - Fork 0
/
EditDnsRequestModel.cs
117 lines (100 loc) · 4.19 KB
/
EditDnsRequestModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using YandexDnsAPI.Enums;
using YandexDnsAPI.Helpers;
namespace YandexDnsAPI.Models.Request
{
public class EditDnsRequestModel
{
/// <summary>
/// Yandex token
/// </summary>
public string Token { get; set; }
/// <summary>
/// DNS record identificator
/// </summary>
public int RecordId { get; set; }
/// <summary>
/// Email address of domain administrator.
/// Requred only for SOA
/// </summary>
public string AdminEmail { get; set; }
/// <summary>
/// Domain properties
/// </summary>
public DomainContent DomainContent { get; set; }
/// <summary>
/// Weight of SRV record relatively of other SRV records with same priority.
/// Required only for SRV
/// </summary>
public int? Weight { get; set; }
/// <summary>
/// TCP or UDP port of host.
/// Required only for SRC record
/// </summary>
public string Port { get; set; }
/// <summary>
/// Canonical host name.
/// Required onl for SRV record
/// </summary>
public string Target { get; set; }
/// <summary>
/// Frequency of checking the secondary DNS servers for a DNS record for this zone.
/// Allowed values between 900 and 86400.
/// Recommented value is 10800.
/// Required for SOA record.
/// </summary>
public int? Refresh { get; set; }
/// <summary>
/// Time in seconds between secondary DNS servers attempts to retrieve zone records.
/// Retries would be sent if the primary server doesn't respond.
/// Allowed values between 90 and 3600.
/// Recommended value is 900.
/// Required for SOA record.
/// </summary>
public int? Retry { get; set; }
/// <summary>
/// Time in seconds after which secondary DNS servers consider the zone records not-existent if primary server doesn't respond.
/// Allowed values between 90 and 3600.
/// Recommended value is 900.
/// Required for SOA record.
/// </summary>
public int? Expire { get; set; }
/// <summary>
/// Time in seconds during which the negative response (ERROR = NXDOMAIN) from DNS server will be cached.
/// Allowed values between 90 and 86400.
/// Recommended value is 10800.
/// Required for SOA record.
/// </summary>
public int? NegCache { get; set; }
public void Validate()
{
ValidationHelper.ThrowIfNullOrEmpty(this.Token);
ValidationHelper.ThrowIfNull(this.DomainContent);
ValidationHelper.ThrowIfNullOrEmpty(this.DomainContent.Domain);
ValidationHelper.ThrowIfNotInBound(this.DomainContent.TTL, 900, 1209600);
ValidationHelper.ThrowIfNotInBound(this.Refresh, 900, 86400);
ValidationHelper.ThrowIfNotInBound(this.Retry, 90, 3600);
ValidationHelper.ThrowIfNotInBound(this.Expire, 90, 3600);
ValidationHelper.ThrowIfNotInBound(this.NegCache, 90, 86400);
ValidationHelper.ThrowIfFalse(!DnsSource.DnsTypes.ContainsKey(this.DomainContent.Type), nameof(this.DomainContent.Type));
if (this.DomainContent.Type == DnsSource.DnsTypeEnum.SOA)
{
ValidationHelper.ThrowIfNull(this.Refresh);
ValidationHelper.ThrowIfNull(this.Retry);
ValidationHelper.ThrowIfNull(this.Expire);
ValidationHelper.ThrowIfNull(this.NegCache);
ValidationHelper.ThrowIfNullOrEmpty(this.AdminEmail);
}
if (this.DomainContent.Type == DnsSource.DnsTypeEnum.SRV)
{
ValidationHelper.ThrowIfNull(this.DomainContent.Priority);
ValidationHelper.ThrowIfNull(this.Weight);
ValidationHelper.ThrowIfNullOrEmpty(this.Port);
ValidationHelper.ThrowIfNullOrEmpty(this.Target);
}
if (this.DomainContent.Type == DnsSource.DnsTypeEnum.MX)
{
ValidationHelper.ThrowIfNull(this.DomainContent.Priority);
}
}
}
}