Commit e1255f78 authored by Raphaël Pinson's avatar Raphaël Pinson
Browse files

Merge pull request #37 from vrillusions/allow-direct-delivery

Allow having mta send mail directly.
parents 1eb19d36 2f461e79
Loading
Loading
Loading
Loading
+18 −5
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@
# === Parameters
#
# [*name*]   - name of the parameter.
# [*ensure*] - present/absent. defaults to present.
# [*ensure*] - present/absent/blank. defaults to present.
# [*value*]  - value of the parameter.
#
# === Requires
@@ -23,12 +23,20 @@
#     value  => 'yes',
#   }
#
define postfix::config ($value, $ensure = present) {
#   postfix::config { 'relayhost':
#     ensure => 'blank',
#   }
#
define postfix::config ($value = undef, $ensure = 'present') {

  validate_string($value)
  validate_string($ensure)
  validate_re($ensure, ['present', 'absent'],
    "\$ensure must be either 'present' or 'absent', got '${ensure}'")
  validate_re($ensure, ['present', 'absent', 'blank'],
    "\$ensure must be either 'present', 'absent' or 'blank', got '${ensure}'")
  if ($ensure == 'present') {
    validate_string($value)
    validate_re($value, '^.+$',
      '$value can not be empty if ensure = present')
  }

  if (!defined(Class['postfix'])) {
    fail 'You must define class postfix before using postfix::config!'
@@ -51,6 +59,11 @@ define postfix::config ($value, $ensure = present) {
        changes => "rm ${name}",
      }
    }
    blank: {
      augeas { "blank postfix '${name}'":
        changes => "clear ${name}",
      }
    }
    default: {}
  }
}
+12 −3
Original line number Diff line number Diff line
@@ -3,14 +3,16 @@
# This class configures a minimal MTA, delivering mail to
# $mydestination.
#
# A valid relay host is required ($relayhost) for outbound email.
# Either a valid relay host or the special word 'direct' is required
# ($relayhost) for outbound email.
#
# transport & virtual maps get configured and can be populated with
# postfix::transport and postfix::virtual
#
# === Parameters
#
# [*relayhost*]     - (string) the relayhost to use
# [*relayhost*]     - (string) the relayhost to use or 'direct' to send mail
#                     directly without a relay.
# [*mydestination*] - (string)
# [*mynetworks*]    - (string)
#
@@ -36,10 +38,17 @@ class postfix::mta (
  validate_re($mynetworks, '^\S+$',
              'Wrong value for $mynetworks')

  # If direct is specified then relayhost should be blank
  if ($relayhost == 'direct') {
    postfix::config { 'relayhost': ensure => 'blank' }
  }
  else {
    postfix::config { 'relayhost': value => $relayhost }
  }

  postfix::config {
    'mydestination':       value => $mydestination;
    'mynetworks':          value => $mynetworks;
    'relayhost':           value => $relayhost;
    'virtual_alias_maps':  value => 'hash:/etc/postfix/virtual';
    'transport_maps':      value => 'hash:/etc/postfix/transport';
  }
+2 −2
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ describe 'postfix::config' do
    it 'should fail' do
      expect {
        should contain_augeas("set postfix 'foo'")
      }.to raise_error(Puppet::Error, /Must pass value to Postfix::Config/)
      }.to raise_error(Puppet::Error, /value can not be empty/)
    end
  end

@@ -46,7 +46,7 @@ describe 'postfix::config' do
    it 'should fail' do
      expect {
        should contain_augeas("set postfix 'foo'")
      }.to raise_error(Puppet::Error, /must be either 'present' or 'absent'/)
      }.to raise_error(Puppet::Error, /must be either 'present', 'absent' or 'blank'/)
    end
  end