From e858fa01889c07b3870b767f7d9ad7ebadf27aa6 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 4 Nov 2021 12:58:18 +0100 Subject: [PATCH] define ocis_url as a shared option in ocis-pkg/config --- ocis-pkg/config/config.go | 5 +++-- ocis/pkg/command/proxy.go | 2 +- ocis/pkg/command/root.go | 4 ++-- proxy/pkg/command/server.go | 8 ++++++++ proxy/pkg/config/config.go | 2 ++ proxy/pkg/config/mappings.go | 2 +- 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index d5c0dc6341..a2f8b5fafc 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -83,8 +83,9 @@ type Config struct { // Mode is mostly used whenever we need to run an extension. The technical debt this introduces is in regard of // what it does. Supervised (0) loads configuration from a unified config file because of known limitations of Viper; whereas // Unsupervised (1) MUST parse config from all known sources. - Mode Mode - File string + Mode Mode + File string + OcisURL string `mapstructure:"ocis_url"` Registry string `mapstructure:"registry"` Log Log `mapstructure:"log"` diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index aaec5a56ed..29ea6b73b6 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -18,7 +18,6 @@ func ProxyCommand(cfg *config.Config) *cli.Command { Name: "proxy", Usage: "Start proxy server", Category: "Extensions", - //Flags: flagset.ServerWithConfig(cfg.Proxy), Subcommands: []*cli.Command{ command.PrintVersion(cfg.Proxy), }, @@ -33,6 +32,7 @@ func ProxyCommand(cfg *config.Config) *cli.Command { } func configureProxy(cfg *config.Config) *svcconfig.Config { + cfg.Proxy.OcisURL = cfg.OcisURL cfg.Proxy.Log.Level = cfg.Log.Level cfg.Proxy.Log.Pretty = cfg.Log.Pretty cfg.Proxy.Log.Color = cfg.Log.Color diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index c37595ff93..a004ec77a7 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -21,7 +21,7 @@ func Execute() error { Usage: "ownCloud Infinite Scale Stack", Compiled: version.Compiled(), Before: func(c *cli.Context) error { - return ParseConfig(cfg) + return ParseConfig(c, cfg) }, Authors: []*cli.Author{ { @@ -63,7 +63,7 @@ func NewLogger(cfg *config.Config) log.Logger { } // ParseConfig loads ocis configuration from known paths. -func ParseConfig(cfg *config.Config) error { +func ParseConfig(c *cli.Context, cfg *config.Config) error { conf, err := ociscfg.BindSourcesToStructs("ocis", cfg) if err != nil { return err diff --git a/proxy/pkg/command/server.go b/proxy/pkg/command/server.go index 521d2f07db..88c6667870 100644 --- a/proxy/pkg/command/server.go +++ b/proxy/pkg/command/server.go @@ -52,6 +52,14 @@ func Server(cfg *config.Config) *cli.Command { cfg.PreSignedURL.AllowedHTTPMethods = ctx.StringSlice("presignedurl-allow-method") } + // we need a starting point to compare the default config values to determine if the outcome of ParseConfig + // modified a value that should be shared just because it is present in the ocis.yaml file. + defaultConfig := config.DefaultConfig() + + if cfg.OcisURL != "" && cfg.OIDC.Issuer == defaultConfig.OIDC.Issuer { + cfg.OIDC.Issuer = cfg.OcisURL + } + if err := loadUserAgent(ctx, cfg); err != nil { return err } diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 5e9c1fb94a..9097390fc1 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -105,6 +105,8 @@ type Cache struct { // Config combines all available configuration parts. type Config struct { + OcisURL string + File string `mapstructure:"file"` Log Log `mapstructure:"log"` Debug Debug `mapstructure:"debug"` diff --git a/proxy/pkg/config/mappings.go b/proxy/pkg/config/mappings.go index a0c6467db7..c09936d542 100644 --- a/proxy/pkg/config/mappings.go +++ b/proxy/pkg/config/mappings.go @@ -123,7 +123,7 @@ func structMappings(cfg *Config) []mapping { Destination: &cfg.InsecureBackends, }, { - EnvVars: []string{"PROXY_OIDC_ISSUER", "OCIS_URL"}, // PROXY_OIDC_ISSUER takes precedence over OCIS_URL + EnvVars: []string{"PROXY_OIDC_ISSUER"}, Destination: &cfg.OIDC.Issuer, }, {