From 138ed2c026896b762d4d95ca2173781946aab654 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Thu, 7 Apr 2022 10:13:16 +0200 Subject: [PATCH 01/17] improve systemd docs and simplify config file arithmetics --- .make/release.mk | 1 + docs/ocis/config.md | 11 ++++---- docs/ocis/deployment/systemd.md | 20 +++++++++----- ocis-pkg/config/defaults/paths.go | 43 ++++++++++++++++++++++++++---- ocis-pkg/config/helpers.go | 34 ++++++++++------------- ocis/docker/Dockerfile.linux.amd64 | 7 +++-- ocis/docker/Dockerfile.linux.arm | 7 +++-- ocis/docker/Dockerfile.linux.arm64 | 7 +++-- 8 files changed, 88 insertions(+), 42 deletions(-) diff --git a/.make/release.mk b/.make/release.mk index 30c3ac08fda..d4dd4286d0d 100644 --- a/.make/release.mk +++ b/.make/release.mk @@ -11,6 +11,7 @@ release-dirs: # docker specific packaging flags DOCKER_LDFLAGS += -X "$(OCIS_REPO)/ocis-pkg/config/defaults.BaseDataPathType=path" -X "$(OCIS_REPO)/ocis-pkg/config/defaults.BaseDataPathValue=/var/lib/ocis" +DOCKER_LDFLAGS += -X "$(OCIS_REPO)/ocis-pkg/config/defaults.BaseConfigPathType=path" -X "$(OCIS_REPO)/ocis-pkg/config/defaults.BaseConfigPathValue=/etc/ocis" release-linux-docker-amd64: release-dirs GOOS=linux \ diff --git a/docs/ocis/config.md b/docs/ocis/config.md index f4ab30cf60b..6f7ecc75e5c 100644 --- a/docs/ocis/config.md +++ b/docs/ocis/config.md @@ -39,15 +39,16 @@ Let's explore the various flows with examples and workflows. Let's explore with examples this approach. -#### Expected loading locations: +#### Expected loading locations -- `$HOME/.ocis/config/` -- `/etc/ocis/` -- `.config/` +- docker images: `/etc/ocis/` +- binary releases: `$HOME/.ocis/config/` followed by the extension name. When configuring the proxy, a valid full path that will get loaded is `$HOME/.ocis/config/proxy.yaml`. -#### Only config files +You can always set another directory as config path in the environment variable `OCIS_CONFIG_DIR`. + +#### Only config files The following config files are present in the default loading locations: diff --git a/docs/ocis/deployment/systemd.md b/docs/ocis/deployment/systemd.md index 8ac0a1d8f27..0eac23aa652 100644 --- a/docs/ocis/deployment/systemd.md +++ b/docs/ocis/deployment/systemd.md @@ -10,17 +10,18 @@ geekdocFilePath: systemd.md {{< toc >}} ## Install the oCIS binary + Download the oCIS binary of your preferred version and for your CPU architecture and operating system from [download.owncloud.com](https://download.owncloud.com/ocis/ocis). Rename the downloaded binary to `ocis` and move it to `/usr/bin/`. As a next step, you need to mark it as executable with `chmod +x /usr/bin/ocis`. When you now run `ocis help` on your command line, you should see the available options for the oCIS command. - ## Systemd service definition Create the Systemd service definition for oCIS in the file `/etc/systemd/system/ocis.service` with following content: -``` + +```systemd [Unit] Description=OCIS server @@ -36,19 +37,23 @@ Restart=always WantedBy=multi-user.target ``` -For reasons of simplicity we are using the root user and group to run oCIS which is not recommended. Please use a non-root user in production environments and modify the oCIS service definition accordingly. - +{{< hint danger >}} +For reasons of simplicity we are using the root user and group to run oCIS, which is not recommended. Please use only privileged users in production environments and modify the oCIS service definition accordingly. +{{< /hint >}} In the service definition we referenced `/etc/ocis/ocis.env` as our file containing environment variables for the oCIS process. In order to create the file we need first to create the folder `/etc/ocis/` and than we can add the actual `/etc/ocis/ocis.env` with following content: -``` -OCIS_URL=https://some-hostname-or-ip:9200 +```bash +OCIS_URL=https://some-host-or-ip:9200 PROXY_HTTP_ADDR=0.0.0.0:9200 OCIS_INSECURE=false OCIS_LOG_LEVEL=error +OCIS_BASE_DATA_PATH=/var/lib/ocis +OCIS_CONFIG_DIR=/etc/ocis + GLAUTH_LDAPS_CERT=/etc/ocis/ldap/ldaps.crt GLAUTH_LDAPS_KEY=/etc/ocis/ldap/ldaps.key IDP_TRANSPORT_TLS_CERT=/etc/ocis/idp/server.crt @@ -59,6 +64,9 @@ PROXY_TRANSPORT_TLS_KEY=/etc/ocis/proxy/server.key Please change your `OCIS_URL` in order to reflect your actual deployment. If you are using self signed certificates you need to set `OCIS_INSECURE=true` in `/etc/ocis/ocis.env`. +In the `ocis.env` file we configured oCIS to store all data in `/var/lib/ocis`, so you need to create that folder and make it writeable for the ocis user (see user / group in the systemd file). + +If you add oCIS config files in `/etc/ocis`, you need to ensure that the directory and config file is readable by the oCIS process's user / group. ## Starting the oCIS service diff --git a/ocis-pkg/config/defaults/paths.go b/ocis-pkg/config/defaults/paths.go index 9980daedaa6..9cecd90fa05 100644 --- a/ocis-pkg/config/defaults/paths.go +++ b/ocis-pkg/config/defaults/paths.go @@ -10,16 +10,16 @@ const () var ( // switch between modes - BaseDataPathType = "homedir" - // don't read from this, only write + BaseDataPathType = "homedir" // or "path" + // default data path BaseDataPathValue = "/var/lib/ocis" ) func BaseDataPath() string { // It is not nice to have hidden / secrete configuration options - // But how can we update the base path for every occurence with a flageset option? - // This is currenlty not possible and needs a new configuration concept + // But how can we update the base path for every occurrence with a flagset option? + // This is currently not possible and needs a new configuration concept p := os.Getenv("OCIS_BASE_DATA_PATH") if p != "" { return p @@ -32,7 +32,7 @@ func BaseDataPath() string { // fallback to BaseDatapathValue for users without home return BaseDataPathValue } - return path.Join(dir, ".ocis") + return path.Join(dir, ".ocis", "config") case "path": return BaseDataPathValue default: @@ -40,3 +40,36 @@ func BaseDataPath() string { return "" } } + +var ( + // switch between modes + BaseConfigPathType = "homedir" // or "path" + // default config path + BaseConfigPathValue = "/etc/ocis" +) + +func BaseConfigPath() string { + + // It is not nice to have hidden / secrete configuration options + // But how can we update the base path for every occurrence with a flagset option? + // This is currently not possible and needs a new configuration concept + p := os.Getenv("OCIS_CONFIG_DIR") + if p != "" { + return p + } + + switch BaseConfigPathType { + case "homedir": + dir, err := os.UserHomeDir() + if err != nil { + // fallback to BaseConfigPathValue for users without home + return BaseConfigPathValue + } + return path.Join(dir, ".ocis") + case "path": + return BaseConfigPathValue + default: + log.Fatalf("BaseConfigPathType %s not found", BaseConfigPathType) + return "" + } +} diff --git a/ocis-pkg/config/helpers.go b/ocis-pkg/config/helpers.go index 6eac8984757..ee005500fb2 100644 --- a/ocis-pkg/config/helpers.go +++ b/ocis-pkg/config/helpers.go @@ -8,37 +8,31 @@ import ( gofig "github.com/gookit/config/v2" gooyaml "github.com/gookit/config/v2/yaml" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) var ( - defaultLocations = []string{ - filepath.Join(os.Getenv("HOME"), "/.ocis/config/"), - "/etc/ocis/", - ".config/", - } - // supportedExtensions is determined by gookit/config. + // we only support the official yaml file ending (http://yaml.org/faq.html) to + // mitigate the loading order problem. + // It would raise this question: does yaml win over yml or vice versa!? supportedExtensions = []string{ "yaml", - "yml", } + // decoderConfigTagname sets the tag name to be used from the config structs + // currently we only support "yaml" because we only support config loading + // from yaml files and the yaml parser has no simple way to set a custom tag name to use + decoderConfigTagName = "yaml" ) -// DefaultConfigSources returns a slice with matched expected config files. It sugars coat several aspects of config file -// management by assuming there are 3 default locations a config file could be. +// configSources returns a slice with matched expected config files. // It uses globbing to match a config file by name, and retrieve any supported extension supported by our drivers. // It sanitizes the output depending on the list of drivers provided. -func DefaultConfigSources(filename string, drivers []string) []string { +func configSources(filename string, drivers []string) []string { var sources []string - locations := []string{} - if v := os.Getenv("OCIS_CONFIG_DIR"); v != "" { - locations = append(locations, v) - // only use the configured config dir - locations = append(locations, os.Getenv("OCIS_CONFIG_DIR")) - } else { - // merge config from all default locations - locations = append(locations, defaultLocations...) + locations := []string{ + defaults.BaseConfigPath(), } for i := range locations { @@ -75,10 +69,10 @@ func sanitizeExtensions(set []string, ext []string, f func(a, b string) bool) [] // BindSourcesToStructs assigns any config value from a config file / env variable to struct `dst`. Its only purpose // is to solely modify `dst`, not dealing with the config structs; and do so in a thread safe manner. func BindSourcesToStructs(extension string, dst interface{}) (*gofig.Config, error) { - sources := DefaultConfigSources(extension, supportedExtensions) + sources := configSources(extension, supportedExtensions) cnf := gofig.NewWithOptions(extension) cnf.WithOptions(func(options *gofig.Options) { - options.DecoderConfig.TagName = "yaml" + options.DecoderConfig.TagName = decoderConfigTagName }) cnf.AddDriver(gooyaml.Driver) _ = cnf.LoadFiles(sources...) diff --git a/ocis/docker/Dockerfile.linux.amd64 b/ocis/docker/Dockerfile.linux.amd64 index 6729daf58b6..8d339141362 100644 --- a/ocis/docker/Dockerfile.linux.amd64 +++ b/ocis/docker/Dockerfile.linux.amd64 @@ -26,9 +26,12 @@ RUN addgroup -g 1000 -S ocis-group && \ RUN mkdir -p /var/lib/ocis && \ chown -R ocis-user:ocis-group /var/lib/ocis && \ - chmod -R 777 /var/lib/ocis + chmod -R 777 /var/lib/ocis && \ + mkdir -p /etc/ocis && \ + chown -R ocis-user:ocis-group /etc/ocis && \ + chmod -R 777 /etc/ocis -VOLUME [ "/var/lib/ocis" ] +VOLUME [ "/var/lib/ocis", "/etc/ocis" ] WORKDIR /var/lib/ocis USER 1000 diff --git a/ocis/docker/Dockerfile.linux.arm b/ocis/docker/Dockerfile.linux.arm index 922246bb051..cb6f757b85f 100644 --- a/ocis/docker/Dockerfile.linux.arm +++ b/ocis/docker/Dockerfile.linux.arm @@ -26,9 +26,12 @@ RUN addgroup -g 1000 -S ocis-group && \ RUN mkdir -p /var/lib/ocis && \ chown -R ocis-user:ocis-group /var/lib/ocis && \ - chmod -R 777 /var/lib/ocis + chmod -R 777 /var/lib/ocis && \ + mkdir -p /etc/ocis && \ + chown -R ocis-user:ocis-group /etc/ocis && \ + chmod -R 777 /etc/ocis -VOLUME [ "/var/lib/ocis" ] +VOLUME [ "/var/lib/ocis", "/etc/ocis" ] WORKDIR /var/lib/ocis USER 1000 diff --git a/ocis/docker/Dockerfile.linux.arm64 b/ocis/docker/Dockerfile.linux.arm64 index 47ccad92636..7601ed39e74 100644 --- a/ocis/docker/Dockerfile.linux.arm64 +++ b/ocis/docker/Dockerfile.linux.arm64 @@ -26,9 +26,12 @@ RUN addgroup -g 1000 -S ocis-group && \ RUN mkdir -p /var/lib/ocis && \ chown -R ocis-user:ocis-group /var/lib/ocis && \ - chmod -R 777 /var/lib/ocis + chmod -R 777 /var/lib/ocis && \ + mkdir -p /etc/ocis && \ + chown -R ocis-user:ocis-group /etc/ocis && \ + chmod -R 777 /etc/ocis -VOLUME [ "/var/lib/ocis" ] +VOLUME [ "/var/lib/ocis", "/etc/ocis" ] WORKDIR /var/lib/ocis USER 1000 From 1311791cf73cc0ef7237329ecf194c45272893fa Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Wed, 13 Apr 2022 14:34:02 +0200 Subject: [PATCH 02/17] add --config-file flag to accounts service --- docs/helpers/configenvextractor.go | 1 + extensions/accounts/pkg/command/server.go | 10 +++ extensions/accounts/pkg/config/config.go | 3 + .../pkg/config/defaults/defaultconfig.go | 2 + extensions/idp/pkg/config/parser/parse.go | 2 +- ocis-pkg/config/helpers.go | 67 +++---------------- 6 files changed, 26 insertions(+), 59 deletions(-) diff --git a/docs/helpers/configenvextractor.go b/docs/helpers/configenvextractor.go index bde518bcc23..5f2d8efc713 100644 --- a/docs/helpers/configenvextractor.go +++ b/docs/helpers/configenvextractor.go @@ -57,6 +57,7 @@ func GenerateIntermediateCode(templatePath string, intermediateCodePath string, func RunIntermediateCode(intermediateCodePath string) { fmt.Println("Running intermediate go code for " + intermediateCodePath) os.Setenv("OCIS_BASE_DATA_PATH", "~/.ocis") + os.Setenv("OCIS_CONFIG_DIR", "~/.ocis") out, err := exec.Command("go", "run", intermediateCodePath).Output() if err != nil { log.Fatal(err) diff --git a/extensions/accounts/pkg/command/server.go b/extensions/accounts/pkg/command/server.go index cad2406868f..65924406dac 100644 --- a/extensions/accounts/pkg/command/server.go +++ b/extensions/accounts/pkg/command/server.go @@ -20,10 +20,20 @@ import ( // Server is the entry point for the server command. func Server(cfg *config.Config) *cli.Command { + configFileFlag := cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + } + return &cli.Command{ Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &configFileFlag, + }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/extensions/accounts/pkg/config/config.go b/extensions/accounts/pkg/config/config.go index 9b46d2dbf17..454f7b29cc8 100644 --- a/extensions/accounts/pkg/config/config.go +++ b/extensions/accounts/pkg/config/config.go @@ -10,6 +10,9 @@ import ( type Config struct { *shared.Commons `yaml:"-"` + ConfigFile string `yaml:"-" env:"ACCOUNTS_CONFIG_FILE" desc:"config file to be used by the accounts extension"` + ConfigFileHasBeenSet bool `yaml:"-"` + Service Service `yaml:"-"` Tracing *Tracing `yaml:"tracing"` diff --git a/extensions/accounts/pkg/config/defaults/defaultconfig.go b/extensions/accounts/pkg/config/defaults/defaultconfig.go index d44ca4aafb3..b9f94e69961 100644 --- a/extensions/accounts/pkg/config/defaults/defaultconfig.go +++ b/extensions/accounts/pkg/config/defaults/defaultconfig.go @@ -19,6 +19,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "accounts.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9182", Token: "", diff --git a/extensions/idp/pkg/config/parser/parse.go b/extensions/idp/pkg/config/parser/parse.go index 101ea85bdcc..d082e313130 100644 --- a/extensions/idp/pkg/config/parser/parse.go +++ b/extensions/idp/pkg/config/parser/parse.go @@ -12,7 +12,7 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFileHasBeenSet, cfg) if err != nil { return err } diff --git a/ocis-pkg/config/helpers.go b/ocis-pkg/config/helpers.go index ee005500fb2..693ed3a6bf1 100644 --- a/ocis-pkg/config/helpers.go +++ b/ocis-pkg/config/helpers.go @@ -1,83 +1,34 @@ package config import ( - "io/fs" - "os" - "path/filepath" - "strings" - gofig "github.com/gookit/config/v2" gooyaml "github.com/gookit/config/v2/yaml" - "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) var ( - // supportedExtensions is determined by gookit/config. - // we only support the official yaml file ending (http://yaml.org/faq.html) to - // mitigate the loading order problem. - // It would raise this question: does yaml win over yml or vice versa!? - supportedExtensions = []string{ - "yaml", - } // decoderConfigTagname sets the tag name to be used from the config structs // currently we only support "yaml" because we only support config loading // from yaml files and the yaml parser has no simple way to set a custom tag name to use decoderConfigTagName = "yaml" ) -// configSources returns a slice with matched expected config files. -// It uses globbing to match a config file by name, and retrieve any supported extension supported by our drivers. -// It sanitizes the output depending on the list of drivers provided. -func configSources(filename string, drivers []string) []string { - var sources []string - - locations := []string{ - defaults.BaseConfigPath(), - } - - for i := range locations { - dirFS := os.DirFS(locations[i]) - pattern := filename + ".*" - matched, _ := fs.Glob(dirFS, pattern) - if len(matched) > 0 { - // prepend path to results - for j := 0; j < len(matched); j++ { - matched[j] = filepath.Join(locations[i], matched[j]) - } - } - sources = append(sources, matched...) - } - - return sanitizeExtensions(sources, drivers, func(a, b string) bool { - return strings.HasSuffix(filepath.Base(a), b) - }) -} - -// sanitizeExtensions removes elements from "set" which extensions are not in "ext". -func sanitizeExtensions(set []string, ext []string, f func(a, b string) bool) []string { - var r []string - for i := 0; i < len(set); i++ { - for j := 0; j < len(ext); j++ { - if f(filepath.Base(set[i]), ext[j]) { - r = append(r, set[i]) - } - } - } - return r -} - // BindSourcesToStructs assigns any config value from a config file / env variable to struct `dst`. Its only purpose // is to solely modify `dst`, not dealing with the config structs; and do so in a thread safe manner. -func BindSourcesToStructs(extension string, dst interface{}) (*gofig.Config, error) { - sources := configSources(extension, supportedExtensions) +func BindSourcesToStructs(extension, ConfigFile string, failOnLoadErr bool, dst interface{}) (*gofig.Config, error) { + sources := []string{ConfigFile} cnf := gofig.NewWithOptions(extension) cnf.WithOptions(func(options *gofig.Options) { options.DecoderConfig.TagName = decoderConfigTagName }) cnf.AddDriver(gooyaml.Driver) - _ = cnf.LoadFiles(sources...) - err := cnf.BindStruct("", &dst) + err := cnf.LoadFiles(sources...) + if err != nil && failOnLoadErr { + // fail only if config file was explicitly set + return nil, err + } + + err = cnf.BindStruct("", &dst) if err != nil { return nil, err } From b8f71895820342571c89dc9371be52c2c18cdc3b Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 19 Apr 2022 12:43:57 +0200 Subject: [PATCH 03/17] finish accounts --- extensions/accounts/pkg/command/server.go | 18 +++++++++++++++--- extensions/accounts/pkg/config/config.go | 6 +++--- extensions/accounts/pkg/config/parser/parse.go | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/extensions/accounts/pkg/command/server.go b/extensions/accounts/pkg/command/server.go index 65924406dac..1852af55c2d 100644 --- a/extensions/accounts/pkg/command/server.go +++ b/extensions/accounts/pkg/command/server.go @@ -20,11 +20,12 @@ import ( // Server is the entry point for the server command. func Server(cfg *config.Config) *cli.Command { + configFile := "" configFileFlag := cli.StringFlag{ Name: "config-file", - Value: cfg.ConfigFile, + DefaultText: cfg.ConfigFile, Usage: "config file to be loaded by the extension", - Destination: &cfg.ConfigFile, + Destination: &configFile, } return &cli.Command{ @@ -35,7 +36,18 @@ func Server(cfg *config.Config) *cli.Command { &configFileFlag, }, Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) + + if configFile != "" { + cfg.ConfigFile = configFile + cfg.ConfigFileHasBeenSet = true + } + + err := parser.ParseConfig(cfg) + if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") + } + return err }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/accounts/pkg/config/config.go b/extensions/accounts/pkg/config/config.go index 454f7b29cc8..b2cf06b1f36 100644 --- a/extensions/accounts/pkg/config/config.go +++ b/extensions/accounts/pkg/config/config.go @@ -10,9 +10,6 @@ import ( type Config struct { *shared.Commons `yaml:"-"` - ConfigFile string `yaml:"-" env:"ACCOUNTS_CONFIG_FILE" desc:"config file to be used by the accounts extension"` - ConfigFileHasBeenSet bool `yaml:"-"` - Service Service `yaml:"-"` Tracing *Tracing `yaml:"tracing"` @@ -31,6 +28,9 @@ type Config struct { HashDifficulty int `yaml:"hash_difficulty" env:"ACCOUNTS_HASH_DIFFICULTY" desc:"The hash difficulty makes sure that validating a password takes at least a certain amount of time."` DemoUsersAndGroups bool `yaml:"demo_users_and_groups" env:"ACCOUNTS_DEMO_USERS_AND_GROUPS" desc:"If this flag is set the service will setup the demo users and groups."` + ConfigFile string `yaml:"-" env:"ACCOUNTS_CONFIG_FILE"` // config file to be used by the accounts extension + ConfigFileHasBeenSet bool `yaml:"-"` + Context context.Context `yaml:"-"` } diff --git a/extensions/accounts/pkg/config/parser/parse.go b/extensions/accounts/pkg/config/parser/parse.go index 91d47c19d8a..3eef371280b 100644 --- a/extensions/accounts/pkg/config/parser/parse.go +++ b/extensions/accounts/pkg/config/parser/parse.go @@ -12,7 +12,7 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFileHasBeenSet, cfg) if err != nil { return err } From 814ecffd42af1cd48fbe0e8412377139532332e7 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 19 Apr 2022 13:40:41 +0200 Subject: [PATCH 04/17] respect the env variable --- extensions/accounts/pkg/command/server.go | 11 ++-------- extensions/accounts/pkg/config/config.go | 3 +-- .../accounts/pkg/config/parser/parse.go | 21 +++++++++++++++---- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/extensions/accounts/pkg/command/server.go b/extensions/accounts/pkg/command/server.go index 1852af55c2d..d573745a81b 100644 --- a/extensions/accounts/pkg/command/server.go +++ b/extensions/accounts/pkg/command/server.go @@ -20,12 +20,11 @@ import ( // Server is the entry point for the server command. func Server(cfg *config.Config) *cli.Command { - configFile := "" configFileFlag := cli.StringFlag{ Name: "config-file", - DefaultText: cfg.ConfigFile, + Value: cfg.ConfigFile, Usage: "config file to be loaded by the extension", - Destination: &configFile, + Destination: &cfg.ConfigFile, } return &cli.Command{ @@ -36,12 +35,6 @@ func Server(cfg *config.Config) *cli.Command { &configFileFlag, }, Before: func(c *cli.Context) error { - - if configFile != "" { - cfg.ConfigFile = configFile - cfg.ConfigFileHasBeenSet = true - } - err := parser.ParseConfig(cfg) if err != nil { logger := logging.Configure(cfg.Service.Name, &config.Log{}) diff --git a/extensions/accounts/pkg/config/config.go b/extensions/accounts/pkg/config/config.go index b2cf06b1f36..d15aca3ba03 100644 --- a/extensions/accounts/pkg/config/config.go +++ b/extensions/accounts/pkg/config/config.go @@ -28,8 +28,7 @@ type Config struct { HashDifficulty int `yaml:"hash_difficulty" env:"ACCOUNTS_HASH_DIFFICULTY" desc:"The hash difficulty makes sure that validating a password takes at least a certain amount of time."` DemoUsersAndGroups bool `yaml:"demo_users_and_groups" env:"ACCOUNTS_DEMO_USERS_AND_GROUPS" desc:"If this flag is set the service will setup the demo users and groups."` - ConfigFile string `yaml:"-" env:"ACCOUNTS_CONFIG_FILE"` // config file to be used by the accounts extension - ConfigFileHasBeenSet bool `yaml:"-"` + ConfigFile string `yaml:"-" env:"ACCOUNTS_CONFIG_FILE" desc:"config file to be used by the accounts extension"` Context context.Context `yaml:"-"` } diff --git a/extensions/accounts/pkg/config/parser/parse.go b/extensions/accounts/pkg/config/parser/parse.go index 3eef371280b..76c84720203 100644 --- a/extensions/accounts/pkg/config/parser/parse.go +++ b/extensions/accounts/pkg/config/parser/parse.go @@ -12,13 +12,29 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFileHasBeenSet, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +42,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } From d6934ab8ebb2f7ccadfee1486ba84e188afa7b7a Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 19 Apr 2022 14:23:22 +0200 Subject: [PATCH 05/17] apply config flag to all extensions --- extensions/accounts/pkg/command/server.go | 14 +++++------- extensions/audit/pkg/command/server.go | 15 ++++++++++++- extensions/audit/pkg/config/config.go | 2 ++ .../pkg/config/defaults/defaultconfig.go | 5 +++++ extensions/audit/pkg/config/parser/parse.go | 21 ++++++++++++++---- extensions/glauth/pkg/command/server.go | 15 ++++++++++++- extensions/glauth/pkg/config/config.go | 2 ++ .../pkg/config/defaults/defaultconfig.go | 2 ++ extensions/glauth/pkg/config/parser/parse.go | 22 +++++++++++++++---- .../graph-explorer/pkg/command/server.go | 17 ++++++++++++-- .../graph-explorer/pkg/config/config.go | 2 ++ .../pkg/config/defaults/defaultconfig.go | 4 ++++ .../graph-explorer/pkg/config/parser/parse.go | 22 ++++++++++++++----- extensions/graph/pkg/command/server.go | 15 ++++++++++++- extensions/graph/pkg/config/config.go | 2 ++ .../pkg/config/defaults/defaultconfig.go | 4 ++++ extensions/graph/pkg/config/parser/parse.go | 21 ++++++++++++++---- extensions/idm/pkg/command/server.go | 15 ++++++++++++- extensions/idm/pkg/config/config.go | 4 +++- .../idm/pkg/config/defaults/defaultconfig.go | 2 ++ extensions/idm/pkg/config/parser/parse.go | 22 +++++++++++++++---- extensions/idp/pkg/command/server.go | 15 ++++++++++++- extensions/idp/pkg/config/config.go | 2 ++ .../idp/pkg/config/defaults/defaultconfig.go | 2 ++ extensions/idp/pkg/config/parser/parse.go | 21 ++++++++++++++---- extensions/nats/pkg/command/server.go | 15 ++++++++++++- extensions/nats/pkg/config/config.go | 2 ++ .../nats/pkg/config/defaults/defaultconfig.go | 2 ++ extensions/nats/pkg/config/parser/parse.go | 21 ++++++++++++++---- .../notifications/pkg/command/server.go | 15 ++++++++++++- extensions/notifications/pkg/config/config.go | 2 ++ .../pkg/config/defaults/defaultconfig.go | 9 +++++++- .../notifications/pkg/config/parser/parse.go | 21 ++++++++++++++---- extensions/ocs/pkg/command/server.go | 15 ++++++++++++- extensions/ocs/pkg/config/config.go | 2 ++ .../ocs/pkg/config/defaults/defaultconfig.go | 4 ++++ extensions/ocs/pkg/config/parser/parse.go | 21 ++++++++++++++---- extensions/proxy/pkg/command/server.go | 15 ++++++++++++- extensions/proxy/pkg/config/config.go | 2 ++ .../pkg/config/defaults/defaultconfig.go | 2 ++ extensions/proxy/pkg/config/parser/parse.go | 22 +++++++++++++++---- extensions/settings/pkg/command/server.go | 15 ++++++++++++- extensions/settings/pkg/config/config.go | 2 ++ .../pkg/config/defaults/defaultconfig.go | 2 ++ .../settings/pkg/config/parser/parse.go | 22 +++++++++++++++---- extensions/storage/pkg/command/gateway.go | 3 ++- extensions/storage/pkg/config/config.go | 2 ++ .../pkg/config/defaults/defaultconfig.go | 2 ++ extensions/store/pkg/command/server.go | 15 ++++++++++++- extensions/store/pkg/config/config.go | 2 ++ .../pkg/config/defaults/defaultconfig.go | 2 ++ extensions/store/pkg/config/parser/parse.go | 21 ++++++++++++++---- extensions/thumbnails/pkg/command/server.go | 15 ++++++++++++- extensions/thumbnails/pkg/config/config.go | 2 ++ .../pkg/config/defaults/defaultconfig.go | 2 ++ .../thumbnails/pkg/config/parser/parse.go | 22 ++++++++++++++----- extensions/web/pkg/command/server.go | 15 ++++++++++++- extensions/web/pkg/config/config.go | 2 ++ .../web/pkg/config/defaults/defaultconfig.go | 4 ++++ extensions/web/pkg/config/parser/parse.go | 21 ++++++++++++++---- extensions/webdav/pkg/command/server.go | 15 ++++++++++++- extensions/webdav/pkg/config/config.go | 2 ++ .../pkg/config/defaults/defaultconfig.go | 4 ++++ extensions/webdav/pkg/config/parser/parse.go | 21 ++++++++++++++---- ocis-pkg/config/config.go | 5 +++-- ocis-pkg/config/defaultconfig.go | 5 +++++ ocis-pkg/config/parser/parse.go | 16 ++++++++++++-- 67 files changed, 584 insertions(+), 93 deletions(-) diff --git a/extensions/accounts/pkg/command/server.go b/extensions/accounts/pkg/command/server.go index d573745a81b..c399a6a558d 100644 --- a/extensions/accounts/pkg/command/server.go +++ b/extensions/accounts/pkg/command/server.go @@ -20,19 +20,17 @@ import ( // Server is the entry point for the server command. func Server(cfg *config.Config) *cli.Command { - configFileFlag := cli.StringFlag{ - Name: "config-file", - Value: cfg.ConfigFile, - Usage: "config file to be loaded by the extension", - Destination: &cfg.ConfigFile, - } - return &cli.Command{ Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", Flags: []cli.Flag{ - &configFileFlag, + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, }, Before: func(c *cli.Context) error { err := parser.ParseConfig(cfg) diff --git a/extensions/audit/pkg/command/server.go b/extensions/audit/pkg/command/server.go index 25a031da0a9..ad2fa2f9854 100644 --- a/extensions/audit/pkg/command/server.go +++ b/extensions/audit/pkg/command/server.go @@ -21,8 +21,21 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) + err := parser.ParseConfig(cfg) + if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") + } + return err }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/audit/pkg/config/config.go b/extensions/audit/pkg/config/config.go index b14a78a752a..3d5e313c32f 100644 --- a/extensions/audit/pkg/config/config.go +++ b/extensions/audit/pkg/config/config.go @@ -18,6 +18,8 @@ type Config struct { Events Events `yaml:"events"` Auditlog Auditlog `yaml:"auditlog"` + ConfigFile string `yaml:"-" env:"AUDIT_CONFIG_FILE" desc:"config file to be used by the audit extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/audit/pkg/config/defaults/defaultconfig.go b/extensions/audit/pkg/config/defaults/defaultconfig.go index 27b94a8147d..a59e98a350c 100644 --- a/extensions/audit/pkg/config/defaults/defaultconfig.go +++ b/extensions/audit/pkg/config/defaults/defaultconfig.go @@ -1,7 +1,10 @@ package defaults import ( + "path" + "github.com/owncloud/ocis/extensions/audit/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) func FullDefaultConfig() *config.Config { @@ -15,6 +18,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "audit.yaml"), + Service: config.Service{ Name: "audit", }, diff --git a/extensions/audit/pkg/config/parser/parse.go b/extensions/audit/pkg/config/parser/parse.go index 7c9179761c0..77b8195c700 100644 --- a/extensions/audit/pkg/config/parser/parse.go +++ b/extensions/audit/pkg/config/parser/parse.go @@ -12,13 +12,29 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +42,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/glauth/pkg/command/server.go b/extensions/glauth/pkg/command/server.go index fda86d30c18..b2bdf422586 100644 --- a/extensions/glauth/pkg/command/server.go +++ b/extensions/glauth/pkg/command/server.go @@ -27,8 +27,21 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) + err := parser.ParseConfig(cfg) + if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") + } + return err }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/glauth/pkg/config/config.go b/extensions/glauth/pkg/config/config.go index aa8479989a3..b55543744b1 100644 --- a/extensions/glauth/pkg/config/config.go +++ b/extensions/glauth/pkg/config/config.go @@ -24,6 +24,8 @@ type Config struct { RoleBundleUUID string `yaml:"role_bundle_uuid" env:"GLAUTH_ROLE_BUNDLE_ID"` + ConfigFile string `yaml:"-" env:"GLAUTH_CONFIG_FILE" desc:"config file to be used by the glauth extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/glauth/pkg/config/defaults/defaultconfig.go b/extensions/glauth/pkg/config/defaults/defaultconfig.go index 4ed303cb3da..e1537835791 100644 --- a/extensions/glauth/pkg/config/defaults/defaultconfig.go +++ b/extensions/glauth/pkg/config/defaults/defaultconfig.go @@ -18,6 +18,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "glauth.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9129", }, diff --git a/extensions/glauth/pkg/config/parser/parse.go b/extensions/glauth/pkg/config/parser/parse.go index 532fb514953..de2a80586fa 100644 --- a/extensions/glauth/pkg/config/parser/parse.go +++ b/extensions/glauth/pkg/config/parser/parse.go @@ -12,12 +12,29 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { return err } defaults.EnsureDefaults(cfg) + + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -25,8 +42,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - // sanitize config - defaults.Sanitize(cfg) return nil } diff --git a/extensions/graph-explorer/pkg/command/server.go b/extensions/graph-explorer/pkg/command/server.go index 093cbe60b33..a3c9f735fde 100644 --- a/extensions/graph-explorer/pkg/command/server.go +++ b/extensions/graph-explorer/pkg/command/server.go @@ -22,8 +22,21 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", - Before: func(ctx *cli.Context) error { - return parser.ParseConfig(cfg) + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, + Before: func(c *cli.Context) error { + err := parser.ParseConfig(cfg) + if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") + } + return err }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/graph-explorer/pkg/config/config.go b/extensions/graph-explorer/pkg/config/config.go index 2bd5bd5a62b..3ce158b5ed2 100644 --- a/extensions/graph-explorer/pkg/config/config.go +++ b/extensions/graph-explorer/pkg/config/config.go @@ -20,6 +20,8 @@ type Config struct { GraphExplorer GraphExplorer `yaml:"graph_explorer"` + ConfigFile string `yaml:"-" env:"GRAPH_EXPLORER_CONFIG_FILE" desc:"config file to be used by the graph-explorer extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/graph-explorer/pkg/config/defaults/defaultconfig.go b/extensions/graph-explorer/pkg/config/defaults/defaultconfig.go index a343da50af6..6048ebeb640 100644 --- a/extensions/graph-explorer/pkg/config/defaults/defaultconfig.go +++ b/extensions/graph-explorer/pkg/config/defaults/defaultconfig.go @@ -1,9 +1,11 @@ package defaults import ( + "path" "strings" "github.com/owncloud/ocis/extensions/graph-explorer/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) func FullDefaultConfig() *config.Config { @@ -17,6 +19,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "graph-explorer.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9136", Token: "", diff --git a/extensions/graph-explorer/pkg/config/parser/parse.go b/extensions/graph-explorer/pkg/config/parser/parse.go index 499fbb8f369..4a219cc2847 100644 --- a/extensions/graph-explorer/pkg/config/parser/parse.go +++ b/extensions/graph-explorer/pkg/config/parser/parse.go @@ -12,13 +12,29 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,9 +42,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - // sanitize config - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/graph/pkg/command/server.go b/extensions/graph/pkg/command/server.go index c7e3e317a36..57a64f17099 100644 --- a/extensions/graph/pkg/command/server.go +++ b/extensions/graph/pkg/command/server.go @@ -22,8 +22,21 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) + err := parser.ParseConfig(cfg) + if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") + } + return err }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/graph/pkg/config/config.go b/extensions/graph/pkg/config/config.go index 4d11d73f93e..41f4a26f040 100644 --- a/extensions/graph/pkg/config/config.go +++ b/extensions/graph/pkg/config/config.go @@ -25,6 +25,8 @@ type Config struct { Identity Identity `yaml:"identity"` Events Events `yaml:"events"` + ConfigFile string `yaml:"-" env:"GRAPH_CONFIG_FILE" desc:"config file to be used by the graph extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/graph/pkg/config/defaults/defaultconfig.go b/extensions/graph/pkg/config/defaults/defaultconfig.go index 49cd9916b57..88ab37f9c6b 100644 --- a/extensions/graph/pkg/config/defaults/defaultconfig.go +++ b/extensions/graph/pkg/config/defaults/defaultconfig.go @@ -1,13 +1,17 @@ package defaults import ( + "path" "strings" "github.com/owncloud/ocis/extensions/graph/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "graph.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9124", Token: "", diff --git a/extensions/graph/pkg/config/parser/parse.go b/extensions/graph/pkg/config/parser/parse.go index cf4612cc881..f22a70aeff8 100644 --- a/extensions/graph/pkg/config/parser/parse.go +++ b/extensions/graph/pkg/config/parser/parse.go @@ -12,13 +12,29 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +42,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/idm/pkg/command/server.go b/extensions/idm/pkg/command/server.go index c63b0f2af70..8a67dd4ea77 100644 --- a/extensions/idm/pkg/command/server.go +++ b/extensions/idm/pkg/command/server.go @@ -28,8 +28,21 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) + err := parser.ParseConfig(cfg) + if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") + } + return err }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/idm/pkg/config/config.go b/extensions/idm/pkg/config/config.go index 2706fe673fd..3e41b671151 100644 --- a/extensions/idm/pkg/config/config.go +++ b/extensions/idm/pkg/config/config.go @@ -17,10 +17,12 @@ type Config struct { Debug Debug `yaml:"debug"` IDM Settings `yaml:"idm"` - CreateDemoUsers bool `yaml:"create_demo_users" env:"IDM_CREATE_DEMO_USERS;ACCOUNTS_DEMO_USERS_AND_GROUPS" desc:"Flag to enabe/disable the creation of the demo users"` + CreateDemoUsers bool `yaml:"create_demo_users" env:"IDM_CREATE_DEMO_USERS;ACCOUNTS_DEMO_USERS_AND_GROUPS" desc:"Flag to enable/disable the creation of the demo users"` ServiceUserPasswords ServiceUserPasswords `yaml:"service_user_passwords"` + ConfigFile string `yaml:"-" env:"IDM_CONFIG_FILE" desc:"config file to be used by the IDM extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/idm/pkg/config/defaults/defaultconfig.go b/extensions/idm/pkg/config/defaults/defaultconfig.go index 983db3c0718..b3cf1179529 100644 --- a/extensions/idm/pkg/config/defaults/defaultconfig.go +++ b/extensions/idm/pkg/config/defaults/defaultconfig.go @@ -18,6 +18,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "idm.yaml"), + Service: config.Service{ Name: "idm", }, diff --git a/extensions/idm/pkg/config/parser/parse.go b/extensions/idm/pkg/config/parser/parse.go index 0998543ad05..4d22908937d 100644 --- a/extensions/idm/pkg/config/parser/parse.go +++ b/extensions/idm/pkg/config/parser/parse.go @@ -12,12 +12,29 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { return err } defaults.EnsureDefaults(cfg) + + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -25,8 +42,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/idp/pkg/command/server.go b/extensions/idp/pkg/command/server.go index c541245d014..862207cb671 100644 --- a/extensions/idp/pkg/command/server.go +++ b/extensions/idp/pkg/command/server.go @@ -22,8 +22,21 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) + err := parser.ParseConfig(cfg) + if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") + } + return err }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/idp/pkg/config/config.go b/extensions/idp/pkg/config/config.go index 83bd84554d0..321bf2cbb4b 100644 --- a/extensions/idp/pkg/config/config.go +++ b/extensions/idp/pkg/config/config.go @@ -22,6 +22,8 @@ type Config struct { IDP Settings `yaml:"idp"` Ldap Ldap `yaml:"ldap"` + ConfigFile string `yaml:"-" env:"IDP_CONFIG_FILE" desc:"config file to be used by the IDP extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/idp/pkg/config/defaults/defaultconfig.go b/extensions/idp/pkg/config/defaults/defaultconfig.go index 2be18b92a46..490af6d86a2 100644 --- a/extensions/idp/pkg/config/defaults/defaultconfig.go +++ b/extensions/idp/pkg/config/defaults/defaultconfig.go @@ -19,6 +19,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "idp1.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9134", }, diff --git a/extensions/idp/pkg/config/parser/parse.go b/extensions/idp/pkg/config/parser/parse.go index d082e313130..97524f71c24 100644 --- a/extensions/idp/pkg/config/parser/parse.go +++ b/extensions/idp/pkg/config/parser/parse.go @@ -12,13 +12,29 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFileHasBeenSet, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +42,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/nats/pkg/command/server.go b/extensions/nats/pkg/command/server.go index 79f3f7f4434..ac47883abb5 100644 --- a/extensions/nats/pkg/command/server.go +++ b/extensions/nats/pkg/command/server.go @@ -19,8 +19,21 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) + err := parser.ParseConfig(cfg) + if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") + } + return err }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/nats/pkg/config/config.go b/extensions/nats/pkg/config/config.go index 3d1c279443b..da5bf190afe 100644 --- a/extensions/nats/pkg/config/config.go +++ b/extensions/nats/pkg/config/config.go @@ -17,6 +17,8 @@ type Config struct { Nats Nats `ociConfig:"nats"` + ConfigFile string `yaml:"-" env:"NATS_CONFIG_FILE" desc:"config file to be used by the NATS extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/nats/pkg/config/defaults/defaultconfig.go b/extensions/nats/pkg/config/defaults/defaultconfig.go index f9435ff4df2..88cc04af545 100644 --- a/extensions/nats/pkg/config/defaults/defaultconfig.go +++ b/extensions/nats/pkg/config/defaults/defaultconfig.go @@ -21,6 +21,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "nats.yaml"), + Service: config.Service{ Name: "nats", }, diff --git a/extensions/nats/pkg/config/parser/parse.go b/extensions/nats/pkg/config/parser/parse.go index 2a427a3bd91..ae95dc8fed2 100644 --- a/extensions/nats/pkg/config/parser/parse.go +++ b/extensions/nats/pkg/config/parser/parse.go @@ -12,13 +12,29 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +42,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/notifications/pkg/command/server.go b/extensions/notifications/pkg/command/server.go index ad7eda613cf..8a729687639 100644 --- a/extensions/notifications/pkg/command/server.go +++ b/extensions/notifications/pkg/command/server.go @@ -20,8 +20,21 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) + err := parser.ParseConfig(cfg) + if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") + } + return err }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/notifications/pkg/config/config.go b/extensions/notifications/pkg/config/config.go index 7cc1838523a..1e56e38b3c2 100644 --- a/extensions/notifications/pkg/config/config.go +++ b/extensions/notifications/pkg/config/config.go @@ -17,6 +17,8 @@ type Config struct { Notifications Notifications `yaml:"notifications"` + ConfigFile string `yaml:"-" env:"NOTIFICATIONS_CONFIG_FILE" desc:"config file to be used by the notifications extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/notifications/pkg/config/defaults/defaultconfig.go b/extensions/notifications/pkg/config/defaults/defaultconfig.go index 19c3cc2df8e..fb82f2c8152 100644 --- a/extensions/notifications/pkg/config/defaults/defaultconfig.go +++ b/extensions/notifications/pkg/config/defaults/defaultconfig.go @@ -1,6 +1,11 @@ package defaults -import "github.com/owncloud/ocis/extensions/notifications/pkg/config" +import ( + "path" + + "github.com/owncloud/ocis/extensions/notifications/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) func FullDefaultConfig() *config.Config { cfg := DefaultConfig() @@ -16,6 +21,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "notifications.yaml"), + Service: config.Service{ Name: "notifications", }, diff --git a/extensions/notifications/pkg/config/parser/parse.go b/extensions/notifications/pkg/config/parser/parse.go index 2a4876a33c5..2bf5b1f0e07 100644 --- a/extensions/notifications/pkg/config/parser/parse.go +++ b/extensions/notifications/pkg/config/parser/parse.go @@ -12,13 +12,29 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +42,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/ocs/pkg/command/server.go b/extensions/ocs/pkg/command/server.go index 0b88c99728e..75bd14056bf 100644 --- a/extensions/ocs/pkg/command/server.go +++ b/extensions/ocs/pkg/command/server.go @@ -23,8 +23,21 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) + err := parser.ParseConfig(cfg) + if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") + } + return err }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/ocs/pkg/config/config.go b/extensions/ocs/pkg/config/config.go index 52d7e954248..c393339bdd9 100644 --- a/extensions/ocs/pkg/config/config.go +++ b/extensions/ocs/pkg/config/config.go @@ -27,6 +27,8 @@ type Config struct { StorageUsersDriver string `yaml:"storage_users_driver" env:"STORAGE_USERS_DRIVER;OCS_STORAGE_USERS_DRIVER"` MachineAuthAPIKey string `yaml:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;OCS_MACHINE_AUTH_API_KEY"` + ConfigFile string `yaml:"-" env:"OCS_CONFIG_FILE" desc:"config file to be used by the ocs extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/ocs/pkg/config/defaults/defaultconfig.go b/extensions/ocs/pkg/config/defaults/defaultconfig.go index 90edea71eb4..f72f4e5b328 100644 --- a/extensions/ocs/pkg/config/defaults/defaultconfig.go +++ b/extensions/ocs/pkg/config/defaults/defaultconfig.go @@ -1,9 +1,11 @@ package defaults import ( + "path" "strings" "github.com/owncloud/ocis/extensions/ocs/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) func FullDefaultConfig() *config.Config { @@ -17,6 +19,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "ocs.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9114", Token: "", diff --git a/extensions/ocs/pkg/config/parser/parse.go b/extensions/ocs/pkg/config/parser/parse.go index b9c312ca3d3..58cf4b00040 100644 --- a/extensions/ocs/pkg/config/parser/parse.go +++ b/extensions/ocs/pkg/config/parser/parse.go @@ -12,13 +12,29 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +42,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/proxy/pkg/command/server.go b/extensions/proxy/pkg/command/server.go index 83322463998..4768797e997 100644 --- a/extensions/proxy/pkg/command/server.go +++ b/extensions/proxy/pkg/command/server.go @@ -42,8 +42,21 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) + err := parser.ParseConfig(cfg) + if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") + } + return err }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/proxy/pkg/config/config.go b/extensions/proxy/pkg/config/config.go index 7beb4d9c4cd..69b1fc632d4 100644 --- a/extensions/proxy/pkg/config/config.go +++ b/extensions/proxy/pkg/config/config.go @@ -34,6 +34,8 @@ type Config struct { InsecureBackends bool `yaml:"insecure_backends" env:"PROXY_INSECURE_BACKENDS"` AuthMiddleware AuthMiddleware `yaml:"auth_middleware"` + ConfigFile string `yaml:"-" env:"PROXY_CONFIG_FILE" desc:"config file to be used by the proxy extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/proxy/pkg/config/defaults/defaultconfig.go b/extensions/proxy/pkg/config/defaults/defaultconfig.go index 487f9f09ab3..816b00514a6 100644 --- a/extensions/proxy/pkg/config/defaults/defaultconfig.go +++ b/extensions/proxy/pkg/config/defaults/defaultconfig.go @@ -10,6 +10,8 @@ import ( func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "proxy.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9205", Token: "", diff --git a/extensions/proxy/pkg/config/parser/parse.go b/extensions/proxy/pkg/config/parser/parse.go index 2f29670f658..1d86cec829b 100644 --- a/extensions/proxy/pkg/config/parser/parse.go +++ b/extensions/proxy/pkg/config/parser/parse.go @@ -12,12 +12,29 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { return err } defaults.EnsureDefaults(cfg) + + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -25,8 +42,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/settings/pkg/command/server.go b/extensions/settings/pkg/command/server.go index 877b48b2fa3..3b3c37cdc66 100644 --- a/extensions/settings/pkg/command/server.go +++ b/extensions/settings/pkg/command/server.go @@ -23,8 +23,21 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) + err := parser.ParseConfig(cfg) + if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") + } + return err }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/settings/pkg/config/config.go b/extensions/settings/pkg/config/config.go index a60b2df1f3f..7753092476e 100644 --- a/extensions/settings/pkg/config/config.go +++ b/extensions/settings/pkg/config/config.go @@ -26,6 +26,8 @@ type Config struct { Asset Asset `yaml:"asset"` TokenManager TokenManager `yaml:"token_manager"` + ConfigFile string `yaml:"-" env:"SETTINGS_CONFIG_FILE" desc:"config file to be used by the settings extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/settings/pkg/config/defaults/defaultconfig.go b/extensions/settings/pkg/config/defaults/defaultconfig.go index 4a3a4cd3189..22ffed1dea5 100644 --- a/extensions/settings/pkg/config/defaults/defaultconfig.go +++ b/extensions/settings/pkg/config/defaults/defaultconfig.go @@ -20,6 +20,8 @@ func FullDefaultConfig() *config.Config { // DefaultConfig returns the default config func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "settings.yaml"), + Service: config.Service{ Name: "settings", }, diff --git a/extensions/settings/pkg/config/parser/parse.go b/extensions/settings/pkg/config/parser/parse.go index 3880a7ebbc4..28fa9218ec7 100644 --- a/extensions/settings/pkg/config/parser/parse.go +++ b/extensions/settings/pkg/config/parser/parse.go @@ -12,12 +12,29 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { return err } defaults.EnsureDefaults(cfg) + + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -25,8 +42,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/storage/pkg/command/gateway.go b/extensions/storage/pkg/command/gateway.go index 944d39d7501..57488aa75ac 100644 --- a/extensions/storage/pkg/command/gateway.go +++ b/extensions/storage/pkg/command/gateway.go @@ -14,6 +14,7 @@ import ( "github.com/mitchellh/mapstructure" "github.com/oklog/run" "github.com/owncloud/ocis/extensions/storage/pkg/config" + "github.com/owncloud/ocis/extensions/storage/pkg/config/defaults" "github.com/owncloud/ocis/extensions/storage/pkg/server/debug" "github.com/owncloud/ocis/extensions/storage/pkg/service/external" "github.com/owncloud/ocis/extensions/storage/pkg/tracing" @@ -415,7 +416,7 @@ func (s GatewaySutureService) Serve(ctx context.Context) error { // ParseConfig loads accounts configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config, storageExtension string) error { - conf, err := ociscfg.BindSourcesToStructs(storageExtension, cfg) + conf, err := ociscfg.BindSourcesToStructs(storageExtension, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { return err } diff --git a/extensions/storage/pkg/config/config.go b/extensions/storage/pkg/config/config.go index cfd35175e71..f21ddae9880 100644 --- a/extensions/storage/pkg/config/config.go +++ b/extensions/storage/pkg/config/config.go @@ -531,6 +531,8 @@ type Config struct { Reva Reva `yaml:"reva"` Tracing Tracing `yaml:"tracing"` Asset Asset `yaml:"asset"` + + ConfigFile string `yaml:"-" env:"STORAGE_CONFIG_FILE" desc:"config file to be used by the storage extensions"` } // New initializes a new configuration with or without defaults. diff --git a/extensions/storage/pkg/config/defaults/defaultconfig.go b/extensions/storage/pkg/config/defaults/defaultconfig.go index 95cc5c6cd2f..14a996e6552 100644 --- a/extensions/storage/pkg/config/defaults/defaultconfig.go +++ b/extensions/storage/pkg/config/defaults/defaultconfig.go @@ -29,6 +29,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "storage.yaml"), + // log is inherited Debug: config.Debug{ Addr: "127.0.0.1:9109", diff --git a/extensions/store/pkg/command/server.go b/extensions/store/pkg/command/server.go index ac14affd2cf..a4601b60b79 100644 --- a/extensions/store/pkg/command/server.go +++ b/extensions/store/pkg/command/server.go @@ -23,8 +23,21 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) + err := parser.ParseConfig(cfg) + if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") + } + return err }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/store/pkg/config/config.go b/extensions/store/pkg/config/config.go index 2c210a34a8a..2888be49731 100644 --- a/extensions/store/pkg/config/config.go +++ b/extensions/store/pkg/config/config.go @@ -20,5 +20,7 @@ type Config struct { Datapath string `yaml:"data_path" env:"STORE_DATA_PATH"` + ConfigFile string `yaml:"-" env:"STORE_CONFIG_FILE" desc:"config file to be used by the store extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/store/pkg/config/defaults/defaultconfig.go b/extensions/store/pkg/config/defaults/defaultconfig.go index 1d84c1c4746..427f87b3404 100644 --- a/extensions/store/pkg/config/defaults/defaultconfig.go +++ b/extensions/store/pkg/config/defaults/defaultconfig.go @@ -18,6 +18,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "store.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9464", Token: "", diff --git a/extensions/store/pkg/config/parser/parse.go b/extensions/store/pkg/config/parser/parse.go index 7c9f02bda38..eee1521239b 100644 --- a/extensions/store/pkg/config/parser/parse.go +++ b/extensions/store/pkg/config/parser/parse.go @@ -12,13 +12,29 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +42,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - // sanitize config - defaults.Sanitize(cfg) return nil } diff --git a/extensions/thumbnails/pkg/command/server.go b/extensions/thumbnails/pkg/command/server.go index 8bfd35a1bdb..7a82d799224 100644 --- a/extensions/thumbnails/pkg/command/server.go +++ b/extensions/thumbnails/pkg/command/server.go @@ -23,8 +23,21 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) + err := parser.ParseConfig(cfg) + if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") + } + return err }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/thumbnails/pkg/config/config.go b/extensions/thumbnails/pkg/config/config.go index 0afad535c69..56f5fcac697 100644 --- a/extensions/thumbnails/pkg/config/config.go +++ b/extensions/thumbnails/pkg/config/config.go @@ -21,6 +21,8 @@ type Config struct { Thumbnail Thumbnail `yaml:"thumbnail"` + ConfigFile string `yaml:"-" env:"THUMBNAILS_CONFIG_FILE" desc:"config file to be used by the thumbnails extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/thumbnails/pkg/config/defaults/defaultconfig.go b/extensions/thumbnails/pkg/config/defaults/defaultconfig.go index c74b85065b1..d3a124b3472 100644 --- a/extensions/thumbnails/pkg/config/defaults/defaultconfig.go +++ b/extensions/thumbnails/pkg/config/defaults/defaultconfig.go @@ -18,6 +18,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "thumbnails.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9189", Token: "", diff --git a/extensions/thumbnails/pkg/config/parser/parse.go b/extensions/thumbnails/pkg/config/parser/parse.go index 4ed73255342..b0ad25d8125 100644 --- a/extensions/thumbnails/pkg/config/parser/parse.go +++ b/extensions/thumbnails/pkg/config/parser/parse.go @@ -12,13 +12,29 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,9 +42,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - // sanitize config - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/web/pkg/command/server.go b/extensions/web/pkg/command/server.go index e62494d0729..2677a422cc8 100644 --- a/extensions/web/pkg/command/server.go +++ b/extensions/web/pkg/command/server.go @@ -23,8 +23,21 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) + err := parser.ParseConfig(cfg) + if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") + } + return err }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/web/pkg/config/config.go b/extensions/web/pkg/config/config.go index dbc7feee051..8f3c50a963d 100644 --- a/extensions/web/pkg/config/config.go +++ b/extensions/web/pkg/config/config.go @@ -22,6 +22,8 @@ type Config struct { File string `yaml:"file" env:"WEB_UI_CONFIG"` // TODO: rename this to a more self explaining string Web Web `yaml:"web"` + ConfigFile string `yaml:"-" env:"WEB_CONFIG_FILE" desc:"config file to be used by the web extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/web/pkg/config/defaults/defaultconfig.go b/extensions/web/pkg/config/defaults/defaultconfig.go index bbfad9bdfd3..8ff59503075 100644 --- a/extensions/web/pkg/config/defaults/defaultconfig.go +++ b/extensions/web/pkg/config/defaults/defaultconfig.go @@ -1,9 +1,11 @@ package defaults import ( + "path" "strings" "github.com/owncloud/ocis/extensions/web/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) func FullDefaultConfig() *config.Config { @@ -17,6 +19,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "web.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9104", Token: "", diff --git a/extensions/web/pkg/config/parser/parse.go b/extensions/web/pkg/config/parser/parse.go index d850943577a..bbb8ea6dab6 100644 --- a/extensions/web/pkg/config/parser/parse.go +++ b/extensions/web/pkg/config/parser/parse.go @@ -12,13 +12,29 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +42,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/webdav/pkg/command/server.go b/extensions/webdav/pkg/command/server.go index 291276cbbe7..a54db5698da 100644 --- a/extensions/webdav/pkg/command/server.go +++ b/extensions/webdav/pkg/command/server.go @@ -22,8 +22,21 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) + err := parser.ParseConfig(cfg) + if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") + } + return err }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/webdav/pkg/config/config.go b/extensions/webdav/pkg/config/config.go index 4efe95ebdfe..f5861d537c3 100644 --- a/extensions/webdav/pkg/config/config.go +++ b/extensions/webdav/pkg/config/config.go @@ -22,5 +22,7 @@ type Config struct { WebdavNamespace string `yaml:"webdav_namespace" env:"STORAGE_WEBDAV_NAMESPACE"` //TODO: prevent this cross config RevaGateway string `yaml:"reva_gateway" env:"REVA_GATEWAY"` + ConfigFile string `yaml:"-" env:"WEBDAV_CONFIG_FILE" desc:"config file to be used by the webdav extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/webdav/pkg/config/defaults/defaultconfig.go b/extensions/webdav/pkg/config/defaults/defaultconfig.go index 48e00e17f1a..40f1d8b20a7 100644 --- a/extensions/webdav/pkg/config/defaults/defaultconfig.go +++ b/extensions/webdav/pkg/config/defaults/defaultconfig.go @@ -1,9 +1,11 @@ package defaults import ( + "path" "strings" "github.com/owncloud/ocis/extensions/webdav/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) func FullDefaultConfig() *config.Config { @@ -17,6 +19,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "webdav.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9119", Token: "", diff --git a/extensions/webdav/pkg/config/parser/parse.go b/extensions/webdav/pkg/config/parser/parse.go index 7597255f9cc..941966fe696 100644 --- a/extensions/webdav/pkg/config/parser/parse.go +++ b/extensions/webdav/pkg/config/parser/parse.go @@ -12,13 +12,29 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +42,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index f7c71952ecb..ec0a498f3fe 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -51,8 +51,6 @@ type Config struct { Tracing shared.Tracing `yaml:"tracing"` Log *shared.Log `yaml:"log"` - Mode Mode // DEPRECATED - File string OcisURL string `yaml:"ocis_url"` Registry string `yaml:"registry"` @@ -76,4 +74,7 @@ type Config struct { Store *store.Config `yaml:"store"` Thumbnails *thumbnails.Config `yaml:"thumbnails"` WebDAV *webdav.Config `yaml:"webdav"` + + ConfigPath string `yaml:"-"` // TODO: use me ? + ConfigFile string `yaml:"-" env:"OCIS_CONFIG_FILE" desc:"config file to be used by the oCIS runtime"` } diff --git a/ocis-pkg/config/defaultconfig.go b/ocis-pkg/config/defaultconfig.go index bc94a224ce8..914f3cde3a5 100644 --- a/ocis-pkg/config/defaultconfig.go +++ b/ocis-pkg/config/defaultconfig.go @@ -1,6 +1,8 @@ package config import ( + "path" + accounts "github.com/owncloud/ocis/extensions/accounts/pkg/config/defaults" audit "github.com/owncloud/ocis/extensions/audit/pkg/config/defaults" glauth "github.com/owncloud/ocis/extensions/glauth/pkg/config/defaults" @@ -18,10 +20,13 @@ import ( thumbnails "github.com/owncloud/ocis/extensions/thumbnails/pkg/config/defaults" web "github.com/owncloud/ocis/extensions/web/pkg/config/defaults" webdav "github.com/owncloud/ocis/extensions/webdav/pkg/config/defaults" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) func DefaultConfig() *Config { return &Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "ocis.yaml"), + TokenManager: TokenManager{ JWTSecret: "Pive-Fumkiu4", }, diff --git a/ocis-pkg/config/parser/parse.go b/ocis-pkg/config/parser/parse.go index ba75a411c0d..179963a5e5e 100644 --- a/ocis-pkg/config/parser/parse.go +++ b/ocis-pkg/config/parser/parse.go @@ -10,7 +10,12 @@ import ( // ParseConfig loads ocis configuration. func ParseConfig(cfg *config.Config) error { - _, err := config.BindSourcesToStructs("ocis", cfg) + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := config.BindSourcesToStructs("ocis", cfg.ConfigFile, cfg.ConfigFile != config.DefaultConfig().ConfigFile, cfg) if err != nil { return err } @@ -27,6 +32,14 @@ func ParseConfig(cfg *config.Config) error { cfg.Log = &shared.Log{} } + if err := loadEnv(cfg); err != nil { + return err + } + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -34,6 +47,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - return nil } From 0644dc857a9e04d576ad9fef02d86cbc680314f1 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 19 Apr 2022 14:23:50 +0200 Subject: [PATCH 06/17] apply config flag to ocis server command --- ocis/pkg/command/server.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ocis/pkg/command/server.go b/ocis/pkg/command/server.go index 00b9c89da31..caa54d341a8 100644 --- a/ocis/pkg/command/server.go +++ b/ocis/pkg/command/server.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/parser" + "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/ocis/pkg/runtime" @@ -15,8 +16,23 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "start a fullstack server (runtime and all extensions in supervised mode)", Category: "fullstack", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(c *cli.Context) error { - return parser.ParseConfig(cfg) + err := parser.ParseConfig(cfg) + if err != nil { + logger := log.NewLogger( + log.Name("oCIS"), + ) + logger.Error().Err(err).Msg("couldn't find the specified config file") + } + return err }, Action: func(c *cli.Context) error { From d13afd598bc4f7a9e0e18b17514fd3b26f429dc7 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 19 Apr 2022 14:39:45 +0200 Subject: [PATCH 07/17] fix config docs paths --- docs/helpers/configenvextractor.go | 3 +-- ocis-pkg/config/config.go | 1 - ocis-pkg/config/defaults/paths.go | 4 ++-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/helpers/configenvextractor.go b/docs/helpers/configenvextractor.go index 5f2d8efc713..fe6fcb97c53 100644 --- a/docs/helpers/configenvextractor.go +++ b/docs/helpers/configenvextractor.go @@ -56,8 +56,7 @@ func GenerateIntermediateCode(templatePath string, intermediateCodePath string, func RunIntermediateCode(intermediateCodePath string) { fmt.Println("Running intermediate go code for " + intermediateCodePath) - os.Setenv("OCIS_BASE_DATA_PATH", "~/.ocis") - os.Setenv("OCIS_CONFIG_DIR", "~/.ocis") + os.Setenv("HOME", "~") // don't write the current absolute user directory for the documentation out, err := exec.Command("go", "run", intermediateCodePath).Output() if err != nil { log.Fatal(err) diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index ec0a498f3fe..6cd48fe4230 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -75,6 +75,5 @@ type Config struct { Thumbnails *thumbnails.Config `yaml:"thumbnails"` WebDAV *webdav.Config `yaml:"webdav"` - ConfigPath string `yaml:"-"` // TODO: use me ? ConfigFile string `yaml:"-" env:"OCIS_CONFIG_FILE" desc:"config file to be used by the oCIS runtime"` } diff --git a/ocis-pkg/config/defaults/paths.go b/ocis-pkg/config/defaults/paths.go index 9cecd90fa05..fbbc2a6372b 100644 --- a/ocis-pkg/config/defaults/paths.go +++ b/ocis-pkg/config/defaults/paths.go @@ -32,7 +32,7 @@ func BaseDataPath() string { // fallback to BaseDatapathValue for users without home return BaseDataPathValue } - return path.Join(dir, ".ocis", "config") + return path.Join(dir, ".ocis") case "path": return BaseDataPathValue default: @@ -65,7 +65,7 @@ func BaseConfigPath() string { // fallback to BaseConfigPathValue for users without home return BaseConfigPathValue } - return path.Join(dir, ".ocis") + return path.Join(dir, ".ocis", "config") case "path": return BaseConfigPathValue default: From 45f49aec1e06611bfb60211f1f9e768e96d45c8c Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 19 Apr 2022 15:26:08 +0200 Subject: [PATCH 08/17] fix config parsing in unsupervised mode --- ocis/pkg/command/accounts.go | 10 +++------- ocis/pkg/command/audit.go | 10 +++------- ocis/pkg/command/glauth.go | 10 +++------- ocis/pkg/command/graph.go | 10 +++------- ocis/pkg/command/graphexplorer.go | 4 ---- ocis/pkg/command/idm.go | 10 +++------- ocis/pkg/command/idp.go | 10 +++------- ocis/pkg/command/natsserver.go | 10 +++------- ocis/pkg/command/notifications.go | 10 +++------- ocis/pkg/command/ocs.go | 10 +++------- ocis/pkg/command/proxy.go | 10 +++------- ocis/pkg/command/server.go | 2 +- ocis/pkg/command/settings.go | 10 +++------- ocis/pkg/command/store.go | 10 +++------- ocis/pkg/command/thumbnails.go | 10 +++------- ocis/pkg/command/web.go | 10 +++------- ocis/pkg/command/webdav.go | 10 +++------- 17 files changed, 46 insertions(+), 110 deletions(-) diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index f8a56bfcc5b..71176908853 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -3,7 +3,6 @@ package command import ( "github.com/owncloud/ocis/extensions/accounts/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -11,12 +10,9 @@ import ( // AccountsCommand is the entrypoint for the accounts command. func AccountsCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.Accounts.Service.Name, - Usage: subcommandDescription(cfg.Accounts.Service.Name), - Category: "extensions", - Before: func(ctx *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: cfg.Accounts.Service.Name, + Usage: subcommandDescription(cfg.Accounts.Service.Name), + Category: "extensions", Subcommands: command.GetCommands(cfg.Accounts), } } diff --git a/ocis/pkg/command/audit.go b/ocis/pkg/command/audit.go index 638367a166b..91522a6b00b 100644 --- a/ocis/pkg/command/audit.go +++ b/ocis/pkg/command/audit.go @@ -3,7 +3,6 @@ package command import ( "github.com/owncloud/ocis/extensions/audit/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -11,12 +10,9 @@ import ( // AuditCommand is the entrypoint for the audit command. func AuditCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "audit", - Usage: "start audit service", - Category: "extensions", - Before: func(ctx *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: cfg.Audit.Service.Name, + Usage: subcommandDescription(cfg.Audit.Service.Name), + Category: "extensions", Subcommands: command.GetCommands(cfg.Audit), } } diff --git a/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index ad91954eb03..e56e9e33a50 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -3,7 +3,6 @@ package command import ( "github.com/owncloud/ocis/extensions/glauth/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -11,12 +10,9 @@ import ( // GLAuthCommand is the entrypoint for the glauth command. func GLAuthCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.GLAuth.Service.Name, - Usage: subcommandDescription(cfg.GLAuth.Service.Name), - Category: "extensions", - Before: func(ctx *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: cfg.GLAuth.Service.Name, + Usage: subcommandDescription(cfg.GLAuth.Service.Name), + Category: "extensions", Subcommands: command.GetCommands(cfg.GLAuth), } } diff --git a/ocis/pkg/command/graph.go b/ocis/pkg/command/graph.go index 836ad44465d..7cc90d3dacb 100644 --- a/ocis/pkg/command/graph.go +++ b/ocis/pkg/command/graph.go @@ -3,7 +3,6 @@ package command import ( "github.com/owncloud/ocis/extensions/graph/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -11,12 +10,9 @@ import ( // GraphCommand is the entrypoint for the graph command. func GraphCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.Graph.Service.Name, - Usage: subcommandDescription(cfg.Graph.Service.Name), - Category: "extensions", - Before: func(ctx *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: cfg.Graph.Service.Name, + Usage: subcommandDescription(cfg.Graph.Service.Name), + Category: "extensions", Subcommands: command.GetCommands(cfg.Graph), } } diff --git a/ocis/pkg/command/graphexplorer.go b/ocis/pkg/command/graphexplorer.go index 95be9e503ff..d9f6b198b7b 100644 --- a/ocis/pkg/command/graphexplorer.go +++ b/ocis/pkg/command/graphexplorer.go @@ -3,7 +3,6 @@ package command import ( "github.com/owncloud/ocis/extensions/graph-explorer/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -14,9 +13,6 @@ func GraphExplorerCommand(cfg *config.Config) *cli.Command { Name: cfg.GraphExplorer.Service.Name, Usage: subcommandDescription(cfg.GraphExplorer.Service.Name), Category: "extensions", - Before: func(ctx *cli.Context) error { - return parser.ParseConfig(cfg) - }, Subcommands: command.GetCommands(cfg.GraphExplorer), } } diff --git a/ocis/pkg/command/idm.go b/ocis/pkg/command/idm.go index d768b6dc58b..a4f86ac5d25 100644 --- a/ocis/pkg/command/idm.go +++ b/ocis/pkg/command/idm.go @@ -3,7 +3,6 @@ package command import ( "github.com/owncloud/ocis/extensions/idm/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -11,12 +10,9 @@ import ( // IDMCommand is the entrypoint for the idm server command. func IDMCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "idm", - Usage: "idm extension commands", - Category: "extensions", - Before: func(ctx *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: "idm", + Usage: "idm extension commands", + Category: "extensions", Subcommands: command.GetCommands(cfg.IDM), } } diff --git a/ocis/pkg/command/idp.go b/ocis/pkg/command/idp.go index 0c6828c5928..5b948907695 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -3,7 +3,6 @@ package command import ( "github.com/owncloud/ocis/extensions/idp/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -11,12 +10,9 @@ import ( // IDPCommand is the entrypoint for the idp command. func IDPCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.IDP.Service.Name, - Usage: subcommandDescription(cfg.IDP.Service.Name), - Category: "extensions", - Before: func(ctx *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: cfg.IDP.Service.Name, + Usage: subcommandDescription(cfg.IDP.Service.Name), + Category: "extensions", Subcommands: command.GetCommands(cfg.IDP), } } diff --git a/ocis/pkg/command/natsserver.go b/ocis/pkg/command/natsserver.go index 1e7f3432317..334412fd1b8 100644 --- a/ocis/pkg/command/natsserver.go +++ b/ocis/pkg/command/natsserver.go @@ -3,7 +3,6 @@ package command import ( "github.com/owncloud/ocis/extensions/nats/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -11,12 +10,9 @@ import ( // NatsServerCommand is the entrypoint for the nats server command. func NatsServerCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "nats-server", - Usage: "start nats server", - Category: "extensions", - Before: func(ctx *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: "nats-server", + Usage: "start nats server", + Category: "extensions", Subcommands: command.GetCommands(cfg.Nats), } } diff --git a/ocis/pkg/command/notifications.go b/ocis/pkg/command/notifications.go index f4108e299af..fb16c3f9ac8 100644 --- a/ocis/pkg/command/notifications.go +++ b/ocis/pkg/command/notifications.go @@ -3,7 +3,6 @@ package command import ( "github.com/owncloud/ocis/extensions/notifications/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -11,12 +10,9 @@ import ( // NatsServerCommand is the entrypoint for the nats server command. func NotificationsCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "notifications", - Usage: "start notifications service", - Category: "extensions", - Before: func(ctx *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: "notifications", + Usage: "start notifications service", + Category: "extensions", Subcommands: command.GetCommands(cfg.Notifications), } } diff --git a/ocis/pkg/command/ocs.go b/ocis/pkg/command/ocs.go index 2fae3beb95d..ee31837e995 100644 --- a/ocis/pkg/command/ocs.go +++ b/ocis/pkg/command/ocs.go @@ -3,7 +3,6 @@ package command import ( "github.com/owncloud/ocis/extensions/ocs/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -11,12 +10,9 @@ import ( // OCSCommand is the entrypoint for the ocs command. func OCSCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.OCS.Service.Name, - Usage: subcommandDescription(cfg.OCS.Service.Name), - Category: "extensions", - Before: func(ctx *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: cfg.OCS.Service.Name, + Usage: subcommandDescription(cfg.OCS.Service.Name), + Category: "extensions", Subcommands: command.GetCommands(cfg.OCS), } } diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index 429ca83e19f..c72387543af 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -3,7 +3,6 @@ package command import ( "github.com/owncloud/ocis/extensions/proxy/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -11,12 +10,9 @@ import ( // ProxyCommand is the entry point for the proxy command. func ProxyCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.Proxy.Service.Name, - Usage: subcommandDescription(cfg.Proxy.Service.Name), - Category: "extensions", - Before: func(ctx *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: cfg.Proxy.Service.Name, + Usage: subcommandDescription(cfg.Proxy.Service.Name), + Category: "extensions", Subcommands: command.GetCommands(cfg.Proxy), } } diff --git a/ocis/pkg/command/server.go b/ocis/pkg/command/server.go index caa54d341a8..e6479a731c5 100644 --- a/ocis/pkg/command/server.go +++ b/ocis/pkg/command/server.go @@ -20,7 +20,7 @@ func Server(cfg *config.Config) *cli.Command { &cli.StringFlag{ Name: "config-file", Value: cfg.ConfigFile, - Usage: "config file to be loaded by the extension", + Usage: "config file to be loaded by the oCIS runtime", Destination: &cfg.ConfigFile, }, }, diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index 32c8b43e690..b59140a6e47 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.go @@ -3,7 +3,6 @@ package command import ( "github.com/owncloud/ocis/extensions/settings/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -11,12 +10,9 @@ import ( // SettingsCommand is the entry point for the settings command. func SettingsCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.Settings.Service.Name, - Usage: subcommandDescription(cfg.Settings.Service.Name), - Category: "extensions", - Before: func(ctx *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: cfg.Settings.Service.Name, + Usage: subcommandDescription(cfg.Settings.Service.Name), + Category: "extensions", Subcommands: command.GetCommands(cfg.Settings), } } diff --git a/ocis/pkg/command/store.go b/ocis/pkg/command/store.go index e37d5ab79f1..239a8f3dcab 100644 --- a/ocis/pkg/command/store.go +++ b/ocis/pkg/command/store.go @@ -3,7 +3,6 @@ package command import ( "github.com/owncloud/ocis/extensions/store/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -12,12 +11,9 @@ import ( func StoreCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.Store.Service.Name, - Usage: subcommandDescription(cfg.Store.Service.Name), - Category: "extensions", - Before: func(ctx *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: cfg.Store.Service.Name, + Usage: subcommandDescription(cfg.Store.Service.Name), + Category: "extensions", Subcommands: command.GetCommands(cfg.Store), } } diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index 8409c98dc07..68cb54559e9 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -3,7 +3,6 @@ package command import ( "github.com/owncloud/ocis/extensions/thumbnails/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -11,12 +10,9 @@ import ( // ThumbnailsCommand is the entrypoint for the thumbnails command. func ThumbnailsCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.Thumbnails.Service.Name, - Usage: subcommandDescription(cfg.Thumbnails.Service.Name), - Category: "extensions", - Before: func(ctx *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: cfg.Thumbnails.Service.Name, + Usage: subcommandDescription(cfg.Thumbnails.Service.Name), + Category: "extensions", Subcommands: command.GetCommands(cfg.Thumbnails), } } diff --git a/ocis/pkg/command/web.go b/ocis/pkg/command/web.go index 0b3ec822e24..e4f6e3cbf38 100644 --- a/ocis/pkg/command/web.go +++ b/ocis/pkg/command/web.go @@ -3,7 +3,6 @@ package command import ( "github.com/owncloud/ocis/extensions/web/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -11,12 +10,9 @@ import ( // WebCommand is the entrypoint for the web command. func WebCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.Web.Service.Name, - Usage: subcommandDescription(cfg.Web.Service.Name), - Category: "extensions", - Before: func(ctx *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: cfg.Web.Service.Name, + Usage: subcommandDescription(cfg.Web.Service.Name), + Category: "extensions", Subcommands: command.GetCommands(cfg.Web), } } diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index 7add32497fa..56ceb624d81 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.go @@ -3,7 +3,6 @@ package command import ( "github.com/owncloud/ocis/extensions/webdav/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -12,12 +11,9 @@ import ( func WebDAVCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.WebDAV.Service.Name, - Usage: subcommandDescription(cfg.WebDAV.Service.Name), - Category: "extensions", - Before: func(ctx *cli.Context) error { - return parser.ParseConfig(cfg) - }, + Name: cfg.WebDAV.Service.Name, + Usage: subcommandDescription(cfg.WebDAV.Service.Name), + Category: "extensions", Subcommands: command.GetCommands(cfg.WebDAV), } } From 3dd7d9293400f86a22c391b10edd0f9717808536 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 19 Apr 2022 15:57:28 +0200 Subject: [PATCH 09/17] fix config extractor --- docs/helpers/configenvextractor.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/helpers/configenvextractor.go b/docs/helpers/configenvextractor.go index fe6fcb97c53..3f08ca0cec9 100644 --- a/docs/helpers/configenvextractor.go +++ b/docs/helpers/configenvextractor.go @@ -56,7 +56,8 @@ func GenerateIntermediateCode(templatePath string, intermediateCodePath string, func RunIntermediateCode(intermediateCodePath string) { fmt.Println("Running intermediate go code for " + intermediateCodePath) - os.Setenv("HOME", "~") // don't write the current absolute user directory for the documentation + os.Setenv("OCIS_BASE_DATA_PATH", "~/.ocis") + os.Setenv("OCIS_CONFIG_DIR", "~/.ocis/config") out, err := exec.Command("go", "run", intermediateCodePath).Output() if err != nil { log.Fatal(err) From eac8c4592856afea7d0d6102237fe8a372d5f7be Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 19 Apr 2022 16:00:48 +0200 Subject: [PATCH 10/17] fix config dir in CI --- .drone.star | 1 + 1 file changed, 1 insertion(+) diff --git a/.drone.star b/.drone.star index 4e76e385e4e..61e425a43b6 100644 --- a/.drone.star +++ b/.drone.star @@ -1709,6 +1709,7 @@ def ocisServer(storage, accounts_hash_difficulty = 4, volumes = [], depends_on = "OCIS_URL": OCIS_URL, "PROXY_TLS": "true", "OCIS_BASE_DATA_PATH": "/mnt/data/ocis", + "OCIS_CONFIG_DIR": "/etc/ocis", # change default secrets "OCIS_JWT_SECRET": "Pive-Fumkiu4", "STORAGE_TRANSFER_SECRET": "replace-me-with-a-transfer-secret", From cf31a647f4acacadd41ac3611183fba3bdd20509 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 19 Apr 2022 16:39:01 +0200 Subject: [PATCH 11/17] Revert "fix config parsing in unsupervised mode" This reverts commit 45f49aec1e06611bfb60211f1f9e768e96d45c8c. --- ocis/pkg/command/accounts.go | 10 +++++++--- ocis/pkg/command/audit.go | 10 +++++++--- ocis/pkg/command/glauth.go | 10 +++++++--- ocis/pkg/command/graph.go | 10 +++++++--- ocis/pkg/command/graphexplorer.go | 4 ++++ ocis/pkg/command/idm.go | 10 +++++++--- ocis/pkg/command/idp.go | 10 +++++++--- ocis/pkg/command/natsserver.go | 10 +++++++--- ocis/pkg/command/notifications.go | 10 +++++++--- ocis/pkg/command/ocs.go | 10 +++++++--- ocis/pkg/command/proxy.go | 10 +++++++--- ocis/pkg/command/server.go | 2 +- ocis/pkg/command/settings.go | 10 +++++++--- ocis/pkg/command/store.go | 10 +++++++--- ocis/pkg/command/thumbnails.go | 10 +++++++--- ocis/pkg/command/web.go | 10 +++++++--- ocis/pkg/command/webdav.go | 10 +++++++--- 17 files changed, 110 insertions(+), 46 deletions(-) diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index 71176908853..f8a56bfcc5b 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/extensions/accounts/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -10,9 +11,12 @@ import ( // AccountsCommand is the entrypoint for the accounts command. func AccountsCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.Accounts.Service.Name, - Usage: subcommandDescription(cfg.Accounts.Service.Name), - Category: "extensions", + Name: cfg.Accounts.Service.Name, + Usage: subcommandDescription(cfg.Accounts.Service.Name), + Category: "extensions", + Before: func(ctx *cli.Context) error { + return parser.ParseConfig(cfg) + }, Subcommands: command.GetCommands(cfg.Accounts), } } diff --git a/ocis/pkg/command/audit.go b/ocis/pkg/command/audit.go index 91522a6b00b..638367a166b 100644 --- a/ocis/pkg/command/audit.go +++ b/ocis/pkg/command/audit.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/extensions/audit/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -10,9 +11,12 @@ import ( // AuditCommand is the entrypoint for the audit command. func AuditCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.Audit.Service.Name, - Usage: subcommandDescription(cfg.Audit.Service.Name), - Category: "extensions", + Name: "audit", + Usage: "start audit service", + Category: "extensions", + Before: func(ctx *cli.Context) error { + return parser.ParseConfig(cfg) + }, Subcommands: command.GetCommands(cfg.Audit), } } diff --git a/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index e56e9e33a50..ad91954eb03 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/extensions/glauth/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -10,9 +11,12 @@ import ( // GLAuthCommand is the entrypoint for the glauth command. func GLAuthCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.GLAuth.Service.Name, - Usage: subcommandDescription(cfg.GLAuth.Service.Name), - Category: "extensions", + Name: cfg.GLAuth.Service.Name, + Usage: subcommandDescription(cfg.GLAuth.Service.Name), + Category: "extensions", + Before: func(ctx *cli.Context) error { + return parser.ParseConfig(cfg) + }, Subcommands: command.GetCommands(cfg.GLAuth), } } diff --git a/ocis/pkg/command/graph.go b/ocis/pkg/command/graph.go index 7cc90d3dacb..836ad44465d 100644 --- a/ocis/pkg/command/graph.go +++ b/ocis/pkg/command/graph.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/extensions/graph/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -10,9 +11,12 @@ import ( // GraphCommand is the entrypoint for the graph command. func GraphCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.Graph.Service.Name, - Usage: subcommandDescription(cfg.Graph.Service.Name), - Category: "extensions", + Name: cfg.Graph.Service.Name, + Usage: subcommandDescription(cfg.Graph.Service.Name), + Category: "extensions", + Before: func(ctx *cli.Context) error { + return parser.ParseConfig(cfg) + }, Subcommands: command.GetCommands(cfg.Graph), } } diff --git a/ocis/pkg/command/graphexplorer.go b/ocis/pkg/command/graphexplorer.go index d9f6b198b7b..95be9e503ff 100644 --- a/ocis/pkg/command/graphexplorer.go +++ b/ocis/pkg/command/graphexplorer.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/extensions/graph-explorer/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -13,6 +14,9 @@ func GraphExplorerCommand(cfg *config.Config) *cli.Command { Name: cfg.GraphExplorer.Service.Name, Usage: subcommandDescription(cfg.GraphExplorer.Service.Name), Category: "extensions", + Before: func(ctx *cli.Context) error { + return parser.ParseConfig(cfg) + }, Subcommands: command.GetCommands(cfg.GraphExplorer), } } diff --git a/ocis/pkg/command/idm.go b/ocis/pkg/command/idm.go index a4f86ac5d25..d768b6dc58b 100644 --- a/ocis/pkg/command/idm.go +++ b/ocis/pkg/command/idm.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/extensions/idm/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -10,9 +11,12 @@ import ( // IDMCommand is the entrypoint for the idm server command. func IDMCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "idm", - Usage: "idm extension commands", - Category: "extensions", + Name: "idm", + Usage: "idm extension commands", + Category: "extensions", + Before: func(ctx *cli.Context) error { + return parser.ParseConfig(cfg) + }, Subcommands: command.GetCommands(cfg.IDM), } } diff --git a/ocis/pkg/command/idp.go b/ocis/pkg/command/idp.go index 5b948907695..0c6828c5928 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/extensions/idp/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -10,9 +11,12 @@ import ( // IDPCommand is the entrypoint for the idp command. func IDPCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.IDP.Service.Name, - Usage: subcommandDescription(cfg.IDP.Service.Name), - Category: "extensions", + Name: cfg.IDP.Service.Name, + Usage: subcommandDescription(cfg.IDP.Service.Name), + Category: "extensions", + Before: func(ctx *cli.Context) error { + return parser.ParseConfig(cfg) + }, Subcommands: command.GetCommands(cfg.IDP), } } diff --git a/ocis/pkg/command/natsserver.go b/ocis/pkg/command/natsserver.go index 334412fd1b8..1e7f3432317 100644 --- a/ocis/pkg/command/natsserver.go +++ b/ocis/pkg/command/natsserver.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/extensions/nats/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -10,9 +11,12 @@ import ( // NatsServerCommand is the entrypoint for the nats server command. func NatsServerCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "nats-server", - Usage: "start nats server", - Category: "extensions", + Name: "nats-server", + Usage: "start nats server", + Category: "extensions", + Before: func(ctx *cli.Context) error { + return parser.ParseConfig(cfg) + }, Subcommands: command.GetCommands(cfg.Nats), } } diff --git a/ocis/pkg/command/notifications.go b/ocis/pkg/command/notifications.go index fb16c3f9ac8..f4108e299af 100644 --- a/ocis/pkg/command/notifications.go +++ b/ocis/pkg/command/notifications.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/extensions/notifications/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -10,9 +11,12 @@ import ( // NatsServerCommand is the entrypoint for the nats server command. func NotificationsCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "notifications", - Usage: "start notifications service", - Category: "extensions", + Name: "notifications", + Usage: "start notifications service", + Category: "extensions", + Before: func(ctx *cli.Context) error { + return parser.ParseConfig(cfg) + }, Subcommands: command.GetCommands(cfg.Notifications), } } diff --git a/ocis/pkg/command/ocs.go b/ocis/pkg/command/ocs.go index ee31837e995..2fae3beb95d 100644 --- a/ocis/pkg/command/ocs.go +++ b/ocis/pkg/command/ocs.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/extensions/ocs/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -10,9 +11,12 @@ import ( // OCSCommand is the entrypoint for the ocs command. func OCSCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.OCS.Service.Name, - Usage: subcommandDescription(cfg.OCS.Service.Name), - Category: "extensions", + Name: cfg.OCS.Service.Name, + Usage: subcommandDescription(cfg.OCS.Service.Name), + Category: "extensions", + Before: func(ctx *cli.Context) error { + return parser.ParseConfig(cfg) + }, Subcommands: command.GetCommands(cfg.OCS), } } diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index c72387543af..429ca83e19f 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/extensions/proxy/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -10,9 +11,12 @@ import ( // ProxyCommand is the entry point for the proxy command. func ProxyCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.Proxy.Service.Name, - Usage: subcommandDescription(cfg.Proxy.Service.Name), - Category: "extensions", + Name: cfg.Proxy.Service.Name, + Usage: subcommandDescription(cfg.Proxy.Service.Name), + Category: "extensions", + Before: func(ctx *cli.Context) error { + return parser.ParseConfig(cfg) + }, Subcommands: command.GetCommands(cfg.Proxy), } } diff --git a/ocis/pkg/command/server.go b/ocis/pkg/command/server.go index e6479a731c5..caa54d341a8 100644 --- a/ocis/pkg/command/server.go +++ b/ocis/pkg/command/server.go @@ -20,7 +20,7 @@ func Server(cfg *config.Config) *cli.Command { &cli.StringFlag{ Name: "config-file", Value: cfg.ConfigFile, - Usage: "config file to be loaded by the oCIS runtime", + Usage: "config file to be loaded by the extension", Destination: &cfg.ConfigFile, }, }, diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index b59140a6e47..32c8b43e690 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/extensions/settings/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -10,9 +11,12 @@ import ( // SettingsCommand is the entry point for the settings command. func SettingsCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.Settings.Service.Name, - Usage: subcommandDescription(cfg.Settings.Service.Name), - Category: "extensions", + Name: cfg.Settings.Service.Name, + Usage: subcommandDescription(cfg.Settings.Service.Name), + Category: "extensions", + Before: func(ctx *cli.Context) error { + return parser.ParseConfig(cfg) + }, Subcommands: command.GetCommands(cfg.Settings), } } diff --git a/ocis/pkg/command/store.go b/ocis/pkg/command/store.go index 239a8f3dcab..e37d5ab79f1 100644 --- a/ocis/pkg/command/store.go +++ b/ocis/pkg/command/store.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/extensions/store/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -11,9 +12,12 @@ import ( func StoreCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.Store.Service.Name, - Usage: subcommandDescription(cfg.Store.Service.Name), - Category: "extensions", + Name: cfg.Store.Service.Name, + Usage: subcommandDescription(cfg.Store.Service.Name), + Category: "extensions", + Before: func(ctx *cli.Context) error { + return parser.ParseConfig(cfg) + }, Subcommands: command.GetCommands(cfg.Store), } } diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index 68cb54559e9..8409c98dc07 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/extensions/thumbnails/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -10,9 +11,12 @@ import ( // ThumbnailsCommand is the entrypoint for the thumbnails command. func ThumbnailsCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.Thumbnails.Service.Name, - Usage: subcommandDescription(cfg.Thumbnails.Service.Name), - Category: "extensions", + Name: cfg.Thumbnails.Service.Name, + Usage: subcommandDescription(cfg.Thumbnails.Service.Name), + Category: "extensions", + Before: func(ctx *cli.Context) error { + return parser.ParseConfig(cfg) + }, Subcommands: command.GetCommands(cfg.Thumbnails), } } diff --git a/ocis/pkg/command/web.go b/ocis/pkg/command/web.go index e4f6e3cbf38..0b3ec822e24 100644 --- a/ocis/pkg/command/web.go +++ b/ocis/pkg/command/web.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/extensions/web/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -10,9 +11,12 @@ import ( // WebCommand is the entrypoint for the web command. func WebCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.Web.Service.Name, - Usage: subcommandDescription(cfg.Web.Service.Name), - Category: "extensions", + Name: cfg.Web.Service.Name, + Usage: subcommandDescription(cfg.Web.Service.Name), + Category: "extensions", + Before: func(ctx *cli.Context) error { + return parser.ParseConfig(cfg) + }, Subcommands: command.GetCommands(cfg.Web), } } diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index 56ceb624d81..7add32497fa 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.go @@ -3,6 +3,7 @@ package command import ( "github.com/owncloud/ocis/extensions/webdav/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/parser" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -11,9 +12,12 @@ import ( func WebDAVCommand(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: cfg.WebDAV.Service.Name, - Usage: subcommandDescription(cfg.WebDAV.Service.Name), - Category: "extensions", + Name: cfg.WebDAV.Service.Name, + Usage: subcommandDescription(cfg.WebDAV.Service.Name), + Category: "extensions", + Before: func(ctx *cli.Context) error { + return parser.ParseConfig(cfg) + }, Subcommands: command.GetCommands(cfg.WebDAV), } } From 3686bd00d31ed8dad47bdc1d173996f2265ceb50 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Wed, 20 Apr 2022 13:16:44 +0200 Subject: [PATCH 12/17] add ocis-config-file option --- ocis/pkg/command/accounts.go | 8 ++++++++ ocis/pkg/command/audit.go | 8 ++++++++ ocis/pkg/command/glauth.go | 8 ++++++++ ocis/pkg/command/graph.go | 8 ++++++++ ocis/pkg/command/graphexplorer.go | 8 ++++++++ ocis/pkg/command/idm.go | 8 ++++++++ ocis/pkg/command/idp.go | 8 ++++++++ ocis/pkg/command/natsserver.go | 8 ++++++++ ocis/pkg/command/notifications.go | 8 ++++++++ ocis/pkg/command/ocdav.go | 8 ++++++++ ocis/pkg/command/ocs.go | 8 ++++++++ ocis/pkg/command/proxy.go | 8 ++++++++ ocis/pkg/command/server.go | 14 +++----------- ocis/pkg/command/settings.go | 8 ++++++++ ocis/pkg/command/storageappprovider.go | 9 ++++++++- ocis/pkg/command/storageauthbasic.go | 9 ++++++++- ocis/pkg/command/storageauthbearer.go | 9 ++++++++- ocis/pkg/command/storageauthmachine.go | 9 ++++++++- ocis/pkg/command/storagefrontend.go | 9 ++++++++- ocis/pkg/command/storagegateway.go | 9 ++++++++- ocis/pkg/command/storagegroupprovider.go | 9 ++++++++- ocis/pkg/command/storagemetadata.go | 8 ++++++++ ocis/pkg/command/storagepubliclink.go | 9 ++++++++- ocis/pkg/command/storageshares.go | 8 ++++++++ ocis/pkg/command/storagesharing.go | 9 ++++++++- ocis/pkg/command/storageuserprovider.go | 9 ++++++++- ocis/pkg/command/storageusers.go | 9 ++++++++- ocis/pkg/command/store.go | 8 ++++++++ ocis/pkg/command/thumbnails.go | 8 ++++++++ ocis/pkg/command/web.go | 8 ++++++++ ocis/pkg/command/webdav.go | 8 ++++++++ 31 files changed, 243 insertions(+), 22 deletions(-) diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index f8a56bfcc5b..5475ffb5cef 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -14,6 +14,14 @@ func AccountsCommand(cfg *config.Config) *cli.Command { Name: cfg.Accounts.Service.Name, Usage: subcommandDescription(cfg.Accounts.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/audit.go b/ocis/pkg/command/audit.go index 638367a166b..fb73c602a1f 100644 --- a/ocis/pkg/command/audit.go +++ b/ocis/pkg/command/audit.go @@ -14,6 +14,14 @@ func AuditCommand(cfg *config.Config) *cli.Command { Name: "audit", Usage: "start audit service", Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index ad91954eb03..a60598db87a 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -14,6 +14,14 @@ func GLAuthCommand(cfg *config.Config) *cli.Command { Name: cfg.GLAuth.Service.Name, Usage: subcommandDescription(cfg.GLAuth.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/graph.go b/ocis/pkg/command/graph.go index 836ad44465d..ad00998082b 100644 --- a/ocis/pkg/command/graph.go +++ b/ocis/pkg/command/graph.go @@ -14,6 +14,14 @@ func GraphCommand(cfg *config.Config) *cli.Command { Name: cfg.Graph.Service.Name, Usage: subcommandDescription(cfg.Graph.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/graphexplorer.go b/ocis/pkg/command/graphexplorer.go index 95be9e503ff..8a407c9056d 100644 --- a/ocis/pkg/command/graphexplorer.go +++ b/ocis/pkg/command/graphexplorer.go @@ -14,6 +14,14 @@ func GraphExplorerCommand(cfg *config.Config) *cli.Command { Name: cfg.GraphExplorer.Service.Name, Usage: subcommandDescription(cfg.GraphExplorer.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/idm.go b/ocis/pkg/command/idm.go index d768b6dc58b..886b6f79d27 100644 --- a/ocis/pkg/command/idm.go +++ b/ocis/pkg/command/idm.go @@ -14,6 +14,14 @@ func IDMCommand(cfg *config.Config) *cli.Command { Name: "idm", Usage: "idm extension commands", Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/idp.go b/ocis/pkg/command/idp.go index 0c6828c5928..e84c31c9508 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -14,6 +14,14 @@ func IDPCommand(cfg *config.Config) *cli.Command { Name: cfg.IDP.Service.Name, Usage: subcommandDescription(cfg.IDP.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/natsserver.go b/ocis/pkg/command/natsserver.go index 1e7f3432317..dd14365c6a9 100644 --- a/ocis/pkg/command/natsserver.go +++ b/ocis/pkg/command/natsserver.go @@ -14,6 +14,14 @@ func NatsServerCommand(cfg *config.Config) *cli.Command { Name: "nats-server", Usage: "start nats server", Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/notifications.go b/ocis/pkg/command/notifications.go index f4108e299af..356fa15b5ed 100644 --- a/ocis/pkg/command/notifications.go +++ b/ocis/pkg/command/notifications.go @@ -14,6 +14,14 @@ func NotificationsCommand(cfg *config.Config) *cli.Command { Name: "notifications", Usage: "start notifications service", Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/ocdav.go b/ocis/pkg/command/ocdav.go index c458ee28564..62ec1119c1d 100644 --- a/ocis/pkg/command/ocdav.go +++ b/ocis/pkg/command/ocdav.go @@ -13,6 +13,14 @@ func OCDavCommand(cfg *config.Config) *cli.Command { Name: "ocdav", Usage: "start ocdav", Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/ocs.go b/ocis/pkg/command/ocs.go index 2fae3beb95d..9c0b5cc7139 100644 --- a/ocis/pkg/command/ocs.go +++ b/ocis/pkg/command/ocs.go @@ -14,6 +14,14 @@ func OCSCommand(cfg *config.Config) *cli.Command { Name: cfg.OCS.Service.Name, Usage: subcommandDescription(cfg.OCS.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index 429ca83e19f..eb639588dfa 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -14,6 +14,14 @@ func ProxyCommand(cfg *config.Config) *cli.Command { Name: cfg.Proxy.Service.Name, Usage: subcommandDescription(cfg.Proxy.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/server.go b/ocis/pkg/command/server.go index caa54d341a8..7acbc557d30 100644 --- a/ocis/pkg/command/server.go +++ b/ocis/pkg/command/server.go @@ -3,7 +3,6 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/parser" - "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/ocis/pkg/runtime" @@ -18,21 +17,14 @@ func Server(cfg *config.Config) *cli.Command { Category: "fullstack", Flags: []cli.Flag{ &cli.StringFlag{ - Name: "config-file", + Name: "ocis-config-file", Value: cfg.ConfigFile, - Usage: "config file to be loaded by the extension", + Usage: "oCIS config file to be loaded by the runtime and extensions", Destination: &cfg.ConfigFile, }, }, Before: func(c *cli.Context) error { - err := parser.ParseConfig(cfg) - if err != nil { - logger := log.NewLogger( - log.Name("oCIS"), - ) - logger.Error().Err(err).Msg("couldn't find the specified config file") - } - return err + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index 32c8b43e690..0338d22878f 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.go @@ -14,6 +14,14 @@ func SettingsCommand(cfg *config.Config) *cli.Command { Name: cfg.Settings.Service.Name, Usage: subcommandDescription(cfg.Settings.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/storageappprovider.go b/ocis/pkg/command/storageappprovider.go index 39444d49262..66e2767e915 100644 --- a/ocis/pkg/command/storageappprovider.go +++ b/ocis/pkg/command/storageappprovider.go @@ -13,7 +13,14 @@ func StorageAppProviderCommand(cfg *config.Config) *cli.Command { Name: "storage-app-provider", Usage: "start storage app-provider service", Category: "extensions", - //Flags: flagset.AppProviderWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storageauthbasic.go b/ocis/pkg/command/storageauthbasic.go index 5059fd1e0ad..22f3aaea79c 100644 --- a/ocis/pkg/command/storageauthbasic.go +++ b/ocis/pkg/command/storageauthbasic.go @@ -13,7 +13,14 @@ func StorageAuthBasicCommand(cfg *config.Config) *cli.Command { Name: "storage-auth-basic", Usage: "start storage auth-basic service", Category: "extensions", - //Flags: flagset.AuthBasicWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storageauthbearer.go b/ocis/pkg/command/storageauthbearer.go index f9b1912f507..464d0206194 100644 --- a/ocis/pkg/command/storageauthbearer.go +++ b/ocis/pkg/command/storageauthbearer.go @@ -13,7 +13,14 @@ func StorageAuthBearerCommand(cfg *config.Config) *cli.Command { Name: "storage-auth-bearer", Usage: "Start storage auth-bearer service", Category: "extensions", - //Flags: flagset.AuthBearerWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storageauthmachine.go b/ocis/pkg/command/storageauthmachine.go index 64bded070cb..fd02f367de1 100644 --- a/ocis/pkg/command/storageauthmachine.go +++ b/ocis/pkg/command/storageauthmachine.go @@ -13,7 +13,14 @@ func StorageAuthMachineCommand(cfg *config.Config) *cli.Command { Name: "storage-auth-machine", Usage: "start storage auth-machine service", Category: "extensions", - //Flags: flagset.AuthMachineWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storagefrontend.go b/ocis/pkg/command/storagefrontend.go index 0bc98cbbdb5..184096fb645 100644 --- a/ocis/pkg/command/storagefrontend.go +++ b/ocis/pkg/command/storagefrontend.go @@ -13,7 +13,14 @@ func StorageFrontendCommand(cfg *config.Config) *cli.Command { Name: "storage-frontend", Usage: "start storage frontend", Category: "extensions", - //Flags: flagset.FrontendWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storagegateway.go b/ocis/pkg/command/storagegateway.go index fb96d116d5a..51f723a61d0 100644 --- a/ocis/pkg/command/storagegateway.go +++ b/ocis/pkg/command/storagegateway.go @@ -13,7 +13,14 @@ func StorageGatewayCommand(cfg *config.Config) *cli.Command { Name: "storage-gateway", Usage: "start storage gateway", Category: "extensions", - //Flags: flagset.GatewayWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storagegroupprovider.go b/ocis/pkg/command/storagegroupprovider.go index a3703ac795e..e92dadba22e 100644 --- a/ocis/pkg/command/storagegroupprovider.go +++ b/ocis/pkg/command/storagegroupprovider.go @@ -13,7 +13,14 @@ func StorageGroupProviderCommand(cfg *config.Config) *cli.Command { Name: "storage-groupprovider", Usage: "start storage groupprovider service", Category: "extensions", - //Flags: flagset.GroupsWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storagemetadata.go b/ocis/pkg/command/storagemetadata.go index ef3d4d205d4..de8edfd4304 100644 --- a/ocis/pkg/command/storagemetadata.go +++ b/ocis/pkg/command/storagemetadata.go @@ -13,6 +13,14 @@ func StorageMetadataCommand(cfg *config.Config) *cli.Command { Name: "storage-metadata", Usage: "start storage and data service for metadata", Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storagepubliclink.go b/ocis/pkg/command/storagepubliclink.go index 516bc6c72d0..529ece013d6 100644 --- a/ocis/pkg/command/storagepubliclink.go +++ b/ocis/pkg/command/storagepubliclink.go @@ -13,7 +13,14 @@ func StoragePublicLinkCommand(cfg *config.Config) *cli.Command { Name: "storage-public-link", Usage: "start storage public link storage", Category: "extensions", - //Flags: flagset.StoragePublicLink(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storageshares.go b/ocis/pkg/command/storageshares.go index e906cb20e0e..b68c00d6bf0 100644 --- a/ocis/pkg/command/storageshares.go +++ b/ocis/pkg/command/storageshares.go @@ -13,6 +13,14 @@ func StorageSharesCommand(cfg *config.Config) *cli.Command { Name: "storage-shares", Usage: "start storage and data provider for shares jail", Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storagesharing.go b/ocis/pkg/command/storagesharing.go index 4a70baa80a3..43f6a1c9c97 100644 --- a/ocis/pkg/command/storagesharing.go +++ b/ocis/pkg/command/storagesharing.go @@ -13,7 +13,14 @@ func StorageSharingCommand(cfg *config.Config) *cli.Command { Name: "storage-sharing", Usage: "start storage sharing service", Category: "extensions", - //Flags: flagset.SharingWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storageuserprovider.go b/ocis/pkg/command/storageuserprovider.go index 896d0572069..951822a46df 100644 --- a/ocis/pkg/command/storageuserprovider.go +++ b/ocis/pkg/command/storageuserprovider.go @@ -13,7 +13,14 @@ func StorageUserProviderCommand(cfg *config.Config) *cli.Command { Name: "storage-userprovider", Usage: "start storage userprovider service", Category: "extensions", - //Flags: flagset.UsersWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storageusers.go b/ocis/pkg/command/storageusers.go index 0c2a62c77c1..5cec411d12c 100644 --- a/ocis/pkg/command/storageusers.go +++ b/ocis/pkg/command/storageusers.go @@ -13,7 +13,14 @@ func StorageUsersCommand(cfg *config.Config) *cli.Command { Name: "storage-users", Usage: "start storage and data provider for /users mount", Category: "extensions", - //Flags: flagset.StorageUsersWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/store.go b/ocis/pkg/command/store.go index e37d5ab79f1..8843000bb78 100644 --- a/ocis/pkg/command/store.go +++ b/ocis/pkg/command/store.go @@ -15,6 +15,14 @@ func StoreCommand(cfg *config.Config) *cli.Command { Name: cfg.Store.Service.Name, Usage: subcommandDescription(cfg.Store.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index 8409c98dc07..3507520ce8d 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -14,6 +14,14 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command { Name: cfg.Thumbnails.Service.Name, Usage: subcommandDescription(cfg.Thumbnails.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/web.go b/ocis/pkg/command/web.go index 0b3ec822e24..2e8025c15b2 100644 --- a/ocis/pkg/command/web.go +++ b/ocis/pkg/command/web.go @@ -14,6 +14,14 @@ func WebCommand(cfg *config.Config) *cli.Command { Name: cfg.Web.Service.Name, Usage: subcommandDescription(cfg.Web.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index 7add32497fa..f94e19140e5 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.go @@ -15,6 +15,14 @@ func WebDAVCommand(cfg *config.Config) *cli.Command { Name: cfg.WebDAV.Service.Name, Usage: subcommandDescription(cfg.WebDAV.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, From 84d3478302b8ca52f786715bf69429fc028b16f2 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Wed, 20 Apr 2022 13:16:58 +0200 Subject: [PATCH 13/17] log inside the parsers --- extensions/accounts/pkg/command/server.go | 7 +------ extensions/accounts/pkg/config/parser/parse.go | 3 +++ extensions/accounts/pkg/service/v0/accounts.go | 2 +- extensions/audit/pkg/command/server.go | 7 +------ extensions/audit/pkg/config/parser/parse.go | 3 +++ extensions/glauth/pkg/command/server.go | 7 +------ extensions/glauth/pkg/config/parser/parse.go | 3 +++ extensions/graph-explorer/pkg/command/server.go | 7 +------ extensions/graph-explorer/pkg/config/parser/parse.go | 3 +++ extensions/graph/pkg/command/server.go | 7 +------ extensions/graph/pkg/config/parser/parse.go | 3 +++ extensions/idm/pkg/command/server.go | 7 +------ extensions/idm/pkg/config/parser/parse.go | 3 +++ extensions/idp/pkg/command/server.go | 7 +------ extensions/idp/pkg/config/parser/parse.go | 3 +++ extensions/nats/pkg/command/server.go | 7 +------ extensions/nats/pkg/config/parser/parse.go | 3 +++ extensions/notifications/pkg/command/server.go | 7 +------ extensions/notifications/pkg/config/parser/parse.go | 3 +++ extensions/ocs/pkg/command/server.go | 7 +------ extensions/ocs/pkg/config/parser/parse.go | 3 +++ extensions/ocs/pkg/service/v0/data/user.go | 2 +- extensions/proxy/pkg/command/server.go | 7 +------ extensions/proxy/pkg/config/parser/parse.go | 3 +++ extensions/settings/pkg/command/server.go | 7 +------ extensions/settings/pkg/config/parser/parse.go | 3 +++ extensions/storage/pkg/command/gateway.go | 2 +- extensions/store/pkg/command/server.go | 7 +------ extensions/store/pkg/config/parser/parse.go | 3 +++ extensions/thumbnails/pkg/command/server.go | 7 +------ extensions/thumbnails/pkg/config/parser/parse.go | 3 +++ extensions/web/pkg/command/server.go | 7 +------ extensions/web/pkg/config/parser/parse.go | 3 +++ extensions/webdav/pkg/command/server.go | 7 +------ extensions/webdav/pkg/config/parser/parse.go | 3 +++ extensions/webdav/pkg/metrics/metrics.go | 4 ++-- 36 files changed, 69 insertions(+), 101 deletions(-) diff --git a/extensions/accounts/pkg/command/server.go b/extensions/accounts/pkg/command/server.go index c399a6a558d..0a3ba93ea57 100644 --- a/extensions/accounts/pkg/command/server.go +++ b/extensions/accounts/pkg/command/server.go @@ -33,12 +33,7 @@ func Server(cfg *config.Config) *cli.Command { }, }, Before: func(c *cli.Context) error { - err := parser.ParseConfig(cfg) - if err != nil { - logger := logging.Configure(cfg.Service.Name, &config.Log{}) - logger.Error().Err(err).Msg("couldn't find the specified config file") - } - return err + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/accounts/pkg/config/parser/parse.go b/extensions/accounts/pkg/config/parser/parse.go index 76c84720203..90632414e54 100644 --- a/extensions/accounts/pkg/config/parser/parse.go +++ b/extensions/accounts/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/accounts/pkg/config" defaults "github.com/owncloud/ocis/extensions/accounts/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/accounts/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -20,6 +21,8 @@ func ParseConfig(cfg *config.Config) error { _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } diff --git a/extensions/accounts/pkg/service/v0/accounts.go b/extensions/accounts/pkg/service/v0/accounts.go index ca7a1c2659c..8c7c83c8f8b 100644 --- a/extensions/accounts/pkg/service/v0/accounts.go +++ b/extensions/accounts/pkg/service/v0/accounts.go @@ -24,12 +24,12 @@ import ( fieldmask_utils "github.com/mennanov/fieldmask-utils" "github.com/owncloud/ocis/extensions/accounts/pkg/storage" accTracing "github.com/owncloud/ocis/extensions/accounts/pkg/tracing" + settings_svc "github.com/owncloud/ocis/extensions/settings/pkg/service/v0" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/middleware" "github.com/owncloud/ocis/ocis-pkg/roles" "github.com/owncloud/ocis/ocis-pkg/sync" settingssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/settings/v0" - settings_svc "github.com/owncloud/ocis/extensions/settings/pkg/service/v0" "github.com/rs/zerolog" merrors "go-micro.dev/v4/errors" "go-micro.dev/v4/metadata" diff --git a/extensions/audit/pkg/command/server.go b/extensions/audit/pkg/command/server.go index ad2fa2f9854..3c4b540021f 100644 --- a/extensions/audit/pkg/command/server.go +++ b/extensions/audit/pkg/command/server.go @@ -30,12 +30,7 @@ func Server(cfg *config.Config) *cli.Command { }, }, Before: func(c *cli.Context) error { - err := parser.ParseConfig(cfg) - if err != nil { - logger := logging.Configure(cfg.Service.Name, &config.Log{}) - logger.Error().Err(err).Msg("couldn't find the specified config file") - } - return err + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/audit/pkg/config/parser/parse.go b/extensions/audit/pkg/config/parser/parse.go index 77b8195c700..d1e84cc2497 100644 --- a/extensions/audit/pkg/config/parser/parse.go +++ b/extensions/audit/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/audit/pkg/config" "github.com/owncloud/ocis/extensions/audit/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/audit/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -20,6 +21,8 @@ func ParseConfig(cfg *config.Config) error { _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } diff --git a/extensions/glauth/pkg/command/server.go b/extensions/glauth/pkg/command/server.go index b2bdf422586..f7d1277bb44 100644 --- a/extensions/glauth/pkg/command/server.go +++ b/extensions/glauth/pkg/command/server.go @@ -36,12 +36,7 @@ func Server(cfg *config.Config) *cli.Command { }, }, Before: func(c *cli.Context) error { - err := parser.ParseConfig(cfg) - if err != nil { - logger := logging.Configure(cfg.Service.Name, &config.Log{}) - logger.Error().Err(err).Msg("couldn't find the specified config file") - } - return err + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/glauth/pkg/config/parser/parse.go b/extensions/glauth/pkg/config/parser/parse.go index de2a80586fa..fd8f98b8df1 100644 --- a/extensions/glauth/pkg/config/parser/parse.go +++ b/extensions/glauth/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/glauth/pkg/config" "github.com/owncloud/ocis/extensions/glauth/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/glauth/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -20,6 +21,8 @@ func ParseConfig(cfg *config.Config) error { _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } diff --git a/extensions/graph-explorer/pkg/command/server.go b/extensions/graph-explorer/pkg/command/server.go index a3c9f735fde..5950ab33a36 100644 --- a/extensions/graph-explorer/pkg/command/server.go +++ b/extensions/graph-explorer/pkg/command/server.go @@ -31,12 +31,7 @@ func Server(cfg *config.Config) *cli.Command { }, }, Before: func(c *cli.Context) error { - err := parser.ParseConfig(cfg) - if err != nil { - logger := logging.Configure(cfg.Service.Name, &config.Log{}) - logger.Error().Err(err).Msg("couldn't find the specified config file") - } - return err + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/graph-explorer/pkg/config/parser/parse.go b/extensions/graph-explorer/pkg/config/parser/parse.go index 4a219cc2847..4a6c4dad0f5 100644 --- a/extensions/graph-explorer/pkg/config/parser/parse.go +++ b/extensions/graph-explorer/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/graph-explorer/pkg/config" "github.com/owncloud/ocis/extensions/graph-explorer/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/graph-explorer/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -20,6 +21,8 @@ func ParseConfig(cfg *config.Config) error { _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } diff --git a/extensions/graph/pkg/command/server.go b/extensions/graph/pkg/command/server.go index 57a64f17099..b62089d96c5 100644 --- a/extensions/graph/pkg/command/server.go +++ b/extensions/graph/pkg/command/server.go @@ -31,12 +31,7 @@ func Server(cfg *config.Config) *cli.Command { }, }, Before: func(c *cli.Context) error { - err := parser.ParseConfig(cfg) - if err != nil { - logger := logging.Configure(cfg.Service.Name, &config.Log{}) - logger.Error().Err(err).Msg("couldn't find the specified config file") - } - return err + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/graph/pkg/config/parser/parse.go b/extensions/graph/pkg/config/parser/parse.go index f22a70aeff8..17041c8497c 100644 --- a/extensions/graph/pkg/config/parser/parse.go +++ b/extensions/graph/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/graph/pkg/config" "github.com/owncloud/ocis/extensions/graph/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/graph/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -20,6 +21,8 @@ func ParseConfig(cfg *config.Config) error { _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } diff --git a/extensions/idm/pkg/command/server.go b/extensions/idm/pkg/command/server.go index 8a67dd4ea77..7aed37e8eb8 100644 --- a/extensions/idm/pkg/command/server.go +++ b/extensions/idm/pkg/command/server.go @@ -37,12 +37,7 @@ func Server(cfg *config.Config) *cli.Command { }, }, Before: func(c *cli.Context) error { - err := parser.ParseConfig(cfg) - if err != nil { - logger := logging.Configure(cfg.Service.Name, &config.Log{}) - logger.Error().Err(err).Msg("couldn't find the specified config file") - } - return err + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/idm/pkg/config/parser/parse.go b/extensions/idm/pkg/config/parser/parse.go index 4d22908937d..f27079b9408 100644 --- a/extensions/idm/pkg/config/parser/parse.go +++ b/extensions/idm/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/idm/pkg/config" "github.com/owncloud/ocis/extensions/idm/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/idm/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -20,6 +21,8 @@ func ParseConfig(cfg *config.Config) error { _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } diff --git a/extensions/idp/pkg/command/server.go b/extensions/idp/pkg/command/server.go index 862207cb671..087b769a773 100644 --- a/extensions/idp/pkg/command/server.go +++ b/extensions/idp/pkg/command/server.go @@ -31,12 +31,7 @@ func Server(cfg *config.Config) *cli.Command { }, }, Before: func(c *cli.Context) error { - err := parser.ParseConfig(cfg) - if err != nil { - logger := logging.Configure(cfg.Service.Name, &config.Log{}) - logger.Error().Err(err).Msg("couldn't find the specified config file") - } - return err + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/idp/pkg/config/parser/parse.go b/extensions/idp/pkg/config/parser/parse.go index 97524f71c24..9d28b54a51c 100644 --- a/extensions/idp/pkg/config/parser/parse.go +++ b/extensions/idp/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/idp/pkg/config" "github.com/owncloud/ocis/extensions/idp/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/idp/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -20,6 +21,8 @@ func ParseConfig(cfg *config.Config) error { _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } diff --git a/extensions/nats/pkg/command/server.go b/extensions/nats/pkg/command/server.go index ac47883abb5..d6959215280 100644 --- a/extensions/nats/pkg/command/server.go +++ b/extensions/nats/pkg/command/server.go @@ -28,12 +28,7 @@ func Server(cfg *config.Config) *cli.Command { }, }, Before: func(c *cli.Context) error { - err := parser.ParseConfig(cfg) - if err != nil { - logger := logging.Configure(cfg.Service.Name, &config.Log{}) - logger.Error().Err(err).Msg("couldn't find the specified config file") - } - return err + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/nats/pkg/config/parser/parse.go b/extensions/nats/pkg/config/parser/parse.go index ae95dc8fed2..f1d97dfc046 100644 --- a/extensions/nats/pkg/config/parser/parse.go +++ b/extensions/nats/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/nats/pkg/config" "github.com/owncloud/ocis/extensions/nats/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/nats/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -20,6 +21,8 @@ func ParseConfig(cfg *config.Config) error { _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } diff --git a/extensions/notifications/pkg/command/server.go b/extensions/notifications/pkg/command/server.go index 8a729687639..951d027fd56 100644 --- a/extensions/notifications/pkg/command/server.go +++ b/extensions/notifications/pkg/command/server.go @@ -29,12 +29,7 @@ func Server(cfg *config.Config) *cli.Command { }, }, Before: func(c *cli.Context) error { - err := parser.ParseConfig(cfg) - if err != nil { - logger := logging.Configure(cfg.Service.Name, &config.Log{}) - logger.Error().Err(err).Msg("couldn't find the specified config file") - } - return err + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/notifications/pkg/config/parser/parse.go b/extensions/notifications/pkg/config/parser/parse.go index 2bf5b1f0e07..bd378a42bc9 100644 --- a/extensions/notifications/pkg/config/parser/parse.go +++ b/extensions/notifications/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/notifications/pkg/config" "github.com/owncloud/ocis/extensions/notifications/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/notifications/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -20,6 +21,8 @@ func ParseConfig(cfg *config.Config) error { _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } diff --git a/extensions/ocs/pkg/command/server.go b/extensions/ocs/pkg/command/server.go index 75bd14056bf..8ff42c3122f 100644 --- a/extensions/ocs/pkg/command/server.go +++ b/extensions/ocs/pkg/command/server.go @@ -32,12 +32,7 @@ func Server(cfg *config.Config) *cli.Command { }, }, Before: func(c *cli.Context) error { - err := parser.ParseConfig(cfg) - if err != nil { - logger := logging.Configure(cfg.Service.Name, &config.Log{}) - logger.Error().Err(err).Msg("couldn't find the specified config file") - } - return err + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/ocs/pkg/config/parser/parse.go b/extensions/ocs/pkg/config/parser/parse.go index 58cf4b00040..99227d51629 100644 --- a/extensions/ocs/pkg/config/parser/parse.go +++ b/extensions/ocs/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/ocs/pkg/config" "github.com/owncloud/ocis/extensions/ocs/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/ocs/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -20,6 +21,8 @@ func ParseConfig(cfg *config.Config) error { _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } diff --git a/extensions/ocs/pkg/service/v0/data/user.go b/extensions/ocs/pkg/service/v0/data/user.go index 34da73400e5..8b210afb570 100644 --- a/extensions/ocs/pkg/service/v0/data/user.go +++ b/extensions/ocs/pkg/service/v0/data/user.go @@ -8,7 +8,7 @@ type Users struct { // User holds the payload for a GetUser response type User struct { Enabled string `json:"enabled" xml:"enabled"` - UserID string `json:"id" xml:"id"`// UserID is mapped to the preferred_name attribute in accounts + UserID string `json:"id" xml:"id"` // UserID is mapped to the preferred_name attribute in accounts DisplayName string `json:"display-name" xml:"display-name"` LegacyDisplayName string `json:"displayname" xml:"displayname"` Email string `json:"email" xml:"email"` diff --git a/extensions/proxy/pkg/command/server.go b/extensions/proxy/pkg/command/server.go index 4768797e997..7107d91f8e5 100644 --- a/extensions/proxy/pkg/command/server.go +++ b/extensions/proxy/pkg/command/server.go @@ -51,12 +51,7 @@ func Server(cfg *config.Config) *cli.Command { }, }, Before: func(c *cli.Context) error { - err := parser.ParseConfig(cfg) - if err != nil { - logger := logging.Configure(cfg.Service.Name, &config.Log{}) - logger.Error().Err(err).Msg("couldn't find the specified config file") - } - return err + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/proxy/pkg/config/parser/parse.go b/extensions/proxy/pkg/config/parser/parse.go index 1d86cec829b..f917435e4d6 100644 --- a/extensions/proxy/pkg/config/parser/parse.go +++ b/extensions/proxy/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/proxy/pkg/config" "github.com/owncloud/ocis/extensions/proxy/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/proxy/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -20,6 +21,8 @@ func ParseConfig(cfg *config.Config) error { _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } diff --git a/extensions/settings/pkg/command/server.go b/extensions/settings/pkg/command/server.go index 3b3c37cdc66..017e35c8132 100644 --- a/extensions/settings/pkg/command/server.go +++ b/extensions/settings/pkg/command/server.go @@ -32,12 +32,7 @@ func Server(cfg *config.Config) *cli.Command { }, }, Before: func(c *cli.Context) error { - err := parser.ParseConfig(cfg) - if err != nil { - logger := logging.Configure(cfg.Service.Name, &config.Log{}) - logger.Error().Err(err).Msg("couldn't find the specified config file") - } - return err + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/settings/pkg/config/parser/parse.go b/extensions/settings/pkg/config/parser/parse.go index 28fa9218ec7..c5049620ffa 100644 --- a/extensions/settings/pkg/config/parser/parse.go +++ b/extensions/settings/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/settings/pkg/config" "github.com/owncloud/ocis/extensions/settings/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/settings/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -20,6 +21,8 @@ func ParseConfig(cfg *config.Config) error { _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } diff --git a/extensions/storage/pkg/command/gateway.go b/extensions/storage/pkg/command/gateway.go index 57488aa75ac..390b393a1a2 100644 --- a/extensions/storage/pkg/command/gateway.go +++ b/extensions/storage/pkg/command/gateway.go @@ -416,7 +416,7 @@ func (s GatewaySutureService) Serve(ctx context.Context) error { // ParseConfig loads accounts configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config, storageExtension string) error { - conf, err := ociscfg.BindSourcesToStructs(storageExtension, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) + conf, err := ociscfg.BindSourcesToStructs(storageExtension, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { return err } diff --git a/extensions/store/pkg/command/server.go b/extensions/store/pkg/command/server.go index a4601b60b79..e0eca9582ca 100644 --- a/extensions/store/pkg/command/server.go +++ b/extensions/store/pkg/command/server.go @@ -32,12 +32,7 @@ func Server(cfg *config.Config) *cli.Command { }, }, Before: func(c *cli.Context) error { - err := parser.ParseConfig(cfg) - if err != nil { - logger := logging.Configure(cfg.Service.Name, &config.Log{}) - logger.Error().Err(err).Msg("couldn't find the specified config file") - } - return err + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/store/pkg/config/parser/parse.go b/extensions/store/pkg/config/parser/parse.go index eee1521239b..0b2016dab53 100644 --- a/extensions/store/pkg/config/parser/parse.go +++ b/extensions/store/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/store/pkg/config" "github.com/owncloud/ocis/extensions/store/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/store/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -20,6 +21,8 @@ func ParseConfig(cfg *config.Config) error { _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } diff --git a/extensions/thumbnails/pkg/command/server.go b/extensions/thumbnails/pkg/command/server.go index 7a82d799224..9b11f445ea6 100644 --- a/extensions/thumbnails/pkg/command/server.go +++ b/extensions/thumbnails/pkg/command/server.go @@ -32,12 +32,7 @@ func Server(cfg *config.Config) *cli.Command { }, }, Before: func(c *cli.Context) error { - err := parser.ParseConfig(cfg) - if err != nil { - logger := logging.Configure(cfg.Service.Name, &config.Log{}) - logger.Error().Err(err).Msg("couldn't find the specified config file") - } - return err + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/thumbnails/pkg/config/parser/parse.go b/extensions/thumbnails/pkg/config/parser/parse.go index b0ad25d8125..5c542917507 100644 --- a/extensions/thumbnails/pkg/config/parser/parse.go +++ b/extensions/thumbnails/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/thumbnails/pkg/config" "github.com/owncloud/ocis/extensions/thumbnails/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/thumbnails/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -20,6 +21,8 @@ func ParseConfig(cfg *config.Config) error { _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } diff --git a/extensions/web/pkg/command/server.go b/extensions/web/pkg/command/server.go index 2677a422cc8..41216330f8e 100644 --- a/extensions/web/pkg/command/server.go +++ b/extensions/web/pkg/command/server.go @@ -32,12 +32,7 @@ func Server(cfg *config.Config) *cli.Command { }, }, Before: func(c *cli.Context) error { - err := parser.ParseConfig(cfg) - if err != nil { - logger := logging.Configure(cfg.Service.Name, &config.Log{}) - logger.Error().Err(err).Msg("couldn't find the specified config file") - } - return err + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/web/pkg/config/parser/parse.go b/extensions/web/pkg/config/parser/parse.go index bbb8ea6dab6..e5f07184fff 100644 --- a/extensions/web/pkg/config/parser/parse.go +++ b/extensions/web/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/web/pkg/config" "github.com/owncloud/ocis/extensions/web/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/web/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -20,6 +21,8 @@ func ParseConfig(cfg *config.Config) error { _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } diff --git a/extensions/webdav/pkg/command/server.go b/extensions/webdav/pkg/command/server.go index a54db5698da..d91bc270e85 100644 --- a/extensions/webdav/pkg/command/server.go +++ b/extensions/webdav/pkg/command/server.go @@ -31,12 +31,7 @@ func Server(cfg *config.Config) *cli.Command { }, }, Before: func(c *cli.Context) error { - err := parser.ParseConfig(cfg) - if err != nil { - logger := logging.Configure(cfg.Service.Name, &config.Log{}) - logger.Error().Err(err).Msg("couldn't find the specified config file") - } - return err + return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/extensions/webdav/pkg/config/parser/parse.go b/extensions/webdav/pkg/config/parser/parse.go index 941966fe696..f5ab2ae810a 100644 --- a/extensions/webdav/pkg/config/parser/parse.go +++ b/extensions/webdav/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/webdav/pkg/config" "github.com/owncloud/ocis/extensions/webdav/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/webdav/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -20,6 +21,8 @@ func ParseConfig(cfg *config.Config) error { _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } diff --git a/extensions/webdav/pkg/metrics/metrics.go b/extensions/webdav/pkg/metrics/metrics.go index ea5f9626e11..d0869cdf829 100644 --- a/extensions/webdav/pkg/metrics/metrics.go +++ b/extensions/webdav/pkg/metrics/metrics.go @@ -28,8 +28,8 @@ func New() *Metrics { BuildInfo: prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: Namespace, Subsystem: Subsystem, - Name: "build_info", - Help: "Build Information", + Name: "build_info", + Help: "Build Information", }, []string{"version"}), } From 9338474f17964c6030c7f0cf8b03043e074f7a39 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Wed, 20 Apr 2022 13:17:35 +0200 Subject: [PATCH 14/17] apply config loading to ocis-pkg --- ocis-pkg/config/config.go | 2 +- ocis-pkg/config/parser/parse.go | 5 +++++ ocis-pkg/sync/cache.go | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index 6cd48fe4230..1a7277a89c9 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -75,5 +75,5 @@ type Config struct { Thumbnails *thumbnails.Config `yaml:"thumbnails"` WebDAV *webdav.Config `yaml:"webdav"` - ConfigFile string `yaml:"-" env:"OCIS_CONFIG_FILE" desc:"config file to be used by the oCIS runtime"` + ConfigFile string `yaml:"-" env:"OCIS_CONFIG_FILE" desc:"config file to be used by the oCIS runtime and extensions"` } diff --git a/ocis-pkg/config/parser/parse.go b/ocis-pkg/config/parser/parse.go index 179963a5e5e..a988adcca20 100644 --- a/ocis-pkg/config/parser/parse.go +++ b/ocis-pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" + "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/shared" ) @@ -17,6 +18,10 @@ func ParseConfig(cfg *config.Config) error { _, err := config.BindSourcesToStructs("ocis", cfg.ConfigFile, cfg.ConfigFile != config.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := log.NewLogger( + log.Name("oCIS"), + ) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } diff --git a/ocis-pkg/sync/cache.go b/ocis-pkg/sync/cache.go index e63690b35d8..9638a93ef79 100644 --- a/ocis-pkg/sync/cache.go +++ b/ocis-pkg/sync/cache.go @@ -11,8 +11,8 @@ type Cache struct { // capacity and length have to be the first words // in order to be 64-aligned on 32-bit architectures. capacity, length uint64 // access atomically - entries sync.Map - pool sync.Pool + entries sync.Map + pool sync.Pool } // CacheEntry represents an entry on the cache. You can type assert on V. From 6aacbb4d4435c1b13846fd085841157151e67dfe Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 26 Apr 2022 10:49:03 +0200 Subject: [PATCH 15/17] add hidden flag --- extensions/accounts/pkg/command/server.go | 4 ++++ extensions/audit/pkg/command/server.go | 4 ++++ extensions/glauth/pkg/command/server.go | 4 ++++ extensions/graph-explorer/pkg/command/server.go | 4 ++++ extensions/graph/pkg/command/server.go | 4 ++++ extensions/idm/pkg/command/server.go | 4 ++++ extensions/idp/pkg/command/server.go | 4 ++++ extensions/nats/pkg/command/server.go | 4 ++++ extensions/notifications/pkg/command/server.go | 4 ++++ extensions/ocs/pkg/command/server.go | 4 ++++ extensions/proxy/pkg/command/server.go | 4 ++++ extensions/settings/pkg/command/server.go | 4 ++++ extensions/store/pkg/command/server.go | 4 ++++ extensions/thumbnails/pkg/command/server.go | 4 ++++ extensions/web/pkg/command/server.go | 4 ++++ extensions/webdav/pkg/command/server.go | 4 ++++ 16 files changed, 64 insertions(+) diff --git a/extensions/accounts/pkg/command/server.go b/extensions/accounts/pkg/command/server.go index 0a3ba93ea57..f15576d96e0 100644 --- a/extensions/accounts/pkg/command/server.go +++ b/extensions/accounts/pkg/command/server.go @@ -31,6 +31,10 @@ func Server(cfg *config.Config) *cli.Command { Usage: "config file to be loaded by the extension", Destination: &cfg.ConfigFile, }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) diff --git a/extensions/audit/pkg/command/server.go b/extensions/audit/pkg/command/server.go index 3c4b540021f..6a9dc614094 100644 --- a/extensions/audit/pkg/command/server.go +++ b/extensions/audit/pkg/command/server.go @@ -28,6 +28,10 @@ func Server(cfg *config.Config) *cli.Command { Usage: "config file to be loaded by the extension", Destination: &cfg.ConfigFile, }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) diff --git a/extensions/glauth/pkg/command/server.go b/extensions/glauth/pkg/command/server.go index f7d1277bb44..ff551ae133c 100644 --- a/extensions/glauth/pkg/command/server.go +++ b/extensions/glauth/pkg/command/server.go @@ -34,6 +34,10 @@ func Server(cfg *config.Config) *cli.Command { Usage: "config file to be loaded by the extension", Destination: &cfg.ConfigFile, }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) diff --git a/extensions/graph-explorer/pkg/command/server.go b/extensions/graph-explorer/pkg/command/server.go index 5950ab33a36..97552b032d0 100644 --- a/extensions/graph-explorer/pkg/command/server.go +++ b/extensions/graph-explorer/pkg/command/server.go @@ -29,6 +29,10 @@ func Server(cfg *config.Config) *cli.Command { Usage: "config file to be loaded by the extension", Destination: &cfg.ConfigFile, }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) diff --git a/extensions/graph/pkg/command/server.go b/extensions/graph/pkg/command/server.go index b62089d96c5..9be7fa218c8 100644 --- a/extensions/graph/pkg/command/server.go +++ b/extensions/graph/pkg/command/server.go @@ -29,6 +29,10 @@ func Server(cfg *config.Config) *cli.Command { Usage: "config file to be loaded by the extension", Destination: &cfg.ConfigFile, }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) diff --git a/extensions/idm/pkg/command/server.go b/extensions/idm/pkg/command/server.go index 7aed37e8eb8..f629c3dc6e8 100644 --- a/extensions/idm/pkg/command/server.go +++ b/extensions/idm/pkg/command/server.go @@ -35,6 +35,10 @@ func Server(cfg *config.Config) *cli.Command { Usage: "config file to be loaded by the extension", Destination: &cfg.ConfigFile, }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) diff --git a/extensions/idp/pkg/command/server.go b/extensions/idp/pkg/command/server.go index 087b769a773..9ea1da17e07 100644 --- a/extensions/idp/pkg/command/server.go +++ b/extensions/idp/pkg/command/server.go @@ -29,6 +29,10 @@ func Server(cfg *config.Config) *cli.Command { Usage: "config file to be loaded by the extension", Destination: &cfg.ConfigFile, }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) diff --git a/extensions/nats/pkg/command/server.go b/extensions/nats/pkg/command/server.go index d6959215280..26474e18f11 100644 --- a/extensions/nats/pkg/command/server.go +++ b/extensions/nats/pkg/command/server.go @@ -26,6 +26,10 @@ func Server(cfg *config.Config) *cli.Command { Usage: "config file to be loaded by the extension", Destination: &cfg.ConfigFile, }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) diff --git a/extensions/notifications/pkg/command/server.go b/extensions/notifications/pkg/command/server.go index 951d027fd56..cb96fb654c2 100644 --- a/extensions/notifications/pkg/command/server.go +++ b/extensions/notifications/pkg/command/server.go @@ -27,6 +27,10 @@ func Server(cfg *config.Config) *cli.Command { Usage: "config file to be loaded by the extension", Destination: &cfg.ConfigFile, }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) diff --git a/extensions/ocs/pkg/command/server.go b/extensions/ocs/pkg/command/server.go index 8ff42c3122f..34c8beabee0 100644 --- a/extensions/ocs/pkg/command/server.go +++ b/extensions/ocs/pkg/command/server.go @@ -30,6 +30,10 @@ func Server(cfg *config.Config) *cli.Command { Usage: "config file to be loaded by the extension", Destination: &cfg.ConfigFile, }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) diff --git a/extensions/proxy/pkg/command/server.go b/extensions/proxy/pkg/command/server.go index 7107d91f8e5..b51cc895a57 100644 --- a/extensions/proxy/pkg/command/server.go +++ b/extensions/proxy/pkg/command/server.go @@ -49,6 +49,10 @@ func Server(cfg *config.Config) *cli.Command { Usage: "config file to be loaded by the extension", Destination: &cfg.ConfigFile, }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) diff --git a/extensions/settings/pkg/command/server.go b/extensions/settings/pkg/command/server.go index 017e35c8132..a5f091e017c 100644 --- a/extensions/settings/pkg/command/server.go +++ b/extensions/settings/pkg/command/server.go @@ -30,6 +30,10 @@ func Server(cfg *config.Config) *cli.Command { Usage: "config file to be loaded by the extension", Destination: &cfg.ConfigFile, }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) diff --git a/extensions/store/pkg/command/server.go b/extensions/store/pkg/command/server.go index e0eca9582ca..2db6888ab5f 100644 --- a/extensions/store/pkg/command/server.go +++ b/extensions/store/pkg/command/server.go @@ -30,6 +30,10 @@ func Server(cfg *config.Config) *cli.Command { Usage: "config file to be loaded by the extension", Destination: &cfg.ConfigFile, }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) diff --git a/extensions/thumbnails/pkg/command/server.go b/extensions/thumbnails/pkg/command/server.go index 9b11f445ea6..2b1cb641abd 100644 --- a/extensions/thumbnails/pkg/command/server.go +++ b/extensions/thumbnails/pkg/command/server.go @@ -30,6 +30,10 @@ func Server(cfg *config.Config) *cli.Command { Usage: "config file to be loaded by the extension", Destination: &cfg.ConfigFile, }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) diff --git a/extensions/web/pkg/command/server.go b/extensions/web/pkg/command/server.go index 41216330f8e..39e0b282f50 100644 --- a/extensions/web/pkg/command/server.go +++ b/extensions/web/pkg/command/server.go @@ -30,6 +30,10 @@ func Server(cfg *config.Config) *cli.Command { Usage: "config file to be loaded by the extension", Destination: &cfg.ConfigFile, }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) diff --git a/extensions/webdav/pkg/command/server.go b/extensions/webdav/pkg/command/server.go index d91bc270e85..47385cde033 100644 --- a/extensions/webdav/pkg/command/server.go +++ b/extensions/webdav/pkg/command/server.go @@ -29,6 +29,10 @@ func Server(cfg *config.Config) *cli.Command { Usage: "config file to be loaded by the extension", Destination: &cfg.ConfigFile, }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) From bc2de7e22f053d4b946952d2b49d367f402e0b0d Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 26 Apr 2022 10:50:01 +0200 Subject: [PATCH 16/17] define slice in place --- ocis-pkg/config/helpers.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ocis-pkg/config/helpers.go b/ocis-pkg/config/helpers.go index 693ed3a6bf1..fa59776da16 100644 --- a/ocis-pkg/config/helpers.go +++ b/ocis-pkg/config/helpers.go @@ -15,14 +15,13 @@ var ( // BindSourcesToStructs assigns any config value from a config file / env variable to struct `dst`. Its only purpose // is to solely modify `dst`, not dealing with the config structs; and do so in a thread safe manner. func BindSourcesToStructs(extension, ConfigFile string, failOnLoadErr bool, dst interface{}) (*gofig.Config, error) { - sources := []string{ConfigFile} cnf := gofig.NewWithOptions(extension) cnf.WithOptions(func(options *gofig.Options) { options.DecoderConfig.TagName = decoderConfigTagName }) cnf.AddDriver(gooyaml.Driver) - err := cnf.LoadFiles(sources...) + err := cnf.LoadFiles([]string{ConfigFile}...) if err != nil && failOnLoadErr { // fail only if config file was explicitly set return nil, err From 63ff2d1430365d45ff5d45d2982c441de83a3601 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 26 Apr 2022 10:54:33 +0200 Subject: [PATCH 17/17] update docs --- docs/ocis/config.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/ocis/config.md b/docs/ocis/config.md index 6f7ecc75e5c..efb81e642eb 100644 --- a/docs/ocis/config.md +++ b/docs/ocis/config.md @@ -44,9 +44,13 @@ Let's explore with examples this approach. - docker images: `/etc/ocis/` - binary releases: `$HOME/.ocis/config/` -followed by the extension name. When configuring the proxy, a valid full path that will get loaded is `$HOME/.ocis/config/proxy.yaml`. +followed by the `.yaml`, eg `proxy.yaml` for the extension configuration. You also can put an `ocis.yaml` config file to the expected loading location to use a single config file. -You can always set another directory as config path in the environment variable `OCIS_CONFIG_DIR`. +You can set another directory as config path in the environment variable `OCIS_CONFIG_DIR`. It will then pick the same file names, but from the folder you configured. + +Another option is to set the `--ocis-config-file` option for the runtime `ocis server --ocis-config-file /path/to/ocis.yaml` or for an extension without runtime `ocis proxy --ocis-config-file /path/to/ocis.yaml server`. For both cases, you can achieve the same by setting the environment variable `OCIS_CONFIG_FILE=/path/to/ocis.yaml`. + +For unsupervised extensions (without runtime), you also can specify a `--config-file` flag to use a non default config file, eg. `ocis proxy server --config-file /path/to/proxy.yaml`. An alternative is to set the extension specific configuration file path environment variable, e.g. `PROXY_CONFIG_FILE=/path/to/proxy.yaml` for the proxy extension. #### Only config files