/
domain.go
402 lines (355 loc) · 12.8 KB
/
domain.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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package registrar
import (
"context"
"fmt"
"net/http"
"reflect"
"time"
"github.com/cloudflare/cloudflare-go/v2/internal/apijson"
"github.com/cloudflare/cloudflare-go/v2/internal/pagination"
"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"
)
// DomainService 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 [NewDomainService] method instead.
type DomainService struct {
Options []option.RequestOption
}
// NewDomainService 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 NewDomainService(opts ...option.RequestOption) (r *DomainService) {
r = &DomainService{}
r.Options = opts
return
}
// Update individual domain.
func (r *DomainService) Update(ctx context.Context, domainName string, params DomainUpdateParams, opts ...option.RequestOption) (res *DomainUpdateResponseUnion, err error) {
opts = append(r.Options[:], opts...)
var env DomainUpdateResponseEnvelope
path := fmt.Sprintf("accounts/%s/registrar/domains/%s", params.AccountID, domainName)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// List domains handled by Registrar.
func (r *DomainService) List(ctx context.Context, query DomainListParams, opts ...option.RequestOption) (res *pagination.SinglePage[Domain], err error) {
var raw *http.Response
opts = append(r.Options, opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := fmt.Sprintf("accounts/%s/registrar/domains", query.AccountID)
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List domains handled by Registrar.
func (r *DomainService) ListAutoPaging(ctx context.Context, query DomainListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[Domain] {
return pagination.NewSinglePageAutoPager(r.List(ctx, query, opts...))
}
// Show individual domain.
func (r *DomainService) Get(ctx context.Context, domainName string, query DomainGetParams, opts ...option.RequestOption) (res *DomainGetResponseUnion, err error) {
opts = append(r.Options[:], opts...)
var env DomainGetResponseEnvelope
path := fmt.Sprintf("accounts/%s/registrar/domains/%s", query.AccountID, domainName)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
type Domain struct {
// Domain identifier.
ID string `json:"id"`
// Shows if a domain is available for transferring into Cloudflare Registrar.
Available bool `json:"available"`
// Indicates if the domain can be registered as a new domain.
CanRegister bool `json:"can_register"`
// Shows time of creation.
CreatedAt time.Time `json:"created_at" format:"date-time"`
// Shows name of current registrar.
CurrentRegistrar string `json:"current_registrar"`
// Shows when domain name registration expires.
ExpiresAt time.Time `json:"expires_at" format:"date-time"`
// Shows whether a registrar lock is in place for a domain.
Locked bool `json:"locked"`
// Shows contact information for domain registrant.
RegistrantContact DomainRegistrantContact `json:"registrant_contact"`
// A comma-separated list of registry status codes. A full list of status codes can
// be found at
// [EPP Status Codes](https://www.icann.org/resources/pages/epp-status-codes-2014-06-16-en).
RegistryStatuses string `json:"registry_statuses"`
// Whether a particular TLD is currently supported by Cloudflare Registrar. Refer
// to [TLD Policies](https://www.cloudflare.com/tld-policies/) for a list of
// supported TLDs.
SupportedTld bool `json:"supported_tld"`
// Statuses for domain transfers into Cloudflare Registrar.
TransferIn DomainTransferIn `json:"transfer_in"`
// Last updated.
UpdatedAt time.Time `json:"updated_at" format:"date-time"`
JSON domainJSON `json:"-"`
}
// domainJSON contains the JSON metadata for the struct [Domain]
type domainJSON struct {
ID apijson.Field
Available apijson.Field
CanRegister apijson.Field
CreatedAt apijson.Field
CurrentRegistrar apijson.Field
ExpiresAt apijson.Field
Locked apijson.Field
RegistrantContact apijson.Field
RegistryStatuses apijson.Field
SupportedTld apijson.Field
TransferIn apijson.Field
UpdatedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Domain) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r domainJSON) RawJSON() string {
return r.raw
}
// Shows contact information for domain registrant.
type DomainRegistrantContact struct {
// Address.
Address string `json:"address,required"`
// City.
City string `json:"city,required"`
// The country in which the user lives.
Country string `json:"country,required,nullable"`
// User's first name
FirstName string `json:"first_name,required,nullable"`
// User's last name
LastName string `json:"last_name,required,nullable"`
// Name of organization.
Organization string `json:"organization,required"`
// User's telephone number
Phone string `json:"phone,required,nullable"`
// State.
State string `json:"state,required"`
// The zipcode or postal code where the user lives.
Zip string `json:"zip,required,nullable"`
// Contact Identifier.
ID string `json:"id"`
// Optional address line for unit, floor, suite, etc.
Address2 string `json:"address2"`
// The contact email address of the user.
Email string `json:"email"`
// Contact fax number.
Fax string `json:"fax"`
JSON domainRegistrantContactJSON `json:"-"`
}
// domainRegistrantContactJSON contains the JSON metadata for the struct
// [DomainRegistrantContact]
type domainRegistrantContactJSON struct {
Address apijson.Field
City apijson.Field
Country apijson.Field
FirstName apijson.Field
LastName apijson.Field
Organization apijson.Field
Phone apijson.Field
State apijson.Field
Zip apijson.Field
ID apijson.Field
Address2 apijson.Field
Email apijson.Field
Fax apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DomainRegistrantContact) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r domainRegistrantContactJSON) RawJSON() string {
return r.raw
}
// Statuses for domain transfers into Cloudflare Registrar.
type DomainTransferIn struct {
// Form of authorization has been accepted by the registrant.
AcceptFoa string `json:"accept_foa"`
// Shows transfer status with the registry.
ApproveTransfer string `json:"approve_transfer"`
// Indicates if cancellation is still possible.
CanCancelTransfer bool `json:"can_cancel_transfer"`
// Privacy guards are disabled at the foreign registrar.
DisablePrivacy interface{} `json:"disable_privacy"`
// Auth code has been entered and verified.
EnterAuthCode string `json:"enter_auth_code"`
// Domain is unlocked at the foreign registrar.
UnlockDomain interface{} `json:"unlock_domain"`
JSON domainTransferInJSON `json:"-"`
}
// domainTransferInJSON contains the JSON metadata for the struct
// [DomainTransferIn]
type domainTransferInJSON struct {
AcceptFoa apijson.Field
ApproveTransfer apijson.Field
CanCancelTransfer apijson.Field
DisablePrivacy apijson.Field
EnterAuthCode apijson.Field
UnlockDomain apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DomainTransferIn) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r domainTransferInJSON) RawJSON() string {
return r.raw
}
// Union satisfied by [registrar.DomainUpdateResponseUnknown],
// [registrar.DomainUpdateResponseArray] or [shared.UnionString].
type DomainUpdateResponseUnion interface {
ImplementsRegistrarDomainUpdateResponseUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*DomainUpdateResponseUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(DomainUpdateResponseArray{}),
},
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
)
}
type DomainUpdateResponseArray []interface{}
func (r DomainUpdateResponseArray) ImplementsRegistrarDomainUpdateResponseUnion() {}
// Union satisfied by [registrar.DomainGetResponseUnknown],
// [registrar.DomainGetResponseArray] or [shared.UnionString].
type DomainGetResponseUnion interface {
ImplementsRegistrarDomainGetResponseUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*DomainGetResponseUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(DomainGetResponseArray{}),
},
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
)
}
type DomainGetResponseArray []interface{}
func (r DomainGetResponseArray) ImplementsRegistrarDomainGetResponseUnion() {}
type DomainUpdateParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
// Auto-renew controls whether subscription is automatically renewed upon domain
// expiration.
AutoRenew param.Field[bool] `json:"auto_renew"`
// Shows whether a registrar lock is in place for a domain.
Locked param.Field[bool] `json:"locked"`
// Privacy option controls redacting WHOIS information.
Privacy param.Field[bool] `json:"privacy"`
}
func (r DomainUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type DomainUpdateResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result DomainUpdateResponseUnion `json:"result,required,nullable"`
// Whether the API call was successful
Success DomainUpdateResponseEnvelopeSuccess `json:"success,required"`
JSON domainUpdateResponseEnvelopeJSON `json:"-"`
}
// domainUpdateResponseEnvelopeJSON contains the JSON metadata for the struct
// [DomainUpdateResponseEnvelope]
type domainUpdateResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DomainUpdateResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r domainUpdateResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type DomainUpdateResponseEnvelopeSuccess bool
const (
DomainUpdateResponseEnvelopeSuccessTrue DomainUpdateResponseEnvelopeSuccess = true
)
func (r DomainUpdateResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case DomainUpdateResponseEnvelopeSuccessTrue:
return true
}
return false
}
type DomainListParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}
type DomainGetParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}
type DomainGetResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result DomainGetResponseUnion `json:"result,required,nullable"`
// Whether the API call was successful
Success DomainGetResponseEnvelopeSuccess `json:"success,required"`
JSON domainGetResponseEnvelopeJSON `json:"-"`
}
// domainGetResponseEnvelopeJSON contains the JSON metadata for the struct
// [DomainGetResponseEnvelope]
type domainGetResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DomainGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r domainGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type DomainGetResponseEnvelopeSuccess bool
const (
DomainGetResponseEnvelopeSuccessTrue DomainGetResponseEnvelopeSuccess = true
)
func (r DomainGetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case DomainGetResponseEnvelopeSuccessTrue:
return true
}
return false
}