Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3f496ad

Browse files
committedMar 17, 2025·
feat(workers): add in secrets endpoints (#4038)
1 parent f1e3af5 commit 3f496ad

7 files changed

+688
-1
lines changed
 

‎.stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 1612
1+
configured_endpoints: 1617
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-8103ad52977aa9c1ce4655e2afd3ade7f6e891aafaa9bd1fbf4630348bc3fd02.yml

‎api.md

+18
Original file line numberDiff line numberDiff line change
@@ -2335,6 +2335,22 @@ Methods:
23352335
- <code title="get /accounts/{account_id}/workers/scripts/{script_name}/versions">client.Workers.Scripts.Versions.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptVersionService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, scriptName <a href="https://pkg.go.dev/builtin#string">string</a>, params <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptVersionListParams">ScriptVersionListParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/packages/pagination">pagination</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/packages/pagination#V4PagePagination">V4PagePagination</a>[<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptVersionListResponse">ScriptVersionListResponse</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
23362336
- <code title="get /accounts/{account_id}/workers/scripts/{script_name}/versions/{version_id}">client.Workers.Scripts.Versions.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptVersionService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, scriptName <a href="https://pkg.go.dev/builtin#string">string</a>, versionID <a href="https://pkg.go.dev/builtin#string">string</a>, query <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptVersionGetParams">ScriptVersionGetParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptVersionGetResponse">ScriptVersionGetResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
23372337

2338+
### Secrets
2339+
2340+
Response Types:
2341+
2342+
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptSecretUpdateResponse">ScriptSecretUpdateResponse</a>
2343+
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptSecretListResponse">ScriptSecretListResponse</a>
2344+
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptSecretDeleteResponse">ScriptSecretDeleteResponse</a>
2345+
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptSecretGetResponse">ScriptSecretGetResponse</a>
2346+
2347+
Methods:
2348+
2349+
- <code title="put /accounts/{account_id}/workers/scripts/{script_name}/secrets">client.Workers.Scripts.Secrets.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptSecretService.Update">Update</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, scriptName <a href="https://pkg.go.dev/builtin#string">string</a>, params <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptSecretUpdateParams">ScriptSecretUpdateParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptSecretUpdateResponse">ScriptSecretUpdateResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
2350+
- <code title="get /accounts/{account_id}/workers/scripts/{script_name}/secrets">client.Workers.Scripts.Secrets.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptSecretService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, scriptName <a href="https://pkg.go.dev/builtin#string">string</a>, query <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptSecretListParams">ScriptSecretListParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/packages/pagination">pagination</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/packages/pagination#SinglePage">SinglePage</a>[<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptSecretListResponse">ScriptSecretListResponse</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
2351+
- <code title="delete /accounts/{account_id}/workers/scripts/{script_name}/secrets/{secret_name}">client.Workers.Scripts.Secrets.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptSecretService.Delete">Delete</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, scriptName <a href="https://pkg.go.dev/builtin#string">string</a>, secretName <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptSecretDeleteParams">ScriptSecretDeleteParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptSecretDeleteResponse">ScriptSecretDeleteResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
2352+
- <code title="get /accounts/{account_id}/workers/scripts/{script_name}/secrets/{secret_name}">client.Workers.Scripts.Secrets.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptSecretService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, scriptName <a href="https://pkg.go.dev/builtin#string">string</a>, secretName <a href="https://pkg.go.dev/builtin#string">string</a>, query <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptSecretGetParams">ScriptSecretGetParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers">workers</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers#ScriptSecretGetResponse">ScriptSecretGetResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
2353+
23382354
## AccountSettings
23392355

23402356
Response Types:
@@ -4562,12 +4578,14 @@ Response Types:
45624578

45634579
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms">workers_for_platforms</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms#DispatchNamespaceScriptSecretUpdateResponse">DispatchNamespaceScriptSecretUpdateResponse</a>
45644580
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms">workers_for_platforms</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms#DispatchNamespaceScriptSecretListResponse">DispatchNamespaceScriptSecretListResponse</a>
4581+
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms">workers_for_platforms</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms#DispatchNamespaceScriptSecretDeleteResponse">DispatchNamespaceScriptSecretDeleteResponse</a>
45654582
- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms">workers_for_platforms</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms#DispatchNamespaceScriptSecretGetResponse">DispatchNamespaceScriptSecretGetResponse</a>
45664583

45674584
Methods:
45684585

45694586
- <code title="put /accounts/{account_id}/workers/dispatch/namespaces/{dispatch_namespace}/scripts/{script_name}/secrets">client.WorkersForPlatforms.Dispatch.Namespaces.Scripts.Secrets.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms#DispatchNamespaceScriptSecretService.Update">Update</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, dispatchNamespace <a href="https://pkg.go.dev/builtin#string">string</a>, scriptName <a href="https://pkg.go.dev/builtin#string">string</a>, params <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms">workers_for_platforms</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms#DispatchNamespaceScriptSecretUpdateParams">DispatchNamespaceScriptSecretUpdateParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms">workers_for_platforms</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms#DispatchNamespaceScriptSecretUpdateResponse">DispatchNamespaceScriptSecretUpdateResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
45704587
- <code title="get /accounts/{account_id}/workers/dispatch/namespaces/{dispatch_namespace}/scripts/{script_name}/secrets">client.WorkersForPlatforms.Dispatch.Namespaces.Scripts.Secrets.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms#DispatchNamespaceScriptSecretService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, dispatchNamespace <a href="https://pkg.go.dev/builtin#string">string</a>, scriptName <a href="https://pkg.go.dev/builtin#string">string</a>, query <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms">workers_for_platforms</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms#DispatchNamespaceScriptSecretListParams">DispatchNamespaceScriptSecretListParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/packages/pagination">pagination</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/packages/pagination#SinglePage">SinglePage</a>[<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms">workers_for_platforms</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms#DispatchNamespaceScriptSecretListResponse">DispatchNamespaceScriptSecretListResponse</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
4588+
- <code title="delete /accounts/{account_id}/workers/dispatch/namespaces/{dispatch_namespace}/scripts/{script_name}/secrets/{secret_name}">client.WorkersForPlatforms.Dispatch.Namespaces.Scripts.Secrets.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms#DispatchNamespaceScriptSecretService.Delete">Delete</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, dispatchNamespace <a href="https://pkg.go.dev/builtin#string">string</a>, scriptName <a href="https://pkg.go.dev/builtin#string">string</a>, secretName <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms">workers_for_platforms</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms#DispatchNamespaceScriptSecretDeleteParams">DispatchNamespaceScriptSecretDeleteParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms">workers_for_platforms</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms#DispatchNamespaceScriptSecretDeleteResponse">DispatchNamespaceScriptSecretDeleteResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
45714589
- <code title="get /accounts/{account_id}/workers/dispatch/namespaces/{dispatch_namespace}/scripts/{script_name}/secrets/{secret_name}">client.WorkersForPlatforms.Dispatch.Namespaces.Scripts.Secrets.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms#DispatchNamespaceScriptSecretService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, dispatchNamespace <a href="https://pkg.go.dev/builtin#string">string</a>, scriptName <a href="https://pkg.go.dev/builtin#string">string</a>, secretName <a href="https://pkg.go.dev/builtin#string">string</a>, query <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms">workers_for_platforms</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms#DispatchNamespaceScriptSecretGetParams">DispatchNamespaceScriptSecretGetParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms">workers_for_platforms</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/workers_for_platforms#DispatchNamespaceScriptSecretGetResponse">DispatchNamespaceScriptSecretGetResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
45724590

45734591
##### Tags

‎workers/script.go

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type ScriptService struct {
3535
Settings *ScriptSettingService
3636
Deployments *ScriptDeploymentService
3737
Versions *ScriptVersionService
38+
Secrets *ScriptSecretService
3839
}
3940

4041
// NewScriptService generates a new service that applies the given options to each
@@ -51,6 +52,7 @@ func NewScriptService(opts ...option.RequestOption) (r *ScriptService) {
5152
r.Settings = NewScriptSettingService(opts...)
5253
r.Deployments = NewScriptDeploymentService(opts...)
5354
r.Versions = NewScriptVersionService(opts...)
55+
r.Secrets = NewScriptSecretService(opts...)
5456
return
5557
}
5658

‎workers/scriptsecret.go

+418
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,418 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package workers
4+
5+
import (
6+
"context"
7+
"errors"
8+
"fmt"
9+
"net/http"
10+
11+
"github.com/cloudflare/cloudflare-go/v4/internal/apijson"
12+
"github.com/cloudflare/cloudflare-go/v4/internal/param"
13+
"github.com/cloudflare/cloudflare-go/v4/internal/requestconfig"
14+
"github.com/cloudflare/cloudflare-go/v4/option"
15+
"github.com/cloudflare/cloudflare-go/v4/packages/pagination"
16+
"github.com/cloudflare/cloudflare-go/v4/shared"
17+
"github.com/cloudflare/cloudflare-go/v4/workers_for_platforms"
18+
)
19+
20+
// ScriptSecretService contains methods and other services that help with
21+
// interacting with the cloudflare API.
22+
//
23+
// Note, unlike clients, this service does not read variables from the environment
24+
// automatically. You should not instantiate this service directly, and instead use
25+
// the [NewScriptSecretService] method instead.
26+
type ScriptSecretService struct {
27+
Options []option.RequestOption
28+
}
29+
30+
// NewScriptSecretService generates a new service that applies the given options to
31+
// each request. These options are applied after the parent client's options (if
32+
// there is one), and before any request-specific options.
33+
func NewScriptSecretService(opts ...option.RequestOption) (r *ScriptSecretService) {
34+
r = &ScriptSecretService{}
35+
r.Options = opts
36+
return
37+
}
38+
39+
// Add a secret to a script.
40+
func (r *ScriptSecretService) Update(ctx context.Context, scriptName string, params ScriptSecretUpdateParams, opts ...option.RequestOption) (res *ScriptSecretUpdateResponse, err error) {
41+
var env ScriptSecretUpdateResponseEnvelope
42+
opts = append(r.Options[:], opts...)
43+
if params.AccountID.Value == "" {
44+
err = errors.New("missing required account_id parameter")
45+
return
46+
}
47+
if scriptName == "" {
48+
err = errors.New("missing required script_name parameter")
49+
return
50+
}
51+
path := fmt.Sprintf("accounts/%s/workers/scripts/%s/secrets", params.AccountID, scriptName)
52+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, params, &env, opts...)
53+
if err != nil {
54+
return
55+
}
56+
res = &env.Result
57+
return
58+
}
59+
60+
// List secrets bound to a script.
61+
func (r *ScriptSecretService) List(ctx context.Context, scriptName string, query ScriptSecretListParams, opts ...option.RequestOption) (res *pagination.SinglePage[ScriptSecretListResponse], err error) {
62+
var raw *http.Response
63+
opts = append(r.Options[:], opts...)
64+
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
65+
if query.AccountID.Value == "" {
66+
err = errors.New("missing required account_id parameter")
67+
return
68+
}
69+
if scriptName == "" {
70+
err = errors.New("missing required script_name parameter")
71+
return
72+
}
73+
path := fmt.Sprintf("accounts/%s/workers/scripts/%s/secrets", query.AccountID, scriptName)
74+
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, nil, &res, opts...)
75+
if err != nil {
76+
return nil, err
77+
}
78+
err = cfg.Execute()
79+
if err != nil {
80+
return nil, err
81+
}
82+
res.SetPageConfig(cfg, raw)
83+
return res, nil
84+
}
85+
86+
// List secrets bound to a script.
87+
func (r *ScriptSecretService) ListAutoPaging(ctx context.Context, scriptName string, query ScriptSecretListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[ScriptSecretListResponse] {
88+
return pagination.NewSinglePageAutoPager(r.List(ctx, scriptName, query, opts...))
89+
}
90+
91+
// Remove a secret from a script.
92+
func (r *ScriptSecretService) Delete(ctx context.Context, scriptName string, secretName string, body ScriptSecretDeleteParams, opts ...option.RequestOption) (res *ScriptSecretDeleteResponse, err error) {
93+
var env ScriptSecretDeleteResponseEnvelope
94+
opts = append(r.Options[:], opts...)
95+
if body.AccountID.Value == "" {
96+
err = errors.New("missing required account_id parameter")
97+
return
98+
}
99+
if scriptName == "" {
100+
err = errors.New("missing required script_name parameter")
101+
return
102+
}
103+
if secretName == "" {
104+
err = errors.New("missing required secret_name parameter")
105+
return
106+
}
107+
path := fmt.Sprintf("accounts/%s/workers/scripts/%s/secrets/%s", body.AccountID, scriptName, secretName)
108+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...)
109+
if err != nil {
110+
return
111+
}
112+
res = &env.Result
113+
return
114+
}
115+
116+
// Get a given secret binding (value omitted) on a script.
117+
func (r *ScriptSecretService) Get(ctx context.Context, scriptName string, secretName string, query ScriptSecretGetParams, opts ...option.RequestOption) (res *ScriptSecretGetResponse, err error) {
118+
var env ScriptSecretGetResponseEnvelope
119+
opts = append(r.Options[:], opts...)
120+
if query.AccountID.Value == "" {
121+
err = errors.New("missing required account_id parameter")
122+
return
123+
}
124+
if scriptName == "" {
125+
err = errors.New("missing required script_name parameter")
126+
return
127+
}
128+
if secretName == "" {
129+
err = errors.New("missing required secret_name parameter")
130+
return
131+
}
132+
path := fmt.Sprintf("accounts/%s/workers/scripts/%s/secrets/%s", query.AccountID, scriptName, secretName)
133+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
134+
if err != nil {
135+
return
136+
}
137+
res = &env.Result
138+
return
139+
}
140+
141+
type ScriptSecretUpdateResponse struct {
142+
// The name of this secret, this is what will be used to access it inside the
143+
// Worker.
144+
Name string `json:"name"`
145+
// The type of secret.
146+
Type ScriptSecretUpdateResponseType `json:"type"`
147+
JSON scriptSecretUpdateResponseJSON `json:"-"`
148+
}
149+
150+
// scriptSecretUpdateResponseJSON contains the JSON metadata for the struct
151+
// [ScriptSecretUpdateResponse]
152+
type scriptSecretUpdateResponseJSON struct {
153+
Name apijson.Field
154+
Type apijson.Field
155+
raw string
156+
ExtraFields map[string]apijson.Field
157+
}
158+
159+
func (r *ScriptSecretUpdateResponse) UnmarshalJSON(data []byte) (err error) {
160+
return apijson.UnmarshalRoot(data, r)
161+
}
162+
163+
func (r scriptSecretUpdateResponseJSON) RawJSON() string {
164+
return r.raw
165+
}
166+
167+
// The type of secret.
168+
type ScriptSecretUpdateResponseType string
169+
170+
const (
171+
ScriptSecretUpdateResponseTypeSecretText ScriptSecretUpdateResponseType = "secret_text"
172+
)
173+
174+
func (r ScriptSecretUpdateResponseType) IsKnown() bool {
175+
switch r {
176+
case ScriptSecretUpdateResponseTypeSecretText:
177+
return true
178+
}
179+
return false
180+
}
181+
182+
type ScriptSecretListResponse struct {
183+
// The name of this secret, this is what will be used to access it inside the
184+
// Worker.
185+
Name string `json:"name"`
186+
// The type of secret.
187+
Type ScriptSecretListResponseType `json:"type"`
188+
JSON scriptSecretListResponseJSON `json:"-"`
189+
}
190+
191+
// scriptSecretListResponseJSON contains the JSON metadata for the struct
192+
// [ScriptSecretListResponse]
193+
type scriptSecretListResponseJSON struct {
194+
Name apijson.Field
195+
Type apijson.Field
196+
raw string
197+
ExtraFields map[string]apijson.Field
198+
}
199+
200+
func (r *ScriptSecretListResponse) UnmarshalJSON(data []byte) (err error) {
201+
return apijson.UnmarshalRoot(data, r)
202+
}
203+
204+
func (r scriptSecretListResponseJSON) RawJSON() string {
205+
return r.raw
206+
}
207+
208+
// The type of secret.
209+
type ScriptSecretListResponseType string
210+
211+
const (
212+
ScriptSecretListResponseTypeSecretText ScriptSecretListResponseType = "secret_text"
213+
)
214+
215+
func (r ScriptSecretListResponseType) IsKnown() bool {
216+
switch r {
217+
case ScriptSecretListResponseTypeSecretText:
218+
return true
219+
}
220+
return false
221+
}
222+
223+
type ScriptSecretDeleteResponse = interface{}
224+
225+
type ScriptSecretGetResponse struct {
226+
// The name of this secret, this is what will be used to access it inside the
227+
// Worker.
228+
Name string `json:"name"`
229+
// The type of secret.
230+
Type ScriptSecretGetResponseType `json:"type"`
231+
JSON scriptSecretGetResponseJSON `json:"-"`
232+
}
233+
234+
// scriptSecretGetResponseJSON contains the JSON metadata for the struct
235+
// [ScriptSecretGetResponse]
236+
type scriptSecretGetResponseJSON struct {
237+
Name apijson.Field
238+
Type apijson.Field
239+
raw string
240+
ExtraFields map[string]apijson.Field
241+
}
242+
243+
func (r *ScriptSecretGetResponse) UnmarshalJSON(data []byte) (err error) {
244+
return apijson.UnmarshalRoot(data, r)
245+
}
246+
247+
func (r scriptSecretGetResponseJSON) RawJSON() string {
248+
return r.raw
249+
}
250+
251+
// The type of secret.
252+
type ScriptSecretGetResponseType string
253+
254+
const (
255+
ScriptSecretGetResponseTypeSecretText ScriptSecretGetResponseType = "secret_text"
256+
)
257+
258+
func (r ScriptSecretGetResponseType) IsKnown() bool {
259+
switch r {
260+
case ScriptSecretGetResponseTypeSecretText:
261+
return true
262+
}
263+
return false
264+
}
265+
266+
type ScriptSecretUpdateParams struct {
267+
// Identifier
268+
AccountID param.Field[string] `path:"account_id,required"`
269+
WorkersSecretModel workers_for_platforms.WorkersSecretModelParam `json:"workers_secret_model,required"`
270+
}
271+
272+
func (r ScriptSecretUpdateParams) MarshalJSON() (data []byte, err error) {
273+
return apijson.MarshalRoot(r.WorkersSecretModel)
274+
}
275+
276+
type ScriptSecretUpdateResponseEnvelope struct {
277+
Errors []shared.ResponseInfo `json:"errors,required"`
278+
Messages []shared.ResponseInfo `json:"messages,required"`
279+
// Whether the API call was successful
280+
Success ScriptSecretUpdateResponseEnvelopeSuccess `json:"success,required"`
281+
Result ScriptSecretUpdateResponse `json:"result"`
282+
JSON scriptSecretUpdateResponseEnvelopeJSON `json:"-"`
283+
}
284+
285+
// scriptSecretUpdateResponseEnvelopeJSON contains the JSON metadata for the struct
286+
// [ScriptSecretUpdateResponseEnvelope]
287+
type scriptSecretUpdateResponseEnvelopeJSON struct {
288+
Errors apijson.Field
289+
Messages apijson.Field
290+
Success apijson.Field
291+
Result apijson.Field
292+
raw string
293+
ExtraFields map[string]apijson.Field
294+
}
295+
296+
func (r *ScriptSecretUpdateResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
297+
return apijson.UnmarshalRoot(data, r)
298+
}
299+
300+
func (r scriptSecretUpdateResponseEnvelopeJSON) RawJSON() string {
301+
return r.raw
302+
}
303+
304+
// Whether the API call was successful
305+
type ScriptSecretUpdateResponseEnvelopeSuccess bool
306+
307+
const (
308+
ScriptSecretUpdateResponseEnvelopeSuccessTrue ScriptSecretUpdateResponseEnvelopeSuccess = true
309+
)
310+
311+
func (r ScriptSecretUpdateResponseEnvelopeSuccess) IsKnown() bool {
312+
switch r {
313+
case ScriptSecretUpdateResponseEnvelopeSuccessTrue:
314+
return true
315+
}
316+
return false
317+
}
318+
319+
type ScriptSecretListParams struct {
320+
// Identifier
321+
AccountID param.Field[string] `path:"account_id,required"`
322+
}
323+
324+
type ScriptSecretDeleteParams struct {
325+
// Identifier
326+
AccountID param.Field[string] `path:"account_id,required"`
327+
}
328+
329+
type ScriptSecretDeleteResponseEnvelope struct {
330+
Errors []shared.ResponseInfo `json:"errors,required"`
331+
Messages []shared.ResponseInfo `json:"messages,required"`
332+
// Whether the API call was successful
333+
Success ScriptSecretDeleteResponseEnvelopeSuccess `json:"success,required"`
334+
Result ScriptSecretDeleteResponse `json:"result,nullable"`
335+
JSON scriptSecretDeleteResponseEnvelopeJSON `json:"-"`
336+
}
337+
338+
// scriptSecretDeleteResponseEnvelopeJSON contains the JSON metadata for the struct
339+
// [ScriptSecretDeleteResponseEnvelope]
340+
type scriptSecretDeleteResponseEnvelopeJSON struct {
341+
Errors apijson.Field
342+
Messages apijson.Field
343+
Success apijson.Field
344+
Result apijson.Field
345+
raw string
346+
ExtraFields map[string]apijson.Field
347+
}
348+
349+
func (r *ScriptSecretDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
350+
return apijson.UnmarshalRoot(data, r)
351+
}
352+
353+
func (r scriptSecretDeleteResponseEnvelopeJSON) RawJSON() string {
354+
return r.raw
355+
}
356+
357+
// Whether the API call was successful
358+
type ScriptSecretDeleteResponseEnvelopeSuccess bool
359+
360+
const (
361+
ScriptSecretDeleteResponseEnvelopeSuccessTrue ScriptSecretDeleteResponseEnvelopeSuccess = true
362+
)
363+
364+
func (r ScriptSecretDeleteResponseEnvelopeSuccess) IsKnown() bool {
365+
switch r {
366+
case ScriptSecretDeleteResponseEnvelopeSuccessTrue:
367+
return true
368+
}
369+
return false
370+
}
371+
372+
type ScriptSecretGetParams struct {
373+
// Identifier
374+
AccountID param.Field[string] `path:"account_id,required"`
375+
}
376+
377+
type ScriptSecretGetResponseEnvelope struct {
378+
Errors []shared.ResponseInfo `json:"errors,required"`
379+
Messages []shared.ResponseInfo `json:"messages,required"`
380+
// Whether the API call was successful
381+
Success ScriptSecretGetResponseEnvelopeSuccess `json:"success,required"`
382+
Result ScriptSecretGetResponse `json:"result"`
383+
JSON scriptSecretGetResponseEnvelopeJSON `json:"-"`
384+
}
385+
386+
// scriptSecretGetResponseEnvelopeJSON contains the JSON metadata for the struct
387+
// [ScriptSecretGetResponseEnvelope]
388+
type scriptSecretGetResponseEnvelopeJSON struct {
389+
Errors apijson.Field
390+
Messages apijson.Field
391+
Success apijson.Field
392+
Result apijson.Field
393+
raw string
394+
ExtraFields map[string]apijson.Field
395+
}
396+
397+
func (r *ScriptSecretGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
398+
return apijson.UnmarshalRoot(data, r)
399+
}
400+
401+
func (r scriptSecretGetResponseEnvelopeJSON) RawJSON() string {
402+
return r.raw
403+
}
404+
405+
// Whether the API call was successful
406+
type ScriptSecretGetResponseEnvelopeSuccess bool
407+
408+
const (
409+
ScriptSecretGetResponseEnvelopeSuccessTrue ScriptSecretGetResponseEnvelopeSuccess = true
410+
)
411+
412+
func (r ScriptSecretGetResponseEnvelopeSuccess) IsKnown() bool {
413+
switch r {
414+
case ScriptSecretGetResponseEnvelopeSuccessTrue:
415+
return true
416+
}
417+
return false
418+
}

