/
dnssec.go
367 lines (321 loc) · 11.5 KB
/
dnssec.go
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package dnssec
import (
"context"
"fmt"
"net/http"
"reflect"
"time"
"github.com/cloudflare/cloudflare-go/v2/internal/apijson"
"github.com/cloudflare/cloudflare-go/v2/internal/param"
"github.com/cloudflare/cloudflare-go/v2/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v2/internal/shared"
"github.com/cloudflare/cloudflare-go/v2/option"
"github.com/tidwall/gjson"
)
// DNSSECService contains methods and other services that help with interacting
// with the cloudflare API. Note, unlike clients, this service does not read
// variables from the environment automatically. You should not instantiate this
// service directly, and instead use the [NewDNSSECService] method instead.
type DNSSECService struct {
Options []option.RequestOption
}
// NewDNSSECService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewDNSSECService(opts ...option.RequestOption) (r *DNSSECService) {
r = &DNSSECService{}
r.Options = opts
return
}
// Delete DNSSEC.
func (r *DNSSECService) Delete(ctx context.Context, params DNSSECDeleteParams, opts ...option.RequestOption) (res *DNSSECDeleteResponseUnion, err error) {
opts = append(r.Options[:], opts...)
var env DNSSECDeleteResponseEnvelope
path := fmt.Sprintf("zones/%s/dnssec", params.ZoneID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Enable or disable DNSSEC.
func (r *DNSSECService) Edit(ctx context.Context, params DNSSECEditParams, opts ...option.RequestOption) (res *DNSSEC, err error) {
opts = append(r.Options[:], opts...)
var env DNSSECEditResponseEnvelope
path := fmt.Sprintf("zones/%s/dnssec", params.ZoneID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Details about DNSSEC status and configuration.
func (r *DNSSECService) Get(ctx context.Context, query DNSSECGetParams, opts ...option.RequestOption) (res *DNSSEC, err error) {
opts = append(r.Options[:], opts...)
var env DNSSECGetResponseEnvelope
path := fmt.Sprintf("zones/%s/dnssec", query.ZoneID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
type DNSSEC struct {
// Algorithm key code.
Algorithm string `json:"algorithm,nullable"`
// Digest hash.
Digest string `json:"digest,nullable"`
// Type of digest algorithm.
DigestAlgorithm string `json:"digest_algorithm,nullable"`
// Coded type for digest algorithm.
DigestType string `json:"digest_type,nullable"`
// If true, multi-signer DNSSEC is enabled on the zone, allowing multiple providers
// to serve a DNSSEC-signed zone at the same time. This is required for DNSKEY
// records (except those automatically generated by Cloudflare) to be added to the
// zone.
//
// See
// [Multi-signer DNSSEC](https://developers.cloudflare.com/dns/dnssec/multi-signer-dnssec/)
// for details.
DNSSECMultiSigner bool `json:"dnssec_multi_signer"`
// If true, allows Cloudflare to transfer in a DNSSEC-signed zone including
// signatures from an external provider, without requiring Cloudflare to sign any
// records on the fly.
//
// Note that this feature has some limitations. See
// [Cloudflare as Secondary](https://developers.cloudflare.com/dns/zone-setups/zone-transfers/cloudflare-as-secondary/setup/#dnssec)
// for details.
DNSSECPresigned bool `json:"dnssec_presigned"`
// Full DS record.
DS string `json:"ds,nullable"`
// Flag for DNSSEC record.
Flags float64 `json:"flags,nullable"`
// Code for key tag.
KeyTag float64 `json:"key_tag,nullable"`
// Algorithm key type.
KeyType string `json:"key_type,nullable"`
// When DNSSEC was last modified.
ModifiedOn time.Time `json:"modified_on,nullable" format:"date-time"`
// Public key for DS record.
PublicKey string `json:"public_key,nullable"`
// Status of DNSSEC, based on user-desired state and presence of necessary records.
Status DNSSECStatus `json:"status"`
JSON dnssecJSON `json:"-"`
}
// dnssecJSON contains the JSON metadata for the struct [DNSSEC]
type dnssecJSON struct {
Algorithm apijson.Field
Digest apijson.Field
DigestAlgorithm apijson.Field
DigestType apijson.Field
DNSSECMultiSigner apijson.Field
DNSSECPresigned apijson.Field
DS apijson.Field
Flags apijson.Field
KeyTag apijson.Field
KeyType apijson.Field
ModifiedOn apijson.Field
PublicKey apijson.Field
Status apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DNSSEC) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r dnssecJSON) RawJSON() string {
return r.raw
}
// Status of DNSSEC, based on user-desired state and presence of necessary records.
type DNSSECStatus string
const (
DNSSECStatusActive DNSSECStatus = "active"
DNSSECStatusPending DNSSECStatus = "pending"
DNSSECStatusDisabled DNSSECStatus = "disabled"
DNSSECStatusPendingDisabled DNSSECStatus = "pending-disabled"
DNSSECStatusError DNSSECStatus = "error"
)
func (r DNSSECStatus) IsKnown() bool {
switch r {
case DNSSECStatusActive, DNSSECStatusPending, DNSSECStatusDisabled, DNSSECStatusPendingDisabled, DNSSECStatusError:
return true
}
return false
}
// Union satisfied by [dnssec.DNSSECDeleteResponseUnknown] or [shared.UnionString].
type DNSSECDeleteResponseUnion interface {
ImplementsDNSSECDNSSECDeleteResponseUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*DNSSECDeleteResponseUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
)
}
type DNSSECDeleteParams struct {
// Identifier
ZoneID param.Field[string] `path:"zone_id,required"`
Body interface{} `json:"body,required"`
}
func (r DNSSECDeleteParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.Body)
}
type DNSSECDeleteResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// Whether the API call was successful
Success DNSSECDeleteResponseEnvelopeSuccess `json:"success,required"`
Result DNSSECDeleteResponseUnion `json:"result"`
JSON dnssecDeleteResponseEnvelopeJSON `json:"-"`
}
// dnssecDeleteResponseEnvelopeJSON contains the JSON metadata for the struct
// [DNSSECDeleteResponseEnvelope]
type dnssecDeleteResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Success apijson.Field
Result apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DNSSECDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r dnssecDeleteResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type DNSSECDeleteResponseEnvelopeSuccess bool
const (
DNSSECDeleteResponseEnvelopeSuccessTrue DNSSECDeleteResponseEnvelopeSuccess = true
)
func (r DNSSECDeleteResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case DNSSECDeleteResponseEnvelopeSuccessTrue:
return true
}
return false
}
type DNSSECEditParams struct {
// Identifier
ZoneID param.Field[string] `path:"zone_id,required"`
// If true, multi-signer DNSSEC is enabled on the zone, allowing multiple providers
// to serve a DNSSEC-signed zone at the same time. This is required for DNSKEY
// records (except those automatically generated by Cloudflare) to be added to the
// zone.
//
// See
// [Multi-signer DNSSEC](https://developers.cloudflare.com/dns/dnssec/multi-signer-dnssec/)
// for details.
DNSSECMultiSigner param.Field[bool] `json:"dnssec_multi_signer"`
// If true, allows Cloudflare to transfer in a DNSSEC-signed zone including
// signatures from an external provider, without requiring Cloudflare to sign any
// records on the fly.
//
// Note that this feature has some limitations. See
// [Cloudflare as Secondary](https://developers.cloudflare.com/dns/zone-setups/zone-transfers/cloudflare-as-secondary/setup/#dnssec)
// for details.
DNSSECPresigned param.Field[bool] `json:"dnssec_presigned"`
// Status of DNSSEC, based on user-desired state and presence of necessary records.
Status param.Field[DNSSECEditParamsStatus] `json:"status"`
}
func (r DNSSECEditParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Status of DNSSEC, based on user-desired state and presence of necessary records.
type DNSSECEditParamsStatus string
const (
DNSSECEditParamsStatusActive DNSSECEditParamsStatus = "active"
DNSSECEditParamsStatusDisabled DNSSECEditParamsStatus = "disabled"
)
func (r DNSSECEditParamsStatus) IsKnown() bool {
switch r {
case DNSSECEditParamsStatusActive, DNSSECEditParamsStatusDisabled:
return true
}
return false
}
type DNSSECEditResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// Whether the API call was successful
Success DNSSECEditResponseEnvelopeSuccess `json:"success,required"`
Result DNSSEC `json:"result"`
JSON dnssecEditResponseEnvelopeJSON `json:"-"`
}
// dnssecEditResponseEnvelopeJSON contains the JSON metadata for the struct
// [DNSSECEditResponseEnvelope]
type dnssecEditResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Success apijson.Field
Result apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DNSSECEditResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r dnssecEditResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type DNSSECEditResponseEnvelopeSuccess bool
const (
DNSSECEditResponseEnvelopeSuccessTrue DNSSECEditResponseEnvelopeSuccess = true
)
func (r DNSSECEditResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case DNSSECEditResponseEnvelopeSuccessTrue:
return true
}
return false
}
type DNSSECGetParams struct {
// Identifier
ZoneID param.Field[string] `path:"zone_id,required"`
}
type DNSSECGetResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// Whether the API call was successful
Success DNSSECGetResponseEnvelopeSuccess `json:"success,required"`
Result DNSSEC `json:"result"`
JSON dnssecGetResponseEnvelopeJSON `json:"-"`
}
// dnssecGetResponseEnvelopeJSON contains the JSON metadata for the struct
// [DNSSECGetResponseEnvelope]
type dnssecGetResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Success apijson.Field
Result apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DNSSECGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r dnssecGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type DNSSECGetResponseEnvelopeSuccess bool
const (
DNSSECGetResponseEnvelopeSuccessTrue DNSSECGetResponseEnvelopeSuccess = true
)
func (r DNSSECGetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case DNSSECGetResponseEnvelopeSuccessTrue:
return true
}
return false
}