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

Update protection of private classes from direct use #336

Merged
merged 2 commits into from
Sep 5, 2017
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
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