39 lines
836 B
Go
39 lines
836 B
Go
package agent
|
|
|
|
import (
|
|
"os"
|
|
|
|
"ollie/paths"
|
|
)
|
|
|
|
// AgentsDirs returns all agent directories. Currently just the default.
|
|
func AgentsDirs() []string {
|
|
return []string{paths.CfgDir() + "/agents"}
|
|
}
|
|
|
|
// AgentConfigPath resolves the config file path for a named agent.
|
|
func AgentConfigPath(agentsDir, name string) string {
|
|
for _, dir := range AgentsDirs() {
|
|
p := dir + "/" + name + ".json"
|
|
if _, err := os.Stat(p); err == nil {
|
|
return p
|
|
}
|
|
}
|
|
return agentsDir + "/" + name + ".json"
|
|
}
|
|
|
|
// LoadConfig loads an agent configuration file by profile name.
|
|
func LoadConfig(agentsDir, name string, open func(string) (*os.File, error)) *AgentConfig {
|
|
if open == nil {
|
|
open = os.Open
|
|
}
|
|
path := AgentConfigPath(agentsDir, name)
|
|
f, err := open(path)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
defer f.Close()
|
|
cfg, _ := Load(f)
|
|
return cfg
|
|
}
|