From 41abe71b4688596478299b3c5189619d9a7756f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 1 Apr 2022 11:43:29 +0000 Subject: [PATCH 1/3] make config dir configurable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- ocis-pkg/config/helpers.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ocis-pkg/config/helpers.go b/ocis-pkg/config/helpers.go index 91fc13fb6..43d239661 100644 --- a/ocis-pkg/config/helpers.go +++ b/ocis-pkg/config/helpers.go @@ -31,14 +31,23 @@ var ( func DefaultConfigSources(filename string, drivers []string) []string { var sources []string - for i := range defaultLocations { - dirFS := os.DirFS(defaultLocations[i]) + locations := []string{} + if os.Getenv("OCIS_CONFIG_DIR") != "" { + // 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...) + } + + 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(defaultLocations[i], matched[j]) + matched[j] = filepath.Join(locations[i], matched[j]) } } sources = append(sources, matched...) From 34fc38683b04cb4cb39ca88c3d811e30b3129ed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 1 Apr 2022 11:47:29 +0000 Subject: [PATCH 2/3] add changelog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- changelog/unreleased/make-config-dir-configurable.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/unreleased/make-config-dir-configurable.md diff --git a/changelog/unreleased/make-config-dir-configurable.md b/changelog/unreleased/make-config-dir-configurable.md new file mode 100644 index 000000000..a310b7f09 --- /dev/null +++ b/changelog/unreleased/make-config-dir-configurable.md @@ -0,0 +1,5 @@ +Enhancement: make config dir configurable + +We have added an `OCIS_CONFIG_DIR` environment variable the will take precedence over the default `/etc/ocis`, `~/.ocis` and `.config` locations. When it is set the default locations will be ignored and only the configuration files in that directory will be read. + +https://github.com/owncloud/ocis/pull/3440 From b9b614ec29dbb8d249a56e3a8f3290d2cfd3670a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 1 Apr 2022 16:05:24 +0200 Subject: [PATCH 3/3] store env var Co-authored-by: kobergj --- ocis-pkg/config/helpers.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ocis-pkg/config/helpers.go b/ocis-pkg/config/helpers.go index 43d239661..6eac89847 100644 --- a/ocis-pkg/config/helpers.go +++ b/ocis-pkg/config/helpers.go @@ -32,7 +32,8 @@ func DefaultConfigSources(filename string, drivers []string) []string { var sources []string locations := []string{} - if os.Getenv("OCIS_CONFIG_DIR") != "" { + 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 {