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