Files
vctp2/internal/settings/settings.go
Nathan Coad 3501967c9e
Some checks are pending
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
continuous-integration/drone/push Build is passing
add ability to store/create encrypted vcenter password
2024-09-27 17:02:02 +10:00

50 lines
1.1 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 {
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
}