mirror of
https://github.com/chatmail/relay.git
synced 2026-05-17 00:18:58 +00:00
simplify required_users configuration (a method is not needed for now)
This commit is contained in:
@@ -270,16 +270,12 @@ def _configure_opendkim(domain: str, dkim_selector: str = "dkim") -> bool:
|
|||||||
|
|
||||||
|
|
||||||
class OpendkimDeployer(Deployer):
|
class OpendkimDeployer(Deployer):
|
||||||
|
required_users = [("opendkim", None, ["opendkim"])]
|
||||||
|
|
||||||
def __init__(self, *, mail_domain, **kwargs):
|
def __init__(self, *, mail_domain, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.mail_domain = mail_domain
|
self.mail_domain = mail_domain
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def required_users():
|
|
||||||
return [
|
|
||||||
("opendkim", None, ["opendkim"]),
|
|
||||||
]
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def install_impl():
|
def install_impl():
|
||||||
apt.packages(
|
apt.packages(
|
||||||
@@ -425,16 +421,13 @@ def _configure_postfix(config: Config, debug: bool = False) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
class PostfixDeployer(Deployer):
|
class PostfixDeployer(Deployer):
|
||||||
|
required_users = [("postfix", None, ["opendkim"]),]
|
||||||
|
|
||||||
def __init__(self, *, config, disable_mail, **kwargs):
|
def __init__(self, *, config, disable_mail, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.config = config
|
self.config = config
|
||||||
self.disable_mail = disable_mail
|
self.disable_mail = disable_mail
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def required_users():
|
|
||||||
return [
|
|
||||||
("postfix", None, ["opendkim"]),
|
|
||||||
]
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def install_impl():
|
def install_impl():
|
||||||
@@ -1005,17 +998,14 @@ class ChatmailVenvDeployer(Deployer):
|
|||||||
|
|
||||||
|
|
||||||
class ChatmailDeployer(Deployer):
|
class ChatmailDeployer(Deployer):
|
||||||
def __init__(self, *, mail_domain, **kwargs):
|
required_users = [
|
||||||
super().__init__(**kwargs)
|
|
||||||
self.mail_domain = mail_domain
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def required_users():
|
|
||||||
return [
|
|
||||||
("vmail", "vmail", None),
|
("vmail", "vmail", None),
|
||||||
("echobot", None, None),
|
("echobot", None, None),
|
||||||
("iroh", None, None),
|
("iroh", None, None),
|
||||||
]
|
]
|
||||||
|
def __init__(self, *, mail_domain, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.mail_domain = mail_domain
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def install_impl():
|
def install_impl():
|
||||||
@@ -1146,10 +1136,6 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
|
|||||||
MtailDeployer(mtail_address=config.mtail_address),
|
MtailDeployer(mtail_address=config.mtail_address),
|
||||||
]
|
]
|
||||||
|
|
||||||
#
|
|
||||||
# Create all groups before users, because some users reference groups
|
|
||||||
# from other classes.
|
|
||||||
#
|
|
||||||
for deployer in all_deployers:
|
for deployer in all_deployers:
|
||||||
deployer.install()
|
deployer.install()
|
||||||
|
|
||||||
|
|||||||
@@ -4,27 +4,21 @@ from pyinfra.operations import server
|
|||||||
|
|
||||||
|
|
||||||
class Deployer:
|
class Deployer:
|
||||||
def __init__(self, **kwargs):
|
|
||||||
|
def __init__(self):
|
||||||
default_stages = "install,configure,activate"
|
default_stages = "install,configure,activate"
|
||||||
self.stages = os.getenv("CMDEPLOY_STAGES", default_stages).split(",")
|
self.stages = os.getenv("CMDEPLOY_STAGES", default_stages).split(",")
|
||||||
self.need_restart = False
|
self.need_restart = False
|
||||||
|
|
||||||
#
|
|
||||||
# In any override, this method should return a list of 3-element
|
|
||||||
# (user, group, secondary-group-list) tuples. If the group is None,
|
|
||||||
# no group is created corresponding to that user. If the secondary
|
|
||||||
# group list is not None, the listed groups are created as well.
|
|
||||||
#
|
|
||||||
@staticmethod
|
|
||||||
def required_users():
|
|
||||||
return []
|
|
||||||
|
|
||||||
def install(self):
|
def install(self):
|
||||||
if "install" not in self.stages:
|
if "install" not in self.stages:
|
||||||
return
|
return
|
||||||
|
|
||||||
# create groups
|
# optional 'required_users' contains a list of (user, group, secondary-group-list) tuples.
|
||||||
for user, group, groups in self.required_users():
|
# If the group is None, no group is created corresponding to that user.
|
||||||
|
# If the secondary group list is not None, all listed groups are created as well.
|
||||||
|
required_users = getattr(self, "required_users", [])
|
||||||
|
for user, group, groups in required_users:
|
||||||
if group is not None:
|
if group is not None:
|
||||||
server.group(
|
server.group(
|
||||||
name="Create {} group".format(group), group=group, system=True
|
name="Create {} group".format(group), group=group, system=True
|
||||||
@@ -34,9 +28,6 @@ class Deployer:
|
|||||||
server.group(
|
server.group(
|
||||||
name="Create {} group".format(group2), group=group2, system=True
|
name="Create {} group".format(group2), group=group2, system=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# create users
|
|
||||||
for user, group, groups in self.required_users():
|
|
||||||
server.user(
|
server.user(
|
||||||
name="Create {} user".format(user),
|
name="Create {} user".format(user),
|
||||||
user=user,
|
user=user,
|
||||||
|
|||||||
Reference in New Issue
Block a user