From c720d18de8403a752ea6b87e1dd6c5a3aad2d5bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Mon, 2 May 2022 14:19:08 +0000 Subject: [PATCH] update config to init changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- extensions/search/pkg/command/server.go | 6 +++++- extensions/search/pkg/config/config.go | 7 +++---- extensions/search/pkg/config/defaults/defaultconfig.go | 7 ++++--- extensions/search/pkg/config/parser/parse.go | 10 +++++++++- extensions/search/pkg/config/reva.go | 5 ----- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/extensions/search/pkg/command/server.go b/extensions/search/pkg/command/server.go index 2c8ae18d58..2582213c49 100644 --- a/extensions/search/pkg/command/server.go +++ b/extensions/search/pkg/command/server.go @@ -23,7 +23,11 @@ func Server(cfg *config.Config) *cli.Command { Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) + err := parser.ParseConfig(cfg) + if err != nil { + fmt.Printf("%v", err) + } + return err }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/search/pkg/config/config.go b/extensions/search/pkg/config/config.go index ae90144ec7..7c7ac33ff6 100644 --- a/extensions/search/pkg/config/config.go +++ b/extensions/search/pkg/config/config.go @@ -18,10 +18,9 @@ type Config struct { GRPC GRPC `ocisConfig:"grpc"` - Datapath string `yaml:"data_path" env:"SEARCH_DATA_PATH"` - Reva Reva `ocisConfig:"reva"` - TokenManager TokenManager `ocisConfig:"token_manager"` - Events Events `yaml:"events"` + Datapath string `yaml:"data_path" env:"SEARCH_DATA_PATH"` + Reva Reva `ocisConfig:"reva"` + Events Events `yaml:"events"` MachineAuthAPIKey string `yaml:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;SEARCH_MACHINE_AUTH_API_KEY"` diff --git a/extensions/search/pkg/config/defaults/defaultconfig.go b/extensions/search/pkg/config/defaults/defaultconfig.go index abd40aa92b..c3c40a7fea 100644 --- a/extensions/search/pkg/config/defaults/defaultconfig.go +++ b/extensions/search/pkg/config/defaults/defaultconfig.go @@ -32,9 +32,6 @@ func DefaultConfig() *config.Config { Reva: config.Reva{ Address: "127.0.0.1:9142", }, - TokenManager: config.TokenManager{ - JWTSecret: "Pive-Fumkiu4", - }, Events: config.Events{ Endpoint: "127.0.0.1:9233", Cluster: "ocis-cluster", @@ -67,6 +64,10 @@ func EnsureDefaults(cfg *config.Config) { } else if cfg.Tracing == nil { cfg.Tracing = &config.Tracing{} } + + if cfg.MachineAuthAPIKey == "" && cfg.Commons != nil && cfg.Commons.MachineAuthAPIKey != "" { + cfg.MachineAuthAPIKey = cfg.Commons.MachineAuthAPIKey + } } func Sanitize(cfg *config.Config) { diff --git a/extensions/search/pkg/config/parser/parse.go b/extensions/search/pkg/config/parser/parse.go index b764382e91..9183f5be88 100644 --- a/extensions/search/pkg/config/parser/parse.go +++ b/extensions/search/pkg/config/parser/parse.go @@ -6,11 +6,12 @@ import ( "github.com/owncloud/ocis/extensions/search/pkg/config" "github.com/owncloud/ocis/extensions/search/pkg/config/defaults" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" ) -// ParseConfig loads accounts configuration from known paths. +// ParseConfig loads configuration from known paths. func ParseConfig(cfg *config.Config) error { _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) if err != nil { @@ -29,5 +30,12 @@ func ParseConfig(cfg *config.Config) error { defaults.Sanitize(cfg) + return Validate(cfg) +} + +func Validate(cfg *config.Config) error { + if cfg.MachineAuthAPIKey == "" { + return shared.MissingMachineAuthApiKeyError(cfg.Service.Name) + } return nil } diff --git a/extensions/search/pkg/config/reva.go b/extensions/search/pkg/config/reva.go index 68bfd2f629..2b299a0f65 100644 --- a/extensions/search/pkg/config/reva.go +++ b/extensions/search/pkg/config/reva.go @@ -4,8 +4,3 @@ package config type Reva struct { Address string `ocisConfig:"address" env:"REVA_GATEWAY"` } - -// TokenManager is the config for using the reva token manager -type TokenManager struct { - JWTSecret string `ocisConfig:"jwt_secret" env:"OCIS_JWT_SECRET;SEARCH_JWT_SECRET"` -}