diff --git a/config/config.go b/config/config.go index 973d8459..7207bb7f 100644 --- a/config/config.go +++ b/config/config.go @@ -21,8 +21,6 @@ import ( "github.com/choria-io/go-choria/puppet" ) -var forceDotParse bool - // Config represents Choria cofnfiguration // // NOTE: When adding or updating doc strings please run `go generate` in the root of the repository @@ -96,6 +94,9 @@ type Config struct { // ConfigFile is the main configuration that got parsed ConfigFile string + // The system-wide configuration directory. Plugins are loaded from there + SystemConfigDirectory string + // ParsedFiles is a list of all files parsed to create the current config ParsedFiles []string @@ -408,23 +409,24 @@ func (c *Config) UnParsedOptions() map[string]string { } func (c *Config) dotdDir() string { - if !forceDotParse { - home, err := iu.HomeDir() - if err == nil { - if strings.HasPrefix(c.ConfigFile, home) { - return "" - } - } - } - - return filepath.Join(filepath.Dir(c.ConfigFile), "plugin.d") + return filepath.Join(c.SystemConfigDirectory, "plugin.d") } func newConfig() *Config { + scd := "" + if iu.FileExist("/etc/choria") { + scd = "/etc/choria" + } else if iu.FileExist("/usr/local/etc/choria") { + scd = "/usr/local/etc/choria" + } else if iu.FileExist("C:\\ProgramData\\choria\\etc") { + scd = "C:\\ProgramData\\choria\\etc" + } + m := &Config{ - Choria: newChoria(), - rawOpts: make(map[string]string), - Puppet: puppet.New(), + Choria: newChoria(), + rawOpts: make(map[string]string), + Puppet: puppet.New(), + SystemConfigDirectory: scd, } err := confkey.SetStructDefaults(m) diff --git a/config/config_test.go b/config/config_test.go index db129204..3dc6c214 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -65,14 +65,12 @@ var _ = Describe("Choria/Config", func() { var c *Config var err error - forceDotParse = true if runtime.GOOS == "windows" { c, err = NewConfig("testdata/choria_windows.cfg") } else { c, err = NewConfig("testdata/choria.cfg") } Expect(err).ToNot(HaveOccurred()) - forceDotParse = false Expect(c.Choria.NetworkWriteDeadline).To(Equal(10 * time.Second)) Expect(c.Registration).To(Equal([]string{"foo"}))