Env vars aren't validated
Opened this issue · 0 comments
jacobweinstock commented
Env vars are not validated like cli flags are.
Expected Behaviour
Env vars should be validated just like cli flags are.
Current Behaviour
A bad env var that wouldn't pass the cli flag validation could cause unexpected behavior.
For example:
# cli flag validation
❯ go run main.go server --bmcTimeout 60
Error: invalid argument "60" for "--bmcTimeout" flag: time: missing unit in duration "60"
Usage:
pbnj server [flags]
Flags:
--bmcTimeout duration Timeout for BMC calls (default 15s)
--enableAuthz enable Authz middleware. Configure with configuration file details
--enableHTTP enable the HTTP server
-h, --help help for server
--hsKey string HS key
--metricsListenAddr string metrics server listen address (default ":8080")
--port string grpc server port (default "50051")
--rsPubKey string RS public key
Global Flags:
--config string config file (default is pbnj.yaml)
--logLevel string log level (default is info (default "info")
invalid argument "60" for "--bmcTimeout" flag: time: missing unit in duration "60"
exit status 1
# no validation for env var. The server starts up with the bmc timeout set to 0
PBNJ_BMCTIMEOUT=60 go run main.go server
{"level":"info","ts":1624559879.264104,"caller":"cmd/server.go:97","msg":"debugging","service":"github.com/tinkerbell/pbnj","timeout":0,"timeout_string":"0s"}
{"level":"info","ts":1624559879.2745972,"caller":"grpcsvr/server.go:129","msg":"starting PBnJ gRPC server","service":"github.com/tinkerbell/pbnj"}
Possible Solution
Steps to Reproduce (for bugs)
Context
Your Environment
-
Operating System and version (e.g. Linux, Windows, MacOS):
-
How are you running Tinkerbell? Using Vagrant & VirtualBox, Vagrant & Libvirt, on Packet using Terraform, or give details:
-
Link to your project or a code example to reproduce issue: