/
hostnamecertificate.go
515 lines (450 loc) · 19.8 KB
/
hostnamecertificate.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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package origin_tls_client_auth
import (
"context"
"fmt"
"net/http"
"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"
)
// HostnameCertificateService 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 [NewHostnameCertificateService]
// method instead.
type HostnameCertificateService struct {
Options []option.RequestOption
}
// NewHostnameCertificateService 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 NewHostnameCertificateService(opts ...option.RequestOption) (r *HostnameCertificateService) {
r = &HostnameCertificateService{}
r.Options = opts
return
}
// Upload a certificate to be used for client authentication on a hostname. 10
// hostname certificates per zone are allowed.
func (r *HostnameCertificateService) New(ctx context.Context, params HostnameCertificateNewParams, opts ...option.RequestOption) (res *HostnameCertificateNewResponse, err error) {
opts = append(r.Options[:], opts...)
var env HostnameCertificateNewResponseEnvelope
path := fmt.Sprintf("zones/%s/origin_tls_client_auth/hostnames/certificates", params.ZoneID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// List Certificates
func (r *HostnameCertificateService) List(ctx context.Context, query HostnameCertificateListParams, opts ...option.RequestOption) (res *pagination.SinglePage[AuthenticatedOriginPull], err error) {
var raw *http.Response
opts = append(r.Options, opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := fmt.Sprintf("zones/%s/origin_tls_client_auth/hostnames/certificates", query.ZoneID)
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 Certificates
func (r *HostnameCertificateService) ListAutoPaging(ctx context.Context, query HostnameCertificateListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[AuthenticatedOriginPull] {
return pagination.NewSinglePageAutoPager(r.List(ctx, query, opts...))
}
// Delete Hostname Client Certificate
func (r *HostnameCertificateService) Delete(ctx context.Context, certificateID string, params HostnameCertificateDeleteParams, opts ...option.RequestOption) (res *HostnameCertificateDeleteResponse, err error) {
opts = append(r.Options[:], opts...)
var env HostnameCertificateDeleteResponseEnvelope
path := fmt.Sprintf("zones/%s/origin_tls_client_auth/hostnames/certificates/%s", params.ZoneID, certificateID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Get the certificate by ID to be used for client authentication on a hostname.
func (r *HostnameCertificateService) Get(ctx context.Context, certificateID string, query HostnameCertificateGetParams, opts ...option.RequestOption) (res *HostnameCertificateGetResponse, err error) {
opts = append(r.Options[:], opts...)
var env HostnameCertificateGetResponseEnvelope
path := fmt.Sprintf("zones/%s/origin_tls_client_auth/hostnames/certificates/%s", query.ZoneID, certificateID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
type Certificate struct {
// Identifier
ID string `json:"id"`
// The hostname certificate.
Certificate string `json:"certificate"`
// The date when the certificate expires.
ExpiresOn time.Time `json:"expires_on" format:"date-time"`
// The certificate authority that issued the certificate.
Issuer string `json:"issuer"`
// The serial number on the uploaded certificate.
SerialNumber string `json:"serial_number"`
// The type of hash used for the certificate.
Signature string `json:"signature"`
// Status of the certificate or the association.
Status CertificateStatus `json:"status"`
// The time when the certificate was uploaded.
UploadedOn time.Time `json:"uploaded_on" format:"date-time"`
JSON certificateJSON `json:"-"`
}
// certificateJSON contains the JSON metadata for the struct [Certificate]
type certificateJSON struct {
ID apijson.Field
Certificate apijson.Field
ExpiresOn apijson.Field
Issuer apijson.Field
SerialNumber apijson.Field
Signature apijson.Field
Status apijson.Field
UploadedOn apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Certificate) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r certificateJSON) RawJSON() string {
return r.raw
}
// Status of the certificate or the association.
type CertificateStatus string
const (
CertificateStatusInitializing CertificateStatus = "initializing"
CertificateStatusPendingDeployment CertificateStatus = "pending_deployment"
CertificateStatusPendingDeletion CertificateStatus = "pending_deletion"
CertificateStatusActive CertificateStatus = "active"
CertificateStatusDeleted CertificateStatus = "deleted"
CertificateStatusDeploymentTimedOut CertificateStatus = "deployment_timed_out"
CertificateStatusDeletionTimedOut CertificateStatus = "deletion_timed_out"
)
func (r CertificateStatus) IsKnown() bool {
switch r {
case CertificateStatusInitializing, CertificateStatusPendingDeployment, CertificateStatusPendingDeletion, CertificateStatusActive, CertificateStatusDeleted, CertificateStatusDeploymentTimedOut, CertificateStatusDeletionTimedOut:
return true
}
return false
}
type HostnameCertificateNewResponse struct {
// Identifier
ID string `json:"id"`
// The hostname certificate.
Certificate string `json:"certificate"`
// The date when the certificate expires.
ExpiresOn time.Time `json:"expires_on" format:"date-time"`
// The certificate authority that issued the certificate.
Issuer string `json:"issuer"`
// The serial number on the uploaded certificate.
SerialNumber string `json:"serial_number"`
// The type of hash used for the certificate.
Signature string `json:"signature"`
// Status of the certificate or the association.
Status HostnameCertificateNewResponseStatus `json:"status"`
// The time when the certificate was uploaded.
UploadedOn time.Time `json:"uploaded_on" format:"date-time"`
JSON hostnameCertificateNewResponseJSON `json:"-"`
}
// hostnameCertificateNewResponseJSON contains the JSON metadata for the struct
// [HostnameCertificateNewResponse]
type hostnameCertificateNewResponseJSON struct {
ID apijson.Field
Certificate apijson.Field
ExpiresOn apijson.Field
Issuer apijson.Field
SerialNumber apijson.Field
Signature apijson.Field
Status apijson.Field
UploadedOn apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *HostnameCertificateNewResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r hostnameCertificateNewResponseJSON) RawJSON() string {
return r.raw
}
// Status of the certificate or the association.
type HostnameCertificateNewResponseStatus string
const (
HostnameCertificateNewResponseStatusInitializing HostnameCertificateNewResponseStatus = "initializing"
HostnameCertificateNewResponseStatusPendingDeployment HostnameCertificateNewResponseStatus = "pending_deployment"
HostnameCertificateNewResponseStatusPendingDeletion HostnameCertificateNewResponseStatus = "pending_deletion"
HostnameCertificateNewResponseStatusActive HostnameCertificateNewResponseStatus = "active"
HostnameCertificateNewResponseStatusDeleted HostnameCertificateNewResponseStatus = "deleted"
HostnameCertificateNewResponseStatusDeploymentTimedOut HostnameCertificateNewResponseStatus = "deployment_timed_out"
HostnameCertificateNewResponseStatusDeletionTimedOut HostnameCertificateNewResponseStatus = "deletion_timed_out"
)
func (r HostnameCertificateNewResponseStatus) IsKnown() bool {
switch r {
case HostnameCertificateNewResponseStatusInitializing, HostnameCertificateNewResponseStatusPendingDeployment, HostnameCertificateNewResponseStatusPendingDeletion, HostnameCertificateNewResponseStatusActive, HostnameCertificateNewResponseStatusDeleted, HostnameCertificateNewResponseStatusDeploymentTimedOut, HostnameCertificateNewResponseStatusDeletionTimedOut:
return true
}
return false
}
type HostnameCertificateDeleteResponse struct {
// Identifier
ID string `json:"id"`
// The hostname certificate.
Certificate string `json:"certificate"`
// The date when the certificate expires.
ExpiresOn time.Time `json:"expires_on" format:"date-time"`
// The certificate authority that issued the certificate.
Issuer string `json:"issuer"`
// The serial number on the uploaded certificate.
SerialNumber string `json:"serial_number"`
// The type of hash used for the certificate.
Signature string `json:"signature"`
// Status of the certificate or the association.
Status HostnameCertificateDeleteResponseStatus `json:"status"`
// The time when the certificate was uploaded.
UploadedOn time.Time `json:"uploaded_on" format:"date-time"`
JSON hostnameCertificateDeleteResponseJSON `json:"-"`
}
// hostnameCertificateDeleteResponseJSON contains the JSON metadata for the struct
// [HostnameCertificateDeleteResponse]
type hostnameCertificateDeleteResponseJSON struct {
ID apijson.Field
Certificate apijson.Field
ExpiresOn apijson.Field
Issuer apijson.Field
SerialNumber apijson.Field
Signature apijson.Field
Status apijson.Field
UploadedOn apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *HostnameCertificateDeleteResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r hostnameCertificateDeleteResponseJSON) RawJSON() string {
return r.raw
}
// Status of the certificate or the association.
type HostnameCertificateDeleteResponseStatus string
const (
HostnameCertificateDeleteResponseStatusInitializing HostnameCertificateDeleteResponseStatus = "initializing"
HostnameCertificateDeleteResponseStatusPendingDeployment HostnameCertificateDeleteResponseStatus = "pending_deployment"
HostnameCertificateDeleteResponseStatusPendingDeletion HostnameCertificateDeleteResponseStatus = "pending_deletion"
HostnameCertificateDeleteResponseStatusActive HostnameCertificateDeleteResponseStatus = "active"
HostnameCertificateDeleteResponseStatusDeleted HostnameCertificateDeleteResponseStatus = "deleted"
HostnameCertificateDeleteResponseStatusDeploymentTimedOut HostnameCertificateDeleteResponseStatus = "deployment_timed_out"
HostnameCertificateDeleteResponseStatusDeletionTimedOut HostnameCertificateDeleteResponseStatus = "deletion_timed_out"
)
func (r HostnameCertificateDeleteResponseStatus) IsKnown() bool {
switch r {
case HostnameCertificateDeleteResponseStatusInitializing, HostnameCertificateDeleteResponseStatusPendingDeployment, HostnameCertificateDeleteResponseStatusPendingDeletion, HostnameCertificateDeleteResponseStatusActive, HostnameCertificateDeleteResponseStatusDeleted, HostnameCertificateDeleteResponseStatusDeploymentTimedOut, HostnameCertificateDeleteResponseStatusDeletionTimedOut:
return true
}
return false
}
type HostnameCertificateGetResponse struct {
// Identifier
ID string `json:"id"`
// The hostname certificate.
Certificate string `json:"certificate"`
// The date when the certificate expires.
ExpiresOn time.Time `json:"expires_on" format:"date-time"`
// The certificate authority that issued the certificate.
Issuer string `json:"issuer"`
// The serial number on the uploaded certificate.
SerialNumber string `json:"serial_number"`
// The type of hash used for the certificate.
Signature string `json:"signature"`
// Status of the certificate or the association.
Status HostnameCertificateGetResponseStatus `json:"status"`
// The time when the certificate was uploaded.
UploadedOn time.Time `json:"uploaded_on" format:"date-time"`
JSON hostnameCertificateGetResponseJSON `json:"-"`
}
// hostnameCertificateGetResponseJSON contains the JSON metadata for the struct
// [HostnameCertificateGetResponse]
type hostnameCertificateGetResponseJSON struct {
ID apijson.Field
Certificate apijson.Field
ExpiresOn apijson.Field
Issuer apijson.Field
SerialNumber apijson.Field
Signature apijson.Field
Status apijson.Field
UploadedOn apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *HostnameCertificateGetResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r hostnameCertificateGetResponseJSON) RawJSON() string {
return r.raw
}
// Status of the certificate or the association.
type HostnameCertificateGetResponseStatus string
const (
HostnameCertificateGetResponseStatusInitializing HostnameCertificateGetResponseStatus = "initializing"
HostnameCertificateGetResponseStatusPendingDeployment HostnameCertificateGetResponseStatus = "pending_deployment"
HostnameCertificateGetResponseStatusPendingDeletion HostnameCertificateGetResponseStatus = "pending_deletion"
HostnameCertificateGetResponseStatusActive HostnameCertificateGetResponseStatus = "active"
HostnameCertificateGetResponseStatusDeleted HostnameCertificateGetResponseStatus = "deleted"
HostnameCertificateGetResponseStatusDeploymentTimedOut HostnameCertificateGetResponseStatus = "deployment_timed_out"
HostnameCertificateGetResponseStatusDeletionTimedOut HostnameCertificateGetResponseStatus = "deletion_timed_out"
)
func (r HostnameCertificateGetResponseStatus) IsKnown() bool {
switch r {
case HostnameCertificateGetResponseStatusInitializing, HostnameCertificateGetResponseStatusPendingDeployment, HostnameCertificateGetResponseStatusPendingDeletion, HostnameCertificateGetResponseStatusActive, HostnameCertificateGetResponseStatusDeleted, HostnameCertificateGetResponseStatusDeploymentTimedOut, HostnameCertificateGetResponseStatusDeletionTimedOut:
return true
}
return false
}
type HostnameCertificateNewParams struct {
// Identifier
ZoneID param.Field[string] `path:"zone_id,required"`
// The hostname certificate.
Certificate param.Field[string] `json:"certificate,required"`
// The hostname certificate's private key.
PrivateKey param.Field[string] `json:"private_key,required"`
}
func (r HostnameCertificateNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type HostnameCertificateNewResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result HostnameCertificateNewResponse `json:"result,required"`
// Whether the API call was successful
Success HostnameCertificateNewResponseEnvelopeSuccess `json:"success,required"`
JSON hostnameCertificateNewResponseEnvelopeJSON `json:"-"`
}
// hostnameCertificateNewResponseEnvelopeJSON contains the JSON metadata for the
// struct [HostnameCertificateNewResponseEnvelope]
type hostnameCertificateNewResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *HostnameCertificateNewResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r hostnameCertificateNewResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type HostnameCertificateNewResponseEnvelopeSuccess bool
const (
HostnameCertificateNewResponseEnvelopeSuccessTrue HostnameCertificateNewResponseEnvelopeSuccess = true
)
func (r HostnameCertificateNewResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case HostnameCertificateNewResponseEnvelopeSuccessTrue:
return true
}
return false
}
type HostnameCertificateListParams struct {
// Identifier
ZoneID param.Field[string] `path:"zone_id,required"`
}
type HostnameCertificateDeleteParams struct {
// Identifier
ZoneID param.Field[string] `path:"zone_id,required"`
Body interface{} `json:"body,required"`
}
func (r HostnameCertificateDeleteParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.Body)
}
type HostnameCertificateDeleteResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result HostnameCertificateDeleteResponse `json:"result,required"`
// Whether the API call was successful
Success HostnameCertificateDeleteResponseEnvelopeSuccess `json:"success,required"`
JSON hostnameCertificateDeleteResponseEnvelopeJSON `json:"-"`
}
// hostnameCertificateDeleteResponseEnvelopeJSON contains the JSON metadata for the
// struct [HostnameCertificateDeleteResponseEnvelope]
type hostnameCertificateDeleteResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *HostnameCertificateDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r hostnameCertificateDeleteResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type HostnameCertificateDeleteResponseEnvelopeSuccess bool
const (
HostnameCertificateDeleteResponseEnvelopeSuccessTrue HostnameCertificateDeleteResponseEnvelopeSuccess = true
)
func (r HostnameCertificateDeleteResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case HostnameCertificateDeleteResponseEnvelopeSuccessTrue:
return true
}
return false
}
type HostnameCertificateGetParams struct {
// Identifier
ZoneID param.Field[string] `path:"zone_id,required"`
}
type HostnameCertificateGetResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result HostnameCertificateGetResponse `json:"result,required"`
// Whether the API call was successful
Success HostnameCertificateGetResponseEnvelopeSuccess `json:"success,required"`
JSON hostnameCertificateGetResponseEnvelopeJSON `json:"-"`
}
// hostnameCertificateGetResponseEnvelopeJSON contains the JSON metadata for the
// struct [HostnameCertificateGetResponseEnvelope]
type hostnameCertificateGetResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *HostnameCertificateGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r hostnameCertificateGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type HostnameCertificateGetResponseEnvelopeSuccess bool
const (
HostnameCertificateGetResponseEnvelopeSuccessTrue HostnameCertificateGetResponseEnvelopeSuccess = true
)
func (r HostnameCertificateGetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case HostnameCertificateGetResponseEnvelopeSuccessTrue:
return true
}
return false
}