Skip to content

Commit 9eb8b97

Browse files
authored
Merge branch 'main' into rcaril/CDTOOL-1216-ngwaf-alerts-crud-support
2 parents e1cea6b + 879a897 commit 9eb8b97

20 files changed

Lines changed: 1737 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- feat(commands/ngwaf/workspaces): add support for update operation for NGWAF workspaces ([#1578](https://github.com/fastly/cli/pull/1578))
99
- feat(commands/ngwaf/lists): add support for CRUD operations for NGWAF Lists at account and workspace levels ([#1582](https://github.com/fastly/cli/pull/1582))
1010
- feat(commands/ngwaf/workspaces/alerts): add support for operations for NGWAF alerts ([#1589](https://github.com/fastly/cli/pull/1589))
11-
11+
- feat(commands/ngwaf/customsignals): add support for CRUD operations for NGWAF Custom Signals ([#1592](https://github.com/fastly/cli/pull/1592))
1212

1313
### Bug fixes:
1414

pkg/commands/commands.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import (
5757
"github.com/fastly/cli/pkg/commands/logtail"
5858
"github.com/fastly/cli/pkg/commands/ngwaf"
5959
"github.com/fastly/cli/pkg/commands/ngwaf/countrylist"
60+
"github.com/fastly/cli/pkg/commands/ngwaf/customsignal"
6061
"github.com/fastly/cli/pkg/commands/ngwaf/iplist"
6162
"github.com/fastly/cli/pkg/commands/ngwaf/signallist"
6263
"github.com/fastly/cli/pkg/commands/ngwaf/stringlist"
@@ -72,6 +73,7 @@ import (
7273
workspaceAlertSlack "github.com/fastly/cli/pkg/commands/ngwaf/workspace/alert/slack"
7374
workspaceAlertWebhook "github.com/fastly/cli/pkg/commands/ngwaf/workspace/alert/webhook"
7475
wscountrylist "github.com/fastly/cli/pkg/commands/ngwaf/workspace/countrylist"
76+
wscustomsignal "github.com/fastly/cli/pkg/commands/ngwaf/workspace/customsignal"
7577
wsiplist "github.com/fastly/cli/pkg/commands/ngwaf/workspace/iplist"
7678
"github.com/fastly/cli/pkg/commands/ngwaf/workspace/redaction"
7779
wssignallistlist "github.com/fastly/cli/pkg/commands/ngwaf/workspace/signallist"
@@ -435,6 +437,12 @@ func Define( // nolint:revive // function-length
435437
ngwafCountryListGet := countrylist.NewGetCommand(ngwafCountryListRoot.CmdClause, data)
436438
ngwafCountryListList := countrylist.NewListCommand(ngwafCountryListRoot.CmdClause, data)
437439
ngwafCountryListUpdate := countrylist.NewUpdateCommand(ngwafCountryListRoot.CmdClause, data)
440+
ngwafCustomSignalRoot := customsignal.NewRootCommand(ngwafRoot.CmdClause, data)
441+
ngwafCustomSignalCreate := customsignal.NewCreateCommand(ngwafCustomSignalRoot.CmdClause, data)
442+
ngwafCustomSignalDelete := customsignal.NewDeleteCommand(ngwafCustomSignalRoot.CmdClause, data)
443+
ngwafCustomSignalGet := customsignal.NewGetCommand(ngwafCustomSignalRoot.CmdClause, data)
444+
ngwafCustomSignalList := customsignal.NewListCommand(ngwafCustomSignalRoot.CmdClause, data)
445+
ngwafCustomSignalUpdate := customsignal.NewUpdateCommand(ngwafCustomSignalRoot.CmdClause, data)
438446
ngwafIPListRoot := iplist.NewRootCommand(ngwafRoot.CmdClause, data)
439447
ngwafIPListCreate := iplist.NewCreateCommand(ngwafIPListRoot.CmdClause, data)
440448
ngwafIPListDelete := iplist.NewDeleteCommand(ngwafIPListRoot.CmdClause, data)
@@ -465,6 +473,12 @@ func Define( // nolint:revive // function-length
465473
ngwafWorkspaceCountryListGet := wscountrylist.NewGetCommand(ngwafWorkspaceCountryListRoot.CmdClause, data)
466474
ngwafWorkspaceCountryListList := wscountrylist.NewListCommand(ngwafWorkspaceCountryListRoot.CmdClause, data)
467475
ngwafWorkspaceCountryListUpdate := wscountrylist.NewUpdateCommand(ngwafWorkspaceCountryListRoot.CmdClause, data)
476+
ngwafWorkspaceCustomSignalRoot := wscustomsignal.NewRootCommand(ngwafWorkspaceRoot.CmdClause, data)
477+
ngwafWorkspaceCustomSignalCreate := wscustomsignal.NewCreateCommand(ngwafWorkspaceCustomSignalRoot.CmdClause, data)
478+
ngwafWorkspaceCustomSignalDelete := wscustomsignal.NewDeleteCommand(ngwafWorkspaceCustomSignalRoot.CmdClause, data)
479+
ngwafWorkspaceCustomSignalGet := wscustomsignal.NewGetCommand(ngwafWorkspaceCustomSignalRoot.CmdClause, data)
480+
ngwafWorkspaceCustomSignalList := wscustomsignal.NewListCommand(ngwafWorkspaceCustomSignalRoot.CmdClause, data)
481+
ngwafWorkspaceCustomSignalUpdate := wscustomsignal.NewUpdateCommand(ngwafWorkspaceCustomSignalRoot.CmdClause, data)
468482
ngwafWorkspaceIPListRoot := wsiplist.NewRootCommand(ngwafWorkspaceRoot.CmdClause, data)
469483
ngwafWorkspaceIPListCreate := wsiplist.NewCreateCommand(ngwafWorkspaceIPListRoot.CmdClause, data)
470484
ngwafWorkspaceIPListDelete := wsiplist.NewDeleteCommand(ngwafWorkspaceIPListRoot.CmdClause, data)
@@ -976,6 +990,12 @@ func Define( // nolint:revive // function-length
976990
ngwafCountryListGet,
977991
ngwafCountryListList,
978992
ngwafCountryListUpdate,
993+
ngwafCustomSignalRoot,
994+
ngwafCustomSignalCreate,
995+
ngwafCustomSignalDelete,
996+
ngwafCustomSignalGet,
997+
ngwafCustomSignalList,
998+
ngwafCustomSignalUpdate,
979999
ngwafIPListRoot,
9801000
ngwafIPListCreate,
9811001
ngwafIPListDelete,
@@ -1005,6 +1025,12 @@ func Define( // nolint:revive // function-length
10051025
ngwafWorkspaceCountryListGet,
10061026
ngwafWorkspaceCountryListList,
10071027
ngwafWorkspaceCountryListUpdate,
1028+
ngwafWorkspaceCustomSignalRoot,
1029+
ngwafWorkspaceCustomSignalCreate,
1030+
ngwafWorkspaceCustomSignalDelete,
1031+
ngwafWorkspaceCustomSignalGet,
1032+
ngwafWorkspaceCustomSignalList,
1033+
ngwafWorkspaceCustomSignalUpdate,
10081034
ngwafWorkspaceIPListRoot,
10091035
ngwafWorkspaceIPListCreate,
10101036
ngwafWorkspaceIPListDelete,
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package customsignal
2+
3+
import (
4+
"context"
5+
"errors"
6+
"io"
7+
8+
"github.com/fastly/go-fastly/v12/fastly"
9+
"github.com/fastly/go-fastly/v12/fastly/ngwaf/v1/scope"
10+
"github.com/fastly/go-fastly/v12/fastly/ngwaf/v1/signals"
11+
12+
"github.com/fastly/cli/pkg/argparser"
13+
fsterr "github.com/fastly/cli/pkg/errors"
14+
"github.com/fastly/cli/pkg/global"
15+
"github.com/fastly/cli/pkg/text"
16+
)
17+
18+
// CreateCommand calls the Fastly API to create account-level custom signals.
19+
type CreateCommand struct {
20+
argparser.Base
21+
argparser.JSONOutput
22+
23+
// Required.
24+
name string
25+
26+
// Optional.
27+
description argparser.OptionalString
28+
}
29+
30+
// NewCreateCommand returns a usable command registered under the parent.
31+
func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateCommand {
32+
c := CreateCommand{
33+
Base: argparser.Base{
34+
Globals: g,
35+
},
36+
}
37+
c.CmdClause = parent.Command("create", "Create an account-level custom signal").Alias("add")
38+
39+
// Required.
40+
c.CmdClause.Flag("name", "User submitted display name of a custom signal. Is immutable and must be between 3 and 25 characters").Required().StringVar(&c.name)
41+
42+
// Optional.
43+
c.CmdClause.Flag("description", "User submitted description of a custom signal.").Action(c.description.Set).StringVar(&c.description.Value)
44+
c.RegisterFlagBool(c.JSONFlag())
45+
46+
return &c
47+
}
48+
49+
// Exec invokes the application logic for the command.
50+
func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error {
51+
if c.Globals.Verbose() && c.JSONOutput.Enabled {
52+
return fsterr.ErrInvalidVerboseJSONCombo
53+
}
54+
var err error
55+
input := &signals.CreateInput{
56+
Name: &c.name,
57+
Scope: &scope.Scope{
58+
Type: scope.ScopeTypeAccount,
59+
AppliesTo: []string{"*"},
60+
},
61+
}
62+
if c.description.WasSet {
63+
input.Description = &c.description.Value
64+
}
65+
66+
fc, ok := c.Globals.APIClient.(*fastly.Client)
67+
if !ok {
68+
return errors.New("failed to convert interface to a fastly client")
69+
}
70+
71+
data, err := signals.Create(context.TODO(), fc, input)
72+
if err != nil {
73+
return err
74+
}
75+
76+
if ok, err := c.WriteJSON(out, data); ok {
77+
return err
78+
}
79+
80+
text.Success(out, "Created account-level custom signal '%s' (signal-id: %s)", data.Name, data.SignalID)
81+
return nil
82+
}

0 commit comments

Comments
 (0)