Skip to content
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

Blacklist Config Values #135

Merged
merged 2 commits into from
Oct 26, 2017
Merged

Blacklist Config Values #135

merged 2 commits into from
Oct 26, 2017

Conversation

jntullo
Copy link

@jntullo jntullo commented Oct 19, 2017

Proposed solution to resolve #134

Rather than rescuing an error, blacklist the :system and :display values. Not allowing the :display value to be called will resolve issues with the config being displayed in the console output, and removing the call to :system removes the need for the rescue block.

cc: @himdel @chrisarcand

@miq-bot add_label bug
@miq-bot assign @abellotti

@himdel
Copy link
Contributor

himdel commented Oct 19, 2017

@jntullo I don't think this is a good solution.

As mentioned in the issue, this is not about 2 methods. This is about every method defined on Object, OpenStruct or Config::Options. Right now, we're hitting problems with 2 of them but that's not really future-proof.

(I'm almost sure if we ever add a gem that extends Object to add a method named after anything already in the config, it will break the API equally well.)

Can we use a whitelist instead?

(But IMO the only fix that would really fix the issue is replace Config::Options with something that doesn't do send.)

@chrisarcand
Copy link
Member

I don't think this is a good solution.

I think this is a great solution - when replacing the config gem quickly or easily is certainly not an option.

@himdel
Copy link
Contributor

himdel commented Oct 19, 2017

@chrisarcand I don't know how much it's being used and what all is used from it, but.. would it really be that hard to replace?

But.. assuming the gem can't be replaced, I'm good with this. I still think we'll hit these problems again, but .. eh, maybe not soon.

@Fryguy
Copy link
Member

Fryguy commented Oct 19, 2017

I agree with @himdel as this is not API's concern to blacklist the config gem. If anything, it belongs in Vmdb::Settings. See my comment in the issue : #134 (comment)

@imtayadeway
Copy link
Contributor

As mentioned in the issue, this is not about 2 methods. This is about every method defined on Object, OpenStruct or Config::Options. Right now, we're hitting problems with 2 of them but that's not really future-proof.

I think a better solution to this is: don't do that. Having a blacklist elsewhere to ensure we don't add conflicting keys to the config I'm all for. The problem in this case was that we were looking for settings that weren't there, and that's the part I'm suggesting we tackle.

@Fryguy
Copy link
Member

Fryguy commented Oct 20, 2017

The problem in this case was that we were looking for settings that weren't there, and that's the part I'm suggesting we tackle.

I don't disagree but this is not API's concern...it's a general concern, and can happen to anyone that tries to access the config. Even so (and I commented in the other thread with this), if all that's trying to be done is verify the presence of a key, then you can also use Settings.to_h.include?(key), which avoids the "doing a key lookup by actually calling a method", which in general you shouldn't do with Settings anyway since any random key is available on an OpenStruct.

Settings.sdkfjhsdkfjh
# => nil
Settings.display
# OMGSOMUCHOUTPUT=>nil

Settings.to_h.include?(:sdkfjhsdkfjh)
# => false
Settings.to_h.include?(:display)
# => false

# And for fun ;)
Settings.sdkfjhsdkfjh = 123
Settings.to_h.include?(:sdkfjhsdkfjh)
=> true

@miq-bot
Copy link
Member

miq-bot commented Oct 23, 2017

Checked commits jntullo/manageiq-api@fa8e1ef~...00d91a7 with ruby 2.3.3, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks fine. 👍

@abellotti
Copy link
Member

Thanks @jntullo for fixing this. 👍

@abellotti abellotti merged commit 8845fb4 into ManageIQ:master Oct 26, 2017
@abellotti abellotti added this to the Sprint 72 Ending Oct 30, 2017 milestone Oct 26, 2017
MaysaMacedo pushed a commit to MaysaMacedo/manageiq-api that referenced this pull request Oct 30, 2017
@cben
Copy link
Contributor

cben commented Nov 1, 2017

Neat! Could you rename the PR (and maybe edit description) to reflect the final solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rein in message passing to Object in collection config
8 participants