@@ -6,17 +6,21 @@ import (
6
6
"strings"
7
7
)
8
8
9
- type Record struct {
10
- Name string `yaml:"host"`
11
- Type string `yaml:"type"`
12
- Ttl int `yaml:"ttl"`
13
- Data string `yaml:"content"`
14
- }
15
-
16
9
const (
10
+ // Record types that are allowed. Found in Porkbun's API documentation.
17
11
TYPE_ALLOWLIST = "A, MX, CNAME, ALIAS, TXT, NS, AAAA, SRV, TLSA, CAA, HTTPS, SVCB"
12
+ // Record types that are allowed to have a priority. Found in Porkbun's web app.
13
+ PRIORITY_ALLOWLIST = "MX, SRV"
18
14
)
19
15
16
+ type Record struct {
17
+ Name string `yaml:"host"`
18
+ Type string `yaml:"type"`
19
+ Ttl int `yaml:"ttl"`
20
+ Data string `yaml:"content"`
21
+ Priority int `yaml:"priority"`
22
+ }
23
+
20
24
func (r Record ) GetName () string {
21
25
return r .Name
22
26
}
@@ -33,6 +37,10 @@ func (r Record) GetData() string {
33
37
return r .Data
34
38
}
35
39
40
+ func (r Record ) GetPriority () string {
41
+ return fmt .Sprint (r .Priority )
42
+ }
43
+
36
44
func (r Record ) Validate () error {
37
45
if r .Name == "" {
38
46
return fmt .Errorf ("host is required" )
@@ -53,6 +61,10 @@ func (r Record) Validate() error {
53
61
return fmt .Errorf ("content is required" )
54
62
}
55
63
64
+ if r .Priority != 0 && ! isPriorityAllowed (r ) {
65
+ return fmt .Errorf ("priority must be one of %v" , PRIORITY_ALLOWLIST )
66
+ }
67
+
56
68
return nil
57
69
}
58
70
@@ -69,4 +81,17 @@ func isTypeAllowed(r Record) bool {
69
81
return true
70
82
}
71
83
84
+ func isPriorityAllowed (r Record ) bool {
85
+ allowedPriorities := make (map [string ]bool )
86
+ for _ , t := range strings .Split (PRIORITY_ALLOWLIST , ", " ) {
87
+ allowedPriorities [t ] = true
88
+ }
89
+
90
+ if _ , ok := allowedPriorities [r .Type ]; ! ok {
91
+ return false
92
+ }
93
+
94
+ return true
95
+ }
96
+
72
97
var _ dns.Record = Record {}
0 commit comments