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

Allow custom package name and management #72

Merged
merged 1 commit into from
Nov 16, 2015
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: 2 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Parameters:

* `$mode` (enforced|permissive|disabled) - sets the operating state for SELinux.
* `$type` (targeted|minimum|mls) - sets the enforcement type.
* `$manage_package` (boolean) - Whether or not to manage the SELinux management package.
* `$package_name` (string) - sets the name of the selinux management package.

## Reference

Expand Down
13 changes: 10 additions & 3 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#
# Parameters:
# - $mode (enforcing|permissive|disabled) - sets the operating state for SELinux.
# - $mode (targeted|minimum|mls) - sets the operating type for SELinux.
# - $type (targeted|minimum|mls) - sets the operating type for SELinux.
# - $manage_package (boolean) - Whether or not to manage the SELinux management package.
# - $package_name (string) - sets the name of the selinux management package.
#
# Actions:
# Configures SELinux to a specific state (enforced|permissive|disabled and targeted|minimum|mls)
Expand All @@ -17,8 +19,10 @@
# This module should not be called directly.
#
class selinux::config (
$mode = $::selinux::mode,
$type = $::selinux::type,
$mode = $::selinux::mode,
$type = $::selinux::type,
$manage_package = $::selinux::manage_package,
$package_name = $::selinux::package_name,
) {

if $caller_module_name != $module_name {
Expand Down Expand Up @@ -69,4 +73,7 @@
match => '^SELINUXTYPE=\w+',
}
}

validate_bool($manage_package)
validate_string($package_name)
}
11 changes: 8 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
# include selinux
#
class selinux (
$mode = $::selinux::params::mode,
$type = $::selinux::params::type,
$mode = $::selinux::params::mode,
$type = $::selinux::params::type,
$manage_package = $::selinux::params::manage_package,
$package_name = $::selinux::params::package_name,
) inherits selinux::params {

class { 'selinux::package': } ->
class { 'selinux::package':
manage_package => $manage_package,
package_name => $package_name,
} ->
class { 'selinux::config': }
}
12 changes: 8 additions & 4 deletions manifests/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@
# Sample Usage:
#
# This class file is not called directly
class selinux::package {
class selinux::package (
$manage_package = $::selinux::params::manage_package,
$package_name = $::selinux::params::package_name,
){

if $caller_module_name != $module_name {
fail("Use of private class ${name} by ${caller_module_name}")
}

package { $::selinux::params::package_name:
ensure => installed,
if $manage_package {
package { $package_name:
ensure => installed,
}
}

}
7 changes: 4 additions & 3 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
# mod_dir = $selinux::params::sx_mod_dir
#
class selinux::params {
$sx_mod_dir = '/usr/share/selinux'
$mode = undef
$type = undef
$sx_mod_dir = '/usr/share/selinux'
$mode = undef
$type = undef
$manage_package = true

case $::osfamily {
'RedHat': {
Expand Down
34 changes: 34 additions & 0 deletions spec/classes/selinux_package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,40 @@
it { should contain_package('policycoreutils-python').with(:ensure => 'installed') }
end

context 'do not manage package' do
let(:facts) do
{
:osfamily => 'RedHat',
:operatingsystem => 'RedHat',
:operatingsystemmajrelease => '5',
}
end
let(:params) do
{
:manage_package => false,
}
end

it { should_not contain_package('policycoreutils').with(:ensure => 'installed') }
end

context 'install a different package name' do
let(:facts) do
{
:osfamily => 'RedHat',
:operatingsystem => 'RedHat',
:operatingsystemmajrelease => '5',
}
end
let(:params) do
{
:package_name => 'some_package',
}
end

it { should contain_package('some_package').with(:ensure => 'installed') }
end

end

end