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

Fixing the issue of updataing acls unnecessarily #76

Merged
merged 2 commits into from
Sep 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cheffish.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.email = '[email protected]'
s.homepage = 'http://github.com/chef/cheffish'

s.add_dependency 'chef-zero', '~> 4.2'
s.add_dependency 'chef-zero', '~> 4.3'

s.add_development_dependency 'chef', '~> 12.2'
s.add_development_dependency 'rake'
Expand Down
9 changes: 8 additions & 1 deletion lib/chef/provider/chef_acl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def create_acl(path)
# Compare the desired and current json for the ACL, and update if different.
modify = {}
desired_acl(acl).each do |permission, desired_json|
differences = json_differences(current_json[permission], desired_json)
differences = json_differences(sort_values(current_json[permission]), sort_values(desired_json))

if differences.size > 0
# Verify we aren't trying to destroy grant permissions
Expand Down Expand Up @@ -144,6 +144,13 @@ def desired_acl(acl_path)
result
end

def sort_values(json)
json.each do |key, value|
json[key] = value.sort if value.is_a?(Array)
end
json
end

def add_rights(acl_path, json)
if new_resource.rights
new_resource.rights.each do |rights|
Expand Down
13 changes: 13 additions & 0 deletions spec/integration/chef_acl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@
group 'g2', {}
group 'g3', {}

it 'Converging chef_acls should ignore order of the values in the acls' do
expect_recipe {
chef_acl 'nodes/x' do
rights :create, users: [ 'u1', 'u2', 'u3' ], clients: [ 'c1', 'c2', 'c3' ], groups: [ 'g1', 'g2', 'g3' ]
end
}.to be_updated
expect_recipe {
chef_acl 'nodes/x' do
rights :create, users: [ 'u2', 'u3', 'u1' ], clients: [ 'c3', 'c2', 'c1' ], groups: [ 'g1', 'g2', 'g3' ]
end
}.to be_up_to_date
end

it 'Converging chef_acl "nodes/x" with multiple groups, users and clients in an acl makes the appropriate changes' do
expect_recipe {
chef_acl 'nodes/x' do
Expand Down