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: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

### Enhancements:
- feat(commands/ngwaf/workspaces): add support for update operation for NGWAF workspaces ([#1578](https://github.com/fastly/cli/pull/1578))
- feat(commands/ngwaf/lists): add support for CRUD operations for NGWAF Lists ([#1582](https://github.com/fastly/cli/pull/1582))
- 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))
- feat(commands/ngwaf/workspaces/alerts): add support for operations for NGWAF alerts ([#1589](https://github.com/fastly/cli/pull/1589))
- feat(commands/ngwaf/customsignals): add support for CRUD operations for NGWAF Custom Signals ([#1592](https://github.com/fastly/cli/pull/1592))

### Bug fixes:
Expand Down
4 changes: 4 additions & 0 deletions pkg/argparser/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ var (
FlagJSONName = "json"
// FlagJSONDesc is the flag description.
FlagJSONDesc = "Render output as JSON"
// FlagNGWAFAlertID is the alert ID.
FlagNGWAFAlertID = "alert-id"
// FlagNGWAFAlertIDDesc is the alert ID flag description.
FlagNGWAFAlertIDDesc = "Alphanumeric string identifying the alert"
// FlagNGWAFWorkspaceID is the workspace ID.
FlagNGWAFWorkspaceID = "workspace-id"
// FlagNGWAFWorkspaceIDDesc is the workspace ID flag description.
Expand Down
111 changes: 111 additions & 0 deletions pkg/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ import (
"github.com/fastly/cli/pkg/commands/ngwaf/stringlist"
"github.com/fastly/cli/pkg/commands/ngwaf/wildcardlist"
"github.com/fastly/cli/pkg/commands/ngwaf/workspace"
"github.com/fastly/cli/pkg/commands/ngwaf/workspace/alert"
workspaceAlertDatadog "github.com/fastly/cli/pkg/commands/ngwaf/workspace/alert/datadog"
workspaceAlertJira "github.com/fastly/cli/pkg/commands/ngwaf/workspace/alert/jira"
workspaceAlertMailinglist "github.com/fastly/cli/pkg/commands/ngwaf/workspace/alert/mailinglist"
workspaceAlertMicrosoftteams "github.com/fastly/cli/pkg/commands/ngwaf/workspace/alert/microsoftteams"
workspaceAlertOpsgenie "github.com/fastly/cli/pkg/commands/ngwaf/workspace/alert/opsgenie"
workspaceAlertPagerduty "github.com/fastly/cli/pkg/commands/ngwaf/workspace/alert/pagerduty"
workspaceAlertSlack "github.com/fastly/cli/pkg/commands/ngwaf/workspace/alert/slack"
workspaceAlertWebhook "github.com/fastly/cli/pkg/commands/ngwaf/workspace/alert/webhook"
wscountrylist "github.com/fastly/cli/pkg/commands/ngwaf/workspace/countrylist"
wscustomsignal "github.com/fastly/cli/pkg/commands/ngwaf/workspace/customsignal"
wsiplist "github.com/fastly/cli/pkg/commands/ngwaf/workspace/iplist"
Expand Down Expand Up @@ -498,6 +507,57 @@ func Define( // nolint:revive // function-length
ngwafVirtualpatchList := virtualpatch.NewListCommand(ngwafVirtualpatchRoot.CmdClause, data)
ngwafVirtualpatchUpdate := virtualpatch.NewUpdateCommand(ngwafVirtualpatchRoot.CmdClause, data)
ngwafVirtualpatchRetrieve := virtualpatch.NewRetrieveCommand(ngwafVirtualpatchRoot.CmdClause, data)
ngwafWorkspaceAlertRoot := alert.NewRootCommand(ngwafWorkspaceRoot.CmdClause, data)
ngwafWorkspaceAlertDatadogRoot := workspaceAlertDatadog.NewRootCommand(ngwafWorkspaceAlertRoot.CmdClause, data)
ngwafWorkspaceAlertDatadogCreate := workspaceAlertDatadog.NewCreateCommand(ngwafWorkspaceAlertDatadogRoot.CmdClause, data)
ngwafWorkspaceAlertDatadogDelete := workspaceAlertDatadog.NewDeleteCommand(ngwafWorkspaceAlertDatadogRoot.CmdClause, data)
ngwafWorkspaceAlertDatadogGet := workspaceAlertDatadog.NewGetCommand(ngwafWorkspaceAlertDatadogRoot.CmdClause, data)
ngwafWorkspaceAlertDatadogList := workspaceAlertDatadog.NewListCommand(ngwafWorkspaceAlertDatadogRoot.CmdClause, data)
ngwafWorkspaceAlertDatadogUpdate := workspaceAlertDatadog.NewUpdateCommand(ngwafWorkspaceAlertDatadogRoot.CmdClause, data)
ngwafWorkspaceAlertJiraRoot := workspaceAlertJira.NewRootCommand(ngwafWorkspaceAlertRoot.CmdClause, data)
ngwafWorkspaceAlertJiraCreate := workspaceAlertJira.NewCreateCommand(ngwafWorkspaceAlertJiraRoot.CmdClause, data)
ngwafWorkspaceAlertJiraDelete := workspaceAlertJira.NewDeleteCommand(ngwafWorkspaceAlertJiraRoot.CmdClause, data)
ngwafWorkspaceAlertJiraGet := workspaceAlertJira.NewGetCommand(ngwafWorkspaceAlertJiraRoot.CmdClause, data)
ngwafWorkspaceAlertJiraList := workspaceAlertJira.NewListCommand(ngwafWorkspaceAlertJiraRoot.CmdClause, data)
ngwafWorkspaceAlertJiraUpdate := workspaceAlertJira.NewUpdateCommand(ngwafWorkspaceAlertJiraRoot.CmdClause, data)
ngwafWorkspaceAlertMailinglistRoot := workspaceAlertMailinglist.NewRootCommand(ngwafWorkspaceAlertRoot.CmdClause, data)
ngwafWorkspaceAlertMailinglistCreate := workspaceAlertMailinglist.NewCreateCommand(ngwafWorkspaceAlertMailinglistRoot.CmdClause, data)
ngwafWorkspaceAlertMailinglistDelete := workspaceAlertMailinglist.NewDeleteCommand(ngwafWorkspaceAlertMailinglistRoot.CmdClause, data)
ngwafWorkspaceAlertMailinglistGet := workspaceAlertMailinglist.NewGetCommand(ngwafWorkspaceAlertMailinglistRoot.CmdClause, data)
ngwafWorkspaceAlertMailinglistList := workspaceAlertMailinglist.NewListCommand(ngwafWorkspaceAlertMailinglistRoot.CmdClause, data)
ngwafWorkspaceAlertMailinglistUpdate := workspaceAlertMailinglist.NewUpdateCommand(ngwafWorkspaceAlertMailinglistRoot.CmdClause, data)
ngwafWorkspaceAlertMicrosoftteamsRoot := workspaceAlertMicrosoftteams.NewRootCommand(ngwafWorkspaceAlertRoot.CmdClause, data)
ngwafWorkspaceAlertMicrosoftteamsCreate := workspaceAlertMicrosoftteams.NewCreateCommand(ngwafWorkspaceAlertMicrosoftteamsRoot.CmdClause, data)
ngwafWorkspaceAlertMicrosoftteamsDelete := workspaceAlertMicrosoftteams.NewDeleteCommand(ngwafWorkspaceAlertMicrosoftteamsRoot.CmdClause, data)
ngwafWorkspaceAlertMicrosoftteamsGet := workspaceAlertMicrosoftteams.NewGetCommand(ngwafWorkspaceAlertMicrosoftteamsRoot.CmdClause, data)
ngwafWorkspaceAlertMicrosoftteamsList := workspaceAlertMicrosoftteams.NewListCommand(ngwafWorkspaceAlertMicrosoftteamsRoot.CmdClause, data)
ngwafWorkspaceAlertMicrosoftteamsUpdate := workspaceAlertMicrosoftteams.NewUpdateCommand(ngwafWorkspaceAlertMicrosoftteamsRoot.CmdClause, data)
ngwafWorkspaceAlertOpsgenieRoot := workspaceAlertOpsgenie.NewRootCommand(ngwafWorkspaceAlertRoot.CmdClause, data)
ngwafWorkspaceAlertOpsgenieCreate := workspaceAlertOpsgenie.NewCreateCommand(ngwafWorkspaceAlertOpsgenieRoot.CmdClause, data)
ngwafWorkspaceAlertOpsgenieDelete := workspaceAlertOpsgenie.NewDeleteCommand(ngwafWorkspaceAlertOpsgenieRoot.CmdClause, data)
ngwafWorkspaceAlertOpsgenieGet := workspaceAlertOpsgenie.NewGetCommand(ngwafWorkspaceAlertOpsgenieRoot.CmdClause, data)
ngwafWorkspaceAlertOpsgenieList := workspaceAlertOpsgenie.NewListCommand(ngwafWorkspaceAlertOpsgenieRoot.CmdClause, data)
ngwafWorkspaceAlertOpsgenieUpdate := workspaceAlertOpsgenie.NewUpdateCommand(ngwafWorkspaceAlertOpsgenieRoot.CmdClause, data)
ngwafWorkspaceAlertPagerdutyRoot := workspaceAlertPagerduty.NewRootCommand(ngwafWorkspaceAlertRoot.CmdClause, data)
ngwafWorkspaceAlertPagerdutyCreate := workspaceAlertPagerduty.NewCreateCommand(ngwafWorkspaceAlertPagerdutyRoot.CmdClause, data)
ngwafWorkspaceAlertPagerdutyDelete := workspaceAlertPagerduty.NewDeleteCommand(ngwafWorkspaceAlertPagerdutyRoot.CmdClause, data)
ngwafWorkspaceAlertPagerdutyGet := workspaceAlertPagerduty.NewGetCommand(ngwafWorkspaceAlertPagerdutyRoot.CmdClause, data)
ngwafWorkspaceAlertPagerdutyList := workspaceAlertPagerduty.NewListCommand(ngwafWorkspaceAlertPagerdutyRoot.CmdClause, data)
ngwafWorkspaceAlertPagerdutyUpdate := workspaceAlertPagerduty.NewUpdateCommand(ngwafWorkspaceAlertPagerdutyRoot.CmdClause, data)
ngwafWorkspaceAlertSlackRoot := workspaceAlertSlack.NewRootCommand(ngwafWorkspaceAlertRoot.CmdClause, data)
ngwafWorkspaceAlertSlackCreate := workspaceAlertSlack.NewCreateCommand(ngwafWorkspaceAlertSlackRoot.CmdClause, data)
ngwafWorkspaceAlertSlackDelete := workspaceAlertSlack.NewDeleteCommand(ngwafWorkspaceAlertSlackRoot.CmdClause, data)
ngwafWorkspaceAlertSlackGet := workspaceAlertSlack.NewGetCommand(ngwafWorkspaceAlertSlackRoot.CmdClause, data)
ngwafWorkspaceAlertSlackList := workspaceAlertSlack.NewListCommand(ngwafWorkspaceAlertSlackRoot.CmdClause, data)
ngwafWorkspaceAlertSlackUpdate := workspaceAlertSlack.NewUpdateCommand(ngwafWorkspaceAlertSlackRoot.CmdClause, data)
ngwafWorkspaceAlertWebhookRoot := workspaceAlertWebhook.NewRootCommand(ngwafWorkspaceAlertRoot.CmdClause, data)
ngwafWorkspaceAlertWebhookCreate := workspaceAlertWebhook.NewCreateCommand(ngwafWorkspaceAlertWebhookRoot.CmdClause, data)
ngwafWorkspaceAlertWebhookDelete := workspaceAlertWebhook.NewDeleteCommand(ngwafWorkspaceAlertWebhookRoot.CmdClause, data)
ngwafWorkspaceAlertWebhookGet := workspaceAlertWebhook.NewGetCommand(ngwafWorkspaceAlertWebhookRoot.CmdClause, data)
ngwafWorkspaceAlertWebhookGetSigningKey := workspaceAlertWebhook.NewGetSigningKeyCommand(ngwafWorkspaceAlertWebhookRoot.CmdClause, data)
ngwafWorkspaceAlertWebhookList := workspaceAlertWebhook.NewListCommand(ngwafWorkspaceAlertWebhookRoot.CmdClause, data)
ngwafWorkspaceAlertWebhookRotateSigningKey := workspaceAlertWebhook.NewRotateSigningKeyCommand(ngwafWorkspaceAlertWebhookRoot.CmdClause, data)
ngwafWorkspaceAlertWebhookUpdate := workspaceAlertWebhook.NewUpdateCommand(ngwafWorkspaceAlertWebhookRoot.CmdClause, data)
objectStorageRoot := objectstorage.NewRootCommand(app, data)
objectStorageAccesskeysRoot := accesskeys.NewRootCommand(objectStorageRoot.CmdClause, data)
objectStorageAccesskeysCreate := accesskeys.NewCreateCommand(objectStorageAccesskeysRoot.CmdClause, data)
Expand Down Expand Up @@ -998,6 +1058,57 @@ func Define( // nolint:revive // function-length
ngwafVirtualpatchRetrieve,
ngwafVirtualpatchRoot,
ngwafVirtualpatchUpdate,
ngwafWorkspaceAlertRoot,
ngwafWorkspaceAlertDatadogRoot,
ngwafWorkspaceAlertDatadogCreate,
ngwafWorkspaceAlertDatadogDelete,
ngwafWorkspaceAlertDatadogGet,
ngwafWorkspaceAlertDatadogList,
ngwafWorkspaceAlertDatadogUpdate,
ngwafWorkspaceAlertJiraRoot,
ngwafWorkspaceAlertJiraCreate,
ngwafWorkspaceAlertJiraDelete,
ngwafWorkspaceAlertJiraGet,
ngwafWorkspaceAlertJiraList,
ngwafWorkspaceAlertJiraUpdate,
ngwafWorkspaceAlertMailinglistRoot,
ngwafWorkspaceAlertMailinglistCreate,
ngwafWorkspaceAlertMailinglistDelete,
ngwafWorkspaceAlertMailinglistGet,
ngwafWorkspaceAlertMailinglistList,
ngwafWorkspaceAlertMailinglistUpdate,
ngwafWorkspaceAlertMicrosoftteamsRoot,
ngwafWorkspaceAlertMicrosoftteamsCreate,
ngwafWorkspaceAlertMicrosoftteamsDelete,
ngwafWorkspaceAlertMicrosoftteamsGet,
ngwafWorkspaceAlertMicrosoftteamsList,
ngwafWorkspaceAlertMicrosoftteamsUpdate,
ngwafWorkspaceAlertOpsgenieRoot,
ngwafWorkspaceAlertOpsgenieCreate,
ngwafWorkspaceAlertOpsgenieDelete,
ngwafWorkspaceAlertOpsgenieGet,
ngwafWorkspaceAlertOpsgenieList,
ngwafWorkspaceAlertOpsgenieUpdate,
ngwafWorkspaceAlertPagerdutyRoot,
ngwafWorkspaceAlertPagerdutyCreate,
ngwafWorkspaceAlertPagerdutyDelete,
ngwafWorkspaceAlertPagerdutyGet,
ngwafWorkspaceAlertPagerdutyList,
ngwafWorkspaceAlertPagerdutyUpdate,
ngwafWorkspaceAlertSlackRoot,
ngwafWorkspaceAlertSlackCreate,
ngwafWorkspaceAlertSlackDelete,
ngwafWorkspaceAlertSlackGet,
ngwafWorkspaceAlertSlackList,
ngwafWorkspaceAlertSlackUpdate,
ngwafWorkspaceAlertWebhookRoot,
ngwafWorkspaceAlertWebhookCreate,
ngwafWorkspaceAlertWebhookDelete,
ngwafWorkspaceAlertWebhookGet,
ngwafWorkspaceAlertWebhookGetSigningKey,
ngwafWorkspaceAlertWebhookList,
ngwafWorkspaceAlertWebhookRotateSigningKey,
ngwafWorkspaceAlertWebhookUpdate,
ngwafWorkspaceRoot,
ngwafWorkspaceCreate,
ngwafWorkspaceDelete,
Expand Down
98 changes: 98 additions & 0 deletions pkg/commands/ngwaf/workspace/alert/datadog/create.go
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,
})
Comment thread
rcaril marked this conversation as resolved.
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
}
Loading
Loading