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 Apr 18, 2018
1 parent dbc5446 commit 40ab462
Show file tree
Hide file tree
Showing 85 changed files with 847 additions and 1,443 deletions.
34 changes: 14 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,22 @@ env:
matrix:
fast_finish: true
include:
- rvm: 2.4.0
env: PUPPET_VERSION="~> 5.0" CHECK=test
- rvm: 2.3.3
env: PUPPET_VERSION="~> 4.0" CHECK=test
- rvm: 2.2.6
env: PUPPET_VERSION="~> 4.0" CHECK=test
- rvm: 2.1.10
env: PUPPET_VERSION="~> 4.0" CHECK=build DEPLOY_TO_FORGE=yes
- rvm: 2.1.10
env: PUPPET_VERSION="~> 4.0" CHECK=test
- 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
- rvm: 2.4.0
env: PUPPET_VERSION="~> 5.0" CHECK=test
- rvm: 2.3.3
env: PUPPET_VERSION="~> 4.0" CHECK=test
- rvm: 2.2.6
env: PUPPET_VERSION="~> 4.0" CHECK=test
- rvm: 2.1.10
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
allow_failures:
- rvm: 2.4.0
branches:
only:
- master
- /^v\d/
- master
- /^v\d/
notifications:
email: false
deploy:
Expand Down
14 changes: 6 additions & 8 deletions examples/example4/profile/manifests/agent.pp
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# Notice: this code contains Puppet 4 syntax! It doesn't run on Puppet 3.
class profile::icinga2::agent(
$parent_endpoints,
$parent_zone,
$agent_ip = $::ipaddress,
Hash $parent_endpoints,
String $parent_zone,
Stdlib::Compat::Ip_address $agent_ip = $::ipaddress,
) {

contain ::profile::icinga2::plugins

validate_hash($parent_endpoints)

class { '::icinga2':
manage_repo => true,
confd => false,
features => ['mainlog'],
features => ['mainlog'],
}

# Feature: api
Expand All @@ -23,8 +21,8 @@
'ZoneName' => {
'endpoints' => [ 'NodeName' ],
'parent' => $parent_zone,
}
}
},
},
}

::icinga2::object::zone { 'linux-commands':
Expand Down
18 changes: 8 additions & 10 deletions examples/example4/profile/manifests/slave.pp
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# Notice: this code contains Puppet 4 syntax! It doesn't run on Puppet 3.
class profile::icinga2::slave(
$slave_zone,
$parent_endpoints,
$parent_zone = 'master',
$slave_ip = $::ipaddress,
String $slave_zone,
Array $parent_endpoints,
String $parent_zone = 'master',
Stdlib::Compat::Ip_address $slave_ip = $::ipaddress,
) {

contain ::profile::icinga2::plugins

validate_array($parent_endpoints)

class { '::icinga2':
manage_repo => true,
confd => false,
features => ['checker','mainlog'],
features => ['checker','mainlog'],
constants => {
'ZoneName' => $slave_zone,
}
},
}

# Feature: api
Expand All @@ -27,8 +25,8 @@
'ZoneName' => {
'endpoints' => [ 'NodeName' ],
'parent' => $parent_zone,
}
}
},
},
}

::icinga2::object::endpoint { $parent_endpoints: }
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
23 changes: 7 additions & 16 deletions manifests/debian/dbconfig.pp
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
# == Class: icinga2::debian::dbconfig
#
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,
) {

assert_private()

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)

# dbconfig config for Debian or Ubuntu
if $::osfamily == 'debian' {

Expand Down
7 changes: 2 additions & 5 deletions manifests/feature.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
#
#
define icinga2::feature(
$ensure = present,
$feature = $title,
Enum['absent', 'present'] $ensure = present,
String $feature = $title,
) {

assert_private()

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
76 changes: 21 additions & 55 deletions manifests/feature/api.pp
Original file line number Diff line number Diff line change
Expand Up @@ -141,26 +141,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 @@ -192,54 +192,24 @@
group => $group,
}

# 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)
}
if $bind_port {
validate_integer($bind_port)
}



# handle the certificate's stuff
case $pki {
'puppet': {
Expand Down Expand Up @@ -313,10 +283,6 @@

'icinga2': {
$_ticket_salt = undef

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
Loading

0 comments on commit 40ab462

Please sign in to comment.