Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): manual updates #3666

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4445,6 +4445,10 @@ Methods:

##### Secrets

Params Types:

- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/workers_for_platforms">workers_for_platforms</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/workers_for_platforms#WorkersSecretModelParam">WorkersSecretModelParam</a>

Response Types:

- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/workers_for_platforms">workers_for_platforms</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/workers_for_platforms#DispatchNamespaceScriptSecretUpdateResponse">DispatchNamespaceScriptSecretUpdateResponse</a>
Expand Down
56 changes: 32 additions & 24 deletions workers_for_platforms/dispatchnamespacescriptsecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,35 @@ func (r *DispatchNamespaceScriptSecretService) Get(ctx context.Context, dispatch
return
}

type WorkersSecretModelParam struct {
// The name of this secret, this is what will be used to access it inside the
// Worker.
Name param.Field[string] `json:"name"`
// The value of the secret.
Text param.Field[string] `json:"text"`
// The type of secret to put.
Type param.Field[WorkersSecretModelType] `json:"type"`
}

func (r WorkersSecretModelParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// The type of secret to put.
type WorkersSecretModelType string

const (
WorkersSecretModelTypeSecretText WorkersSecretModelType = "secret_text"
)

func (r WorkersSecretModelType) IsKnown() bool {
switch r {
case WorkersSecretModelTypeSecretText:
return true
}
return false
}

type DispatchNamespaceScriptSecretUpdateResponse struct {
// The name of this secret, this is what will be used to access it inside the
// Worker.
Expand Down Expand Up @@ -249,33 +278,12 @@ func (r DispatchNamespaceScriptSecretGetResponseType) IsKnown() bool {

type DispatchNamespaceScriptSecretUpdateParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
// The name of this secret, this is what will be used to access it inside the
// Worker.
Name param.Field[string] `json:"name"`
// The value of the secret.
Text param.Field[string] `json:"text"`
// The type of secret to put.
Type param.Field[DispatchNamespaceScriptSecretUpdateParamsType] `json:"type"`
AccountID param.Field[string] `path:"account_id,required"`
WorkersSecretModel WorkersSecretModelParam `json:"workers_secret_model,required"`
}

func (r DispatchNamespaceScriptSecretUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// The type of secret to put.
type DispatchNamespaceScriptSecretUpdateParamsType string

const (
DispatchNamespaceScriptSecretUpdateParamsTypeSecretText DispatchNamespaceScriptSecretUpdateParamsType = "secret_text"
)

func (r DispatchNamespaceScriptSecretUpdateParamsType) IsKnown() bool {
switch r {
case DispatchNamespaceScriptSecretUpdateParamsTypeSecretText:
return true
}
return false
return apijson.MarshalRoot(r.WorkersSecretModel)
}

type DispatchNamespaceScriptSecretUpdateResponseEnvelope struct {
Expand Down
8 changes: 5 additions & 3 deletions workers_for_platforms/dispatchnamespacescriptsecret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ func TestDispatchNamespaceScriptSecretUpdateWithOptionalParams(t *testing.T) {
"this-is_my_script-01",
workers_for_platforms.DispatchNamespaceScriptSecretUpdateParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
Name: cloudflare.F("MY_SECRET"),
Text: cloudflare.F("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"),
Type: cloudflare.F(workers_for_platforms.DispatchNamespaceScriptSecretUpdateParamsTypeSecretText),
WorkersSecretModel: workers_for_platforms.WorkersSecretModelParam{
Name: cloudflare.F("MY_SECRET"),
Text: cloudflare.F("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"),
Type: cloudflare.F(workers_for_platforms.WorkersSecretModelTypeSecretText),
},
},
)
if err != nil {
Expand Down