AUTH-2729 added log file and level to cmd flags to match config file settings
This commit is contained in:
parent
2f70b05c64
commit
f8638839c0
|
@ -44,6 +44,17 @@ func StartForwarder(forwarder config.Forwarder, shutdown <-chan struct{}, logger
|
||||||
// (which you can put Access in front of)
|
// (which you can put Access in front of)
|
||||||
func ssh(c *cli.Context) error {
|
func ssh(c *cli.Context) error {
|
||||||
logDirectory, logLevel := config.FindLogSettings()
|
logDirectory, logLevel := config.FindLogSettings()
|
||||||
|
|
||||||
|
flagLogDirectory := c.String(sshLogDirectoryFlag)
|
||||||
|
if flagLogDirectory != "" {
|
||||||
|
logDirectory = flagLogDirectory
|
||||||
|
}
|
||||||
|
|
||||||
|
flagLogLevel := c.String(sshLogLevelFlag)
|
||||||
|
if flagLogLevel != "" {
|
||||||
|
logLevel = flagLogLevel
|
||||||
|
}
|
||||||
|
|
||||||
logger, err := logger.New(logger.DefaultFile(logDirectory), logger.LogLevelString(logLevel))
|
logger, err := logger.New(logger.DefaultFile(logDirectory), logger.LogLevelString(logLevel))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error setting up logger")
|
return errors.Wrap(err, "error setting up logger")
|
||||||
|
|
|
@ -25,14 +25,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
sshHostnameFlag = "hostname"
|
sshHostnameFlag = "hostname"
|
||||||
sshDestinationFlag = "destination"
|
sshDestinationFlag = "destination"
|
||||||
sshURLFlag = "url"
|
sshURLFlag = "url"
|
||||||
sshHeaderFlag = "header"
|
sshHeaderFlag = "header"
|
||||||
sshTokenIDFlag = "service-token-id"
|
sshTokenIDFlag = "service-token-id"
|
||||||
sshTokenSecretFlag = "service-token-secret"
|
sshTokenSecretFlag = "service-token-secret"
|
||||||
sshGenCertFlag = "short-lived-cert"
|
sshGenCertFlag = "short-lived-cert"
|
||||||
sshConfigTemplate = `
|
sshLogDirectoryFlag = "log-directory"
|
||||||
|
sshLogLevelFlag = "log-level"
|
||||||
|
sshConfigTemplate = `
|
||||||
Add to your {{.Home}}/.ssh/config:
|
Add to your {{.Home}}/.ssh/config:
|
||||||
|
|
||||||
Host {{.Hostname}}
|
Host {{.Hostname}}
|
||||||
|
@ -154,6 +156,16 @@ func Commands() []*cli.Command {
|
||||||
Aliases: []string{"secret"},
|
Aliases: []string{"secret"},
|
||||||
Usage: "specify an Access service token secret you wish to use.",
|
Usage: "specify an Access service token secret you wish to use.",
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: sshLogDirectoryFlag,
|
||||||
|
Aliases: []string{"logfile"}, //added to match the tunnel side
|
||||||
|
Usage: "Save application log to this directory for reporting issues.",
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: sshLogLevelFlag,
|
||||||
|
Aliases: []string{"loglevel"}, //added to match the tunnel side
|
||||||
|
Usage: "Application logging level {fatal, error, info, debug}. ",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -90,6 +90,8 @@ const (
|
||||||
// bastionFlag is to enable bastion, or jump host, operation
|
// bastionFlag is to enable bastion, or jump host, operation
|
||||||
bastionFlag = "bastion"
|
bastionFlag = "bastion"
|
||||||
|
|
||||||
|
logDirectoryFlag = "log-directory"
|
||||||
|
|
||||||
debugLevelWarning = "At debug level, request URL, method, protocol, content legnth and header will be logged. " +
|
debugLevelWarning = "At debug level, request URL, method, protocol, content legnth and header will be logged. " +
|
||||||
"Response status, content length and header will also be logged in debug level."
|
"Response status, content length and header will also be logged in debug level."
|
||||||
)
|
)
|
||||||
|
@ -213,7 +215,7 @@ func Init(v string, s, g chan struct{}) {
|
||||||
|
|
||||||
func createLogger(c *cli.Context, isTransport bool) (logger.Service, error) {
|
func createLogger(c *cli.Context, isTransport bool) (logger.Service, error) {
|
||||||
loggerOpts := []logger.Option{}
|
loggerOpts := []logger.Option{}
|
||||||
logPath := c.String("logfile")
|
logPath := c.String(logDirectoryFlag)
|
||||||
if logPath != "" {
|
if logPath != "" {
|
||||||
loggerOpts = append(loggerOpts, logger.DefaultFile(logPath))
|
loggerOpts = append(loggerOpts, logger.DefaultFile(logPath))
|
||||||
}
|
}
|
||||||
|
@ -828,8 +830,9 @@ func tunnelFlags(shouldHide bool) []cli.Flag {
|
||||||
Hidden: shouldHide,
|
Hidden: shouldHide,
|
||||||
}),
|
}),
|
||||||
altsrc.NewStringFlag(&cli.StringFlag{
|
altsrc.NewStringFlag(&cli.StringFlag{
|
||||||
Name: "logfile",
|
Name: logDirectoryFlag,
|
||||||
Usage: "Save application log to this file for reporting issues.",
|
Aliases: []string{"logfile"}, // This flag used to be called logfile when it was a single file
|
||||||
|
Usage: "Save application log to this directory for reporting issues.",
|
||||||
EnvVars: []string{"TUNNEL_LOGFILE"},
|
EnvVars: []string{"TUNNEL_LOGFILE"},
|
||||||
Hidden: shouldHide,
|
Hidden: shouldHide,
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in New Issue