Commit 788d8764 authored by Raphaël Pinson's avatar Raphaël Pinson Committed by GitHub
Browse files

Data types (#169)

* Use data types

* Use data types

* Use data types

* Use data types

* Use data types

* Use data types

* Use data types
parent 06fe7674
......@@ -44,22 +44,15 @@
# }
#
define postfix::conffile (
$ensure = 'present',
$source = undef,
$content = undef,
$path = "/etc/postfix/${name}",
$mode = '0644',
$options = {},
Enum['present', 'absent', 'directory'] $ensure = 'present',
Variant[Array[String], String, Undef] $source = undef,
Optional[String] $content = undef,
Stdlib::Absolutepath $path = "/etc/postfix/${name}",
String $mode = '0644',
Hash $options = {},
) {
include ::postfix::params
validate_absolute_path($path)
if !is_string($source) and !is_array($source) { fail("value for source should be either String type or Array type got ${source}") }
if !is_string($content) { fail("value for content should be String type; got ${content}") }
validate_re($ensure, ['present', 'absent', 'directory'],
"\$ensure must be either 'present', 'absent' or 'directory', got '${ensure}'")
validate_hash($options)
if (!defined(Class['postfix'])) {
fail 'You must define class postfix before using postfix::config!'
}
......@@ -68,7 +61,6 @@ define postfix::conffile (
fail 'You must provide either \'source\' or \'content\', not both'
}
validate_hash($options)
if !$source and !$content and $ensure == 'present' and empty($options) {
fail 'You must provide \'options\' hash parameter if you don\'t provide \'source\' neither \'content\''
}
......
......@@ -27,13 +27,15 @@
# ensure => 'blank',
# }
#
define postfix::config ($value = undef, $ensure = 'present') {
define postfix::config (
Optional[String] $value = undef,
Enum['present', 'absent', 'blank'] $ensure = 'present',
) {
validate_re($ensure, ['present', 'absent', 'blank'],
"\$ensure must be either 'present', 'absent' or 'blank', got '${ensure}'")
if ($ensure == 'present') {
validate_re($value, '^.+$',
'$value can not be empty if ensure = present')
assert_type(Pattern[/^.+$/], $value) |$e, $a| {
fail '$value can not be empty if ensure = present'
}
}
if (!defined(Class['postfix'])) {
......
......@@ -19,9 +19,9 @@ class postfix::files {
$use_schleuder = $postfix::use_schleuder
$use_sympa = $postfix::use_sympa
validate_string($mastercf_source)
validate_string($master_smtp)
validate_string($master_smtps)
assert_type(Optional[String], $mastercf_source)
assert_type(Optional[String], $master_smtp)
assert_type(Optional[String], $master_smtps)
File {
replace => $manage_conffiles,
......
......@@ -25,17 +25,13 @@
# }
#
define postfix::hash (
$ensure='present',
$source=undef,
$content=undef,
Enum['present', 'absent'] $ensure='present',
Variant[Array[String], String, Undef] $source=undef,
Variant[Array[String], String, Undef] $content=undef,
) {
include ::postfix::params
validate_absolute_path($name)
if !is_string($source) and !is_array($source) { fail("value for source should be either String type or Array type got ${source}") }
if !is_string($content) and !is_array($content) { fail("value for source should be either String type or Array type got ${content}") }
validate_re($ensure, ['present', 'absent'],
"\$ensure must be either 'present' or 'absent', got '${ensure}'")
assert_type(Stdlib::Absolutepath, $name)
if (!defined(Class['postfix'])) {
fail 'You must define class postfix before using postfix::config!'
......
......@@ -72,64 +72,38 @@
# }
#
class postfix (
$alias_maps = 'hash:/etc/aliases',
$inet_interfaces = 'all',
$ldap = false,
$ldap_base = undef,
$ldap_host = undef,
$ldap_options = undef,
$mail_user = 'vmail', # postfix_mail_user
$mailman = false,
$maincf_source = "puppet:///modules/${module_name}/main.cf",
$manage_conffiles = true,
$manage_mailx = true,
$mastercf_source = undef,
$master_smtp = undef, # postfix_master_smtp
$master_smtps = undef, # postfix_master_smtps
$master_submission = undef, # postfix_master_submission
$mta = false,
$mydestination = '$myorigin', # postfix_mydestination
$mynetworks = '127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128', # postfix_mynetworks
$myorigin = $::fqdn,
$relayhost = undef, # postfix_relayhost
$manage_root_alias = true,
$root_mail_recipient = 'nobody', # root_mail_recipient
$satellite = false,
$smtp_listen = '127.0.0.1', # postfix_smtp_listen
$use_amavisd = false, # postfix_use_amavisd
$use_dovecot_lda = false, # postfix_use_dovecot_lda
$use_schleuder = false, # postfix_use_schleuder
$use_sympa = false, # postfix_use_sympa
$postfix_ensure = 'present',
$mailx_ensure = 'present',
String $alias_maps = 'hash:/etc/aliases',
String $inet_interfaces = 'all',
Boolean $ldap = false,
Optional[String] $ldap_base = undef,
Optional[String] $ldap_host = undef,
Optional[String] $ldap_options = undef,
String $mail_user = 'vmail', # postfix_mail_user
Boolean $mailman = false,
String $maincf_source = "puppet:///modules/${module_name}/main.cf",
Boolean $manage_conffiles = true,
Boolean $manage_mailx = true,
Optional[String] $mastercf_source = undef,
Optional[String] $master_smtp = undef, # postfix_master_smtp
Optional[String] $master_smtps = undef, # postfix_master_smtps
Optional[String] $master_submission = undef, # postfix_master_submission
Boolean $mta = false,
String $mydestination = '$myorigin', # postfix_mydestination
String $mynetworks = '127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128', # postfix_mynetworks
String $myorigin = $::fqdn,
Optional[String] $relayhost = undef, # postfix_relayhost
Boolean $manage_root_alias = true,
Variant[Array[String], String] $root_mail_recipient = 'nobody', # root_mail_recipient
Boolean $satellite = false,
String $smtp_listen = '127.0.0.1', # postfix_smtp_listen
Boolean $use_amavisd = false, # postfix_use_amavisd
Boolean $use_dovecot_lda = false, # postfix_use_dovecot_lda
Boolean $use_schleuder = false, # postfix_use_schleuder
Boolean $use_sympa = false, # postfix_use_sympa
String $postfix_ensure = 'present',
String $mailx_ensure = 'present',
) inherits postfix::params {
validate_bool($ldap)
validate_bool($mailman)
validate_bool($mta)
validate_bool($manage_root_alias)
validate_bool($manage_mailx)
validate_bool($satellite)
validate_bool($use_amavisd)
validate_bool($use_dovecot_lda)
validate_bool($use_schleuder)
validate_bool($use_sympa)
validate_string($alias_maps)
validate_string($inet_interfaces)
validate_string($mail_user)
validate_string($mydestination)
validate_string($mynetworks)
validate_string($myorigin)
validate_string($relayhost)
if ! is_array($root_mail_recipient) {
validate_string($root_mail_recipient)
}
validate_string($smtp_listen)
$_smtp_listen = $mailman ? {
true => '0.0.0.0',
default => $smtp_listen,
......
......@@ -15,9 +15,9 @@
#
class postfix::ldap {
validate_string($postfix::ldap_base)
validate_string($postfix::ldap_host)
validate_string($postfix::ldap_options)
assert_type(String, $postfix::ldap_base)
assert_type(String, $postfix::ldap_host)
assert_type(String, $postfix::ldap_options)
if $::osfamily == 'Debian' {
package {'postfix-ldap':
......
......@@ -27,20 +27,14 @@
# }
#
define postfix::map (
$ensure = 'present',
$source = undef,
$content = undef,
$type = 'hash',
$path = "/etc/postfix/${name}",
Enum['present', 'absent'] $ensure = 'present',
Variant[Array[String], String, Undef] $source = undef,
Variant[Array[String], String, Undef] $content = undef,
String $type = 'hash',
Stdlib::Absolutepath $path = "/etc/postfix/${name}",
) {
include ::postfix::params
validate_absolute_path($path)
if !is_string($source) and !is_array($source) { fail("value for source should be either String type or Array type got ${source}") }
if !is_string($content) and !is_array($content) { fail("value for source should be either String type or Array type got ${content}") }
validate_re($ensure, ['present', 'absent'],
"\$ensure must be either 'present' or 'absent', got '${ensure}'")
if (!defined(Class['postfix'])) {
fail 'You must define class postfix before using postfix::config!'
}
......
......@@ -26,18 +26,11 @@
# }
#
class postfix::mta (
$mydestination = $postfix::mydestination,
$mynetworks = $postfix::mynetworks,
$relayhost = $postfix::relayhost,
Pattern[/^\S+(?:,\s*\S+)*$/] $mydestination = $postfix::mydestination,
Pattern[/^(?:\S+?(?:(?:,\s)|(?:\s))?)*$/] $mynetworks = $postfix::mynetworks,
Pattern[/^\S+$/] $relayhost = $postfix::relayhost,
) {
validate_re($relayhost, '^\S+$',
'Wrong value for $relayhost')
validate_re($mydestination, '^\S+(?:,\s*\S+)*$',
'Wrong value for $mydestination')
validate_re($mynetworks, '^(?:\S+?(?:(?:,\s)|(?:\s))?)*$',
'Wrong value for $mynetworks')
# If direct is specified then relayhost should be blank
if ($relayhost == 'direct') {
postfix::config { 'relayhost': ensure => 'blank' }
......
......@@ -28,7 +28,7 @@ class postfix::satellite (
$relayhost = $postfix::relayhost,
) {
validate_re($postfix::myorigin, '^\S+$')
assert_type(Pattern[/^\S+$/], $postfix::myorigin)
class { '::postfix::mta':
mydestination => $mydestination,
......
......@@ -35,19 +35,13 @@
# }
#
define postfix::transport (
$destination=undef,
$nexthop=undef,
$file='/etc/postfix/transport',
$ensure='present'
Optional[String] $destination = undef,
Optional[String] $nexthop=undef,
Stdlib::Absolutepath $file='/etc/postfix/transport',
Enum['present', 'absent'] $ensure='present'
) {
include ::postfix::augeas
validate_string($destination)
validate_string($nexthop)
validate_string($file)
validate_absolute_path($file)
validate_string($ensure)
case $ensure {
'present': {
if ($destination) {
......
......@@ -35,17 +35,12 @@
# }
#
define postfix::virtual (
$destination,
$file='/etc/postfix/virtual',
$ensure='present'
String $destination,
Stdlib::Absolutepath $file='/etc/postfix/virtual',
Enum['present', 'absent'] $ensure='present'
) {
include ::postfix::augeas
validate_string($destination)
validate_string($file)
validate_absolute_path($file)
validate_string($ensure)
case $ensure {
'present': {
$changes = [
......
......@@ -31,7 +31,7 @@ describe 'postfix::conffile' do
it 'should fail' do
expect {
is_expected.to contain_file('postfix conffile foo')
}.to raise_error(Puppet::Error, /must be either 'present', 'absent' or 'directory'/)
}.to raise_error(Puppet::Error, /got 'running'/)
end
end
......
......@@ -52,7 +52,7 @@ describe 'postfix::config' do
it 'should fail' do
expect {
is_expected.to contain_augeas("set postfix 'foo'")
}.to raise_error(Puppet::Error, /must be either 'present', 'absent' or 'blank'/)
}.to raise_error(Puppet::Error, /got 'running'/)
end
end
......
......@@ -31,7 +31,7 @@ describe 'postfix::hash' do
it 'should fail' do
expect {
is_expected.to contain_file('/tmp/foo')
}.to raise_error(Puppet::Error, /must be either 'present' or 'absent'/)
}.to raise_error(Puppet::Error, /got 'running'/)
end
end
......@@ -40,7 +40,7 @@ describe 'postfix::hash' do
it 'should fail' do
expect {
is_expected.to contain_file('/tmp/foo')
}.to raise_error(Puppet::Error, /"foo" is not an absolute path/)
}.to raise_error(Puppet::Error, /got 'foo'/)
end
end
......
......@@ -31,7 +31,7 @@ describe 'postfix::map' do
it 'should fail' do
expect {
is_expected.to contain_file('postfix map foo')
}.to raise_error(Puppet::Error, /must be either 'present' or 'absent'/)
}.to raise_error(Puppet::Error, /got 'running'/)
end
end
......
......@@ -63,7 +63,7 @@ describe 'postfix::transport' do
it 'should fail' do
expect {
is_expected.to contain_augeas('Postfix transport - foo')
}.to raise_error(Puppet::Error, /"baz" is not an absolute path/)
}.to raise_error(Puppet::Error, /got 'baz'/)
end
end
......@@ -89,7 +89,7 @@ describe 'postfix::transport' do
it 'should fail' do
expect {
is_expected.to contain_augeas('Postfix transport - foo')
}.to raise_error(Puppet::Error, /\$ensure must be either/)
}.to raise_error(Puppet::Error, /got 'running'/)
end
end
......
......@@ -58,7 +58,7 @@ describe 'postfix::virtual' do
it 'should fail' do
expect {
is_expected.to contain_augeas('Postfix virtual - foo')
}.to raise_error(Puppet::Error, /"baz" is not an absolute path/)
}.to raise_error(Puppet::Error, /got 'baz'/)
end
end
......@@ -84,7 +84,7 @@ describe 'postfix::virtual' do
it 'should fail' do
expect {
is_expected.to contain_augeas('Postfix virtual - foo')
}.to raise_error(Puppet::Error, /\$ensure must be either/)
}.to raise_error(Puppet::Error, /got 'running'/)
end
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment