diff --git a/cmdeploy/src/cmdeploy/__init__.py b/cmdeploy/src/cmdeploy/__init__.py index 1cfe478f..1dce8168 100644 --- a/cmdeploy/src/cmdeploy/__init__.py +++ b/cmdeploy/src/cmdeploy/__init__.py @@ -270,16 +270,12 @@ def _configure_opendkim(domain: str, dkim_selector: str = "dkim") -> bool: class OpendkimDeployer(Deployer): + required_users = [("opendkim", None, ["opendkim"])] + def __init__(self, *, mail_domain, **kwargs): super().__init__(**kwargs) self.mail_domain = mail_domain - @staticmethod - def required_users(): - return [ - ("opendkim", None, ["opendkim"]), - ] - @staticmethod def install_impl(): apt.packages( @@ -425,16 +421,13 @@ def _configure_postfix(config: Config, debug: bool = False) -> bool: class PostfixDeployer(Deployer): + required_users = [("postfix", None, ["opendkim"]),] + def __init__(self, *, config, disable_mail, **kwargs): super().__init__(**kwargs) self.config = config self.disable_mail = disable_mail - @staticmethod - def required_users(): - return [ - ("postfix", None, ["opendkim"]), - ] @staticmethod def install_impl(): @@ -1005,17 +998,14 @@ class ChatmailVenvDeployer(Deployer): class ChatmailDeployer(Deployer): - def __init__(self, *, mail_domain, **kwargs): - super().__init__(**kwargs) - self.mail_domain = mail_domain - - @staticmethod - def required_users(): - return [ + required_users = [ ("vmail", "vmail", None), ("echobot", None, None), ("iroh", None, None), - ] + ] + def __init__(self, *, mail_domain, **kwargs): + super().__init__(**kwargs) + self.mail_domain = mail_domain @staticmethod def install_impl(): @@ -1146,10 +1136,6 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None: MtailDeployer(mtail_address=config.mtail_address), ] - # - # Create all groups before users, because some users reference groups - # from other classes. - # for deployer in all_deployers: deployer.install() diff --git a/cmdeploy/src/cmdeploy/deployer.py b/cmdeploy/src/cmdeploy/deployer.py index 7ef0afa4..f6355d5b 100644 --- a/cmdeploy/src/cmdeploy/deployer.py +++ b/cmdeploy/src/cmdeploy/deployer.py @@ -4,27 +4,21 @@ from pyinfra.operations import server class Deployer: - def __init__(self, **kwargs): + + def __init__(self): default_stages = "install,configure,activate" self.stages = os.getenv("CMDEPLOY_STAGES", default_stages).split(",") 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): if "install" not in self.stages: return - # create groups - for user, group, groups in self.required_users(): + # optional 'required_users' contains a list of (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, 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: server.group( name="Create {} group".format(group), group=group, system=True @@ -34,9 +28,6 @@ class Deployer: server.group( name="Create {} group".format(group2), group=group2, system=True ) - - # create users - for user, group, groups in self.required_users(): server.user( name="Create {} user".format(user), user=user,