forked from andrexus/goinwx
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdnssec.go
More file actions
215 lines (173 loc) · 5.41 KB
/
dnssec.go
File metadata and controls
215 lines (173 loc) · 5.41 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package goinwx
import (
"errors"
"time"
"github.com/fatih/structs"
"github.com/go-viper/mapstructure/v2"
)
const (
methodDNSSecAddDNSKey = "dnssec.adddnskey"
methodDNSSecDeleteAll = "dnssec.deleteall"
methodDNSSecDeleteDNSKey = "dnssec.deletednskey"
methodDNSSecDisableDNSSec = "dnssec.disablednssec"
methodDNSSecEnableDNSSec = "dnssec.enablednssec"
methodDNSSecInfo = "dnssec.info"
methodDNSSecListKeys = "dnssec.listkeys"
)
// DNSSecService API access to DNSSEC.
type DNSSecService service
// Add adds one DNSKEY to a specified domain.
func (s *DNSSecService) Add(request *DNSSecAddRequest) (*DNSSecAddResponse, error) {
if request == nil {
return nil, errors.New("request can't be nil")
}
requestMap := structs.Map(request)
req := s.client.NewRequest(methodDNSSecAddDNSKey, requestMap)
resp, err := s.client.Do(req)
if err != nil {
return nil, err
}
var result DNSSecAddResponse
err = mapstructure.Decode(resp, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// DeleteAll deletes all DNSKEY/DS entries for a domain.
func (s *DNSSecService) DeleteAll(domain string) error {
req := s.client.NewRequest(methodDNSSecDeleteAll, map[string]any{
"domainName": domain,
})
_, err := s.client.Do(req)
if err != nil {
return err
}
return nil
}
// DeleteDNSKey deletes one DNSKEY from a specified domain.
func (s *DNSSecService) DeleteDNSKey(key string) error {
req := s.client.NewRequest(methodDNSSecDeleteDNSKey, map[string]any{
"key": key,
})
_, err := s.client.Do(req)
if err != nil {
return err
}
return nil
}
// Disable disables automated DNSSEC management for a domain.
func (s *DNSSecService) Disable(domain string) error {
req := s.client.NewRequest(methodDNSSecDisableDNSSec, map[string]any{
"domainName": domain,
})
_, err := s.client.Do(req)
if err != nil {
return err
}
return nil
}
// Enable enables automated DNSSEC management for a domain.
func (s *DNSSecService) Enable(domain string) error {
req := s.client.NewRequest(methodDNSSecEnableDNSSec, map[string]any{
"domainName": domain,
})
_, err := s.client.Do(req)
if err != nil {
return err
}
return nil
}
// Info gets current DNSSEC information.
func (s *DNSSecService) Info(domains []string) (*DNSSecInfoResponse, error) {
req := s.client.NewRequest(methodDNSSecInfo, map[string]any{
"domains": domains,
})
resp, err := s.client.Do(req)
if err != nil {
return nil, err
}
var result DNSSecInfoResponse
err = mapstructure.Decode(resp, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// List lists domains.
func (s *DNSSecService) List(request *DNSSecServiceListRequest) (*DNSSecServiceList, error) {
if request == nil {
return nil, errors.New("request can't be nil")
}
requestMap := structs.Map(request)
req := s.client.NewRequest(methodDNSSecListKeys, requestMap)
resp, err := s.client.Do(req)
if err != nil {
return nil, err
}
var result DNSSecServiceList
err = mapstructure.Decode(resp, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// DNSSecAddRequest API model.
type DNSSecAddRequest struct {
DomainName string `structs:"domainName,omitempty"`
DNSKey string `structs:"dnskey,omitempty"`
DS string `structs:"ds,omitempty"`
CalculateDigest bool `structs:"calculateDigest,omitempty"`
DigestType int `structs:"digestType,omitempty"`
}
// DNSSecAddResponse API model.
type DNSSecAddResponse struct {
DNSKey string `mapstructure:"dnskey"`
DS string `mapstructure:"ds"`
}
// DNSSecInfoResponse API model.
type DNSSecInfoResponse struct {
Data []DNSSecInfo `mapstructure:"data"`
}
// DNSSecInfo API model.
type DNSSecInfo struct {
Domain string `mapstructure:"domain"`
KeyCount int `mapstructure:"keyCount"`
DNSSecStatus string `mapstructure:"dnsSecStatus"`
}
// DNSSecServiceListRequest API model.
type DNSSecServiceListRequest struct {
DomainName string `structs:"domainName,omitempty"`
DomainNameIdn string `structs:"domainNameIdn,omitempty"`
KeyTag int `structs:"keyTag,omitempty"`
FlagID int `structs:"flagId,omitempty"`
AlgorithmID int `structs:"algorithmId,omitempty"`
PublicKey string `structs:"publicKey,omitempty"`
DigestTypeID int `structs:"digestTypeId,omitempty"`
Digest string `structs:"digest,omitempty"`
CreatedBefore string `structs:"createdBefore,omitempty"`
CreatedAfter string `structs:"createdAfter,omitempty"`
Status string `structs:"status,omitempty"`
Active int `structs:"active,omitempty"`
Page int `structs:"page,omitempty"`
PageLimit int `structs:"pagelimit,omitempty"`
}
// DNSSecServiceList API model.
type DNSSecServiceList struct {
DNSKeys []DNSSecServiceListResponse `mapstructure:"dnskey"`
}
// DNSSecServiceListResponse API model.
type DNSSecServiceListResponse struct {
OwnerName string `mapstructure:"ownerName"`
ID int `mapstructure:"id"`
DomainID int `mapstructure:"domainId"`
KeyTag int `mapstructure:"keyTag"`
FlagID int `mapstructure:"flagId"`
AlgorithmID int `mapstructure:"algorithmId"`
PublicKey string `mapstructure:"publicKey"`
DigestTypeID int `mapstructure:"digestTypeId"`
Digest string `mapstructure:"digest"`
Created time.Time `mapstructure:"created"`
Status string `mapstructure:"status"`
Active int `mapstructure:"active"`
}