-
Notifications
You must be signed in to change notification settings - Fork 70
[CDTOOL-1218] Add Support for NGWAF Redaction Commands #1581
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
Merged
rcaril
merged 4 commits into
main
from
rcaril/CDTOOL-1218-add-CRUD-commands-for-ngwaf-redactions
Nov 20, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package redaction | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "io" | ||
|
|
||
| "github.com/fastly/go-fastly/v12/fastly" | ||
| "github.com/fastly/go-fastly/v12/fastly/ngwaf/v1/workspaces/redactions" | ||
|
|
||
| "github.com/fastly/cli/pkg/argparser" | ||
| "github.com/fastly/cli/pkg/global" | ||
| "github.com/fastly/cli/pkg/text" | ||
| ) | ||
|
|
||
| // CreateCommand calls the Fastly API to create a redaction. | ||
| type CreateCommand struct { | ||
| argparser.Base | ||
| argparser.JSONOutput | ||
|
|
||
| // Required. | ||
| field string | ||
| redactionType string | ||
| workspaceID argparser.OptionalWorkspaceID | ||
| } | ||
|
|
||
| // NewUpdateCommand returns a usable command registered under the parent. | ||
| func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateCommand { | ||
| c := CreateCommand{ | ||
| Base: argparser.Base{ | ||
| Globals: g, | ||
| }, | ||
| } | ||
| c.CmdClause = parent.Command("create", "Create a redaction") | ||
|
|
||
| // Required. | ||
| c.CmdClause.Flag("field", "The name of the field that should be redacted.").Required().StringVar(&c.field) | ||
| c.CmdClause.Flag("type", "The type of field that is being redacted.").Required().StringVar(&c.redactionType) | ||
| c.RegisterFlag(argparser.StringFlagOpts{ | ||
| Name: argparser.FlagNGWAFWorkspaceID, | ||
| Description: argparser.FlagNGWAFWorkspaceIDDesc, | ||
| Dst: &c.workspaceID.Value, | ||
| Action: c.workspaceID.Set, | ||
| }) | ||
|
|
||
| // Optional. | ||
| c.RegisterFlagBool(c.JSONFlag()) | ||
|
|
||
| return &c | ||
| } | ||
|
|
||
| // Exec invokes the application logic for the command. | ||
| func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { | ||
| // Call Parse() to ensure that we check if workspaceID | ||
| // is set or to throw the appropriate error. | ||
| if err := c.workspaceID.Parse(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| var err error | ||
| input := &redactions.CreateInput{ | ||
| Field: &c.field, | ||
| Type: &c.redactionType, | ||
| WorkspaceID: &c.workspaceID.Value, | ||
| } | ||
|
|
||
| fc, ok := c.Globals.APIClient.(*fastly.Client) | ||
| if !ok { | ||
| return errors.New("failed to convert interface to a fastly client") | ||
| } | ||
|
|
||
| data, err := redactions.Create(context.TODO(), fc, input) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if ok, err := c.WriteJSON(out, data); ok { | ||
| return err | ||
| } | ||
|
|
||
| text.Success(out, "Created redaction '%s' (field: %s, type: %s)", data.RedactionID, data.Field, data.Type) | ||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| package redaction | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "io" | ||
|
|
||
| "github.com/fastly/go-fastly/v12/fastly" | ||
|
|
||
| "github.com/fastly/go-fastly/v12/fastly/ngwaf/v1/workspaces/redactions" | ||
|
|
||
| "github.com/fastly/cli/pkg/argparser" | ||
| fsterr "github.com/fastly/cli/pkg/errors" | ||
| "github.com/fastly/cli/pkg/global" | ||
| "github.com/fastly/cli/pkg/text" | ||
| ) | ||
|
|
||
| // DeleteCommand calls the Fastly API to delete a workspace. | ||
| type DeleteCommand struct { | ||
| argparser.Base | ||
| argparser.JSONOutput | ||
|
|
||
| // Required. | ||
| workspaceID argparser.OptionalWorkspaceID | ||
| redactionID string | ||
| } | ||
|
|
||
| // NewDeleteCommand returns a usable command registered under the parent. | ||
| func NewDeleteCommand(parent argparser.Registerer, g *global.Data) *DeleteCommand { | ||
| c := DeleteCommand{ | ||
| Base: argparser.Base{ | ||
| Globals: g, | ||
| }, | ||
| } | ||
|
|
||
| c.CmdClause = parent.Command("delete", "Delete a redaction") | ||
|
|
||
| // Required. | ||
| c.CmdClause.Flag("redaction-id", "Workspace ID").Required().StringVar(&c.redactionID) | ||
| c.RegisterFlag(argparser.StringFlagOpts{ | ||
| Name: argparser.FlagNGWAFWorkspaceID, | ||
| Description: argparser.FlagNGWAFWorkspaceIDDesc, | ||
| Dst: &c.workspaceID.Value, | ||
| Action: c.workspaceID.Set, | ||
| }) | ||
|
|
||
| // Optional. | ||
| c.RegisterFlagBool(c.JSONFlag()) | ||
|
|
||
| return &c | ||
| } | ||
|
|
||
| // Exec invokes the application logic for the command. | ||
| func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { | ||
| // Call Parse() to ensure that we check if workspaceID | ||
| // is set or to throw the appropriate error. | ||
| if err := c.workspaceID.Parse(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if c.Globals.Verbose() && c.JSONOutput.Enabled { | ||
| return fsterr.ErrInvalidVerboseJSONCombo | ||
| } | ||
|
|
||
| fc, ok := c.Globals.APIClient.(*fastly.Client) | ||
| if !ok { | ||
| return errors.New("failed to convert interface to a fastly client") | ||
| } | ||
|
|
||
| err := redactions.Delete(context.TODO(), fc, &redactions.DeleteInput{ | ||
| RedactionID: &c.redactionID, | ||
| WorkspaceID: &c.workspaceID.Value, | ||
| }) | ||
| if err != nil { | ||
| c.Globals.ErrLog.Add(err) | ||
| return err | ||
| } | ||
|
|
||
| if c.JSONOutput.Enabled { | ||
| o := struct { | ||
| ID string `json:"id"` | ||
| Deleted bool `json:"deleted"` | ||
| }{ | ||
| c.redactionID, | ||
| true, | ||
| } | ||
| _, err := c.WriteJSON(out, o) | ||
| return err | ||
| } | ||
|
|
||
| text.Success(out, "Deleted redaction (id: %s)", c.redactionID) | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| package redaction | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "io" | ||
|
|
||
| "github.com/fastly/go-fastly/v12/fastly" | ||
| "github.com/fastly/go-fastly/v12/fastly/ngwaf/v1/workspaces/redactions" | ||
|
|
||
| "github.com/fastly/cli/pkg/argparser" | ||
| fsterr "github.com/fastly/cli/pkg/errors" | ||
| "github.com/fastly/cli/pkg/global" | ||
| "github.com/fastly/cli/pkg/text" | ||
| ) | ||
|
|
||
| // ListCommand calls the Fastly API to list redactions in a workspace. | ||
| type ListCommand struct { | ||
| argparser.Base | ||
| argparser.JSONOutput | ||
|
|
||
| // Required. | ||
| workspaceID argparser.OptionalWorkspaceID | ||
|
|
||
| // Optional. | ||
| limit argparser.OptionalInt | ||
| } | ||
|
|
||
| // NewListCommand returns a usable command registered under the parent. | ||
| func NewListCommand(parent argparser.Registerer, g *global.Data) *ListCommand { | ||
| c := ListCommand{ | ||
| Base: argparser.Base{ | ||
| Globals: g, | ||
| }, | ||
| } | ||
|
|
||
| c.CmdClause = parent.Command("list", "List redactions in a workspace") | ||
|
|
||
| // Required. | ||
| c.RegisterFlag(argparser.StringFlagOpts{ | ||
| Name: argparser.FlagNGWAFWorkspaceID, | ||
| Description: argparser.FlagNGWAFWorkspaceIDDesc, | ||
| Dst: &c.workspaceID.Value, | ||
| Action: c.workspaceID.Set, | ||
| }) | ||
|
|
||
| // Optional. | ||
| c.CmdClause.Flag("limit", "Limit how many results are returned").Action(c.limit.Set).IntVar(&c.limit.Value) | ||
| c.RegisterFlagBool(c.JSONFlag()) | ||
|
|
||
| return &c | ||
| } | ||
|
|
||
| // Exec invokes the application logic for the command. | ||
| func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { | ||
| // Call Parse() to ensure that we check if workspaceID | ||
| // is set or to throw the appropriate error. | ||
| if err := c.workspaceID.Parse(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if c.Globals.Verbose() && c.JSONOutput.Enabled { | ||
| return fsterr.ErrInvalidVerboseJSONCombo | ||
| } | ||
|
|
||
| fc, ok := c.Globals.APIClient.(*fastly.Client) | ||
| if !ok { | ||
| return errors.New("failed to convert interface to a fastly client") | ||
| } | ||
|
|
||
| input := &redactions.ListInput{ | ||
| WorkspaceID: &c.workspaceID.Value, | ||
| } | ||
|
|
||
| if c.limit.WasSet { | ||
| input.Limit = &c.limit.Value | ||
| } | ||
|
|
||
| data, err := redactions.List(context.TODO(), fc, input) | ||
| if err != nil { | ||
| c.Globals.ErrLog.Add(err) | ||
| return err | ||
| } | ||
|
|
||
| if ok, err := c.WriteJSON(out, data); ok { | ||
| return err | ||
| } | ||
|
|
||
| text.PrintRedactionTbl(out, data.Data) | ||
| return nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.