Closed dylan-tock closed 8 months ago
@dylan-tock Thank you for adding the functionality!
One small thing - I noticed the build failed after I merged your changes. I fixed it by committing the go.sum
and go.mod
files. Could you pay attention to them next time? 🙏
@dylan-tock Thank you for adding the functionality! One small thing - I noticed the build failed after I merged your changes. I fixed it by committing the
go.sum
andgo.mod
files. Could you pay attention to them next time? 🙏
So very sorry about this. I thought I'd done so, but will pay more attention to it and do more local testing for future PRs.
Overview
This PR addresses the open issue requesting the ability to configure username/password via config file vs environment variables. This adds that ability, adds tests for the newly introduced functions, and refactors some of the configuration logic to make it more testable. I worked to make this as backward compatible as possible so not changes are needed to continue using Environment variables for configuration.
Changes
maxctrl_exporter.go
GetEnvVar()
function to encapsulate thevar := os.Getenv(name); if var == "" { var = defaultValue }
logic and moved all config setting via Environment Variables to a separate function.readConfigFile()
andparseConfigFile()
to read in a YAML file (by default, namedmaxctrl_exporter.yaml
, but changeable via Environment variable) and update the config based on that file. The config file will have a higher priority than Environment variables.maxctrl_exporter_test.go
Added tests for functions newly added to
maxctrl_exporter.go
. Added a cheeky Copyright line (along with Apache 2.0 license block) asMakefile.common
was checking that one existed. I added my name since I wasn't comfortable adding the names of anyone else.Makefile.common
Added a verbose option to the
common-test
block to provide more detailed testing output, specifically the names of tests that passed/failed.maxctrl_exporter.yaml.example
An example file containing configurable parameters. To guard against anyone accidentally copying this to
maxctrl_exporter.yaml
and checking it into git, I also addedmaxctrl_exporter.yaml
to the.gitignore
file.