-
-
Notifications
You must be signed in to change notification settings - Fork 60
Add loader_options, use to add ejson_namespace nil support #126
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
Conversation
This is supported by the env and doppler loaders. EJSON is the odd one out
|
Thanks for the proposal! Agree, it makes. Though I'm not sure I think, we should introduce an API to pass custom options to loaders. Smth like: class MyConfig < Anyway::Config
loader_options ejson_prefix: ""
end |
|
Hey @palkan, yeah I prefer that, certainly more modular for those adding their own loaders. I went with Introduced some low level tests but I wasn't sure how best to write tests for Config since right now only the EJSON loader uses this functionality. I also used If you want to take this PR over at this point, feel free to make your own changes. |
palkan
left a comment
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.
Thanks! LGTM.
Please, take a look at the comments and CI failures.
spec/loaders/ejson_spec.rb
Outdated
| end | ||
|
|
||
| it "parses default EJSON" do | ||
| # It also includes the public key, but we don't care about it |
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.
Maybe, it makes sense to remove "_public_key" from the resulting hash to avoid it's potential leakage?
lib/anyway/config.rb
Outdated
|
|
||
| return @loader_options if instance_variable_defined?(:@loader_options) | ||
|
|
||
| @loader_options = {} |
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, we also need to take care of inheritance (see other class-level configuration methods)
lib/anyway/loaders/ejson.rb
Outdated
| next unless secrets_hash | ||
|
|
||
| config_hash = secrets_hash[name] | ||
| config_hash = if ejson_namespace.nil? |
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 perhaps false would be a better option actually.
Agree, false sounds better. Let's just replace the check with unless ejson_namespace to handle both nil and false
Being a public key it should not be sensitive, but it also serves no purpose to expose it to the user.
|
All changes made and hopefully CI passes now (I don't have JRuby to test against so somewhat coding blind there) |
|
Thanks! I'll take care of linting issues. |
What is the purpose of this pull request?
Ensures that EJSON, like the ENV and Doppler loaders, supports not utilising the namespaced configuration feature.
Happy to follow up with tests and docs if you think this is reasonable!
Is there anything you'd like reviewers to focus on?
To keep the API surface small I have used theenv_prefixkeyword, even though its not really a prefix in this context (JSON nested keys). I figure consistency is preferable.Checklist