From 932e19151076ee9f83acb0dfa1662ed9b72228c3 Mon Sep 17 00:00:00 2001 From: Michael Manganiello Date: Thu, 6 Apr 2023 20:53:03 -0300 Subject: [PATCH] Allow configuration files with yml extension If a `collector.yml` or `scrutiny.yml` configuration file is present, use it as long as a `.yaml` version is not available too. Fixes #79 --- collector/cmd/collector-metrics/collector-metrics.go | 8 +++++++- webapp/backend/cmd/scrutiny/scrutiny.go | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/collector/cmd/collector-metrics/collector-metrics.go b/collector/cmd/collector-metrics/collector-metrics.go index 39d0a49..2c9f709 100644 --- a/collector/cmd/collector-metrics/collector-metrics.go +++ b/collector/cmd/collector-metrics/collector-metrics.go @@ -30,8 +30,14 @@ func main() { os.Exit(1) } + configFilePath := "/opt/scrutiny/config/collector.yaml" + configFilePathAlternative := "/opt/scrutiny/config/collector.yml" + if !utils.FileExists(configFilePath) && utils.FileExists(configFilePathAlternative) { + configFilePath = configFilePathAlternative + } + //we're going to load the config file manually, since we need to validate it. - err = config.ReadConfig("/opt/scrutiny/config/collector.yaml") // Find and read the config file + err = config.ReadConfig(configFilePath) // Find and read the config file if _, ok := err.(errors.ConfigFileMissingError); ok { // Handle errors reading the config file //ignore "could not find config file" } else if err != nil { diff --git a/webapp/backend/cmd/scrutiny/scrutiny.go b/webapp/backend/cmd/scrutiny/scrutiny.go index 4d9f62f..ead9ff9 100644 --- a/webapp/backend/cmd/scrutiny/scrutiny.go +++ b/webapp/backend/cmd/scrutiny/scrutiny.go @@ -29,8 +29,14 @@ func main() { os.Exit(1) } + configFilePath := "/opt/scrutiny/config/scrutiny.yaml" + configFilePathAlternative := "/opt/scrutiny/config/scrutiny.yml" + if !utils.FileExists(configFilePath) && utils.FileExists(configFilePathAlternative) { + configFilePath = configFilePathAlternative + } + //we're going to load the config file manually, since we need to validate it. - err = config.ReadConfig("/opt/scrutiny/config/scrutiny.yaml") // Find and read the config file + err = config.ReadConfig(configFilePath) // Find and read the config file if _, ok := err.(errors.ConfigFileMissingError); ok { // Handle errors reading the config file //ignore "could not find config file" } else if err != nil {