Skip to content

Commit

Permalink
replace validate_* with data types
Browse files Browse the repository at this point in the history
  • Loading branch information
baurmatt committed Aug 4, 2017
1 parent 5bfda45 commit 23d76b1
Show file tree
Hide file tree
Showing 86 changed files with 888 additions and 1,469 deletions.
8 changes: 0 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ matrix:
env: PUPPET_VERSION="~> 4.0" CHECK=build DEPLOY_TO_FORGE=yes
- rvm: 2.1.10
env: PUPPET_VERSION="~> 4.0" CHECK=test PARALLEL_TEST_PROCESSORS=4
- rvm: 2.1.10
env: PUPPET_VERSION="~> 3.8" STRICT_VARIABLES="yes" FUTURE_PARSER="yes" CHECK=test FIXTURES_YML=.fixtures.puppet3.yml
- rvm: 2.1.10
env: PUPPET_VERSION="~> 3.8" STRICT_VARIABLES="yes" CHECK=test FIXTURES_YML=.fixtures.puppet3.yml
- rvm: 1.9.3
env: PUPPET_VERSION="~> 3.8" STRICT_VARIABLES="yes" CHECK=test FIXTURES_YML=.fixtures.puppet3.yml
- rvm: 1.9.3
env: PUPPET_VERSION="~> 3.8" STRICT_VARIABLES="yes" FUTURE_PARSER="yes" CHECK=test FIXTURES_YML=.fixtures.puppet3.yml
allow_failures:
- rvm: 2.4.0
branches:
Expand Down
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
12 changes: 4 additions & 8 deletions manifests/config/fragment.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#
#
define icinga2::config::fragment(
$content,
$target,
$code_name = $title,
$order = '0',
String $content,
Stdlib::Absolutepath $target,
String $code_name = $title,
Pattern[/^\d+$/] $order = '0',
) {

include ::icinga2::params
Expand All @@ -44,10 +44,6 @@
} # default
}

validate_string($content)
validate_absolute_path($target)
validate_string($order)

