feat: add basic postfix config helpers
This commit is contained in:
parent
a45a619cf3
commit
2a83142d95
6
docs/api/wuttamess.postfix.rst
Normal file
6
docs/api/wuttamess.postfix.rst
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
``wuttamess.postfix``
|
||||||
|
=====================
|
||||||
|
|
||||||
|
.. automodule:: wuttamess.postfix
|
||||||
|
:members:
|
|
@ -31,4 +31,5 @@ project.
|
||||||
|
|
||||||
api/wuttamess
|
api/wuttamess
|
||||||
api/wuttamess.apt
|
api/wuttamess.apt
|
||||||
|
api/wuttamess.postfix
|
||||||
api/wuttamess.sync
|
api/wuttamess.sync
|
||||||
|
|
67
src/wuttamess/postfix.py
Normal file
67
src/wuttamess/postfix.py
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
# -*- coding: utf-8; -*-
|
||||||
|
################################################################################
|
||||||
|
#
|
||||||
|
# WuttaMess -- Fabric Automation Helpers
|
||||||
|
# Copyright © 2024 Lance Edgar
|
||||||
|
#
|
||||||
|
# This file is part of Wutta Framework.
|
||||||
|
#
|
||||||
|
# Wutta Framework is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the Free
|
||||||
|
# Software Foundation, either version 3 of the License, or (at your option) any
|
||||||
|
# later version.
|
||||||
|
#
|
||||||
|
# Wutta Framework is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
# more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along with
|
||||||
|
# Wutta Framework. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
"""
|
||||||
|
Postfix mail service
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def set_config(c, setting, value):
|
||||||
|
"""
|
||||||
|
Configure the given setting with the given value.
|
||||||
|
"""
|
||||||
|
c.run(f"postconf -e '{setting}={value}'")
|
||||||
|
|
||||||
|
|
||||||
|
def set_myhostname(c, hostname):
|
||||||
|
"""
|
||||||
|
Configure the ``myhostname`` setting with the given string.
|
||||||
|
"""
|
||||||
|
set_config(c, 'myhostname', hostname)
|
||||||
|
|
||||||
|
|
||||||
|
def set_myorigin(c, origin):
|
||||||
|
"""
|
||||||
|
Configure the ``myorigin`` setting with the given string.
|
||||||
|
"""
|
||||||
|
set_config(c, 'myorigin', origin)
|
||||||
|
|
||||||
|
|
||||||
|
def set_mydestination(c, *destinations):
|
||||||
|
"""
|
||||||
|
Configure the ``mydestinations`` setting with the given strings.
|
||||||
|
"""
|
||||||
|
set_config(c, 'mydestination', ', '.join(destinations))
|
||||||
|
|
||||||
|
|
||||||
|
def set_mynetworks(c, *networks):
|
||||||
|
"""
|
||||||
|
Configure the ``mynetworks`` setting with the given strings.
|
||||||
|
"""
|
||||||
|
set_config(c, 'mynetworks', ' '.join(networks))
|
||||||
|
|
||||||
|
|
||||||
|
def set_relayhost(c, relayhost):
|
||||||
|
"""
|
||||||
|
Configure the ``relayhost`` setting with the given string
|
||||||
|
"""
|
||||||
|
set_config(c, 'relayhost', relayhost)
|
54
tests/test_postfix.py
Normal file
54
tests/test_postfix.py
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
# -*- coding: utf-8; -*-
|
||||||
|
|
||||||
|
from unittest import TestCase
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
from wuttamess import postfix as mod
|
||||||
|
|
||||||
|
|
||||||
|
class TestSetConfig(TestCase):
|
||||||
|
|
||||||
|
def test_basic(self):
|
||||||
|
c = MagicMock()
|
||||||
|
mod.set_config(c, 'foo', 'bar')
|
||||||
|
c.run.assert_called_once_with("postconf -e 'foo=bar'")
|
||||||
|
|
||||||
|
|
||||||
|
class TestSetMyhostname(TestCase):
|
||||||
|
|
||||||
|
def test_basic(self):
|
||||||
|
c = MagicMock()
|
||||||
|
mod.set_myhostname(c, 'test.example.com')
|
||||||
|
c.run.assert_called_once_with("postconf -e 'myhostname=test.example.com'")
|
||||||
|
|
||||||
|
|
||||||
|
class TestSetMyorigin(TestCase):
|
||||||
|
|
||||||
|
def test_basic(self):
|
||||||
|
c = MagicMock()
|
||||||
|
mod.set_myorigin(c, 'example.com')
|
||||||
|
c.run.assert_called_once_with("postconf -e 'myorigin=example.com'")
|
||||||
|
|
||||||
|
|
||||||
|
class TestSetMydestination(TestCase):
|
||||||
|
|
||||||
|
def test_basic(self):
|
||||||
|
c = MagicMock()
|
||||||
|
mod.set_mydestination(c, 'example.com', 'test.example.com', 'localhost')
|
||||||
|
c.run.assert_called_once_with("postconf -e 'mydestination=example.com, test.example.com, localhost'")
|
||||||
|
|
||||||
|
|
||||||
|
class TestSetMynetworks(TestCase):
|
||||||
|
|
||||||
|
def test_basic(self):
|
||||||
|
c = MagicMock()
|
||||||
|
mod.set_mynetworks(c, '127.0.0.0/8', '[::1]/128')
|
||||||
|
c.run.assert_called_once_with("postconf -e 'mynetworks=127.0.0.0/8 [::1]/128'")
|
||||||
|
|
||||||
|
|
||||||
|
class TestSetRelayhost(TestCase):
|
||||||
|
|
||||||
|
def test_basic(self):
|
||||||
|
c = MagicMock()
|
||||||
|
mod.set_relayhost(c, 'mail.example.com')
|
||||||
|
c.run.assert_called_once_with("postconf -e 'relayhost=mail.example.com'")
|
Loading…
Reference in a new issue