TUN-1086: fixed config option

This commit is contained in:
Austin Cherry 2018-10-05 14:58:21 -05:00
parent 71b113cad3
commit 5cd4fab9dd
2 changed files with 23 additions and 40 deletions

View File

@ -8,7 +8,6 @@ import (
"golang.org/x/crypto/ssh/terminal" "golang.org/x/crypto/ssh/terminal"
"github.com/cloudflare/cloudflared/cmd/cloudflared/access" "github.com/cloudflare/cloudflared/cmd/cloudflared/access"
"github.com/cloudflare/cloudflared/cmd/cloudflared/config"
"github.com/cloudflare/cloudflared/cmd/cloudflared/tunnel" "github.com/cloudflare/cloudflared/cmd/cloudflared/tunnel"
"github.com/cloudflare/cloudflared/cmd/cloudflared/updater" "github.com/cloudflare/cloudflared/cmd/cloudflared/updater"
"github.com/cloudflare/cloudflared/log" "github.com/cloudflare/cloudflared/log"
@ -17,7 +16,6 @@ import (
"github.com/getsentry/raven-go" "github.com/getsentry/raven-go"
"github.com/mitchellh/go-homedir" "github.com/mitchellh/go-homedir"
"gopkg.in/urfave/cli.v2" "gopkg.in/urfave/cli.v2"
"gopkg.in/urfave/cli.v2/altsrc"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -56,7 +54,7 @@ func main() {
and configure access control.` and configure access control.`
app.Flags = flags() app.Flags = flags()
app.Action = action(Version, shutdownC, graceShutdownC) app.Action = action(Version, shutdownC, graceShutdownC)
app.Before = before(app.Flags) app.Before = tunnel.Before
app.Commands = commands() app.Commands = commands()
tunnel.Init(Version, shutdownC, graceShutdownC) // we need this to support the tunnel sub command... tunnel.Init(Version, shutdownC, graceShutdownC) // we need this to support the tunnel sub command...
@ -105,24 +103,6 @@ func action(version string, shutdownC, graceShutdownC chan struct{}) cli.ActionF
} }
} }
func before(flags []cli.Flag) cli.BeforeFunc {
return func(context *cli.Context) error {
inputSource, err := config.FindInputSourceContext(context)
if err != nil {
logger.WithError(err).Infof("Cannot load configuration from %s", context.String("config"))
return err
} else if inputSource != nil {
err := altsrc.ApplyInputSourceValues(context, inputSource, flags)
if err != nil {
logger.WithError(err).Infof("Cannot apply configuration from %s", context.String("config"))
return err
}
logger.Infof("Applied configuration from %s", context.String("config"))
}
return nil
}
}
func userHomeDir() (string, error) { func userHomeDir() (string, error) {
// This returns the home dir of the executing user using OS-specific method // This returns the home dir of the executing user using OS-specific method
// for discovering the home dir. It's not recommended to call this function // for discovering the home dir. It's not recommended to call this function

View File

@ -121,25 +121,8 @@ func Commands() []*cli.Command {
} }
return err return err
}, },
Before: func(c *cli.Context) error { Before: Before,
if c.String("config") == "" { Usage: "SQL Gateway is an SQL over HTTP reverse proxy",
logger.Warnf("Cannot determine default configuration path. No file %v in %v", config.DefaultConfigFiles, config.DefaultConfigDirs)
}
inputSource, err := config.FindInputSourceContext(c)
if err != nil {
logger.WithError(err).Infof("Cannot load configuration from %s", c.String("config"))
return err
} else if inputSource != nil {
err := altsrc.ApplyInputSourceValues(c, inputSource, c.App.Flags)
if err != nil {
logger.WithError(err).Infof("Cannot apply configuration from %s", c.String("config"))
return err
}
logger.Infof("Applied configuration from %s", c.String("config"))
}
return nil
},
Usage: "SQL Gateway is an SQL over HTTP reverse proxy",
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.BoolFlag{ &cli.BoolFlag{
Name: "db", Name: "db",
@ -166,6 +149,7 @@ func Commands() []*cli.Command {
cmds = append(cmds, &cli.Command{ cmds = append(cmds, &cli.Command{
Name: "tunnel", Name: "tunnel",
Action: tunnel, Action: tunnel,
Before: Before,
Category: "Tunnel", Category: "Tunnel",
Usage: "Make a locally-running web service accessible over the internet using Argo Tunnel.", Usage: "Make a locally-running web service accessible over the internet using Argo Tunnel.",
ArgsUsage: "[origin-url]", ArgsUsage: "[origin-url]",
@ -338,6 +322,25 @@ func StartServer(c *cli.Context, version string, shutdownC, graceShutdownC chan
return waitToShutdown(&wg, errC, shutdownC, graceShutdownC, c.Duration("grace-period")) return waitToShutdown(&wg, errC, shutdownC, graceShutdownC, c.Duration("grace-period"))
} }
func Before(c *cli.Context) error {
if c.String("config") == "" {
logger.Warnf("Cannot determine default configuration path. No file %v in %v", config.DefaultConfigFiles, config.DefaultConfigDirs)
}
inputSource, err := config.FindInputSourceContext(c)
if err != nil {
logger.WithError(err).Infof("Cannot load configuration from %s", c.String("config"))
return err
} else if inputSource != nil {
err := altsrc.ApplyInputSourceValues(c, inputSource, c.App.Flags)
if err != nil {
logger.WithError(err).Infof("Cannot apply configuration from %s", c.String("config"))
return err
}
logger.Infof("Applied configuration from %s", c.String("config"))
}
return nil
}
func waitToShutdown(wg *sync.WaitGroup, func waitToShutdown(wg *sync.WaitGroup,
errC chan error, errC chan error,
shutdownC, graceShutdownC chan struct{}, shutdownC, graceShutdownC chan struct{},