if !defined(Concat[$target]) {
concat { $target:
ensure => present,
Expand Down
27 changes: 8 additions & 19 deletions manifests/debian/dbconfig.pp
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
class icinga2::debian::dbconfig(
$dbtype,
$dbserver,
$dbport,
$dbname,
$dbuser,
$dbpass,
$ssl = false,
Enum['mysql', 'pgsql'] $dbtype,
String $dbserver,
Integer[1,65535] $dbport,
String $dbname,
String $dbuser,
String $dbpass,
Boolean $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.")
}

validate_re($dbtype, [ '^mysql$', '^pgsql$' ],
"${dbtype} isn't supported. Valid values are 'mysql' and 'pgsql'.")
validate_string($dbserver)
validate_integer($dbport)
validate_string($dbname)
validate_string($dbuser)
validate_string($dbpass)
validate_bool($ssl)
assert_private()

# dbconfig config for Debian or Ubuntu
if $::osfamily == 'debian' {
Expand Down
11 changes: 3 additions & 8 deletions manifests/feature.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@
#
#
define icinga2::feature(
$ensure = present,
$feature = $title,
Enum['absent', 'present'] $ensure = present,
String $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.")
}
assert_private()

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

validate_re($ensure, [ '^present$', '^absent$' ],
"${ensure} isn't supported. Valid values are 'present' and 'absent'.")

$user = $::icinga2::params::user
$group = $::icinga2::params::group
$conf_dir = $::icinga2::params::conf_dir
Expand Down
103 changes: 39 additions & 64 deletions manifests/feature/api.pp
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,26 @@
#
#
class icinga2::feature::api(
$ensure = present,
$pki = 'puppet',
$ssl_key_path = undef,
$ssl_cert_path = undef,
$ssl_csr_path = undef,
$ssl_cacert_path = undef,
$accept_config = false,
$accept_commands = false,
$ca_host = undef,
$ca_port = 5665,
$ticket_salt = 'TicketSalt',
$endpoints = { 'NodeName' => {} },
$zones = { 'ZoneName' => { endpoints => [ 'NodeName' ] } },
$ssl_key = undef,
$ssl_cert = undef,
$ssl_cacert = undef,
$ssl_protocolmin = undef,
$ssl_cipher_list = undef,
$bind_host = undef,
$bind_port = undef,
Enum['absent', 'present'] $ensure = present,
Enum['ca', 'icinga2', 'none', 'puppet'] $pki = 'puppet',
Optional[Stdlib::Absolutepath] $ssl_key_path = undef,
Optional[Stdlib::Absolutepath] $ssl_cert_path = undef,
Optional[Stdlib::Absolutepath] $ssl_csr_path = undef,
Optional[Stdlib::Absolutepath] $ssl_cacert_path = undef,
Boolean $accept_config = false,
Boolean $accept_commands = false,
Optional[String] $ca_host = undef,
Integer[1,65535] $ca_port = 5665,
String $ticket_salt = 'TicketSalt',
Hash $endpoints = { 'NodeName' => {} },
Hash $zones = { 'ZoneName' => { endpoints => [ 'NodeName' ] } },
Optional[String] $ssl_key = undef,
Optional[String] $ssl_cert = undef,
Optional[String] $ssl_cacert = undef,
Optional[String] $ssl_protocolmin = undef,
Optional[String] $ssl_cipher_list = undef,
Optional[String] $bind_host = undef,
Optional[Integer[1,65535]] $bind_port = undef,
) {

if ! defined(Class['::icinga2']) {
Expand Down Expand Up @@ -194,53 +194,30 @@
path => $::path,
}

# validation
validate_re($ensure, [ '^present$', '^absent$' ],
"${ensure} isn't supported. Valid values are 'present' and 'absent'.")
validate_re($pki, [ '^puppet$', '^none$', '^icinga2', '^ca' ],
"${pki} isn't supported. Valid values are 'puppet', 'none', 'icinga2' and 'ca (deprecated)'.")
validate_bool($accept_config)
validate_bool($accept_commands)
validate_string($ticket_salt)
validate_hash($endpoints)
validate_hash($zones)

# Set defaults for certificate stuff and/or do validation
# Set defaults for certificate stuff
if $ssl_key_path {
validate_absolute_path($ssl_key_path)
$_ssl_key_path = $ssl_key_path }
else {
$_ssl_key_path = "${pki_dir}/${node_name}.key" }
if $ssl_cert_path {
validate_absolute_path($ssl_cert_path)
$_ssl_cert_path = $ssl_cert_path }
else {
$_ssl_cert_path = "${pki_dir}/${node_name}.crt" }
if $ssl_csr_path {
validate_absolute_path($ssl_csr_path)
$_ssl_csr_path = $ssl_csr_path }
else {
$_ssl_csr_path = "${pki_dir}/${node_name}.csr" }
if $ssl_cacert_path {
validate_absolute_path($ssl_cacert_path)
$_ssl_cacert_path = $ssl_cacert_path }
else {
$_ssl_cacert_path = "${pki_dir}/ca.crt" }

if $ssl_protocolmin {
validate_string($ssl_protocolmin)
}
if $ssl_cipher_list {
validate_string($ssl_cipher_list)
}
if $bind_host {
validate_string($bind_host)
$_ssl_key_path = $ssl_key_path
} else {
$_ssl_key_path = "${pki_dir}/${node_name}.key"
}
if $bind_port {
validate_integer($bind_port)

if $ssl_cert_path {
$_ssl_cert_path = $ssl_cert_path
} else {
$_ssl_cert_path = "${pki_dir}/${node_name}.crt"
}

if $ssl_csr_path {
$_ssl_csr_path = $ssl_csr_path
} else {
$_ssl_csr_path = "${pki_dir}/${node_name}.csr"
}

if $ssl_cacert_path {
$_ssl_cacert_path = $ssl_cacert_path
} else {
$_ssl_cacert_path = "${pki_dir}/ca.crt"
}

# handle the certificate's stuff
case $pki {
Expand Down Expand Up @@ -308,8 +285,6 @@
} # none

'icinga2': {
validate_string($ca_host)
validate_integer($ca_port)

$ticket_id = icinga2_ticket_id($node_name, $ticket_salt)
$trusted_cert = "${pki_dir}/trusted-cert.crt"
Expand Down
10 changes: 2 additions & 8 deletions manifests/feature/checker.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#
#
class icinga2::feature::checker(
$ensure = present,
$concurrent_checks = undef,
Enum['absent', 'present'] $ensure = present,
Optional[Integer[1]] $concurrent_checks = undef,
) {

if ! defined(Class['::icinga2']) {
Expand All @@ -26,12 +26,6 @@
default => undef,
}

# validation
validate_re($ensure, [ '^present$', '^absent$' ],
"${ensure} isn't supported. Valid values are 'present' and 'absent'.")

if $concurrent_checks { validate_integer($concurrent_checks) }

# compose attributes
$attrs = {
concurrent_checks => $concurrent_checks,
Expand Down
8 changes: 2 additions & 6 deletions manifests/feature/command.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#
#
class icinga2::feature::command(
$ensure = present,
$command_path = "${::icinga2::params::run_dir}/cmd/icinga2.cmd",
Enum['absent', 'present'] $ensure = present,
Stdlib::Absolutepath $command_path = "${::icinga2::params::run_dir}/cmd/icinga2.cmd",
) {

if ! defined(Class['::icinga2']) {
Expand All @@ -27,10 +27,6 @@
default => undef,
}

validate_re($ensure, [ '^present$', '^absent$' ],
"${ensure} isn't supported. Valid values are 'present' and 'absent'.")
validate_absolute_path($command_path)

# compose attributes
$attrs = {
command_path => $command_path,
Expand Down
12 changes: 3 additions & 9 deletions manifests/feature/compatlog.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#
#
class icinga2::feature::compatlog(
$ensure = present,
$log_dir = "${::icinga2::params::log_dir}/compat",
$rotation_method = 'DAILY',
Enum['absent', 'present'] $ensure = present,
Stdlib::Absolutepath $log_dir = "${::icinga2::params::log_dir}/compat",
Enum['DAILY', 'HOURLY', 'MONTHLY', 'WEEKLY'] $rotation_method = 'DAILY',
) {

if ! defined(Class['::icinga2']) {
Expand All @@ -32,12 +32,6 @@
default => undef,
}

# validation
validate_re($ensure, [ '^present$', '^absent$' ],
"${ensure} isn't supported. Valid values are 'present' and 'absent'.")
validate_absolute_path($log_dir)
validate_re($rotation_method, ['^HOURLY$','^DAILY$','^WEEKLY$','^MONTHLY$'])

# compose attributes
$attrs = {
log_dir => $log_dir,
Expand Down
9 changes: 2 additions & 7 deletions manifests/feature/debuglog.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#
#
class icinga2::feature::debuglog(
$ensure = present,
$path = "${::icinga2::params::log_dir}/debug.log",
Enum['absent', 'present'] $ensure = present,
Stdlib::Absolutepath $path = "${::icinga2::params::log_dir}/debug.log",
) {

if ! defined(Class['::icinga2']) {
Expand All @@ -28,11 +28,6 @@
default => undef,
}

# validation
validate_re($ensure, [ '^present$', '^absent$' ],
"${ensure} isn't supported. Valid values are 'present' and 'absent'.")
validate_absolute_path($path)

# compose attributes
$attrs = {
severity => 'debug',
Expand Down
18 changes: 5 additions & 13 deletions manifests/feature/gelf.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
#
#
class icinga2::feature::gelf(
$ensure = present,
$host = '127.0.0.1',
$port = '12201',
$source = 'icinga2',
$enable_send_perfdata = false,
Enum['absent', 'present'] $ensure = present,
String $host = '127.0.0.1',
Integer[1,65535] $port = 12201,
String $source = 'icinga2',
Boolean $enable_send_perfdata = false,
) {

if ! defined(Class['::icinga2']) {
Expand All @@ -38,14 +38,6 @@
default => undef,
}

# validation
validate_re($ensure, [ '^present$', '^absent$' ],
"${ensure} isn't supported. Valid values are 'present' and 'absent'.")
validate_string($host)
validate_integer($port)
validate_string($source)
validate_bool($enable_send_perfdata)

# compose attributes
$attrs = {
host => $host,
Expand Down
Loading

0 comments on commit 23d76b1

Please sign in to comment.