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 mesh and peering type policy #653

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 %w[acl operator keyring].include?(rule['resource'])
if %w[acl operator keyring mesh peering].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 @@ -42,11 +42,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') || %w[acl operator keyring].include?(value['resource'])
raise ArgumentError, 'Policy rule needs to specify a segment' unless value.key?('segment') || %w[acl operator keyring mesh peering].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) || %w[acl operator keyring].include?(value['resource'])
raise ArgumentError, 'Policy rule segment must be a string' unless value['segment'].is_a?(String) || %w[acl operator keyring mesh peering].include?(value['resource'])
raise ArgumentError, 'Policy rule disposition must be a string' unless value['disposition'].is_a?(String)
end

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

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

Expand All @@ -159,7 +181,7 @@
end
end

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