feat: add flags for bind address config options
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
parent
cdefd1f788
commit
c55d84b5d2
@ -30,13 +30,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type serveOptions struct {
|
type serveOptions struct {
|
||||||
|
// Config file path
|
||||||
config string
|
config string
|
||||||
|
|
||||||
|
// Flags
|
||||||
|
webHTTPAddr string
|
||||||
|
webHTTPSAddr string
|
||||||
|
telemetryAddr string
|
||||||
|
grpcAddr string
|
||||||
}
|
}
|
||||||
|
|
||||||
func commandServe() *cobra.Command {
|
func commandServe() *cobra.Command {
|
||||||
options := serveOptions{}
|
options := serveOptions{}
|
||||||
|
|
||||||
return &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "serve [flags] [config file]",
|
Use: "serve [flags] [config file]",
|
||||||
Short: "Launch Dex",
|
Short: "Launch Dex",
|
||||||
Example: "dex serve config.yaml",
|
Example: "dex serve config.yaml",
|
||||||
@ -50,6 +57,15 @@ func commandServe() *cobra.Command {
|
|||||||
return runServe(options)
|
return runServe(options)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flags := cmd.Flags()
|
||||||
|
|
||||||
|
flags.StringVar(&options.webHTTPAddr, "web-http-addr", "", "Web HTTP address")
|
||||||
|
flags.StringVar(&options.webHTTPSAddr, "web-https-addr", "", "Web HTTPS address")
|
||||||
|
flags.StringVar(&options.telemetryAddr, "telemetry-addr", "", "Telemetry address")
|
||||||
|
flags.StringVar(&options.grpcAddr, "grpc-addr", "", "gRPC API address")
|
||||||
|
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func runServe(options serveOptions) error {
|
func runServe(options serveOptions) error {
|
||||||
@ -64,6 +80,8 @@ func runServe(options serveOptions) error {
|
|||||||
return fmt.Errorf("error parse config file %s: %v", configFile, err)
|
return fmt.Errorf("error parse config file %s: %v", configFile, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applyConfigOverrides(options, &c)
|
||||||
|
|
||||||
logger, err := newLogger(c.Logger.Level, c.Logger.Format)
|
logger, err := newLogger(c.Logger.Level, c.Logger.Format)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid config: %v", err)
|
return fmt.Errorf("invalid config: %v", err)
|
||||||
@ -383,3 +401,21 @@ func newLogger(level string, format string) (log.Logger, error) {
|
|||||||
Level: logLevel,
|
Level: logLevel,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func applyConfigOverrides(options serveOptions, config *Config) {
|
||||||
|
if options.webHTTPAddr != "" {
|
||||||
|
config.Web.HTTP = options.webHTTPAddr
|
||||||
|
}
|
||||||
|
|
||||||
|
if options.webHTTPSAddr != "" {
|
||||||
|
config.Web.HTTPS = options.webHTTPSAddr
|
||||||
|
}
|
||||||
|
|
||||||
|
if options.telemetryAddr != "" {
|
||||||
|
config.Telemetry.HTTP = options.telemetryAddr
|
||||||
|
}
|
||||||
|
|
||||||
|
if options.grpcAddr != "" {
|
||||||
|
config.GRPC.Addr = options.grpcAddr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user