-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optionally use Environment Variables for Config #57
Conversation
That's great - thanks Steve! Will check this out ASAP 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! A few minor comments.
I think it's possible the ./seqfwd config -k <key> -v <value>
command will now copy the contents of environment variables into the config file, which we might not want.
@@ -45,8 +48,28 @@ public static SeqForwarderConfig ReadOrInit(string filename) | |||
} | |||
|
|||
var content = File.ReadAllText(filename); | |||
return JsonConvert.DeserializeObject<SeqForwarderConfig>(content, SerializerSettings) ?? | |||
throw new ArgumentException("Configuration content is null."); | |||
var seqForwarderConfig = JsonConvert.DeserializeObject<SeqForwarderConfig>(content, SerializerSettings); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
combinedConfig
, possibly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think throwing when DeserializeObject
returns null might be safer here, since it'd indicate either a bug or malformed configuration file, both of which we might want to know about. The later check won't be triggered if any environment variable is set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. I thought the config file might be optional but on second thoughts just the env vars are. I've made these two changes now (1be8759)
For the Config command, I've changed it so it only reads from the config file (env vars aren't loaded). More what the user expects? (6744940) |
Looks great, thanks Steve 👍 |
Hi Nick
I've had a go at implementing Environment Variables for the config. Hopefully it's what you had in mind but you may have a better strategy. Here's some explanations for the pull request;
Example Environment Variable names:
FORWARDER_OUTPUT_RAWPAYLOADLIMITBYTES
FORWARDER_DIAGNOSTICS_INTERNALLOGGINGLEVEL
Its using the
Microsoft.Extensions.Configuration.ConfigurationBuilder
to load the Environment Variables and theGetValue()
method to get each variable the right type.Its renamed property
EncodedApiKey
toApiKey
so that the environment variableFORWARDER_OUTPUT_APIKEY
would match. (Also updated the check that excludes it inConfigCommand
).With these changes, the Config command lists the config file with environment variables overwritten, and writes update the config file with any changes as well as any overwritten environment variables. Not sure if that is the expectation.
If you have ideas for improvement I'm all ears. If you think a different way would be better that's ok too.
Addresses #55