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

Replace validate_* with data types #350

Merged
merged 16 commits into from
Apr 19, 2018
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ pkg/
Gemfile.lock
/.ruby-*
.bundle
.vendor/
vendor/
log/
36 changes: 14 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ cache: bundler
before_install:
- bundle -v
- rm Gemfile.lock || true
- gem update --system
- gem update bundler
- gem --version
- bundle -v
script:
Expand All @@ -19,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 PARALLEL_TEST_PROCESSORS=4
- rvm: 2.3.3
env: PUPPET_VERSION="~> 4.0" CHECK=test PARALLEL_TEST_PROCESSORS=4
- rvm: 2.2.6
env: PUPPET_VERSION="~> 4.0" CHECK=test PARALLEL_TEST_PROCESSORS=4
- rvm: 2.1.10
env: PUPPET_VERSION="~> 4.0" CHECK=test PARALLEL_TEST_PROCESSORS=4
- rvm: 2.1.10
env: PUPPET_VERSION="~> 4.0" CHECK=build DEPLOY_TO_FORGE=yes
allow_failures:
- rvm: 2.4.0
branches:
only:
- master
- /^v\d/
- master
- /^v\d/
notifications:
email: false
deploy:
Expand Down
3 changes: 3 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Alan Jenkins <[email protected]>
Alessandro Lorenzi <[email protected]>
Alexander Schaber <[email protected]>
Andrea Cervesato <[email protected]>
Andreas Ntaflos <[email protected]>
Andreas Paul <[email protected]>
Blerim Sheqa <[email protected]>
Expand All @@ -21,6 +22,8 @@ Rudy Gevaert <[email protected]>
Simon Hoenscheid <[email protected]>
Stefan Kleindl <[email protected]>
Thomas Dalichow <[email protected]>
Till Adam <[email protected]>
Tom De Vylder <[email protected]>
Tomas Barton <[email protected]>
Wyatt Alt <[email protected]>
Zach Leslie <[email protected]>
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# Change Log

## [v1.3.5](https://github.com/Icinga/puppet-icinga2/tree/v1.3.5) (2018-01-24)
[Full Changelog](https://github.com/Icinga/puppet-icinga2/compare/v1.3.4...v1.3.5)

**Implemented enhancements:**

- icinga2 binary is wrong on rhel5 [\#409](https://github.com/Icinga/puppet-icinga2/issues/409)
- Add feature Elasticsearch [\#408](https://github.com/Icinga/puppet-icinga2/issues/408)
- Add feature elasticsearch [\#399](https://github.com/Icinga/puppet-icinga2/issues/399)
- Added cloudlinux to supported operating systems. Is nearly identical … [\#424](https://github.com/Icinga/puppet-icinga2/pull/424) ([koma85](https://github.com/koma85))

**Fixed bugs:**

- Setting up icinga2 with a different port than default for idodb leads to an error [\#411](https://github.com/Icinga/puppet-icinga2/issues/411)
- fix \#411 Setting up Icinga 2 with a different port than default for i… [\#413](https://github.com/Icinga/puppet-icinga2/pull/413) ([lbetz](https://github.com/lbetz))
- fix for repository.d directory on master-systems [\#412](https://github.com/Icinga/puppet-icinga2/pull/412) ([matthiasritter](https://github.com/matthiasritter))

**Closed issues:**

- escaping broken with double quotes? [\#416](https://github.com/Icinga/puppet-icinga2/issues/416)
- Icinga resource doesn't create ca directory and required files [\#415](https://github.com/Icinga/puppet-icinga2/issues/415)
- icinga2 option generates self signed certificates that are rejected by master [\#405](https://github.com/Icinga/puppet-icinga2/issues/405)
- manage repo trough proxy [\#394](https://github.com/Icinga/puppet-icinga2/issues/394)

**Merged pull requests:**

- trivial copy edits [\#420](https://github.com/Icinga/puppet-icinga2/pull/420) ([wkalt](https://github.com/wkalt))
- Fix confd example path [\#417](https://github.com/Icinga/puppet-icinga2/pull/417) ([dnsmichi](https://github.com/dnsmichi))
- fix \#409 icinga2 binary is wrong on rhel5 [\#410](https://github.com/Icinga/puppet-icinga2/pull/410) ([lbetz](https://github.com/lbetz))

## [v1.3.4](https://github.com/Icinga/puppet-icinga2/tree/v1.3.4) (2017-11-22)
[Full Changelog](https://github.com/Icinga/puppet-icinga2/compare/v1.3.3...v1.3.4)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ available in Icinga 2 can be enabled and configured with this module.

This module depends on:

* [puppetlabs/stdlib] >= 4.10.0
* [puppetlabs/concat] >= 2.0.1
* [puppetlabs/stdlib] >= 4.16.0
* [puppetlabs/concat] >= 2.1.0

Depending on your setup following modules may also be required:

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
2 changes: 1 addition & 1 deletion lib/puppet_x/icinga2/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def self.attributes(attrs, globals, consts, indent=2)

def self.value_types(value)

if value =~ /^\d+\.?\d*[dhms]?$/ || value =~ /^(true|false)$/ || value =~ /^!?(host|service|user)\./ || value =~ /^\{{2}.*\}{2}$/
if value =~ /^\d+\.?\d*[dhms]?$/ || value =~ /^(true|false|null)$/ || value =~ /^!?(host|service|user)\./ || value =~ /^\{{2}.*\}{2}$/
result = value
else
if $constants.index { |x| if $hash_attrs.include?(x) then value =~ /^!?(#{x})(\..+$|$)/ else value =~ /^!?#{x}$/ end }
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
Loading