1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-06-15 00:15:00 +02:00

Replace options loading with viper

This commit is contained in:
Joel Speed
2020-04-13 11:34:25 +01:00
parent 8749cbb424
commit c5be09ca48
9 changed files with 27 additions and 147 deletions

24
main.go
View File

@ -12,9 +12,9 @@ import (
"syscall"
"time"
"github.com/BurntSushi/toml"
options "github.com/mreiferson/go-options"
"github.com/oauth2-proxy/oauth2-proxy/pkg/apis/options"
"github.com/oauth2-proxy/oauth2-proxy/pkg/logger"
"github.com/spf13/pflag"
)
func main() {
@ -149,7 +149,10 @@ func main() {
flagSet.String("user-id-claim", "email", "which claim contains the user ID")
flagSet.Parse(os.Args[1:])
pflagSet := pflag.NewFlagSet("oauth2-proxy", pflag.ExitOnError)
pflagSet.AddGoFlagSet(flagSet)
pflagSet.Parse(os.Args[1:])
if *showVersion {
fmt.Printf("oauth2-proxy %s (built with %s)\n", VERSION, runtime.Version())
@ -157,18 +160,13 @@ func main() {
}
opts := NewOptions()
cfg := make(EnvOptions)
if *config != "" {
_, err := toml.DecodeFile(*config, &cfg)
if err != nil {
logger.Fatalf("ERROR: failed to load config file %s - %s", *config, err)
}
err := options.Load(*config, pflagSet, opts)
if err != nil {
logger.Printf("ERROR: Failed to load config: %v", err)
os.Exit(1)
}
cfg.LoadEnvForStruct(opts)
options.Resolve(opts, flagSet, cfg)
err := opts.Validate()
err = opts.Validate()
if err != nil {
logger.Printf("%s", err)
os.Exit(1)