61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package settings
|
|
|
|
import (
|
|
"log/slog"
|
|
"os"
|
|
"vctp/internal/utils"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
// SettingsYML struct holds various runtime data that is too cumbersome to specify via command line, eg replacement properties
|
|
type SettingsYML struct {
|
|
Settings struct {
|
|
/*
|
|
Replacements []struct {
|
|
Key string `yaml:"Key"`
|
|
Value string `yaml:"Value"`
|
|
} `yaml:"replacements"`
|
|
|
|
Omapi struct {
|
|
KeyName string `yaml:"key_name"`
|
|
KeySecret string `yaml:"key_secret"`
|
|
} `yaml:"omapi"`
|
|
*/
|
|
TenantsToFilter []string `yaml:"tenants_to_filter"`
|
|
NodeChargeClusters []string `yaml:"node_charge_clusters"`
|
|
SrmActiveActiveVms []string `yaml:"srm_activeactive_vms"`
|
|
VcenterAddresses []string `yaml:"vcenter_addresses"`
|
|
} `yaml:"settings"`
|
|
}
|
|
|
|
func ReadYMLSettings(logger *slog.Logger, settingsPath string) (SettingsYML, error) {
|
|
// Create config structure
|
|
var settings SettingsYML
|
|
|
|
// Check for empty filename
|
|
if len(settingsPath) == 0 {
|
|
return settings, nil
|
|
}
|
|
|
|
path := utils.GetFilePath(settingsPath)
|
|
|
|
// Open config file
|
|
file, err := os.Open(path)
|
|
if err != nil {
|
|
return settings, err
|
|
}
|
|
logger.Debug("Opened settings yaml file", "file_path", path)
|
|
defer file.Close()
|
|
|
|
// Init new YAML decode
|
|
d := yaml.NewDecoder(file)
|
|
|
|
// Start YAML decoding from file
|
|
if err := d.Decode(&settings); err != nil {
|
|
return settings, err
|
|
}
|
|
|
|
return settings, nil
|
|
}
|