Skip to content

Commit

Permalink
use CreateChallengeWidgetRequest to create ChallengeWidgets
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyb3r-Jak3 committed Apr 15, 2023
1 parent 723fc94 commit 7fdb309
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion challenge_widgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ type ChallengeWidget struct {
Region string `json:"region,omitempty"`
}

type CreateChallengeWidgetRequest struct {
Name string `json:"name,omitempty"`
Domains []string `json:"domains,omitempty"`
Mode string `json:"mode,omitempty"`
BotFightMode bool `json:"bot_fight_mode,omitempty"`
Region string `json:"region,omitempty"`
OffLabel bool `json:"off_label,omitempty"`
}

type ChallengeWidgetResponse struct {
Response
Result ChallengeWidget `json:"result"`
Expand All @@ -48,7 +57,7 @@ type RotateChallengeWidgetRequest struct {
// CreateChallengeWidget creates a new challenge widgets.
//
// API reference: https://api.cloudflare.com/#challenge-widgets-properties
func (api *API) CreateChallengeWidget(ctx context.Context, rc *ResourceContainer, params ChallengeWidget) (ChallengeWidget, error) {
func (api *API) CreateChallengeWidget(ctx context.Context, rc *ResourceContainer, params CreateChallengeWidgetRequest) (ChallengeWidget, error) {
if rc.Identifier == "" {
return ChallengeWidget{}, ErrMissingAccountID
}
Expand Down
4 changes: 2 additions & 2 deletions challenge_widgets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ func TestChallengeWidgets_Create(t *testing.T) {
})

// Make sure missing account ID is thrown
_, err := client.CreateChallengeWidget(context.Background(), AccountIdentifier(""), ChallengeWidget{})
_, err := client.CreateChallengeWidget(context.Background(), AccountIdentifier(""), CreateChallengeWidgetRequest{})
if assert.Error(t, err) {
assert.Equal(t, ErrMissingAccountID, err)
}

out, err := client.CreateChallengeWidget(context.Background(), AccountIdentifier(testAccountID), ChallengeWidget{
out, err := client.CreateChallengeWidget(context.Background(), AccountIdentifier(testAccountID), CreateChallengeWidgetRequest{
Name: "blog.cloudflare.com login form",
Mode: "invisible",
BotFightMode: true,
Expand Down

0 comments on commit 7fdb309

Please sign in to comment.