Provide better 'bad key' value error message#1558
Conversation
lib/config_validator.rb
Outdated
There was a problem hiding this comment.
env will always be ENV since that is the default, and we don't set it to anything else. So, instead of this conditional, what do you think about updating the message in the warning method to say something like "You have invalid values (yes/no) for [bad keys] in config/application.yml or your environment. Please change them to true or false."?
|
Thanks for this PR, and congrats on your first GitHub pull request! Out of curiosity, can you please explain how you are configuring the environment? Are you not using |
|
Thanks, I'll take your suggestion. My edits are partly out of ignorance about how things are working, but I hit this issue and spent time trying to figure it out so I thought I'd save someone else by changing the message. I configured this on a CentOS 7 VM using your instructions in README. I just wanted to try it locally to see if I could get it up and running. I hit a couple of things that may be environment-related, but I got it going. BTW, the environment variable I hit this on is IMSETTINGS_INTEGRATE_DESKTOP (was set to 'yes'). I think this is a great idea for common authentication for government agencies and I hope it is well adopted. It would be a win-win for the agencies that use it and also the public users. |
|
Ah, I see. Thanks for the details. Do you want to take a stab at fixing that? If not, I'd be happy to work on it. |
|
Exactly, and sure, I'll take a stab at it. Thanks! |
|
Here's my stab at it - hopefully, I got it right. I notice that with the configuration settings, Figaro creates 2 environment variables, one with the setting name as the key and one with the key prefixed with "FIGARO_". If we're only interested in the configuration settings and not the other environment variables, then we can collect up the keys having both definitions (prefixed and not prefixed). These are the changes I've made. Prior to commit, I've tested this out by printing the key/value combinations I've found and I'm satisfied that we're getting only the configuration values for the application. I hope this is what you're looking for. |
lib/config_validator.rb
Outdated
There was a problem hiding this comment.
Was there a particular reason for switching to regex? It's almost twice as slow as checking the array. Can we do this instead?
%w[yes no].include?(env[key].strip.downcase)
lib/config_validator.rb
Outdated
There was a problem hiding this comment.
Can we rename the keys argument to env, since that is what is passed in?
spec/lib/config_validator_spec.rb
Outdated
There was a problem hiding this comment.
Single space after period?
spec/lib/config_validator_spec.rb
Outdated
There was a problem hiding this comment.
In order to test the stripping and downcasing, can you please add some more candidate keys, such as " YES" and "NO "?
|
thanks for your patience and suggestions: Was there a particular reason for switching to regex? It's almost twice as slow as checking the array. Can we do this instead? You're right. Can we rename the keys argument to env, since that is what is passed in? Yes Single space after period? Yup, I'm a student of when you put 2 spaces after sentences - hard habit to break. In order to test the stripping and downcasing, can you please add some more candidate keys, such as " YES" and "NO "? Added 2 relevant tests. Thanks! |
monfresh
left a comment
There was a problem hiding this comment.
Looks great. Thanks! Please squash your commits into one.
**Why**: - Current implementation looks at all environment variables, both those associated with application configuration and those that don't apply (e.g., IMSETTINGS_INTEGRATE_DESKTOP). Non-configuration settings with bad values will cause warnings. This change aims to target validation to only the configuration values. **How**: - Select keys (environment variable names) that have a 2nd definition prefixed with "FIGARO_" - these are the key/value pairs associated with application configuration. - Check values case insensitive, ignoring white space. - Add test cases.
14cb296 to
dad14d9
Compare
|
Thanks! Squash is done. |
Why:
yes/no values instead of true/false - prior message pointed
to application.yml instead of environment, wasting debug time
How:
come from environment instead
removed