Merge pull request #3440 from owncloud/make-config-dir-configurable

Make config dir configurable via `OCIS_CONFIG_DIR` env var
This commit is contained in:
Jörn Friedrich Dreyer
2022-04-01 21:56:00 +02:00
committed by GitHub
2 changed files with 18 additions and 3 deletions
@@ -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
+13 -3
View File
@@ -31,14 +31,24 @@ var (
func DefaultConfigSources(filename string, drivers []string) []string {
var sources []string
for i := range defaultLocations {
dirFS := os.DirFS(defaultLocations[i])
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...)
}
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...)