Skip to content

Commit

Permalink
Merge pull request #336 from Icinga/protection-of-private-classes-is-…
Browse files Browse the repository at this point in the history
…wrong-333

Update protection of private classes from direct use
  • Loading branch information
lbetz committed Sep 5, 2017
2 parents 1b8b2e2 + 8320f30 commit 16a317b
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 25 deletions.
4 changes: 1 addition & 3 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
#
class icinga2::config {

if defined($caller_module_name) and $module_name != $caller_module_name {
fail("icinga2::config is a private class of the module icinga2, you're not permitted to use it.")
}
assert_private()

$constants = prefix($::icinga2::_constants, 'const ')
$conf_dir = $::icinga2::params::conf_dir
Expand Down
4 changes: 1 addition & 3 deletions manifests/debian/dbconfig.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
$ssl = false,
) {

if defined($caller_module_name) and $module_name != $caller_module_name and $caller_module_name != '' {
fail("icinga2::debian::dbconfig is a private define resource of the module icinga2, you're not permitted to use it.")
}
assert_private()

validate_re($dbtype, [ '^mysql$', '^pgsql$' ],
"${dbtype} isn't supported. Valid values are 'mysql' and 'pgsql'.")
Expand Down
8 changes: 1 addition & 7 deletions manifests/feature.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@
$feature = $title,
) {

if defined($caller_module_name) and $module_name != $caller_module_name and $caller_module_name != '' {
fail("icinga2::feature is a private define resource of the module icinga2, you're not permitted to use it.")
}

if ! defined(Class['::icinga2']) {
fail('You must include the icinga2 base class before using any icinga2 feature class!')
}
assert_private()

validate_re($ensure, [ '^present$', '^absent$' ],
"${ensure} isn't supported. Valid values are 'present' and 'absent'.")
Expand Down
4 changes: 1 addition & 3 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
#
class icinga2::install {

if defined($caller_module_name) and $module_name != $caller_module_name {
fail("icinga2::install is a private class of the module icinga2, you're not permitted to use it.")
}
assert_private()

$package = $::icinga2::params::package
$conf_dir = $::icinga2::params::conf_dir
Expand Down
4 changes: 1 addition & 3 deletions manifests/object.pp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@
$attrs = {},
) {

if defined($caller_module_name) and $module_name != $caller_module_name and $caller_module_name != '' {
fail("icinga2::object is a private define resource of the module icinga2, you're not permitted to use it.")
}
assert_private()

include ::icinga2::params

Expand Down
4 changes: 1 addition & 3 deletions manifests/repo.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
#
class icinga2::repo {

if defined($caller_module_name) and $module_name != $caller_module_name {
fail("icinga2::repo is a private class of the module icinga2, you're not permitted to use it.")
}
assert_private()

if $::icinga2::manage_repo and $::icinga2::manage_package {

Expand Down
4 changes: 1 addition & 3 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
#
class icinga2::service {

if defined($caller_module_name) and $module_name != $caller_module_name {
fail("icinga2::service is a private class of the module icinga2, you're not permitted to use it.")
}
assert_private()

$ensure = $::icinga2::ensure
$enable = $::icinga2::enable
Expand Down
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_facts.yml', __FILE__))
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_module_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_module_facts.yml', __FILE__))
c.default_facts = default_facts

c.before(:each) do
# Stub assert_private function from stdlib to not fail within this test
Puppet::Parser::Functions.newfunction(:assert_private) { |_| }
end
end

0 comments on commit 16a317b

Please sign in to comment.