From 056103dba505de3995c2726fb9dc696a75810bb9 Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Thu, 30 May 2024 16:52:34 +0200 Subject: [PATCH 1/4] Update environment variable handling for retention days The code changes modify the handling of the `RETENTION_DAYS` environment variable in the `clone-module` and `restore-module` actions. The variable is now converted to an integer before being used. This update improves the consistency and reliability of the code. --- imageroot/actions/clone-module/50configure-module | 1 + imageroot/actions/restore-module/06copyenv | 1 + imageroot/actions/restore-module/50configure-module | 1 + 3 files changed, 3 insertions(+) diff --git a/imageroot/actions/clone-module/50configure-module b/imageroot/actions/clone-module/50configure-module index 8991beb..0d5274a 100755 --- a/imageroot/actions/clone-module/50configure-module +++ b/imageroot/actions/clone-module/50configure-module @@ -14,5 +14,6 @@ configure_retval = agent.tasks.run(agent_id=os.environ['AGENT_ID'], action='conf "host": os.environ["TRAEFIK_HOST"], "http2https": os.environ["TRAEFIK_HTTP2HTTPS"] == 'True', "restore": True, + "retention_days": int(os.environ["RETENTION_DAYS"]), }) agent.assert_exp(configure_retval['exit_code'] == 0, "The configure-module subtask failed!") diff --git a/imageroot/actions/restore-module/06copyenv b/imageroot/actions/restore-module/06copyenv index a474691..4aa19a8 100755 --- a/imageroot/actions/restore-module/06copyenv +++ b/imageroot/actions/restore-module/06copyenv @@ -19,6 +19,7 @@ for evar in [ "TRAEFIK_HTTP2HTTPS", "TRAEFIK_LETS_ENCRYPT", "MAIL_SERVER", + "RETENTION_DAYS", ]: agent.set_env(evar, original_environment[evar]) diff --git a/imageroot/actions/restore-module/50configure-module b/imageroot/actions/restore-module/50configure-module index 82f885a..24a86cf 100755 --- a/imageroot/actions/restore-module/50configure-module +++ b/imageroot/actions/restore-module/50configure-module @@ -19,5 +19,6 @@ configure_retval = agent.tasks.run(agent_id=os.environ['AGENT_ID'], action='conf "host": renv["TRAEFIK_HOST"], "http2https": renv["TRAEFIK_HTTP2HTTPS"] == 'True', "restore": True, + 'retention_days': int(renv['RETENTION_DAYS']), }) agent.assert_exp(configure_retval['exit_code'] == 0, "The configure-module subtask failed!") From 6f5ea6f85dfc43c9e17756c78e33f0caa0ab7307 Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Thu, 30 May 2024 19:01:23 +0200 Subject: [PATCH 2/4] Use add-relay-rule on restoration and clone action --- imageroot/actions/configure-module/90add-relay-rule | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imageroot/actions/configure-module/90add-relay-rule b/imageroot/actions/configure-module/90add-relay-rule index bc36c9e..3396e84 100755 --- a/imageroot/actions/configure-module/90add-relay-rule +++ b/imageroot/actions/configure-module/90add-relay-rule @@ -27,7 +27,7 @@ ip_address = rdb.hget(f'node/{node_id}/vpn', 'ip_address') if providers: mail_id = providers[0]["module_id"] - if not os.environ.get("MAIL_SERVER"): + if not os.environ.get("MAIL_SERVER") or data.get("restore", False): # first configuration, we add the relay rule response = agent.tasks.run(f"module/{mail_id}", action='add-relay-rule', data={ "rule_type": "always-bcc", From 2fe3e21893eb869fb3f3d14054c54926a4387775 Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Thu, 30 May 2024 19:23:08 +0200 Subject: [PATCH 3/4] Add comments on restore True --- imageroot/actions/clone-module/50configure-module | 2 +- imageroot/actions/configure-module/90add-relay-rule | 1 + imageroot/actions/restore-module/50configure-module | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/imageroot/actions/clone-module/50configure-module b/imageroot/actions/clone-module/50configure-module index 0d5274a..a304132 100755 --- a/imageroot/actions/clone-module/50configure-module +++ b/imageroot/actions/clone-module/50configure-module @@ -13,7 +13,7 @@ configure_retval = agent.tasks.run(agent_id=os.environ['AGENT_ID'], action='conf "lets_encrypt": os.environ["TRAEFIK_LETS_ENCRYPT"] == 'True', "host": os.environ["TRAEFIK_HOST"], "http2https": os.environ["TRAEFIK_HTTP2HTTPS"] == 'True', - "restore": True, + "restore": True, # restore the configuration to the relay rule and the alwaysBccAddress "retention_days": int(os.environ["RETENTION_DAYS"]), }) agent.assert_exp(configure_retval['exit_code'] == 0, "The configure-module subtask failed!") diff --git a/imageroot/actions/configure-module/90add-relay-rule b/imageroot/actions/configure-module/90add-relay-rule index 3396e84..b7c4126 100755 --- a/imageroot/actions/configure-module/90add-relay-rule +++ b/imageroot/actions/configure-module/90add-relay-rule @@ -27,6 +27,7 @@ ip_address = rdb.hget(f'node/{node_id}/vpn', 'ip_address') if providers: mail_id = providers[0]["module_id"] + # we configure the first time and if we are in a clone or restore action if not os.environ.get("MAIL_SERVER") or data.get("restore", False): # first configuration, we add the relay rule response = agent.tasks.run(f"module/{mail_id}", action='add-relay-rule', data={ diff --git a/imageroot/actions/restore-module/50configure-module b/imageroot/actions/restore-module/50configure-module index 24a86cf..114ba36 100755 --- a/imageroot/actions/restore-module/50configure-module +++ b/imageroot/actions/restore-module/50configure-module @@ -18,7 +18,7 @@ configure_retval = agent.tasks.run(agent_id=os.environ['AGENT_ID'], action='conf "lets_encrypt": renv["TRAEFIK_LETS_ENCRYPT"] == 'True', "host": renv["TRAEFIK_HOST"], "http2https": renv["TRAEFIK_HTTP2HTTPS"] == 'True', - "restore": True, + "restore": True, # restore the configuration to the relay rule and the alwaysBccAddress 'retention_days': int(renv['RETENTION_DAYS']), }) agent.assert_exp(configure_retval['exit_code'] == 0, "The configure-module subtask failed!") From 6e06b9ebc135a26cafb727fcc5ba6b81a0933828 Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Thu, 30 May 2024 19:32:59 +0200 Subject: [PATCH 4/4] The mail server is configured once, archive cannot alter settings except only for restoration/clone action The code changes remove unnecessary code related to altering relay rules and setting always-bcc address for the mail server in the `configure-module` script. This simplifies the script and improves its efficiency. --- .../actions/configure-module/90add-relay-rule | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/imageroot/actions/configure-module/90add-relay-rule b/imageroot/actions/configure-module/90add-relay-rule index b7c4126..555779a 100755 --- a/imageroot/actions/configure-module/90add-relay-rule +++ b/imageroot/actions/configure-module/90add-relay-rule @@ -45,21 +45,5 @@ if providers: "bcc": "archive@"+os.environ['MODULE_ID'] }) agent.assert_exp(response['exit_code'] == 0) - else: - response = agent.tasks.run(f"module/{mail_id}", action='alter-relay-rule', data={ - "rule_type": "always-bcc", - "rule_subject": "archive@"+os.environ['MODULE_ID'], - "host": ip_address, - "port": int(os.environ['TCP_PORT_ARCHIVE']), - "mandatory_tls": False, - "username": "", - "password": "", - "enabled": True}) - agent.assert_exp(response['exit_code'] == 0) - # we need to set bcc address for the mail server - response = agent.tasks.run(f"module/{mail_id}", action='set-always-bcc', data={ - "bcc": "archive@"+os.environ['MODULE_ID'] - }) - agent.assert_exp(response['exit_code'] == 0) agent.set_env("MAIL_SERVER", data["mail_server"])