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

Add feature to save each key in different data bag item #246

Merged
merged 4 commits into from
Dec 2, 2016
Merged

Add feature to save each key in different data bag item #246

merged 4 commits into from
Dec 2, 2016

Conversation

rveznaver
Copy link

As described in #237.

Robert Veznaver added 2 commits November 21, 2016 17:18
Signed-off-by: Robert Veznaver <r.veznaver@criteo.com>
Signed-off-by: Robert Veznaver <r.veznaver@criteo.com>
return (ckey ? true : false) unless ckey.nil?
# check if the key is saved in sparse mode
spath = "#{@raw_data["id"]}_key_#{key}"
skey = if Chef::Config[:solo_legacy_mode]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this block of code should be factorized (including the spatch computation)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Will try to fix once tests pass.

@raw_data.keys.include?(key)
# check if the key is in the write-back cache
ckey = @cache[key]
return (ckey ? true : false) unless ckey.nil?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OPT:
(if you really want to return true value)

return !!ckey if ckey

or if you just want to return true-ish value

return ckey if ckey

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to write !!ckey unless ckey.nil? ?
Rubocop doesn't like that :(

@cache.each do |key, val|
spath = "#{@raw_data["id"]}_key_#{key}"
# delete across all modes on key deletion
if val == false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless val

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nil and false do not have the same meaning in the write-back cache

begin
Chef::DataBagItem.destroy(@data_bag, spath)
rescue Net::HTTPServerException => http_error
nil if http_error.response.code == "404"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why you specify nil here since this can't be a returned value

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I copied it without checking :) Will fix.

Robert Veznaver added 2 commits November 23, 2016 15:22
Signed-off-by: Robert Veznaver <r.veznaver@criteo.com>
Signed-off-by: Robert Veznaver <r.veznaver@criteo.com>
@rveznaver
Copy link
Author

pinging @thommay for input

@thommay
Copy link
Contributor

thommay commented Nov 28, 2016

I think the major question I have here is does it still make sense for ItemKeys to inherit from DataBagItem? If it does not, does the code get simpler?

@rveznaver
Copy link
Author

@thommay I had the same question, but have chosen to err on the side of code consistency. IMO, if ItemKeys were to be a standalone, hash-like class, then Items should be as well, but that would require a more thorough refactor.

@thommay
Copy link
Contributor

thommay commented Nov 28, 2016

I think ItemKeys could change without needing to change Item (which is still fundamentally a DBI at the end of the day).

@rveznaver
Copy link
Author

So is ItemKeys :)

@thommay
Copy link
Contributor

thommay commented Dec 2, 2016

OK. I'm going to merge this as is, since it's clearly better. Then I'm going to do another release candidate.

@thommay thommay merged commit f56515c into chef:master Dec 2, 2016
@thommay
Copy link
Contributor

thommay commented Dec 2, 2016

Thanks, @rveznaver for the great PR.

@rveznaver
Copy link
Author

Thanks, I'll soon start working on the next step: adding knife support and sparse mode cucumber tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Adds new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants