add settings yaml
Some checks are pending
continuous-integration/drone/push Build is passing
CI / Lint (push) Waiting to run
CI / Test (push) Waiting to run
CI / End-to-End (push) Waiting to run
CI / Publish Docker (push) Blocked by required conditions

This commit is contained in:
2024-09-26 17:24:36 +10:00
parent 44c4bb2d66
commit dcbbff830d
7 changed files with 128 additions and 19 deletions

View File

@@ -0,0 +1,60 @@
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
}