Skip to content

Commit

Permalink
add policykit::params class
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Hoblitt committed Aug 30, 2013
1 parent 8b01bd9 commit da6d309
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 10 deletions.
5 changes: 2 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-syntax/tasks/puppet-syntax'
require 'puppet-lint/tasks/puppet-lint'

#PuppetSyntax.exclude_paths = ["vendor/**/*"]
#PuppetLint.configuration.send("disable_class_inherits_from_params_class")
#PuppetLint.configuration.send("disable_variable_scope")
PuppetLint.configuration.send("disable_class_inherits_from_params_class")
PuppetLint.configuration.send("disable_80chars")
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", 'tests/**/*.pp']

task :default => [
Expand Down
8 changes: 4 additions & 4 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
# License: GPLv3
#

class policykit {
class policykit inherits policykit::params {

package { 'policykit-1':
ensure => latest,
package { $policykit::params::policykit_package:
ensure => present,
alias => 'policykit',
}

file { '/etc/polkit-1/localauthority/50-local.d':
file { $policykit::params::policykit_local_path:
ensure => directory,
require => Package['policykit'],
}
Expand Down
7 changes: 4 additions & 3 deletions manifests/localauthority.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# result_any => 'no',
# }
#

define policykit::localauthority(
$identity,
$action,
Expand All @@ -31,13 +30,15 @@
validate_string($result_active)
validate_re($ensure, ['^present$', '^absent'])

File { owner => 'root', group => 'root' }
include policykit

$safe_name = regsubst($name, '[^a-zA-Z-]', '_', 'G')
$config_file = "/etc/polkit-1/localauthority/50-local.d/${safe_name}.pkla"
$config_file = "${policykit::params::policykit_local_path}/${safe_name}.pkla"

file { $config_file:
ensure => $ensure,
owner => 'root',
group => 'root',
mode => '0644',
content => "[${name}]
Identity=${identity}
Expand Down
32 changes: 32 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# == Class: policykit::params
#
# This class should be considered private.
#
# === Authors
#
# Joshua Hoblitt <[email protected]>
#
# === Copyright
#
# Copyright (C) 2013 Joshua Hoblitt
#
class policykit::params {

case $::osfamily {
'redhat': {
case $::lsbmajdistrelease {
6: {
$policykit_package = 'policykit-1'
$policykit_local_path = '/etc/polkit-1/localauthority/50-local.d'
}
default: {
fail("Module ${module_name} is not supported on lsbmajdistrelease ${::lsbmajdistrelease}")
}
}
}
default: {
fail("Module ${module_name} is not supported on ${::operatingsystem}")
}
}

}
41 changes: 41 additions & 0 deletions spec/classes/policykit_params_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'spec_helper'

describe 'policykit::params', :type => :class do
describe 'for osfamily RedHat' do
let :facts do
{
:osfamily => 'RedHat',
}
end

describe 'el6.x' do
before { facts[:lsbmajdistrelease] = '6' }

it { should include_class('policykit::params') }
end

describe 'unsupported lsbmajdistrelease' do
before { facts[:lsbmajdistrelease] = '7' }

it 'should fail' do
expect { should include_class('policykit::params') }.
to raise_error(Puppet::Error, /not supported on lsbmajdistrelease 7/)
end
end
end

describe 'unsupported osfamily' do
let :facts do
{
:osfamily => 'Debian',
:operatingsystem => 'Debian',
}
end

it 'should fail' do
expect { should include_class('policykit::params') }.
to raise_error(Puppet::Error, /not supported on Debian/)
end
end

end
7 changes: 7 additions & 0 deletions spec/classes/policykit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
describe 'policykit', :type => :class do

describe 'for osfamily RedHat' do
let :facts do
{
:osfamily => 'RedHat',
:lsbmajdistrelease => '6',
}
end

it { should contain_class('policykit') }
end

Expand Down
6 changes: 6 additions & 0 deletions spec/defines/localauthority_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
require 'spec_helper'

describe 'policykit::localauthority', :type => :define do
let :facts do
{
:osfamily => 'RedHat',
:lsbmajdistrelease => '6',
}
end

describe 'simple case' do
let(:title) { 'foo' }
Expand Down

0 comments on commit da6d309

Please sign in to comment.