-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/update-go-scalingo
- Loading branch information
Showing
18 changed files
with
991 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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,25 @@ | ||
package autocomplete | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Scalingo/cli/config" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
func NotifiersAutoComplete(c *cli.Context) error { | ||
appName := CurrentAppCompletion(c) | ||
if appName == "" { | ||
return nil | ||
} | ||
|
||
client := config.ScalingoClient() | ||
resources, err := client.NotifiersList(appName) | ||
if err == nil { | ||
for _, resource := range resources { | ||
fmt.Println(resource.GetID()) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains 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 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,25 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/Scalingo/cli/cmd/autocomplete" | ||
"github.com/Scalingo/cli/notification_platforms" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
var ( | ||
NotificationPlatformListCommand = cli.Command{ | ||
Name: "notification-platforms", | ||
Category: "Notifiers - Global", | ||
Description: "List all notification platforms you can use with a notifier.", | ||
Usage: "List all notification platforms", | ||
Action: func(c *cli.Context) { | ||
err := notification_platforms.List() | ||
if err != nil { | ||
errorQuit(err) | ||
} | ||
}, | ||
BashComplete: func(c *cli.Context) { | ||
autocomplete.CmdFlagsAutoComplete(c, "platforms-list") | ||
}, | ||
} | ||
) |
This file contains 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,250 @@ | ||
package cmd | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/Scalingo/cli/appdetect" | ||
"github.com/Scalingo/cli/cmd/autocomplete" | ||
"github.com/Scalingo/cli/notifiers" | ||
scalingo "github.com/Scalingo/go-scalingo" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
var ( | ||
NotifiersListCommand = cli.Command{ | ||
Name: "notifiers", | ||
Category: "Notifiers", | ||
Usage: "List your notifiers", | ||
Flags: []cli.Flag{appFlag}, | ||
Description: ` List all notifiers of your app: | ||
$ scalingo -a myapp notifiers | ||
# See also 'notifiers-add' and 'notifiers-remove' | ||
`, | ||
Before: AuthenticateHook, | ||
Action: func(c *cli.Context) { | ||
currentApp := appdetect.CurrentApp(c) | ||
var err error | ||
if len(c.Args()) == 0 { | ||
err = notifiers.List(currentApp) | ||
} else { | ||
cli.ShowCommandHelp(c, "notifiers") | ||
} | ||
|
||
if err != nil { | ||
errorQuit(err) | ||
} | ||
}, | ||
BashComplete: func(c *cli.Context) { | ||
autocomplete.CmdFlagsAutoComplete(c, "notifiers") | ||
}, | ||
} | ||
|
||
NotifiersDetailsCommand = cli.Command{ | ||
Name: "notifiers-details", | ||
Category: "Notifiers", | ||
Usage: "Show details of your notifiers", | ||
Flags: []cli.Flag{appFlag}, | ||
Description: ` Show details of your notifiers: | ||
$ scalingo -a myapp notifiers-details <ID> | ||
# See also 'notifiers' | ||
`, | ||
Before: AuthenticateHook, | ||
Action: func(c *cli.Context) { | ||
currentApp := appdetect.CurrentApp(c) | ||
var err error | ||
if len(c.Args()) == 1 { | ||
err = notifiers.Details(currentApp, c.Args()[0]) | ||
} else { | ||
cli.ShowCommandHelp(c, "notifiers-details") | ||
} | ||
|
||
if err != nil { | ||
errorQuit(err) | ||
} | ||
}, | ||
BashComplete: func(c *cli.Context) { | ||
autocomplete.CmdFlagsAutoComplete(c, "notifiers-details") | ||
autocomplete.NotifiersAutoComplete(c) | ||
}, | ||
} | ||
|
||
NotifiersAddCommand = cli.Command{ | ||
Name: "notifiers-add", | ||
Category: "Notifiers", | ||
Flags: []cli.Flag{ | ||
appFlag, | ||
cli.BoolFlag{Name: "enable, e", Usage: "Enable the notifier (default)"}, | ||
cli.BoolFlag{Name: "disable, d", Usage: "Disable the notifier"}, | ||
cli.StringFlag{Name: "platform, p", Value: "", Usage: "The notifier platform"}, | ||
cli.StringFlag{Name: "name, n", Value: "", Usage: "Name of the notifier"}, | ||
cli.BoolFlag{Name: "send-all-events, sa", Usage: "If true the notifier will send all events. Default: false"}, | ||
cli.StringFlag{Name: "events, ev", Value: "", Usage: "List of selected events. Default: []"}, | ||
cli.StringFlag{Name: "webhook-url, u", Value: "", Usage: "The webhook url to send notification (if applicable)"}, | ||
cli.StringFlag{Name: "phone", Value: "", Usage: "The phone number to send notifications (if applicable)"}, | ||
cli.StringFlag{Name: "email", Value: "", Usage: "The email to send notifications (if applicable)"}, | ||
}, | ||
Usage: "Add a notifier for your application", | ||
Description: `Add a notifier for your application: | ||
Examples | ||
$ scalingo -a myapp notifiers-add \ | ||
--platform slack \ | ||
--name "My notifier" \ | ||
--webhook-url "https://hooks.slack.com/services/1234" \ | ||
--events "deployment stop_app" | ||
$ scalingo -a myapp notifiers-add \ | ||
--platform webhook \ | ||
--name "My notifier" \ | ||
--webhook-url "https://custom-webhook.com" \ | ||
--send-all-events true | ||
# Use 'platforms-list' to see all available platforms | ||
# See also 'notifiers' and 'notifiers-remove' | ||
`, | ||
Before: AuthenticateHook, | ||
Action: func(c *cli.Context) { | ||
currentApp := appdetect.CurrentApp(c) | ||
|
||
if c.String("platform") == "" { | ||
cli.ShowCommandHelp(c, "notifiers-add") | ||
} | ||
|
||
var active bool | ||
if c.IsSet("disable") { | ||
active = false | ||
} else { | ||
active = true | ||
} | ||
sendAllEvents := c.Bool("send-all-events") | ||
|
||
params := scalingo.NotifierParams{ | ||
Active: &active, | ||
Name: c.String("name"), | ||
SendAllEvents: &sendAllEvents, | ||
SelectedEvents: strings.Split(c.String("events"), " "), | ||
|
||
// Type data options | ||
PhoneNumber: c.String("phone"), | ||
Email: c.String("email"), | ||
WebhookURL: c.String("webhook-url"), | ||
} | ||
|
||
err := notifiers.Provision(currentApp, c.String("platform"), params) | ||
if err != nil { | ||
errorQuit(err) | ||
} | ||
}, | ||
BashComplete: func(c *cli.Context) { | ||
autocomplete.CmdFlagsAutoComplete(c, "notifiers-add") | ||
}, | ||
} | ||
|
||
NotifiersUpdateCommand = cli.Command{ | ||
Name: "notifiers-update", | ||
Category: "Notifiers", | ||
Flags: []cli.Flag{ | ||
appFlag, | ||
cli.BoolFlag{Name: "enable, e", Usage: "Enable the notifier"}, | ||
cli.BoolFlag{Name: "disable, d", Usage: "Disable the notifier"}, | ||
cli.StringFlag{Name: "name, n", Value: "", Usage: "Name of the notifier"}, | ||
cli.BoolFlag{Name: "send-all-events, sa", Usage: "If true the notifier will send all events. Default: false"}, | ||
cli.StringFlag{Name: "events, ev", Value: "", Usage: "List of selected events. Default: []"}, | ||
cli.StringFlag{Name: "webhook-url, u", Value: "", Usage: "The webhook url to send notification (if applicable)"}, | ||
cli.StringFlag{Name: "phone", Value: "", Usage: "The phone number to send notifications (if applicable)"}, | ||
cli.StringFlag{Name: "email", Value: "", Usage: "The email to send notifications (if applicable)"}, | ||
}, | ||
Usage: "Update a notifier", | ||
Description: `Update a notifier: | ||
Examples | ||
$ scalingo -a myapp notifiers-update --disable <ID> | ||
$ scalingo -a myapp notifiers-update \ | ||
--name "My notifier" \ | ||
--webhook-url https://custom-webhook.com \ | ||
--send-all-events true \ | ||
<ID> | ||
# See also 'notifiers' and 'notifiers-remove' | ||
`, | ||
Before: AuthenticateHook, | ||
Action: func(c *cli.Context) { | ||
currentApp := appdetect.CurrentApp(c) | ||
var err error | ||
|
||
var active *bool | ||
if c.IsSet("enable") { | ||
tmpActive := true | ||
active = &tmpActive | ||
} else if c.IsSet("disable") { | ||
tmpActive := false | ||
active = &tmpActive | ||
} else { | ||
active = nil | ||
} | ||
|
||
var sendAllEvents *bool | ||
if c.IsSet("send-all-events") { | ||
tmpEvents := c.Bool("send-all-events") | ||
sendAllEvents = &tmpEvents | ||
} else { | ||
sendAllEvents = nil | ||
} | ||
|
||
params := scalingo.NotifierParams{ | ||
Active: active, | ||
Name: c.String("name"), | ||
SendAllEvents: sendAllEvents, | ||
SelectedEvents: strings.Split(c.String("events"), " "), | ||
|
||
// Type data options | ||
PhoneNumber: c.String("phone"), | ||
Email: c.String("email"), | ||
WebhookURL: c.String("webhook-url"), | ||
} | ||
if len(c.Args()) >= 1 { | ||
err = notifiers.Update(currentApp, c.Args()[0], params) | ||
} else { | ||
cli.ShowCommandHelp(c, "notifiers-update") | ||
} | ||
if err != nil { | ||
errorQuit(err) | ||
} | ||
}, | ||
BashComplete: func(c *cli.Context) { | ||
autocomplete.CmdFlagsAutoComplete(c, "notifiers-update") | ||
autocomplete.NotifiersAutoComplete(c) | ||
}, | ||
} | ||
|
||
NotifiersRemoveCommand = cli.Command{ | ||
Name: "notifiers-remove", | ||
Category: "Notifiers", | ||
Flags: []cli.Flag{appFlag}, | ||
Usage: "Remove an existing notifier from your app", | ||
Description: `Remove an existing notifier from your app: | ||
$ scalingo -a myapp notifier-remove <ID> | ||
# See also 'notifiers' and 'notifiers-add' | ||
`, | ||
Before: AuthenticateHook, | ||
Action: func(c *cli.Context) { | ||
currentApp := appdetect.CurrentApp(c) | ||
var err error | ||
if len(c.Args()) == 1 { | ||
err = notifiers.Destroy(currentApp, c.Args()[0]) | ||
} else { | ||
cli.ShowCommandHelp(c, "notifiers-remove") | ||
} | ||
if err != nil { | ||
errorQuit(err) | ||
} | ||
}, | ||
BashComplete: func(c *cli.Context) { | ||
autocomplete.CmdFlagsAutoComplete(c, "notifiers-remove") | ||
autocomplete.NotifiersAutoComplete(c) | ||
}, | ||
} | ||
) |
This file contains 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
Oops, something went wrong.