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

Modules 1192 - rename facts param on actionpolicy::rule to remove conflict with $facts hash #161

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@ matrix:
env: PUPPET_GEM_VERSION="~> 3.0"
- rvm: 2.0.0
env: PUPPET_GEM_VERSION="~> 3.0"
- rvm: 1.9.3
env: PUPPET_GEM_VERSION="~> 3.7.0"
- rvm: 2.0.0
env: PUPPET_GEM_VERSION="~> 3.7.0"
- rvm: 1.9.3
env: PUPPET_GEM_VERSION="~> 3.7.0" TRUSTED_NODE_DATA="yes"
- rvm: 2.0.0
env: PUPPET_GEM_VERSION="~> 3.7.0" TRUSTED_NODE_DATA="yes"
notifications:
email: false
3 changes: 2 additions & 1 deletion Gemfile
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ source 'https://rubygems.org'

group :development, :test do
gem 'rake'
gem 'puppetlabs_spec_helper'
gem 'puppetlabs_spec_helper', '>= 0.7.0', :require => false
gem 'rspec-system-puppet', '~>2.0'
gem 'puppet-lint'
end

Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,8 @@ String: defaults to 'deny'. The default actionpolicy to apply to the agent.
### `mcollective::actionpolicy::rule` defined type

`mcollective::actionpolicy::rule` represents a single actionpolicy policy
entry.
entry. See the actionpolicy plugin [Policy File Format](https://github.com/puppetlabs/mcollective-actionpolicy-auth#policy-file-format)
for specific restrictions on the values of these fields.

#### Parameters

Expand All @@ -586,9 +587,11 @@ String: defaults to '*'. What callerids should match this rule.

String: defaults to '*'. What actions should match this rule.

##### `facts`
##### `fact_filter`

String: defaults to '*'. What facts should match this rule.
String: defaults to '*'. What facts should match this rule. This can be either
'*', a space-separated list of ``fact=value`` pairs (which match if every listed
fact matches), or any valid [compound filter string](http://docs.puppetlabs.com/mcollective/reference/basic/basic_cli_usage.html#complex-compound-or-select-queries). This matches the "facts" field of the policy file lines.

##### `classes`

Expand Down
13 changes: 7 additions & 6 deletions manifests/actionpolicy/rule.pp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Define - mcollective::actionpolicy::rule
define mcollective::actionpolicy::rule(
$agent,
$action = 'allow',
$callerid = '*',
$actions = '*',
$facts = '*',
$classes = '*'
$action = 'allow',
$callerid = '*',
$actions = '*',
$fact_filter = '*',
$classes = '*'
) {
validate_string($fact_filter)
datacat_fragment { "mcollective::actionpolicy::rule ${title}":
target => "mcollective::actionpolicy ${agent}",
data => {
Expand All @@ -15,7 +16,7 @@
'action' => $action,
'callerid' => $callerid,
'actions' => $actions,
'facts' => $facts,
'facts' => $fact_filter,
'classes' => $classes,
},
],
Expand Down
54 changes: 54 additions & 0 deletions spec/defines/mcollective__actionpolicy__rule_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require 'spec_helper'

describe 'mcollective::actionpolicy::rule', :type => :define do
context 'default-puppet' do
let(:title) { 'default-puppet' }
let(:params) do
{
:agent => 'puppet',
}
end

it {
should contain_datacat_fragment('mcollective::actionpolicy::rule default-puppet') \
.with_target('mcollective::actionpolicy puppet') \
.with_data({
'lines' => [
{
'action' => 'allow',
'callerid' => '*',
'actions' => '*',
'facts' => '*',
'classes' => '*',
},
],
})
}
end

context 'facts-specified' do
let(:title) { 'default-puppet' }
let(:params) do
{
:agent => 'puppet',
:fact_filter => 'environment=dev and !customer=acme',
}
end

it {
should contain_datacat_fragment('mcollective::actionpolicy::rule default-puppet') \
.with_target('mcollective::actionpolicy puppet') \
.with_data({
'lines' => [
{
'action' => 'allow',
'callerid' => '*',
'actions' => '*',
'facts' => 'environment=dev and !customer=acme',
'classes' => '*',
},
],
})
}
end
end
2 changes: 1 addition & 1 deletion templates/actionpolicy.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
policy default <%= @data['default'] %>
<%
lines = @data['lines'].collect do |line|
line.values_at(*%w{ action callerid actions facts classes }).join("\t")
line.values_at(*%w{ action callerid actions fact_filter classes }).join("\t")

Choose a reason for hiding this comment

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

This is not necessary, because the hash still has the key facts:
https://github.com/puppet-community/puppet-mcollective/pull/161/files#diff-26b416a07573e48cd8576ce727abff8aL18

You break the policy file with that change

end
-%>
<%= lines.sort.join("\n") %>