Open fredbi opened 4 years ago
// 1. Defaults: none at the moment (defaults are set together with flags)
// 2. Override via environment variables
// NOTE:
// Since there is no viper env prefix set, we use raw viper key names from env vars, i.e. $CONTEXT will set
// the context config key, something that is hard-wired below as DATAMON_CONTEXT...
//
// Setting a prefix like "DATAMON" would be impractical, since DATAMON_CONFIG (the location of the local config file)
// would conflict with the Config confif key (the bucket of the remote config).
//
// TODO: IMHO we should rename the 'config' key as 'remoteConfig', remove the DATAMON_CONTEXT code below and use
// viper.SetEnvPrefix("DATAMON").
//
Agree that this is drifting away from the original intent of this PR. Let's have this one merged and move on forward.
My suggestion was merely about exploiting the capabilities of spf13/viper regarding env vars.
Just a word to say that viper is quite popular in goland, notwithstanding the qualities of your python references. My comment (now removed and traced as a new github issue) as intended to provide you with some understanding of the viper-way of doing it.
Not wanting to play the cargo cult developer here, not wanting either to waste to much time on this.
My point with this comment, was that (i) atm, it just doesn't work as a regular user would expect (principle of no surprise broken) and (ii) Since we've adopted the cobra/viper/pflags triptych, I'd favor ways in line with what the lib is suggesting us
i'd like to make specific mention of the way the GOOGLE_APPLICATION_CREDENTIALS
(or whatever it is) variable gets used: it's not just read by cobra. it's read by the google-cloud-go library. note in cmd/
where the golang binary sets the variable if its not set while the otherwise standard non-standard of spf13's cobra and viper are reading in and assembling the config from defaults.
this data path around the golang binary (insomuch as the OS globals are used rather, even, than a global in a golang package) is troubling enough in its own right that i don't think we can make any universal decisions about env vars without first figuring out how to pass the token usually obtained via gcloud
+browser-based oauth dance (or stored in a Secret on k8s) to google-cloud-go without using an environment variable.
or
we could at least ensure that datamon only writes to GOOGLE_APPLICATION_CREDENTIALS
, just choosing a different name for the READ op constituted by viper/cobra. at least then we have some tighter constraint on this register machine (to be greatly exaggerated) the current google-cloud-go usage is asking the operating system to function as.
Tracing here a thread in PR, for follow-up: