From 1f56e9e72262e98e0970631d632f8e4993b12934 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sun, 22 Oct 2017 01:18:44 +0200 Subject: [PATCH] replace validate_* with datatypes in init --- manifests/init.pp | 89 +++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 50 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 5fb4168a1..76afe8df6 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -112,63 +112,52 @@ # Sample Usage: # class prometheus ( - $manage_user = true, - $user = $::prometheus::params::user, - $manage_group = true, - $purge_config_dir = true, - $group = $::prometheus::params::group, - $extra_groups = $::prometheus::params::extra_groups, - $bin_dir = $::prometheus::params::bin_dir, - $shared_dir = $::prometheus::params::shared_dir, - $arch = $::prometheus::params::arch, - $version = $::prometheus::params::version, - $install_method = $::prometheus::params::install_method, - $os = $::prometheus::params::os, - $download_url = undef, - $download_url_base = $::prometheus::params::download_url_base, - $download_extension = $::prometheus::params::download_extension, - $package_name = $::prometheus::params::package_name, - $package_ensure = $::prometheus::params::package_ensure, - $config_dir = $::prometheus::params::config_dir, - $localstorage = $::prometheus::params::localstorage, - $extra_options = '', - $config_hash = {}, - $config_defaults = {}, - $config_template = $::prometheus::params::config_template, - $config_mode = $::prometheus::params::config_mode, - $service_enable = true, - $service_ensure = 'running', - $manage_service = true, - $restart_on_change = true, - $init_style = $::prometheus::params::init_style, - $global_config = $::prometheus::params::global_config, - $rule_files = $::prometheus::params::rule_files, - $scrape_configs = $::prometheus::params::scrape_configs, - $alerts = $::prometheus::params::alerts, - $alert_relabel_config = $::prometheus::params::alert_relabel_config, - $alertmanagers_config = $::prometheus::params::alertmanagers_config, + Boolean $manage_user = true, + $user = $::prometheus::params::user, + $manage_group = true, + Boolean $purge_config_dir = true, + $group = $::prometheus::params::group, + $extra_groups = $::prometheus::params::extra_groups, + $bin_dir = $::prometheus::params::bin_dir, + $shared_dir = $::prometheus::params::shared_dir, + $arch = $::prometheus::params::arch, + $version = $::prometheus::params::version, + $install_method = $::prometheus::params::install_method, + $os = $::prometheus::params::os, + $download_url = undef, + $download_url_base = $::prometheus::params::download_url_base, + $download_extension = $::prometheus::params::download_extension, + $package_name = $::prometheus::params::package_name, + $package_ensure = $::prometheus::params::package_ensure, + $config_dir = $::prometheus::params::config_dir, + $localstorage = $::prometheus::params::localstorage, + $extra_options = '', + Hash $config_hash = {}, + Hash $config_defaults = {}, + $config_template = $::prometheus::params::config_template, + $config_mode = $::prometheus::params::config_mode, + $service_enable = true, + $service_ensure = 'running', + Boolean $manage_service = true, + Boolean $restart_on_change = true, + $init_style = $::prometheus::params::init_style, + Hash $global_config = $::prometheus::params::global_config, + Array $rule_files = $::prometheus::params::rule_files, + Array $scrape_configs = $::prometheus::params::scrape_configs, + $alerts = $::prometheus::params::alerts, + Array $alert_relabel_config = $::prometheus::params::alert_relabel_config, + Array $alertmanagers_config = $::prometheus::params::alertmanagers_config, ) inherits prometheus::params { + if( versioncmp($::prometheus::version, '1.0.0') == -1 ){ - $real_download_url = pick($download_url, + $real_download_url = pick($download_url, "${download_url_base}/download/${version}/${package_name}-${version}.${os}-${arch}.${download_extension}") } else { - $real_download_url = pick($download_url, + $real_download_url = pick($download_url, "${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}") } - validate_bool($purge_config_dir) - validate_bool($manage_user) - validate_bool($manage_service) - validate_bool($restart_on_change) - validate_hash($config_hash) - validate_hash($config_defaults) - validate_hash($global_config) - validate_array($rule_files) - validate_array($scrape_configs) - validate_array($alert_relabel_config) - validate_array($alertmanagers_config) - $config_hash_real = deep_merge($config_defaults, $config_hash) - validate_hash($config_hash_real) + $config_hash_real = assert_type(Hash, deep_merge($config_defaults, $config_hash)) anchor {'prometheus_first': } -> class { '::prometheus::install': }