‎workers/scriptsecret_test.go

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package workers_test
4+
5+
import (
6+
"context"
7+
"errors"
8+
"os"
9+
"testing"
10+
11+
"github.com/cloudflare/cloudflare-go/v4"
12+
"github.com/cloudflare/cloudflare-go/v4/internal/testutil"
13+
"github.com/cloudflare/cloudflare-go/v4/option"
14+
"github.com/cloudflare/cloudflare-go/v4/workers"
15+
"github.com/cloudflare/cloudflare-go/v4/workers_for_platforms"
16+
)
17+
18+
func TestScriptSecretUpdateWithOptionalParams(t *testing.T) {
19+
baseURL := "http://localhost:4010"
20+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
21+
baseURL = envURL
22+
}
23+
if !testutil.CheckTestServer(t, baseURL) {
24+
return
25+
}
26+
client := cloudflare.NewClient(
27+
option.WithBaseURL(baseURL),
28+
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
29+
option.WithAPIEmail("user@example.com"),
30+
)
31+
_, err := client.Workers.Scripts.Secrets.Update(
32+
context.TODO(),
33+
"this-is_my_script-01",
34+
workers.ScriptSecretUpdateParams{
35+
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
36+
WorkersSecretModel: workers_for_platforms.WorkersSecretModelParam{
37+
Name: cloudflare.F("MY_SECRET"),
38+
Text: cloudflare.F("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"),
39+
Type: cloudflare.F(workers_for_platforms.WorkersSecretModelTypeSecretText),
40+
},
41+
},
42+
)
43+
if err != nil {
44+
var apierr *cloudflare.Error
45+
if errors.As(err, &apierr) {
46+
t.Log(string(apierr.DumpRequest(true)))
47+
}
48+
t.Fatalf("err should be nil: %s", err.Error())
49+
}
50+
}
51+
52+
func TestScriptSecretList(t *testing.T) {
53+
baseURL := "http://localhost:4010"
54+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
55+
baseURL = envURL
56+
}
57+
if !testutil.CheckTestServer(t, baseURL) {
58+
return
59+
}
60+
client := cloudflare.NewClient(
61+
option.WithBaseURL(baseURL),
62+
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
63+
option.WithAPIEmail("user@example.com"),
64+
)
65+
_, err := client.Workers.Scripts.Secrets.List(
66+
context.TODO(),
67+
"this-is_my_script-01",
68+
workers.ScriptSecretListParams{
69+
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
70+
},
71+
)
72+
if err != nil {
73+
var apierr *cloudflare.Error
74+
if errors.As(err, &apierr) {
75+
t.Log(string(apierr.DumpRequest(true)))
76+
}
77+
t.Fatalf("err should be nil: %s", err.Error())
78+
}
79+
}
80+
81+
func TestScriptSecretDelete(t *testing.T) {
82+
baseURL := "http://localhost:4010"
83+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
84+
baseURL = envURL
85+
}
86+
if !testutil.CheckTestServer(t, baseURL) {
87+
return
88+
}
89+
client := cloudflare.NewClient(
90+
option.WithBaseURL(baseURL),
91+
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
92+
option.WithAPIEmail("user@example.com"),
93+
)
94+
_, err := client.Workers.Scripts.Secrets.Delete(
95+
context.TODO(),
96+
"this-is_my_script-01",
97+
"mySecret",
98+
workers.ScriptSecretDeleteParams{
99+
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
100+
},
101+
)
102+
if err != nil {
103+
var apierr *cloudflare.Error
104+
if errors.As(err, &apierr) {
105+
t.Log(string(apierr.DumpRequest(true)))
106+
}
107+
t.Fatalf("err should be nil: %s", err.Error())
108+
}
109+
}
110+
111+
func TestScriptSecretGet(t *testing.T) {
112+
baseURL := "http://localhost:4010"
113+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
114+
baseURL = envURL
115+
}
116+
if !testutil.CheckTestServer(t, baseURL) {
117+
return
118+
}
119+
client := cloudflare.NewClient(
120+
option.WithBaseURL(baseURL),
121+
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
122+
option.WithAPIEmail("user@example.com"),
123+
)
124+
_, err := client.Workers.Scripts.Secrets.Get(
125+
context.TODO(),
126+
"this-is_my_script-01",
127+
"mySecret",
128+
workers.ScriptSecretGetParams{
129+
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
130+
},
131+
)
132+
if err != nil {
133+
var apierr *cloudflare.Error
134+
if errors.As(err, &apierr) {
135+
t.Log(string(apierr.DumpRequest(true)))
136+
}
137+
t.Fatalf("err should be nil: %s", err.Error())
138+
}
139+
}

