/
dispatchnamespacescriptsetting.go
507 lines (445 loc) · 20.8 KB
/
dispatchnamespacescriptsetting.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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package workers_for_platforms
import (
"context"
"fmt"
"net/http"
"reflect"
"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/option"
"github.com/cloudflare/cloudflare-go/v2/shared"
"github.com/cloudflare/cloudflare-go/v2/workers"
"github.com/tidwall/gjson"
)
// DispatchNamespaceScriptSettingService 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
// [NewDispatchNamespaceScriptSettingService] method instead.
type DispatchNamespaceScriptSettingService struct {
Options []option.RequestOption
}
// NewDispatchNamespaceScriptSettingService 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 NewDispatchNamespaceScriptSettingService(opts ...option.RequestOption) (r *DispatchNamespaceScriptSettingService) {
r = &DispatchNamespaceScriptSettingService{}
r.Options = opts
return
}
// Patch script metadata, such as bindings
func (r *DispatchNamespaceScriptSettingService) Edit(ctx context.Context, dispatchNamespace string, scriptName string, params DispatchNamespaceScriptSettingEditParams, opts ...option.RequestOption) (res *DispatchNamespaceScriptSettingEditResponse, err error) {
opts = append(r.Options[:], opts...)
var env DispatchNamespaceScriptSettingEditResponseEnvelope
path := fmt.Sprintf("accounts/%s/workers/dispatch/namespaces/%s/scripts/%s/settings", params.AccountID, dispatchNamespace, scriptName)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Get script settings from a script uploaded to a Workers for Platforms namespace.
func (r *DispatchNamespaceScriptSettingService) Get(ctx context.Context, dispatchNamespace string, scriptName string, query DispatchNamespaceScriptSettingGetParams, opts ...option.RequestOption) (res *DispatchNamespaceScriptSettingGetResponse, err error) {
opts = append(r.Options[:], opts...)
var env DispatchNamespaceScriptSettingGetResponseEnvelope
path := fmt.Sprintf("accounts/%s/workers/dispatch/namespaces/%s/scripts/%s/settings", query.AccountID, dispatchNamespace, scriptName)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
type DispatchNamespaceScriptSettingEditResponse struct {
// List of bindings attached to this Worker
Bindings []workers.Binding `json:"bindings"`
// Opt your Worker into changes after this date
CompatibilityDate string `json:"compatibility_date"`
// Opt your Worker into specific changes
CompatibilityFlags []string `json:"compatibility_flags"`
// Limits to apply for this Worker.
Limits DispatchNamespaceScriptSettingEditResponseLimits `json:"limits"`
// Whether Logpush is turned on for the Worker.
Logpush bool `json:"logpush"`
// Migrations to apply for Durable Objects associated with this Worker.
Migrations DispatchNamespaceScriptSettingEditResponseMigrations `json:"migrations"`
Placement workers.PlacementConfiguration `json:"placement"`
// Tags to help you manage your Workers
Tags []string `json:"tags"`
// List of Workers that will consume logs from the attached Worker.
TailConsumers []workers.ConsumerScript `json:"tail_consumers"`
// Specifies the usage model for the Worker (e.g. 'bundled' or 'unbound').
UsageModel string `json:"usage_model"`
JSON dispatchNamespaceScriptSettingEditResponseJSON `json:"-"`
}
// dispatchNamespaceScriptSettingEditResponseJSON contains the JSON metadata for
// the struct [DispatchNamespaceScriptSettingEditResponse]
type dispatchNamespaceScriptSettingEditResponseJSON struct {
Bindings apijson.Field
CompatibilityDate apijson.Field
CompatibilityFlags apijson.Field
Limits apijson.Field
Logpush apijson.Field
Migrations apijson.Field
Placement apijson.Field
Tags apijson.Field
TailConsumers apijson.Field
UsageModel apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DispatchNamespaceScriptSettingEditResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r dispatchNamespaceScriptSettingEditResponseJSON) RawJSON() string {
return r.raw
}
// Limits to apply for this Worker.
type DispatchNamespaceScriptSettingEditResponseLimits struct {
// The amount of CPU time this Worker can use in milliseconds.
CPUMs int64 `json:"cpu_ms"`
JSON dispatchNamespaceScriptSettingEditResponseLimitsJSON `json:"-"`
}
// dispatchNamespaceScriptSettingEditResponseLimitsJSON contains the JSON metadata
// for the struct [DispatchNamespaceScriptSettingEditResponseLimits]
type dispatchNamespaceScriptSettingEditResponseLimitsJSON struct {
CPUMs apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DispatchNamespaceScriptSettingEditResponseLimits) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r dispatchNamespaceScriptSettingEditResponseLimitsJSON) RawJSON() string {
return r.raw
}
// Migrations to apply for Durable Objects associated with this Worker.
type DispatchNamespaceScriptSettingEditResponseMigrations struct {
// Tag to set as the latest migration tag.
NewTag string `json:"new_tag"`
// Tag used to verify against the latest migration tag for this Worker. If they
// don't match, the upload is rejected.
OldTag string `json:"old_tag"`
DeletedClasses interface{} `json:"deleted_classes,required"`
NewClasses interface{} `json:"new_classes,required"`
RenamedClasses interface{} `json:"renamed_classes,required"`
TransferredClasses interface{} `json:"transferred_classes,required"`
Steps interface{} `json:"steps,required"`
JSON dispatchNamespaceScriptSettingEditResponseMigrationsJSON `json:"-"`
union DispatchNamespaceScriptSettingEditResponseMigrationsUnion
}
// dispatchNamespaceScriptSettingEditResponseMigrationsJSON contains the JSON
// metadata for the struct [DispatchNamespaceScriptSettingEditResponseMigrations]
type dispatchNamespaceScriptSettingEditResponseMigrationsJSON struct {
NewTag apijson.Field
OldTag apijson.Field
DeletedClasses apijson.Field
NewClasses apijson.Field
RenamedClasses apijson.Field
TransferredClasses apijson.Field
Steps apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r dispatchNamespaceScriptSettingEditResponseMigrationsJSON) RawJSON() string {
return r.raw
}
func (r *DispatchNamespaceScriptSettingEditResponseMigrations) UnmarshalJSON(data []byte) (err error) {
err = apijson.UnmarshalRoot(data, &r.union)
if err != nil {
return err
}
return apijson.Port(r.union, &r)
}
func (r DispatchNamespaceScriptSettingEditResponseMigrations) AsUnion() DispatchNamespaceScriptSettingEditResponseMigrationsUnion {
return r.union
}
// Migrations to apply for Durable Objects associated with this Worker.
//
// Union satisfied by [workers.SingleStepMigration] or [workers.SteppedMigration].
type DispatchNamespaceScriptSettingEditResponseMigrationsUnion interface {
ImplementsWorkersForPlatformsDispatchNamespaceScriptSettingEditResponseMigrations()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*DispatchNamespaceScriptSettingEditResponseMigrationsUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(workers.SingleStepMigration{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(workers.SteppedMigration{}),
},
)
}
type DispatchNamespaceScriptSettingGetResponse struct {
// List of bindings attached to this Worker
Bindings []workers.Binding `json:"bindings"`
// Opt your Worker into changes after this date
CompatibilityDate string `json:"compatibility_date"`
// Opt your Worker into specific changes
CompatibilityFlags []string `json:"compatibility_flags"`
// Limits to apply for this Worker.
Limits DispatchNamespaceScriptSettingGetResponseLimits `json:"limits"`
// Whether Logpush is turned on for the Worker.
Logpush bool `json:"logpush"`
// Migrations to apply for Durable Objects associated with this Worker.
Migrations DispatchNamespaceScriptSettingGetResponseMigrations `json:"migrations"`
Placement workers.PlacementConfiguration `json:"placement"`
// Tags to help you manage your Workers
Tags []string `json:"tags"`
// List of Workers that will consume logs from the attached Worker.
TailConsumers []workers.ConsumerScript `json:"tail_consumers"`
// Specifies the usage model for the Worker (e.g. 'bundled' or 'unbound').
UsageModel string `json:"usage_model"`
JSON dispatchNamespaceScriptSettingGetResponseJSON `json:"-"`
}
// dispatchNamespaceScriptSettingGetResponseJSON contains the JSON metadata for the
// struct [DispatchNamespaceScriptSettingGetResponse]
type dispatchNamespaceScriptSettingGetResponseJSON struct {
Bindings apijson.Field
CompatibilityDate apijson.Field
CompatibilityFlags apijson.Field
Limits apijson.Field
Logpush apijson.Field
Migrations apijson.Field
Placement apijson.Field
Tags apijson.Field
TailConsumers apijson.Field
UsageModel apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DispatchNamespaceScriptSettingGetResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r dispatchNamespaceScriptSettingGetResponseJSON) RawJSON() string {
return r.raw
}
// Limits to apply for this Worker.
type DispatchNamespaceScriptSettingGetResponseLimits struct {
// The amount of CPU time this Worker can use in milliseconds.
CPUMs int64 `json:"cpu_ms"`
JSON dispatchNamespaceScriptSettingGetResponseLimitsJSON `json:"-"`
}
// dispatchNamespaceScriptSettingGetResponseLimitsJSON contains the JSON metadata
// for the struct [DispatchNamespaceScriptSettingGetResponseLimits]
type dispatchNamespaceScriptSettingGetResponseLimitsJSON struct {
CPUMs apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DispatchNamespaceScriptSettingGetResponseLimits) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r dispatchNamespaceScriptSettingGetResponseLimitsJSON) RawJSON() string {
return r.raw
}
// Migrations to apply for Durable Objects associated with this Worker.
type DispatchNamespaceScriptSettingGetResponseMigrations struct {
// Tag to set as the latest migration tag.
NewTag string `json:"new_tag"`
// Tag used to verify against the latest migration tag for this Worker. If they
// don't match, the upload is rejected.
OldTag string `json:"old_tag"`
DeletedClasses interface{} `json:"deleted_classes,required"`
NewClasses interface{} `json:"new_classes,required"`
RenamedClasses interface{} `json:"renamed_classes,required"`
TransferredClasses interface{} `json:"transferred_classes,required"`
Steps interface{} `json:"steps,required"`
JSON dispatchNamespaceScriptSettingGetResponseMigrationsJSON `json:"-"`
union DispatchNamespaceScriptSettingGetResponseMigrationsUnion
}
// dispatchNamespaceScriptSettingGetResponseMigrationsJSON contains the JSON
// metadata for the struct [DispatchNamespaceScriptSettingGetResponseMigrations]
type dispatchNamespaceScriptSettingGetResponseMigrationsJSON struct {
NewTag apijson.Field
OldTag apijson.Field
DeletedClasses apijson.Field
NewClasses apijson.Field
RenamedClasses apijson.Field
TransferredClasses apijson.Field
Steps apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r dispatchNamespaceScriptSettingGetResponseMigrationsJSON) RawJSON() string {
return r.raw
}
func (r *DispatchNamespaceScriptSettingGetResponseMigrations) UnmarshalJSON(data []byte) (err error) {
err = apijson.UnmarshalRoot(data, &r.union)
if err != nil {
return err
}
return apijson.Port(r.union, &r)
}
func (r DispatchNamespaceScriptSettingGetResponseMigrations) AsUnion() DispatchNamespaceScriptSettingGetResponseMigrationsUnion {
return r.union
}
// Migrations to apply for Durable Objects associated with this Worker.
//
// Union satisfied by [workers.SingleStepMigration] or [workers.SteppedMigration].
type DispatchNamespaceScriptSettingGetResponseMigrationsUnion interface {
ImplementsWorkersForPlatformsDispatchNamespaceScriptSettingGetResponseMigrations()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*DispatchNamespaceScriptSettingGetResponseMigrationsUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(workers.SingleStepMigration{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(workers.SteppedMigration{}),
},
)
}
type DispatchNamespaceScriptSettingEditParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
Settings param.Field[DispatchNamespaceScriptSettingEditParamsSettings] `json:"settings"`
}
func (r DispatchNamespaceScriptSettingEditParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type DispatchNamespaceScriptSettingEditParamsSettings struct {
// List of bindings attached to this Worker
Bindings param.Field[[]workers.BindingUnionParam] `json:"bindings"`
// Opt your Worker into changes after this date
CompatibilityDate param.Field[string] `json:"compatibility_date"`
// Opt your Worker into specific changes
CompatibilityFlags param.Field[[]string] `json:"compatibility_flags"`
// Limits to apply for this Worker.
Limits param.Field[DispatchNamespaceScriptSettingEditParamsSettingsLimits] `json:"limits"`
// Whether Logpush is turned on for the Worker.
Logpush param.Field[bool] `json:"logpush"`
// Migrations to apply for Durable Objects associated with this Worker.
Migrations param.Field[DispatchNamespaceScriptSettingEditParamsSettingsMigrationsUnion] `json:"migrations"`
Placement param.Field[workers.PlacementConfigurationParam] `json:"placement"`
// Tags to help you manage your Workers
Tags param.Field[[]string] `json:"tags"`
// List of Workers that will consume logs from the attached Worker.
TailConsumers param.Field[[]workers.ConsumerScriptParam] `json:"tail_consumers"`
// Specifies the usage model for the Worker (e.g. 'bundled' or 'unbound').
UsageModel param.Field[string] `json:"usage_model"`
}
func (r DispatchNamespaceScriptSettingEditParamsSettings) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Limits to apply for this Worker.
type DispatchNamespaceScriptSettingEditParamsSettingsLimits struct {
// The amount of CPU time this Worker can use in milliseconds.
CPUMs param.Field[int64] `json:"cpu_ms"`
}
func (r DispatchNamespaceScriptSettingEditParamsSettingsLimits) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Migrations to apply for Durable Objects associated with this Worker.
type DispatchNamespaceScriptSettingEditParamsSettingsMigrations struct {
// Tag to set as the latest migration tag.
NewTag param.Field[string] `json:"new_tag"`
// Tag used to verify against the latest migration tag for this Worker. If they
// don't match, the upload is rejected.
OldTag param.Field[string] `json:"old_tag"`
DeletedClasses param.Field[interface{}] `json:"deleted_classes,required"`
NewClasses param.Field[interface{}] `json:"new_classes,required"`
RenamedClasses param.Field[interface{}] `json:"renamed_classes,required"`
TransferredClasses param.Field[interface{}] `json:"transferred_classes,required"`
Steps param.Field[interface{}] `json:"steps,required"`
}
func (r DispatchNamespaceScriptSettingEditParamsSettingsMigrations) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r DispatchNamespaceScriptSettingEditParamsSettingsMigrations) ImplementsWorkersForPlatformsDispatchNamespaceScriptSettingEditParamsSettingsMigrationsUnion() {
}
// Migrations to apply for Durable Objects associated with this Worker.
//
// Satisfied by [workers.SingleStepMigrationParam],
// [workers.SteppedMigrationParam],
// [DispatchNamespaceScriptSettingEditParamsSettingsMigrations].
type DispatchNamespaceScriptSettingEditParamsSettingsMigrationsUnion interface {
ImplementsWorkersForPlatformsDispatchNamespaceScriptSettingEditParamsSettingsMigrationsUnion()
}
type DispatchNamespaceScriptSettingEditResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// Whether the API call was successful
Success DispatchNamespaceScriptSettingEditResponseEnvelopeSuccess `json:"success,required"`
Result DispatchNamespaceScriptSettingEditResponse `json:"result"`
JSON dispatchNamespaceScriptSettingEditResponseEnvelopeJSON `json:"-"`
}
// dispatchNamespaceScriptSettingEditResponseEnvelopeJSON contains the JSON
// metadata for the struct [DispatchNamespaceScriptSettingEditResponseEnvelope]
type dispatchNamespaceScriptSettingEditResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Success apijson.Field
Result apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DispatchNamespaceScriptSettingEditResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r dispatchNamespaceScriptSettingEditResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type DispatchNamespaceScriptSettingEditResponseEnvelopeSuccess bool
const (
DispatchNamespaceScriptSettingEditResponseEnvelopeSuccessTrue DispatchNamespaceScriptSettingEditResponseEnvelopeSuccess = true
)
func (r DispatchNamespaceScriptSettingEditResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case DispatchNamespaceScriptSettingEditResponseEnvelopeSuccessTrue:
return true
}
return false
}
type DispatchNamespaceScriptSettingGetParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}
type DispatchNamespaceScriptSettingGetResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// Whether the API call was successful
Success DispatchNamespaceScriptSettingGetResponseEnvelopeSuccess `json:"success,required"`
Result DispatchNamespaceScriptSettingGetResponse `json:"result"`
JSON dispatchNamespaceScriptSettingGetResponseEnvelopeJSON `json:"-"`
}
// dispatchNamespaceScriptSettingGetResponseEnvelopeJSON contains the JSON metadata
// for the struct [DispatchNamespaceScriptSettingGetResponseEnvelope]
type dispatchNamespaceScriptSettingGetResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Success apijson.Field
Result apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DispatchNamespaceScriptSettingGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r dispatchNamespaceScriptSettingGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type DispatchNamespaceScriptSettingGetResponseEnvelopeSuccess bool
const (
DispatchNamespaceScriptSettingGetResponseEnvelopeSuccessTrue DispatchNamespaceScriptSettingGetResponseEnvelopeSuccess = true
)
func (r DispatchNamespaceScriptSettingGetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case DispatchNamespaceScriptSettingGetResponseEnvelopeSuccessTrue:
return true
}
return false
}