33 lines
705 B
Go
33 lines
705 B
Go
package agent
|
|
|
|
import (
|
|
"os"
|
|
|
|
"ollie/util"
|
|
)
|
|
|
|
// AgentsDirs returns all agent directories. Currently just the default.
|
|
func AgentsDirs() []string {
|
|
return []string{util.CfgDir() + "/agents"}
|
|
}
|
|
|
|
// AgentConfigPath resolves the config file path for a named agent.
|
|
func AgentConfigPath(agentsDir, name string) string {
|
|
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
|
|
}
|