‎workers_for_platforms/dispatchnamespacescriptsecret.go

+79
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,35 @@ func (r *DispatchNamespaceScriptSecretService) ListAutoPaging(ctx context.Contex
9595
return pagination.NewSinglePageAutoPager(r.List(ctx, dispatchNamespace, scriptName, query, opts...))
9696
}
9797

98+
// Remove a secret from a script uploaded to a Workers for Platforms namespace.
99+
func (r *DispatchNamespaceScriptSecretService) Delete(ctx context.Context, dispatchNamespace string, scriptName string, secretName string, body DispatchNamespaceScriptSecretDeleteParams, opts ...option.RequestOption) (res *DispatchNamespaceScriptSecretDeleteResponse, err error) {
100+
var env DispatchNamespaceScriptSecretDeleteResponseEnvelope
101+
opts = append(r.Options[:], opts...)
102+
if body.AccountID.Value == "" {
103+
err = errors.New("missing required account_id parameter")
104+
return
105+
}
106+
if dispatchNamespace == "" {
107+
err = errors.New("missing required dispatch_namespace parameter")
108+
return
109+
}
110+
if scriptName == "" {
111+
err = errors.New("missing required script_name parameter")
112+
return
113+
}
114+
if secretName == "" {
115+
err = errors.New("missing required secret_name parameter")
116+
return
117+
}
118+
path := fmt.Sprintf("accounts/%s/workers/dispatch/namespaces/%s/scripts/%s/secrets/%s", body.AccountID, dispatchNamespace, scriptName, secretName)
119+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...)
120+
if err != nil {
121+
return
122+
}
123+
res = &env.Result
124+
return
125+
}
126+
98127
// Get a given secret binding (value omitted) on a script uploaded to a Workers for
99128
// Platforms namespace.
100129
func (r *DispatchNamespaceScriptSecretService) Get(ctx context.Context, dispatchNamespace string, scriptName string, secretName string, query DispatchNamespaceScriptSecretGetParams, opts ...option.RequestOption) (res *DispatchNamespaceScriptSecretGetResponse, err error) {
@@ -236,6 +265,8 @@ func (r DispatchNamespaceScriptSecretListResponseType) IsKnown() bool {
236265
return false
237266
}
238267

268+
type DispatchNamespaceScriptSecretDeleteResponse = interface{}
269+
239270
type DispatchNamespaceScriptSecretGetResponse struct {
240271
// The name of this secret, this is what will be used to access it inside the
241272
// Worker.
@@ -335,6 +366,54 @@ type DispatchNamespaceScriptSecretListParams struct {
335366
AccountID param.Field[string] `path:"account_id,required"`
336367
}
337368

369+
type DispatchNamespaceScriptSecretDeleteParams struct {
370+
// Identifier
371+
AccountID param.Field[string] `path:"account_id,required"`
372+
}
373+
374+
type DispatchNamespaceScriptSecretDeleteResponseEnvelope struct {
375+
Errors []shared.ResponseInfo `json:"errors,required"`
376+
Messages []shared.ResponseInfo `json:"messages,required"`
377+
// Whether the API call was successful
378+
Success DispatchNamespaceScriptSecretDeleteResponseEnvelopeSuccess `json:"success,required"`
379+
Result DispatchNamespaceScriptSecretDeleteResponse `json:"result,nullable"`
380+
JSON dispatchNamespaceScriptSecretDeleteResponseEnvelopeJSON `json:"-"`
381+
}
382+
383+
// dispatchNamespaceScriptSecretDeleteResponseEnvelopeJSON contains the JSON
384+
// metadata for the struct [DispatchNamespaceScriptSecretDeleteResponseEnvelope]
385+
type dispatchNamespaceScriptSecretDeleteResponseEnvelopeJSON struct {
386+
Errors apijson.Field
387+
Messages apijson.Field
388+
Success apijson.Field
389+
Result apijson.Field
390+
raw string
391+
ExtraFields map[string]apijson.Field
392+
}
393+
394+
func (r *DispatchNamespaceScriptSecretDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
395+
return apijson.UnmarshalRoot(data, r)
396+
}
397+
398+
func (r dispatchNamespaceScriptSecretDeleteResponseEnvelopeJSON) RawJSON() string {
399+
return r.raw
400+
}
401+
402+
// Whether the API call was successful
403+
type DispatchNamespaceScriptSecretDeleteResponseEnvelopeSuccess bool
404+
405+
const (
406+
DispatchNamespaceScriptSecretDeleteResponseEnvelopeSuccessTrue DispatchNamespaceScriptSecretDeleteResponseEnvelopeSuccess = true
407+
)
408+
409+
func (r DispatchNamespaceScriptSecretDeleteResponseEnvelopeSuccess) IsKnown() bool {
410+
switch r {
411+
case DispatchNamespaceScriptSecretDeleteResponseEnvelopeSuccessTrue:
412+
return true
413+
}
414+
return false
415+
}
416+
338417
type DispatchNamespaceScriptSecretGetParams struct {
339418
// Identifier
340419
AccountID param.Field[string] `path:"account_id,required"`

‎workers_for_platforms/dispatchnamespacescriptsecret_test.go

+31
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,37 @@ func TestDispatchNamespaceScriptSecretList(t *testing.T) {
7979
}
8080
}
8181

82+
func TestDispatchNamespaceScriptSecretDelete(t *testing.T) {
83+
baseURL := "http://localhost:4010"
84+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
85+
baseURL = envURL
86+
}
87+
if !testutil.CheckTestServer(t, baseURL) {
88+
return
89+
}
90+
client := cloudflare.NewClient(
91+
option.WithBaseURL(baseURL),
92+
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
93+
option.WithAPIEmail("user@example.com"),
94+
)
95+
_, err := client.WorkersForPlatforms.Dispatch.Namespaces.Scripts.Secrets.Delete(
96+
context.TODO(),
97+
"my-dispatch-namespace",
98+
"this-is_my_script-01",
99+
"mySecret",
100+
workers_for_platforms.DispatchNamespaceScriptSecretDeleteParams{
101+
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
102+
},
103+
)
104+
if err != nil {
105+
var apierr *cloudflare.Error
106+
if errors.As(err, &apierr) {
107+
t.Log(string(apierr.DumpRequest(true)))
108+
}
109+
t.Fatalf("err should be nil: %s", err.Error())
110+
}
111+
}
112+
82113
func TestDispatchNamespaceScriptSecretGet(t *testing.T) {
83114
baseURL := "http://localhost:4010"
84115
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {

0 commit comments

Comments
 (0)
Please sign in to comment.