Skip to content
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

### Enhancements:

- feat(ngwaf): add `--autoEnableNewVirtualPatches` flag to `ngwaf workspace create` and `ngwaf workspace update` for Automated Virtual Patching, and show it in `ngwaf workspace get` ([#1953](https://github.com/fastly/cli/pull/1953))

### Dependencies:

- build(deps): `github.com/fastly/go-fastly` from v17.8.0 to v18.0.0 ([#1949](https://github.com/fastly/cli/pull/1949))
- build(deps): `golang.org/x/term` from 0.46.0 to 0.47.0 ([#1944](https://github.com/fastly/cli/pull/1944))
- build(deps): `golang.org/x/crypto` from 0.57.0 to 0.58.0 ([#1944](https://github.com/fastly/cli/pull/1944))
Expand Down
15 changes: 10 additions & 5 deletions pkg/commands/ngwaf/workspace/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ type CreateCommand struct {
name string

// Optional.
attackThresholds argparser.OptionalString
defaultBlockingCode argparser.OptionalInt
defaultRedirectURL argparser.OptionalString
clientIPHeaders argparser.OptionalString
ipAnonymization argparser.OptionalString
attackThresholds argparser.OptionalString
defaultBlockingCode argparser.OptionalInt
defaultRedirectURL argparser.OptionalString
clientIPHeaders argparser.OptionalString
ipAnonymization argparser.OptionalString
autoEnableVirtualPatches argparser.OptionalBool
}

// NewCreateCommand returns a usable command registered under the parent.
Expand All @@ -54,6 +55,7 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman
c.CmdClause.Flag("defaultBlockingCode", "Default status code that is returned when a request to your web application is blocked.").Action(c.defaultBlockingCode.Set).IntVar(&c.defaultBlockingCode.Value)
c.CmdClause.Flag("defaultRedirectURL", "Redirect url to be used if code 301 or 302 is used.").Action(c.defaultRedirectURL.Set).StringVar(&c.defaultRedirectURL.Value)
c.CmdClause.Flag("ipAnonymization", "Agents will anonymize IP addresses according to the option selected.").Action(c.ipAnonymization.Set).StringVar(&c.ipAnonymization.Value)
c.CmdClause.Flag("autoEnableNewVirtualPatches", "Automatically enable, in block mode, virtual patches released after this setting is enabled. Virtual patches released before it was enabled are not changed. Use --no-autoEnableNewVirtualPatches to disable.").Action(c.autoEnableVirtualPatches.Set).BoolVar(&c.autoEnableVirtualPatches.Value)
c.RegisterFlagBool(c.JSONFlag())

return &c
Expand Down Expand Up @@ -88,6 +90,9 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error {
if c.ipAnonymization.WasSet {
input.IPAnonymization = &c.ipAnonymization.Value
}
if c.autoEnableVirtualPatches.WasSet {
input.AutoEnableNewVirtualPatches = &c.autoEnableVirtualPatches.Value
}

fc, ok := c.Globals.APIClient.(*fastly.Client)
if !ok {
Expand Down
21 changes: 13 additions & 8 deletions pkg/commands/ngwaf/workspace/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ type UpdateCommand struct {
workspaceID string

// Optional.
description argparser.OptionalString
blockingMode argparser.OptionalString
name argparser.OptionalString
attackThresholds argparser.OptionalString
defaultBlockingCode argparser.OptionalInt
defaultRedirectURL argparser.OptionalString
clientIPHeaders argparser.OptionalString
ipAnonymization argparser.OptionalString
description argparser.OptionalString
blockingMode argparser.OptionalString
name argparser.OptionalString
attackThresholds argparser.OptionalString
defaultBlockingCode argparser.OptionalInt
defaultRedirectURL argparser.OptionalString
clientIPHeaders argparser.OptionalString
ipAnonymization argparser.OptionalString
autoEnableVirtualPatches argparser.OptionalBool
}

// NewUpdateCommand returns a usable command registered under the parent.
Expand All @@ -56,6 +57,7 @@ func NewUpdateCommand(parent argparser.Registerer, g *global.Data) *UpdateComman
c.CmdClause.Flag("defaultBlockingCode", "Default status code that is returned when a request to your web application is blocked.").Action(c.defaultBlockingCode.Set).IntVar(&c.defaultBlockingCode.Value)
c.CmdClause.Flag("defaultRedirectURL", "Redirect url to be used if code 301 or 302 is used.").Action(c.defaultRedirectURL.Set).StringVar(&c.defaultRedirectURL.Value)
c.CmdClause.Flag("ipAnonymization", "Agents will anonymize IP addresses according to the option selected.").Action(c.ipAnonymization.Set).StringVar(&c.ipAnonymization.Value)
c.CmdClause.Flag("autoEnableNewVirtualPatches", "Automatically enable, in block mode, virtual patches released after this setting is enabled. Virtual patches released before it was enabled are not changed. Use --no-autoEnableNewVirtualPatches to disable.").Action(c.autoEnableVirtualPatches.Set).BoolVar(&c.autoEnableVirtualPatches.Value)
c.RegisterFlagBool(c.JSONFlag())

return &c
Expand Down Expand Up @@ -99,6 +101,9 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error {
if c.ipAnonymization.WasSet {
input.IPAnonymization = &c.ipAnonymization.Value
}
if c.autoEnableVirtualPatches.WasSet {
input.AutoEnableNewVirtualPatches = &c.autoEnableVirtualPatches.Value
}

fc, ok := c.Globals.APIClient.(*fastly.Client)
if !ok {
Expand Down
14 changes: 14 additions & 0 deletions pkg/commands/ngwaf/workspace/workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ func TestWorkspacesCreate(t *testing.T) {
},
WantOutput: fstfmt.Success("Created workspace '%s' (workspace-id: %s)", workspaceName, workspaceID),
},
{
Name: "validate --autoEnableNewVirtualPatches flag",
Args: fmt.Sprintf("--description %s --name %s --blockingMode %s --autoEnableNewVirtualPatches", workspaceDescription, workspaceName, workspaceMode),
Client: &http.Client{
Transport: &testutil.MockRoundTripper{
Response: &http.Response{
StatusCode: http.StatusOK,
Status: http.StatusText(http.StatusOK),
Body: io.NopCloser(bytes.NewReader(testutil.GenJSON(workspace))),
},
},
},
WantOutput: fstfmt.Success("Created workspace '%s' (workspace-id: %s)", workspaceName, workspaceID),
},
{
Name: "validate optional --json flag",
Args: fmt.Sprintf("--description %s --name %s --blockingMode %s --clientIPHeaders %s --json", workspaceDescription, workspaceName, workspaceMode, workspaceClientIPHeaders),
Expand Down
3 changes: 3 additions & 0 deletions pkg/text/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func PrintWorkspace(out io.Writer, workspaceToPrint *workspaces.Workspace) {
if workspaceToPrint.IPAnonymization != "" {
fmt.Fprintf(out, "IP Anonymization: %s\n", workspaceToPrint.IPAnonymization)
}
if workspaceToPrint.AutoEnableNewVirtualPatches != nil {
fmt.Fprintf(out, "Auto Enable New Virtual Patches: %t\n", *workspaceToPrint.AutoEnableNewVirtualPatches)
}
fmt.Fprintf(out, "Updated (UTC): %s\n", workspaceToPrint.UpdatedAt.UTC().Format(time.Format))
}

Expand Down
Loading