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 special rule format for keyring type policy #582

Merged
merged 1 commit into from
Sep 28, 2021
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 lib/puppet/provider/consul_policy/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def self.encode_rules(rules)
encoded = []

rules.each do |rule|
if ['acl', 'operator'].include?(rule['resource'])
if ['acl', 'operator', 'keyring'].include?(rule['resource'])
encoded.push("#{rule['resource']} = \"#{rule['disposition']}\"")
else
encoded.push("#{rule['resource']} \"#{rule['segment']}\" {\n policy = \"#{rule['disposition']}\"\n}")
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/consul_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
raise ArgumentError, 'Policy rule must be a hash' unless value.is_a?(Hash)

raise ArgumentError, 'Policy rule needs to specify a resource' unless value.key?('resource')
raise ArgumentError, 'Policy rule needs to specify a segment' unless value.key?('segment') || ['acl', 'operator'].include?(value['resource'])
raise ArgumentError, 'Policy rule needs to specify a segment' unless value.key?('segment') || ['acl', 'operator', 'keyring'].include?(value['resource'])
raise ArgumentError, 'Policy rule needs to specify a disposition' unless value.key?('disposition')

raise ArgumentError, 'Policy rule resource must be a string' unless value['resource'].is_a?(String)
raise ArgumentError, 'Policy rule segment must be a string' unless value['segment'].is_a?(String) || ['acl', 'operator'].include?(value['resource'])
raise ArgumentError, 'Policy rule segment must be a string' unless value['segment'].is_a?(String) || ['acl', 'operator', 'keyring'].include?(value['resource'])
raise ArgumentError, 'Policy rule disposition must be a string' unless value['disposition'].is_a?(String)
end

Expand Down
15 changes: 13 additions & 2 deletions spec/unit/puppet/type/consul_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
}.to raise_error(Puppet::Error, %r{Policy rule disposition must be a string})
end

context 'resource is acl or operator' do
context 'resource is acl, operator or keyring' do
it 'passes if rule segment is missing' do
expect {
Puppet::Type.type(:consul_policy).new(
Expand All @@ -121,6 +121,17 @@
},
],
)
Puppet::Type.type(:consul_policy).new(
name: 'testing',
id: '39c75e12-7f43-0a40-dfba-9aa3fcda08d4',
description: 'test description',
rules: [
{
'resource' => 'keyring',
'disposition' => 'read'
},
],
)
}.not_to raise_error
end

Expand All @@ -142,7 +153,7 @@
end
end

context 'resource is neither acl nor operator' do
context 'resource is neither acl nor operator nor keyring' do
it 'fails if rule segment is missing' do
expect {
Puppet::Type.type(:consul_policy).new(
Expand Down