Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#2173) Load plugins configuration from the system directory #2174

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}))
Expand Down
Loading