Skip to content

Commit 641cfc2

Browse files
Archirkchirkov
andauthored
Add support for ALIAS, CAA and SSHFP records (#25)
* Add support for ALIAS, CAA and SSHFP records * Fix comment typos * Add doc for new record opts Co-authored-by: chirkov <chirkov@selectel.ru>
1 parent b4bb143 commit 641cfc2

File tree

5 files changed

+166
-1
lines changed

5 files changed

+166
-1
lines changed

pkg/v1/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const (
1616
appName = "domains-go"
1717

1818
// appVersion is a version of the application.
19-
appVersion = "0.3.0"
19+
appVersion = "0.4.0"
2020

2121
// userAgent contains a basic user agent that will be used in queries.
2222
userAgent = appName + "/" + appVersion

pkg/v1/record/doc.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,39 @@ Example of domain record updating
6464
log.Fatal(err)
6565
}
6666
fmt.Printf("%+v\n", updatedRecord)
67+
68+
Examples of option struct for different types of records
69+
70+
ALIAS
71+
72+
createOpts := &record.CreateOpts{
73+
Name: "sub.example.com",
74+
Type: record.TypeALIAS,
75+
TTL: 60,
76+
Content: "example.com",
77+
}
78+
79+
CAA
80+
81+
createOpts := &record.CreateOpts{
82+
Name: "example.com",
83+
Type: record.TypeCAA,
84+
TTL: 60,
85+
Tag: "issue",
86+
Flag: 32,
87+
Value: "letsencrypt.org",
88+
}
89+
90+
SSHFP
91+
92+
createOpts := &record.CreateOpts{
93+
Name: "example.com",
94+
Type: record.TypeSSHFP,
95+
TTL: 60,
96+
Algrotihm: 1,
97+
FingerprintType: 2,
98+
Fingerprint: "RtvgDtzHTaRB5d2Yy5c1",
99+
}
100+
67101
*/
68102
package record

pkg/v1/record/requests_opts.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,30 @@ type CreateOpts struct {
3636
// Target represents the canonical hostname of the machine providing the service.
3737
// For SRV records only.
3838
Target string `json:"target,omitempty"`
39+
40+
// Tag represents the identifier of the property represented by the record.
41+
// For CAA records only.
42+
Tag string `json:"tag,omitempty"`
43+
44+
// Flag represents the critical flag, that has a specific meaning per RFC.
45+
// For CAA records only.
46+
Flag *int `json:"flag,omitempty"`
47+
48+
// The value associated with the tag.
49+
// For CAA records only.
50+
Value string `json:"value,omitempty"`
51+
52+
// Algorithm.
53+
// For SSHFP records only.
54+
Algorithm *int `json:"algorithm,omitempty"`
55+
56+
// Algorithm used to hash the public key
57+
// For SSHFP records only.
58+
FingerprintType *int `json:"fingerprint_type,omitempty"`
59+
60+
// Hexadecimal representation of the hash result, as text.
61+
// For SSHFP records only.
62+
Fingerprint string `json:"fingerprint,omitempty"`
3963
}
4064

4165
// UpdateOpts represents requests options to update a domain record.
@@ -74,4 +98,28 @@ type UpdateOpts struct {
7498
// Target represents the canonical hostname of the machine providing the service.
7599
// For SRV records only.
76100
Target string `json:"target,omitempty"`
101+
102+
// Tag represents the identifier of the property represented by the record.
103+
// For CAA records only.
104+
Tag string `json:"tag,omitempty"`
105+
106+
// Flag represents the critical flag, that has a specific meaning per RFC.
107+
// For CAA records only.
108+
Flag *int `json:"flag,omitempty"`
109+
110+
// The value associated with the tag.
111+
// For CAA records only.
112+
Value string `json:"value,omitempty"`
113+
114+
// Algorithm.
115+
// For SSHFP records only.
116+
Algorithm *int `json:"algorithm,omitempty"`
117+
118+
// Algorithm used to hash the public key
119+
// For SSHFP records only.
120+
FingerprintType *int `json:"fingerprint_type,omitempty"`
121+
122+
// Hexadecimal representation of the hash result, as text.
123+
// For SSHFP records only.
124+
Fingerprint string `json:"fingerprint,omitempty"`
77125
}

pkg/v1/record/schemas.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const (
1414
TypeSOA Type = "SOA"
1515
TypeMX Type = "MX"
1616
TypeSRV Type = "SRV"
17+
TypeCAA Type = "CAA"
18+
TypeSSHFP Type = "SSHFP"
19+
TypeALIAS Type = "ALIAS"
1720
TypeUnknown Type = "UNKNOWN"
1821
)
1922

@@ -60,6 +63,30 @@ type View struct {
6063
// Target represents the canonical hostname of the machine providing the service.
6164
// For SRV records only.
6265
Target string `json:"target,omitempty"`
66+
67+
// Tag represents the identifier of the property represented by the record.
68+
// For CAA records only.
69+
Tag string `json:"tag,omitempty"`
70+
71+
// Flag represents the critical flag, that has a specific meaning per RFC.
72+
// For CAA records only.
73+
Flag *int `json:"flag,omitempty"`
74+
75+
// The value associated with the tag.
76+
// For CAA records only.
77+
Value string `json:"value,omitempty"`
78+
79+
// Algorithm.
80+
// For SSHFP records only.
81+
Algorithm *int `json:"algorithm,omitempty"`
82+
83+
// Algorithm used to hash the public key
84+
// For SSHFP records only.
85+
FingerprintType *int `json:"fingerprint_type,omitempty"`
86+
87+
// Hexadecimal representation of the hash result, as text.
88+
// For SSHFP records only.
89+
Fingerprint string `json:"fingerprint,omitempty"`
6390
}
6491

6592
func (result *View) UnmarshalJSON(b []byte) error {
@@ -93,6 +120,12 @@ func (result *View) UnmarshalJSON(b []byte) error {
93120
result.Type = TypeSRV
94121
case TypeSOA:
95122
result.Type = TypeSOA
123+
case TypeCAA:
124+
result.Type = TypeCAA
125+
case TypeALIAS:
126+
result.Type = TypeALIAS
127+
case TypeSSHFP:
128+
result.Type = TypeSSHFP
96129
default:
97130
result.Type = TypeUnknown
98131
}

pkg/v1/record/testing/fixtures.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,31 @@ const testListResponseRaw = `
107107
"port" : 5222,
108108
"type" : "SRV",
109109
"priority" : 20
110+
},
111+
{
112+
"name" : "caa.testdomain.xyz",
113+
"ttl" : 86400,
114+
"id" : 4892462,
115+
"type" : "CAA",
116+
"tag" : "issue",
117+
"flag" : 1,
118+
"value" : "letsencrypt.com"
119+
},
120+
{
121+
"name" : "sshfp.testdomain.xyz",
122+
"ttl" : 86400,
123+
"id" : 4892472,
124+
"type" : "SSHFP",
125+
"algorithm" : 1,
126+
"fingerprint_type" : 1,
127+
"fingerprint" : "001a2B3CFF"
128+
},
129+
{
130+
"name" : "testdomain.zyx",
131+
"ttl" : 86400,
132+
"id" : 4892482,
133+
"type" : "ALIAS",
134+
"content" : "testdomain.xyz"
110135
}
111136
]
112137
`
@@ -182,6 +207,31 @@ var expectedListResponse = []*record.View{
182207
Target: "xmpp.example.com",
183208
TTL: 86400,
184209
},
210+
{
211+
ID: 4892462,
212+
Name: "caa.testdomain.xyz",
213+
Type: record.TypeCAA,
214+
Tag: "issue",
215+
Flag: testutils.IntPtr(1),
216+
Value: "letsencrypt.com",
217+
TTL: 86400,
218+
},
219+
{
220+
ID: 4892472,
221+
Name: "sshfp.testdomain.xyz",
222+
Type: record.TypeSSHFP,
223+
Algorithm: testutils.IntPtr(1),
224+
FingerprintType: testutils.IntPtr(1),
225+
Fingerprint: "001a2B3CFF",
226+
TTL: 86400,
227+
},
228+
{
229+
ID: 4892482,
230+
Name: "testdomain.zyx",
231+
Type: record.TypeALIAS,
232+
Content: "testdomain.xyz",
233+
TTL: 86400,
234+
},
185235
}
186236

187237
// testCreateRecordOptsRaw represents a raw request options for Create request.

0 commit comments

Comments
 (0)