-
Notifications
You must be signed in to change notification settings - Fork 640
/
Copy pathconfig.go
598 lines (512 loc) · 20.1 KB
/
config.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
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package hyperdrive
import (
"context"
"errors"
"fmt"
"net/http"
"github.com/cloudflare/cloudflare-go/v4/internal/apijson"
"github.com/cloudflare/cloudflare-go/v4/internal/param"
"github.com/cloudflare/cloudflare-go/v4/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v4/option"
"github.com/cloudflare/cloudflare-go/v4/packages/pagination"
"github.com/cloudflare/cloudflare-go/v4/shared"
)
// ConfigService 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 [NewConfigService] method instead.
type ConfigService struct {
Options []option.RequestOption
}
// NewConfigService 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 NewConfigService(opts ...option.RequestOption) (r *ConfigService) {
r = &ConfigService{}
r.Options = opts
return
}
// Creates and returns a new Hyperdrive configuration.
func (r *ConfigService) New(ctx context.Context, params ConfigNewParams, opts ...option.RequestOption) (res *Hyperdrive, err error) {
var env ConfigNewResponseEnvelope
opts = append(r.Options[:], opts...)
if params.AccountID.Value == "" {
err = errors.New("missing required account_id parameter")
return
}
path := fmt.Sprintf("accounts/%s/hyperdrive/configs", params.AccountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Updates and returns the specified Hyperdrive configuration.
func (r *ConfigService) Update(ctx context.Context, hyperdriveID string, params ConfigUpdateParams, opts ...option.RequestOption) (res *Hyperdrive, err error) {
var env ConfigUpdateResponseEnvelope
opts = append(r.Options[:], opts...)
if params.AccountID.Value == "" {
err = errors.New("missing required account_id parameter")
return
}
if hyperdriveID == "" {
err = errors.New("missing required hyperdrive_id parameter")
return
}
path := fmt.Sprintf("accounts/%s/hyperdrive/configs/%s", params.AccountID, hyperdriveID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Returns a list of Hyperdrives
func (r *ConfigService) List(ctx context.Context, query ConfigListParams, opts ...option.RequestOption) (res *pagination.SinglePage[Hyperdrive], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
if query.AccountID.Value == "" {
err = errors.New("missing required account_id parameter")
return
}
path := fmt.Sprintf("accounts/%s/hyperdrive/configs", query.AccountID)
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, nil, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// Returns a list of Hyperdrives
func (r *ConfigService) ListAutoPaging(ctx context.Context, query ConfigListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[Hyperdrive] {
return pagination.NewSinglePageAutoPager(r.List(ctx, query, opts...))
}
// Deletes the specified Hyperdrive.
func (r *ConfigService) Delete(ctx context.Context, hyperdriveID string, body ConfigDeleteParams, opts ...option.RequestOption) (res *ConfigDeleteResponse, err error) {
var env ConfigDeleteResponseEnvelope
opts = append(r.Options[:], opts...)
if body.AccountID.Value == "" {
err = errors.New("missing required account_id parameter")
return
}
if hyperdriveID == "" {
err = errors.New("missing required hyperdrive_id parameter")
return
}
path := fmt.Sprintf("accounts/%s/hyperdrive/configs/%s", body.AccountID, hyperdriveID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Patches and returns the specified Hyperdrive configuration. Custom caching
// settings are not kept if caching is disabled.
func (r *ConfigService) Edit(ctx context.Context, hyperdriveID string, params ConfigEditParams, opts ...option.RequestOption) (res *Hyperdrive, err error) {
var env ConfigEditResponseEnvelope
opts = append(r.Options[:], opts...)
if params.AccountID.Value == "" {
err = errors.New("missing required account_id parameter")
return
}
if hyperdriveID == "" {
err = errors.New("missing required hyperdrive_id parameter")
return
}
path := fmt.Sprintf("accounts/%s/hyperdrive/configs/%s", params.AccountID, hyperdriveID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Returns the specified Hyperdrive configuration.
func (r *ConfigService) Get(ctx context.Context, hyperdriveID string, query ConfigGetParams, opts ...option.RequestOption) (res *Hyperdrive, err error) {
var env ConfigGetResponseEnvelope
opts = append(r.Options[:], opts...)
if query.AccountID.Value == "" {
err = errors.New("missing required account_id parameter")
return
}
if hyperdriveID == "" {
err = errors.New("missing required hyperdrive_id parameter")
return
}
path := fmt.Sprintf("accounts/%s/hyperdrive/configs/%s", query.AccountID, hyperdriveID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
type ConfigDeleteResponse = interface{}
type ConfigNewParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
Hyperdrive HyperdriveParam `json:"hyperdrive,required"`
}
func (r ConfigNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.Hyperdrive)
}
type ConfigNewResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result Hyperdrive `json:"result,required"`
// Whether the API call was successful
Success ConfigNewResponseEnvelopeSuccess `json:"success,required"`
JSON configNewResponseEnvelopeJSON `json:"-"`
}
// configNewResponseEnvelopeJSON contains the JSON metadata for the struct
// [ConfigNewResponseEnvelope]
type configNewResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ConfigNewResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r configNewResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type ConfigNewResponseEnvelopeSuccess bool
const (
ConfigNewResponseEnvelopeSuccessTrue ConfigNewResponseEnvelopeSuccess = true
)
func (r ConfigNewResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case ConfigNewResponseEnvelopeSuccessTrue:
return true
}
return false
}
type ConfigUpdateParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
Hyperdrive HyperdriveParam `json:"hyperdrive,required"`
}
func (r ConfigUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.Hyperdrive)
}
type ConfigUpdateResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result Hyperdrive `json:"result,required"`
// Whether the API call was successful
Success ConfigUpdateResponseEnvelopeSuccess `json:"success,required"`
JSON configUpdateResponseEnvelopeJSON `json:"-"`
}
// configUpdateResponseEnvelopeJSON contains the JSON metadata for the struct
// [ConfigUpdateResponseEnvelope]
type configUpdateResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ConfigUpdateResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r configUpdateResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type ConfigUpdateResponseEnvelopeSuccess bool
const (
ConfigUpdateResponseEnvelopeSuccessTrue ConfigUpdateResponseEnvelopeSuccess = true
)
func (r ConfigUpdateResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case ConfigUpdateResponseEnvelopeSuccessTrue:
return true
}
return false
}
type ConfigListParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}
type ConfigDeleteParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}
type ConfigDeleteResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result ConfigDeleteResponse `json:"result,required,nullable"`
// Whether the API call was successful
Success ConfigDeleteResponseEnvelopeSuccess `json:"success,required"`
JSON configDeleteResponseEnvelopeJSON `json:"-"`
}
// configDeleteResponseEnvelopeJSON contains the JSON metadata for the struct
// [ConfigDeleteResponseEnvelope]
type configDeleteResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ConfigDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r configDeleteResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type ConfigDeleteResponseEnvelopeSuccess bool
const (
ConfigDeleteResponseEnvelopeSuccessTrue ConfigDeleteResponseEnvelopeSuccess = true
)
func (r ConfigDeleteResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case ConfigDeleteResponseEnvelopeSuccessTrue:
return true
}
return false
}
type ConfigEditParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
Caching param.Field[ConfigEditParamsCachingUnion] `json:"caching"`
Name param.Field[string] `json:"name"`
Origin param.Field[ConfigEditParamsOriginUnion] `json:"origin"`
}
func (r ConfigEditParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type ConfigEditParamsCaching struct {
// When set to true, disables the caching of SQL responses. (Default: false)
Disabled param.Field[bool] `json:"disabled"`
// When present, specifies max duration for which items should persist in the
// cache. Not returned if set to default. (Default: 60)
MaxAge param.Field[int64] `json:"max_age"`
// When present, indicates the number of seconds cache may serve the response after
// it becomes stale. Not returned if set to default. (Default: 15)
StaleWhileRevalidate param.Field[int64] `json:"stale_while_revalidate"`
}
func (r ConfigEditParamsCaching) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r ConfigEditParamsCaching) implementsConfigEditParamsCachingUnion() {}
// Satisfied by
// [hyperdrive.ConfigEditParamsCachingHyperdriveHyperdriveCachingCommon],
// [hyperdrive.ConfigEditParamsCachingHyperdriveHyperdriveCachingEnabled],
// [ConfigEditParamsCaching].
type ConfigEditParamsCachingUnion interface {
implementsConfigEditParamsCachingUnion()
}
type ConfigEditParamsCachingHyperdriveHyperdriveCachingCommon struct {
// When set to true, disables the caching of SQL responses. (Default: false)
Disabled param.Field[bool] `json:"disabled"`
}
func (r ConfigEditParamsCachingHyperdriveHyperdriveCachingCommon) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r ConfigEditParamsCachingHyperdriveHyperdriveCachingCommon) implementsConfigEditParamsCachingUnion() {
}
type ConfigEditParamsCachingHyperdriveHyperdriveCachingEnabled struct {
// When set to true, disables the caching of SQL responses. (Default: false)
Disabled param.Field[bool] `json:"disabled"`
// When present, specifies max duration for which items should persist in the
// cache. Not returned if set to default. (Default: 60)
MaxAge param.Field[int64] `json:"max_age"`
// When present, indicates the number of seconds cache may serve the response after
// it becomes stale. Not returned if set to default. (Default: 15)
StaleWhileRevalidate param.Field[int64] `json:"stale_while_revalidate"`
}
func (r ConfigEditParamsCachingHyperdriveHyperdriveCachingEnabled) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r ConfigEditParamsCachingHyperdriveHyperdriveCachingEnabled) implementsConfigEditParamsCachingUnion() {
}
type ConfigEditParamsOrigin struct {
// The Client ID of the Access token to use when connecting to the origin database.
AccessClientID param.Field[string] `json:"access_client_id"`
// The Client Secret of the Access token to use when connecting to the origin
// database. This value is write-only and never returned by the API.
AccessClientSecret param.Field[string] `json:"access_client_secret"`
// The name of your origin database.
Database param.Field[string] `json:"database"`
// The host (hostname or IP) of your origin database.
Host param.Field[string] `json:"host"`
// The password required to access your origin database. This value is write-only
// and never returned by the API.
Password param.Field[string] `json:"password"`
// The port (default: 5432 for Postgres) of your origin database.
Port param.Field[int64] `json:"port"`
// Specifies the URL scheme used to connect to your origin database.
Scheme param.Field[ConfigEditParamsOriginScheme] `json:"scheme"`
// The user of your origin database.
User param.Field[string] `json:"user"`
}
func (r ConfigEditParamsOrigin) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r ConfigEditParamsOrigin) implementsConfigEditParamsOriginUnion() {}
// Satisfied by [hyperdrive.ConfigEditParamsOriginHyperdriveHyperdriveDatabase],
// [hyperdrive.ConfigEditParamsOriginHyperdriveInternetOrigin],
// [hyperdrive.ConfigEditParamsOriginHyperdriveOverAccessOrigin],
// [ConfigEditParamsOrigin].
type ConfigEditParamsOriginUnion interface {
implementsConfigEditParamsOriginUnion()
}
type ConfigEditParamsOriginHyperdriveHyperdriveDatabase struct {
// The name of your origin database.
Database param.Field[string] `json:"database"`
// The password required to access your origin database. This value is write-only
// and never returned by the API.
Password param.Field[string] `json:"password"`
// Specifies the URL scheme used to connect to your origin database.
Scheme param.Field[ConfigEditParamsOriginHyperdriveHyperdriveDatabaseScheme] `json:"scheme"`
// The user of your origin database.
User param.Field[string] `json:"user"`
}
func (r ConfigEditParamsOriginHyperdriveHyperdriveDatabase) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r ConfigEditParamsOriginHyperdriveHyperdriveDatabase) implementsConfigEditParamsOriginUnion() {}
// Specifies the URL scheme used to connect to your origin database.
type ConfigEditParamsOriginHyperdriveHyperdriveDatabaseScheme string
const (
ConfigEditParamsOriginHyperdriveHyperdriveDatabaseSchemePostgres ConfigEditParamsOriginHyperdriveHyperdriveDatabaseScheme = "postgres"
ConfigEditParamsOriginHyperdriveHyperdriveDatabaseSchemePostgresql ConfigEditParamsOriginHyperdriveHyperdriveDatabaseScheme = "postgresql"
)
func (r ConfigEditParamsOriginHyperdriveHyperdriveDatabaseScheme) IsKnown() bool {
switch r {
case ConfigEditParamsOriginHyperdriveHyperdriveDatabaseSchemePostgres, ConfigEditParamsOriginHyperdriveHyperdriveDatabaseSchemePostgresql:
return true
}
return false
}
type ConfigEditParamsOriginHyperdriveInternetOrigin struct {
// The host (hostname or IP) of your origin database.
Host param.Field[string] `json:"host,required"`
// The port (default: 5432 for Postgres) of your origin database.
Port param.Field[int64] `json:"port,required"`
}
func (r ConfigEditParamsOriginHyperdriveInternetOrigin) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r ConfigEditParamsOriginHyperdriveInternetOrigin) implementsConfigEditParamsOriginUnion() {}
type ConfigEditParamsOriginHyperdriveOverAccessOrigin struct {
// The Client ID of the Access token to use when connecting to the origin database.
AccessClientID param.Field[string] `json:"access_client_id,required"`
// The Client Secret of the Access token to use when connecting to the origin
// database. This value is write-only and never returned by the API.
AccessClientSecret param.Field[string] `json:"access_client_secret,required"`
// The host (hostname or IP) of your origin database.
Host param.Field[string] `json:"host,required"`
}
func (r ConfigEditParamsOriginHyperdriveOverAccessOrigin) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r ConfigEditParamsOriginHyperdriveOverAccessOrigin) implementsConfigEditParamsOriginUnion() {}
// Specifies the URL scheme used to connect to your origin database.
type ConfigEditParamsOriginScheme string
const (
ConfigEditParamsOriginSchemePostgres ConfigEditParamsOriginScheme = "postgres"
ConfigEditParamsOriginSchemePostgresql ConfigEditParamsOriginScheme = "postgresql"
)
func (r ConfigEditParamsOriginScheme) IsKnown() bool {
switch r {
case ConfigEditParamsOriginSchemePostgres, ConfigEditParamsOriginSchemePostgresql:
return true
}
return false
}
type ConfigEditResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result Hyperdrive `json:"result,required"`
// Whether the API call was successful
Success ConfigEditResponseEnvelopeSuccess `json:"success,required"`
JSON configEditResponseEnvelopeJSON `json:"-"`
}
// configEditResponseEnvelopeJSON contains the JSON metadata for the struct
// [ConfigEditResponseEnvelope]
type configEditResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ConfigEditResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r configEditResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type ConfigEditResponseEnvelopeSuccess bool
const (
ConfigEditResponseEnvelopeSuccessTrue ConfigEditResponseEnvelopeSuccess = true
)
func (r ConfigEditResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case ConfigEditResponseEnvelopeSuccessTrue:
return true
}
return false
}
type ConfigGetParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}
type ConfigGetResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result Hyperdrive `json:"result,required"`
// Whether the API call was successful
Success ConfigGetResponseEnvelopeSuccess `json:"success,required"`
JSON configGetResponseEnvelopeJSON `json:"-"`
}
// configGetResponseEnvelopeJSON contains the JSON metadata for the struct
// [ConfigGetResponseEnvelope]
type configGetResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ConfigGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r configGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type ConfigGetResponseEnvelopeSuccess bool
const (
ConfigGetResponseEnvelopeSuccessTrue ConfigGetResponseEnvelopeSuccess = true
)
func (r ConfigGetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case ConfigGetResponseEnvelopeSuccessTrue:
return true
}
return false
}