diff --git a/lib/puppet/provider/consul_policy/default.rb b/lib/puppet/provider/consul_policy/default.rb index e396abfc..df54db30 100644 --- a/lib/puppet/provider/consul_policy/default.rb +++ b/lib/puppet/provider/consul_policy/default.rb @@ -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}") diff --git a/lib/puppet/type/consul_policy.rb b/lib/puppet/type/consul_policy.rb index 058a667d..e95eca0c 100644 --- a/lib/puppet/type/consul_policy.rb +++ b/lib/puppet/type/consul_policy.rb @@ -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 diff --git a/spec/unit/puppet/type/consul_policy_spec.rb b/spec/unit/puppet/type/consul_policy_spec.rb index 1e248248..1eaf3183 100644 --- a/spec/unit/puppet/type/consul_policy_spec.rb +++ b/spec/unit/puppet/type/consul_policy_spec.rb @@ -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( @@ -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 @@ -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(