2020-11-30 09:37:17 +00:00
|
|
|
package csconfig
|
|
|
|
|
2021-03-24 17:16:17 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
2020-11-30 09:37:17 +00:00
|
|
|
type ConfigurationPaths struct {
|
|
|
|
ConfigDir string `yaml:"config_dir"`
|
|
|
|
DataDir string `yaml:"data_dir,omitempty"`
|
|
|
|
SimulationFilePath string `yaml:"simulation_path,omitempty"`
|
|
|
|
HubIndexFile string `yaml:"index_path,omitempty"` //path of the .index.json
|
|
|
|
HubDir string `yaml:"hub_dir,omitempty"`
|
2021-08-25 09:43:29 +00:00
|
|
|
PluginDir string `yaml:"plugin_dir,omitempty"`
|
|
|
|
NotificationDir string `yaml:"notification_dir,omitempty"`
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
2021-03-24 17:16:17 +00:00
|
|
|
|
|
|
|
func (c *Config) LoadConfigurationPaths() error {
|
|
|
|
var err error
|
|
|
|
if c.ConfigPaths == nil {
|
|
|
|
return fmt.Errorf("no configuration paths provided")
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.ConfigPaths.DataDir == "" {
|
|
|
|
return fmt.Errorf("please provide a data directory with the 'data_dir' directive in the 'config_paths' section")
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.ConfigPaths.HubDir == "" {
|
|
|
|
c.ConfigPaths.HubDir = filepath.Clean(c.ConfigPaths.ConfigDir + "/hub")
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.ConfigPaths.HubIndexFile == "" {
|
|
|
|
c.ConfigPaths.HubIndexFile = filepath.Clean(c.ConfigPaths.HubDir + "/.index.json")
|
|
|
|
}
|
|
|
|
|
|
|
|
var configPathsCleanup = []*string{
|
|
|
|
&c.ConfigPaths.HubDir,
|
|
|
|
&c.ConfigPaths.HubIndexFile,
|
|
|
|
&c.ConfigPaths.ConfigDir,
|
|
|
|
&c.ConfigPaths.DataDir,
|
|
|
|
&c.ConfigPaths.SimulationFilePath,
|
2021-08-25 09:43:29 +00:00
|
|
|
&c.ConfigPaths.PluginDir,
|
|
|
|
&c.ConfigPaths.NotificationDir,
|
2021-03-24 17:16:17 +00:00
|
|
|
}
|
|
|
|
for _, k := range configPathsCleanup {
|
|
|
|
if *k == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
*k, err = filepath.Abs(*k)
|
|
|
|
if err != nil {
|
2023-06-23 12:04:58 +00:00
|
|
|
return fmt.Errorf("failed to get absolute path of '%s': %w", *k, err)
|
2021-03-24 17:16:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|