Skip to content

Commit

Permalink
Merge pull request #692 from Scalingo/feat/605/router-logs
Browse files Browse the repository at this point in the history
feat(router-logs): add command to enable/disable router-logs
  • Loading branch information
sihamais authored Nov 4, 2021
2 parents 5b11bd7 + 81583c5 commit e4c7b79
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### To be Released

* feat(router-logs): add command `router-logs` to enable/disable router logs on your application [#692](https://github.com/Scalingo/cli/pull/692)
* feat(open): add command `open` to open app on default browser [#691](https://github.com/Scalingo/cli/pull/691)
* feat(addons-info): add command `addons-info` to display information of an add-on [#689](https://github.com/Scalingo/cli/pull/689)
* feat(dashboard): add command `dashboard` to open dashboard of specified app on default browser [#686](https://github.com/Scalingo/cli/pull/686)
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ COMMANDS:
ps Display your application containers
scale, s Scale your application instantly
restart Restart processes of your app
force-https
sticky-session
force-https Enable/Disable automatic redirection of traffic to HTTPS for your application
sticky-session Enable/Disable sticky sessions for your application
router-logs Enable/Disable router logs for your application
set-canonical-domain Set a canonical domain.
unset-canonical-domain Unset a canonical domain.
db-tunnel Create an encrypted connection to access your database
Expand Down
25 changes: 24 additions & 1 deletion apps/routing_settings.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package apps

import (
"gopkg.in/errgo.v1"

"github.com/Scalingo/cli/config"
"github.com/Scalingo/cli/io"
"gopkg.in/errgo.v1"
)

func ForceHTTPS(appName string, enable bool) error {
Expand Down Expand Up @@ -48,3 +49,25 @@ func StickySession(appName string, enable bool) error {
io.Statusf("Sticky session has been %sd on %s\n", action, appName)
return nil
}

func RouterLogs(appName string, enable bool) error {
c, err := config.ScalingoClient()
if err != nil {
return errgo.Notef(err, "fail to get Scalingo client")
}

_, err = c.AppsRouterLogs(appName, enable)
if err != nil {
return errgo.Notef(err, "fail to configure router-logs feature")
}

var action string
if enable {
action = "enable"
} else {
action = "disable"
}

io.Statusf("Router logs have been %sd on %s\n", action, appName)
return nil
}
1 change: 1 addition & 0 deletions cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ var (
// Routing Settings
forceHTTPSCommand,
stickySessionCommand,
routerLogsCommand,
setCanonicalDomainCommand,
unsetCanonicalDomainCommand,

Expand Down
44 changes: 41 additions & 3 deletions cmd/routing_settings.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package cmd

import (
"github.com/urfave/cli"

"github.com/Scalingo/cli/appdetect"
"github.com/Scalingo/cli/apps"
"github.com/Scalingo/cli/cmd/autocomplete"
"github.com/urfave/cli"
)

var (
forceHTTPSCommand = cli.Command{
Name: "force-https",
Category: "App Management",
Usage: "",
Usage: "Enable/Disable automatic redirection of traffic to HTTPS for your application",
Flags: []cli.Flag{
appFlag,
cli.BoolFlag{Name: "enable, e", Usage: "Enable force HTTPS (default)"},
Expand Down Expand Up @@ -47,7 +48,7 @@ var (
stickySessionCommand = cli.Command{
Name: "sticky-session",
Category: "App Management",
Usage: "",
Usage: "Enable/Disable sticky sessions for your application",
Flags: []cli.Flag{
appFlag,
cli.BoolFlag{Name: "enable, e", Usage: "Enable sticky session (default)"},
Expand Down Expand Up @@ -79,4 +80,41 @@ var (
autocomplete.CmdFlagsAutoComplete(c, "sticky-session")
},
}

routerLogsCommand = cli.Command{
Name: "router-logs",
Category: "App Management",
Usage: "Enable/disable router logs for your application",
Flags: []cli.Flag{
appFlag,
cli.BoolFlag{Name: "enable, e", Usage: "Enable router logs"},
cli.BoolFlag{Name: "disable, d", Usage: "Disable router logs (default)"},
},
Description: `Enable/disable router logs for your application.
Example
scalingo --app my-app router-logs --enable
`,
Action: func(c *cli.Context) {
currentApp := appdetect.CurrentApp(c)
if len(c.Args()) > 1 {
cli.ShowCommandHelp(c, "router-logs")
return
}

enable := false
if c.IsSet("enable") {
enable = true
}

err := apps.RouterLogs(currentApp, enable)
if err != nil {
errorQuit(err)
}
},
BashComplete: func(c *cli.Context) {
autocomplete.CmdFlagsAutoComplete(c, "router-logs")
},
}

)
6 changes: 6 additions & 0 deletions vendor/github.com/Scalingo/go-scalingo/v4/apps.go

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

0 comments on commit e4c7b79

Please sign in to comment.