/
origintlsclientauth.go
384 lines (334 loc) · 13.4 KB
/
origintlsclientauth.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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package origin_tls_client_auth
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"
)
// OriginTLSClientAuthService 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 [NewOriginTLSClientAuthService]
// method instead.
type OriginTLSClientAuthService struct {
Options []option.RequestOption
Hostnames *HostnameService
Settings *SettingService
}
// NewOriginTLSClientAuthService 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 NewOriginTLSClientAuthService(opts ...option.RequestOption) (r *OriginTLSClientAuthService) {
r = &OriginTLSClientAuthService{}
r.Options = opts
r.Hostnames = NewHostnameService(opts...)
r.Settings = NewSettingService(opts...)
return
}
// Upload your own certificate you want Cloudflare to use for edge-to-origin
// communication to override the shared certificate. Please note that it is
// important to keep only one certificate active. Also, make sure to enable
// zone-level authenticated origin pulls by making a PUT call to settings endpoint
// to see the uploaded certificate in use.
func (r *OriginTLSClientAuthService) New(ctx context.Context, params OriginTLSClientAuthNewParams, opts ...option.RequestOption) (res *OriginTLSClientAuthNewResponseUnion, err error) {
opts = append(r.Options[:], opts...)
var env OriginTLSClientAuthNewResponseEnvelope
path := fmt.Sprintf("zones/%s/origin_tls_client_auth", params.ZoneID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// List Certificates
func (r *OriginTLSClientAuthService) List(ctx context.Context, query OriginTLSClientAuthListParams, opts ...option.RequestOption) (res *pagination.SinglePage[ZoneAuthenticatedOriginPull], 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", 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 *OriginTLSClientAuthService) ListAutoPaging(ctx context.Context, query OriginTLSClientAuthListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[ZoneAuthenticatedOriginPull] {
return pagination.NewSinglePageAutoPager(r.List(ctx, query, opts...))
}
// Delete Certificate
func (r *OriginTLSClientAuthService) Delete(ctx context.Context, certificateID string, params OriginTLSClientAuthDeleteParams, opts ...option.RequestOption) (res *OriginTLSClientAuthDeleteResponseUnion, err error) {
opts = append(r.Options[:], opts...)
var env OriginTLSClientAuthDeleteResponseEnvelope
path := fmt.Sprintf("zones/%s/origin_tls_client_auth/%s", params.ZoneID, certificateID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Get Certificate Details
func (r *OriginTLSClientAuthService) Get(ctx context.Context, certificateID string, query OriginTLSClientAuthGetParams, opts ...option.RequestOption) (res *OriginTLSClientAuthGetResponseUnion, err error) {
opts = append(r.Options[:], opts...)
var env OriginTLSClientAuthGetResponseEnvelope
path := fmt.Sprintf("zones/%s/origin_tls_client_auth/%s", query.ZoneID, certificateID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
type ZoneAuthenticatedOriginPull struct {
// Identifier
ID string `json:"id"`
// The zone's leaf certificate.
Certificate string `json:"certificate"`
// When the certificate from the authority expires.
ExpiresOn time.Time `json:"expires_on" format:"date-time"`
// The certificate authority that issued the certificate.
Issuer string `json:"issuer"`
// The type of hash used for the certificate.
Signature string `json:"signature"`
// Status of the certificate activation.
Status ZoneAuthenticatedOriginPullStatus `json:"status"`
// This is the time the certificate was uploaded.
UploadedOn time.Time `json:"uploaded_on" format:"date-time"`
JSON zoneAuthenticatedOriginPullJSON `json:"-"`
}
// zoneAuthenticatedOriginPullJSON contains the JSON metadata for the struct
// [ZoneAuthenticatedOriginPull]
type zoneAuthenticatedOriginPullJSON struct {
ID apijson.Field
Certificate apijson.Field
ExpiresOn apijson.Field
Issuer apijson.Field
Signature apijson.Field
Status apijson.Field
UploadedOn apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ZoneAuthenticatedOriginPull) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r zoneAuthenticatedOriginPullJSON) RawJSON() string {
return r.raw
}
// Status of the certificate activation.
type ZoneAuthenticatedOriginPullStatus string
const (
ZoneAuthenticatedOriginPullStatusInitializing ZoneAuthenticatedOriginPullStatus = "initializing"
ZoneAuthenticatedOriginPullStatusPendingDeployment ZoneAuthenticatedOriginPullStatus = "pending_deployment"
ZoneAuthenticatedOriginPullStatusPendingDeletion ZoneAuthenticatedOriginPullStatus = "pending_deletion"
ZoneAuthenticatedOriginPullStatusActive ZoneAuthenticatedOriginPullStatus = "active"
ZoneAuthenticatedOriginPullStatusDeleted ZoneAuthenticatedOriginPullStatus = "deleted"
ZoneAuthenticatedOriginPullStatusDeploymentTimedOut ZoneAuthenticatedOriginPullStatus = "deployment_timed_out"
ZoneAuthenticatedOriginPullStatusDeletionTimedOut ZoneAuthenticatedOriginPullStatus = "deletion_timed_out"
)
func (r ZoneAuthenticatedOriginPullStatus) IsKnown() bool {
switch r {
case ZoneAuthenticatedOriginPullStatusInitializing, ZoneAuthenticatedOriginPullStatusPendingDeployment, ZoneAuthenticatedOriginPullStatusPendingDeletion, ZoneAuthenticatedOriginPullStatusActive, ZoneAuthenticatedOriginPullStatusDeleted, ZoneAuthenticatedOriginPullStatusDeploymentTimedOut, ZoneAuthenticatedOriginPullStatusDeletionTimedOut:
return true
}
return false
}
// Union satisfied by
// [origin_tls_client_auth.OriginTLSClientAuthNewResponseUnknown] or
// [shared.UnionString].
type OriginTLSClientAuthNewResponseUnion interface {
ImplementsOriginTLSClientAuthOriginTLSClientAuthNewResponseUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*OriginTLSClientAuthNewResponseUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
)
}
// Union satisfied by
// [origin_tls_client_auth.OriginTLSClientAuthDeleteResponseUnknown] or
// [shared.UnionString].
type OriginTLSClientAuthDeleteResponseUnion interface {
ImplementsOriginTLSClientAuthOriginTLSClientAuthDeleteResponseUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*OriginTLSClientAuthDeleteResponseUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
)
}
// Union satisfied by
// [origin_tls_client_auth.OriginTLSClientAuthGetResponseUnknown] or
// [shared.UnionString].
type OriginTLSClientAuthGetResponseUnion interface {
ImplementsOriginTLSClientAuthOriginTLSClientAuthGetResponseUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*OriginTLSClientAuthGetResponseUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
)
}
type OriginTLSClientAuthNewParams struct {
// Identifier
ZoneID param.Field[string] `path:"zone_id,required"`
// The zone's leaf certificate.
Certificate param.Field[string] `json:"certificate,required"`
// The zone's private key.
PrivateKey param.Field[string] `json:"private_key,required"`
}
func (r OriginTLSClientAuthNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type OriginTLSClientAuthNewResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result OriginTLSClientAuthNewResponseUnion `json:"result,required"`
// Whether the API call was successful
Success OriginTLSClientAuthNewResponseEnvelopeSuccess `json:"success,required"`
JSON originTLSClientAuthNewResponseEnvelopeJSON `json:"-"`
}
// originTLSClientAuthNewResponseEnvelopeJSON contains the JSON metadata for the
// struct [OriginTLSClientAuthNewResponseEnvelope]
type originTLSClientAuthNewResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *OriginTLSClientAuthNewResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r originTLSClientAuthNewResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type OriginTLSClientAuthNewResponseEnvelopeSuccess bool
const (
OriginTLSClientAuthNewResponseEnvelopeSuccessTrue OriginTLSClientAuthNewResponseEnvelopeSuccess = true
)
func (r OriginTLSClientAuthNewResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case OriginTLSClientAuthNewResponseEnvelopeSuccessTrue:
return true
}
return false
}
type OriginTLSClientAuthListParams struct {
// Identifier
ZoneID param.Field[string] `path:"zone_id,required"`
}
type OriginTLSClientAuthDeleteParams struct {
// Identifier
ZoneID param.Field[string] `path:"zone_id,required"`
Body interface{} `json:"body,required"`
}
func (r OriginTLSClientAuthDeleteParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.Body)
}
type OriginTLSClientAuthDeleteResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result OriginTLSClientAuthDeleteResponseUnion `json:"result,required"`
// Whether the API call was successful
Success OriginTLSClientAuthDeleteResponseEnvelopeSuccess `json:"success,required"`
JSON originTLSClientAuthDeleteResponseEnvelopeJSON `json:"-"`
}
// originTLSClientAuthDeleteResponseEnvelopeJSON contains the JSON metadata for the
// struct [OriginTLSClientAuthDeleteResponseEnvelope]
type originTLSClientAuthDeleteResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *OriginTLSClientAuthDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r originTLSClientAuthDeleteResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type OriginTLSClientAuthDeleteResponseEnvelopeSuccess bool
const (
OriginTLSClientAuthDeleteResponseEnvelopeSuccessTrue OriginTLSClientAuthDeleteResponseEnvelopeSuccess = true
)
func (r OriginTLSClientAuthDeleteResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case OriginTLSClientAuthDeleteResponseEnvelopeSuccessTrue:
return true
}
return false
}
type OriginTLSClientAuthGetParams struct {
// Identifier
ZoneID param.Field[string] `path:"zone_id,required"`
}
type OriginTLSClientAuthGetResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result OriginTLSClientAuthGetResponseUnion `json:"result,required"`
// Whether the API call was successful
Success OriginTLSClientAuthGetResponseEnvelopeSuccess `json:"success,required"`
JSON originTLSClientAuthGetResponseEnvelopeJSON `json:"-"`
}
// originTLSClientAuthGetResponseEnvelopeJSON contains the JSON metadata for the
// struct [OriginTLSClientAuthGetResponseEnvelope]
type originTLSClientAuthGetResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *OriginTLSClientAuthGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r originTLSClientAuthGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type OriginTLSClientAuthGetResponseEnvelopeSuccess bool
const (
OriginTLSClientAuthGetResponseEnvelopeSuccessTrue OriginTLSClientAuthGetResponseEnvelopeSuccess = true
)
func (r OriginTLSClientAuthGetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case OriginTLSClientAuthGetResponseEnvelopeSuccessTrue:
return true
}
return false
}