-
Notifications
You must be signed in to change notification settings - Fork 73
[CDTOOL- 1216] Support for NGWAF Alerts #1589
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
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
333b7b3
Datadog Alert CRUD
rcaril 57374f9
jira + workspace require override
rcaril 51f0746
move comment
rcaril e4fd6f3
alerts & tests
rcaril 2100a7c
Test Updates and Revert back to Parse() Usage
rcaril 1300373
Merge branch 'main' into rcaril/CDTOOL-1216-ngwaf-alerts-crud-support
rcaril 0117249
changelog updates
rcaril 831f832
Linting Fix
rcaril c099f59
Merge branch 'main' into rcaril/CDTOOL-1216-ngwaf-alerts-crud-support
rcaril 66b372e
more linting fixes
rcaril b8efbe4
Merge branch 'rcaril/CDTOOL-1216-ngwaf-alerts-crud-support' of github…
rcaril 3bb2c77
Duplicate Command Fix
rcaril 5fe2404
Merge branch 'main' into rcaril/CDTOOL-1216-ngwaf-alerts-crud-support
rcaril 1a24eac
Alert Common Refactor
rcaril 6fedc2f
Linting Fixes
rcaril 57d00c1
Removed shared references from root.go parent package.
rcaril e1cea6b
Update CHANGELOG.md
rcaril 9eb8b97
Merge branch 'main' into rcaril/CDTOOL-1216-ngwaf-alerts-crud-support
rcaril bd783e0
Merge branch 'main' into rcaril/CDTOOL-1216-ngwaf-alerts-crud-support
rcaril c0a04a3
Merge branch 'main' into rcaril/CDTOOL-1216-ngwaf-alerts-crud-support
rcaril 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
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,98 @@ | ||
| package datadog | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "io" | ||
|
|
||
| "github.com/fastly/cli/pkg/argparser" | ||
| "github.com/fastly/cli/pkg/commands/ngwaf/workspace/alert" | ||
|
|
||
| fsterr "github.com/fastly/cli/pkg/errors" | ||
| "github.com/fastly/cli/pkg/global" | ||
| "github.com/fastly/cli/pkg/text" | ||
| "github.com/fastly/go-fastly/v12/fastly" | ||
| "github.com/fastly/go-fastly/v12/fastly/ngwaf/v1/workspaces/alerts/datadog" | ||
| ) | ||
|
|
||
| // CreateCommand calls the Fastly API to create Datadog alerts. | ||
| type CreateCommand struct { | ||
| argparser.Base | ||
| argparser.JSONOutput | ||
|
|
||
| // Required. | ||
| WorkspaceID argparser.OptionalWorkspaceID | ||
| Key string | ||
| Site string | ||
|
|
||
| // Optional. | ||
| Description argparser.OptionalString | ||
| } | ||
|
|
||
| // NewCreateCommand 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 Datadog alert").Alias("add") | ||
|
|
||
| // Required. | ||
| c.RegisterFlag(argparser.StringFlagOpts{ | ||
| Name: argparser.FlagNGWAFWorkspaceID, | ||
| Description: argparser.FlagNGWAFWorkspaceIDDesc, | ||
| Dst: &c.WorkspaceID.Value, | ||
| Action: c.WorkspaceID.Set, | ||
| }) | ||
| c.CmdClause.Flag("key", "Datadog integration key.").Required().StringVar(&c.Key) | ||
| c.CmdClause.Flag("site", "Datadog site.").Required().StringVar(&c.Site) | ||
|
|
||
| // Optional. | ||
| c.CmdClause.Flag("description", "An optional description for the alert.").Action(c.Description.Set).StringVar(&c.Description.Value) | ||
| 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 | ||
| } | ||
| if c.Globals.Verbose() && c.JSONOutput.Enabled { | ||
| return fsterr.ErrInvalidVerboseJSONCombo | ||
| } | ||
|
|
||
| input := &datadog.CreateInput{ | ||
| WorkspaceID: &c.WorkspaceID.Value, | ||
| Config: &datadog.CreateConfig{ | ||
| Key: &c.Key, | ||
| Site: &c.Site, | ||
| }, | ||
| // Set 'Events' to the only possible value, 'flag' | ||
| Events: alert.GetDefaultEvents(), | ||
| } | ||
| if c.Description.WasSet { | ||
| input.Description = &c.Description.Value | ||
| } | ||
|
|
||
| fc, ok := c.Globals.APIClient.(*fastly.Client) | ||
| if !ok { | ||
| return errors.New("failed to convert interface to a fastly client") | ||
| } | ||
|
|
||
| data, err := datadog.Create(context.TODO(), fc, input) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if ok, err := c.WriteJSON(out, data); ok { | ||
| return err | ||
| } | ||
|
|
||
| text.Success(out, "Created a '%s' alert '%s' (workspace-id: %s)", data.Type, data.ID, c.WorkspaceID.Value) | ||
| return nil | ||
| } | ||
Oops, something went wrong.
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.