Skip to content

Commit

Permalink
Merge pull request #561 from Scalingo/feature/552/add_log_drains_add_cmd
Browse files Browse the repository at this point in the history
Log drains add command
  • Loading branch information
EtienneM authored May 20, 2020
2 parents 81e8df9 + 6db77af commit 363c29e
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* Add log drains list command
[#560](https://github.com/Scalingo/cli/pull/560)
[go-scalingo #163](https://github.com/Scalingo/go-scalingo/pull/163)
* Add log drains add command
[#561](https://github.com/Scalingo/cli/pull/561)
[go-scalingo #164](https://github.com/Scalingo/go-scalingo/pull/164)

### 1.17.0

Expand Down
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ COMMANDS:
App Management:
destroy Destroy an app /!\
rename Rename an application
apps-info Display the application information
logs, l Get the logs of your applications
logs-archives, la Get the logs archives of your applications
run, r Run any command for your app
Expand Down Expand Up @@ -162,15 +163,14 @@ COMMANDS:
logout Logout from Scalingo
regions List available regions
config Configure the CLI
signup Create your Scalingo account
self Get the logged in profile
whoami Get the logged in profile
Integration Link:
integration-link Show repo link linked with your app
integration-link-create Create a repo link between your scm integration and your app
integration-link-update Update the repo link linked with your app
integration-link-delete Delete repo link linked with your app
integration-link Show integration link of your app
integration-link-create Link your Scalingo application to an integration
integration-link-update Update the integration link parameters
integration-link-delete Delete the link between your Scalingo application and the integration
integration-link-manual-deploy Trigger a manual deployment of the specified branch
integration-link-manual-review-app Trigger a review app creation of the pull/merge request ID specified
Expand All @@ -180,6 +180,10 @@ COMMANDS:
integrations-delete Unlink your Scalingo account and your account on a tool such as github.com
integrations-import-keys Import public SSH keys from integration account
Log drains:
log-drains-add Add a log drain to an application
log-drains List the log drains of an application
Notifiers:
notifiers List your notifiers
notifiers-details Show details of your notifiers
Expand All @@ -196,12 +200,14 @@ COMMANDS:
keys-remove Remove a public SSH key
Region migrations:
migrations-create Migrate an app to another region
migrations List all migrations linked to an app
migrations-follow Follow a running migration
migration-create Start migrating an app to another region
migration-run Run a specific migration step
migration-abort Abort a migration
migrations List all migrations linked to an app
migration-follow Follow a running migration
Review Apps:
review-apps See review apps of parent application
review-apps Show review apps of the parent application
Runtime Stacks:
stacks List the available runtime stacks
Expand Down
1 change: 1 addition & 0 deletions cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ var (
migrationFollowCommand,

// Log drains
logDrainsAddCommand,
logDrainsListCommand,

gitSetup,
Expand Down
49 changes: 48 additions & 1 deletion cmd/log_drains.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/Scalingo/cli/appdetect"
"github.com/Scalingo/cli/cmd/autocomplete"
"github.com/Scalingo/cli/log_drains"
"github.com/Scalingo/go-scalingo"
"github.com/urfave/cli"
)

Expand All @@ -15,7 +16,9 @@ var (
Usage: "List the log drains of an application",
Description: `List all the log drains of an application:
$ scalingo --app my-app log-drains`,
$ scalingo --app my-app log-drains
# See also commands 'log-drains-add'`,

Action: func(c *cli.Context) {
currentApp := appdetect.CurrentApp(c)
Expand All @@ -33,4 +36,48 @@ var (
autocomplete.CmdFlagsAutoComplete(c, "log-drains")
},
}

logDrainsAddCommand = cli.Command{
Name: "log-drains-add",
Category: "Log drains",
Usage: "Add a log drain to an application",
Flags: []cli.Flag{appFlag,
cli.StringFlag{Name: "type", Usage: "Communication protocol", Required: true},
cli.StringFlag{Name: "url", Usage: "URL of self hosted ELK"},
cli.StringFlag{Name: "host", Usage: "Host of logs management service"},
cli.StringFlag{Name: "port", Usage: "Port of logs management service"},
cli.StringFlag{Name: "token", Usage: "Used by certain vendor for authentication"},
cli.StringFlag{Name: "drain-region", Usage: "Used by certain logs management service to identify the region of their servers"},
},
Description: `Add a log drain to an application:
Examples:
$ scalingo --app my-app log-drains-add --type datadog --token 123456789abcdef --drain-region eu-west-2
$ scalingo --app my-app log-drains-add --type ovh-graylog --token 123456789abcdef --host tag3.logs.ovh.com
$ scalingo --app my-app log-drains-add --type logentries --token 123456789abcdef
$ scalingo --app my-app log-drains-add --type papertrail --host logs2.papertrailapp.com --port 12345
$ scalingo --app my-app log-drains-add --type syslog --host custom.logstash.com --port 12345
$ scalingo --app my-app log-drains-add --type elk --url https://my-user:[email protected]
# See also commands 'log-drains'`,

Action: func(c *cli.Context) {
currentApp := appdetect.CurrentApp(c)

err := log_drains.Add(currentApp, scalingo.LogDrainAddParams{
Type: c.String("type"),
URL: c.String("url"),
Host: c.String("host"),
Port: c.String("port"),
Token: c.String("token"),
DrainRegion: c.String("drain-region"),
})
if err != nil {
errorQuit(err)
}
},
BashComplete: func(c *cli.Context) {
autocomplete.CmdFlagsAutoComplete(c, "log-drains")
},
}
)
23 changes: 23 additions & 0 deletions log_drains/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package log_drains

import (
"github.com/Scalingo/cli/config"
"github.com/Scalingo/cli/io"
"github.com/Scalingo/go-scalingo"
"gopkg.in/errgo.v1"
)

func Add(app string, params scalingo.LogDrainAddParams) error {
c, err := config.ScalingoClient()
if err != nil {
return errgo.Notef(err, "fail to get Scalingo client to add a log drain")
}

d, err := c.LogDrainAdd(app, params)
if err != nil {
return errgo.Notef(err, "fail to add drain to the application")
}

io.Status("Log drain", d.Drain.URL, "has been added to the application", app)
return nil
}
44 changes: 42 additions & 2 deletions vendor/github.com/Scalingo/go-scalingo/log_drains.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/Scalingo/go-scalingo/version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 363c29e

Please sign in to comment.