Skip to content

Commit

Permalink
Revert "Refactor configure-module action to use 'always-bcc' rule typ…
Browse files Browse the repository at this point in the history
…e for relay and set BCC address using os.environ['MODULE_ID']"

This reverts commit ebf0dd5.
  • Loading branch information
stephdl committed Apr 26, 2024
1 parent 65057ed commit 636bb9a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
6 changes: 5 additions & 1 deletion imageroot/actions/configure-module/02_validate_bcc_server
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def get_always_bcc(email):
# check if the always_bcc is set to the email
elif response['output']['bcc'] == email:
sys.exit(0)
# check if the always_bcc is previouslys set to piler ([email protected])
elif response['output']['bcc'] == 'archive@'+os.environ.get('TRAEFIK_HOST'):
sys.exit(0)
else:
agent.set_status('validation-failed')
json.dump([{'field':'mail_server','parameter':'mail_server','value': response['output']['bcc'],'error':'always_bcc_is_already_set'}], fp=sys.stdout)
Expand All @@ -41,4 +44,5 @@ def get_always_bcc(email):

if providers:
# we need to set bcc address for the mail server
get_always_bcc('archive@'+os.environ['MODULE_ID'])
get_always_bcc('archive@'+data['host'])

14 changes: 7 additions & 7 deletions imageroot/actions/configure-module/90add-relay-rule
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if providers:
# first configuration, we add the relay rule
response = agent.tasks.run(f"module/{mail_id}", action='add-relay-rule', data={
"rule_type": "always-bcc",
"rule_subject": "archive@"+os.environ['MODULE_ID'],
"rule_subject": "archive@"+data["host"],
"host": ip_address,
"port": int(os.environ['TCP_PORT_ARCHIVE']),
"mandatory_tls": False,
Expand All @@ -41,7 +41,7 @@ if providers:
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']
"bcc": "archive@"+data["host"]
})
agent.assert_exp(response['exit_code'] == 0)
elif os.environ.get("MAIL_SERVER") and data["mail_server"] != os.environ.get("MAIL_SERVER"):
Expand All @@ -52,7 +52,7 @@ if providers:
if providers_old:
mail_id_old = providers_old[0]["module_id"]
response = agent.tasks.run(f"module/{mail_id_old}", action='remove-relay-rule', data={
"rule_subject": "archive@"+os.environ['MODULE_ID']})
"rule_subject": "archive@"+data["host"]})
agent.assert_exp(response['exit_code'] == 0)
# we need to remove bcc address for the mail server
response = agent.tasks.run(f"module/{mail_id_old}", action='set-always-bcc', data={
Expand All @@ -62,7 +62,7 @@ if providers:
# add the new relay rule
response = agent.tasks.run(f"module/{mail_id}", action='add-relay-rule', data={
"rule_type": "always-bcc",
"rule_subject": "archive@"+os.environ['MODULE_ID'],
"rule_subject": "archive@"+data["host"],
"host": ip_address,
"port": int(os.environ['TCP_PORT_ARCHIVE']),
"mandatory_tls": False,
Expand All @@ -72,14 +72,14 @@ if providers:
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']
"bcc": "archive@"+data["host"]
})
agent.assert_exp(response['exit_code'] == 0)
else:
# same mail server, we just update the relay rule
response = agent.tasks.run(f"module/{mail_id}", action='alter-relay-rule', data={
"rule_type": "always-bcc",
"rule_subject": "archive@"+os.environ['MODULE_ID'],
"rule_subject": "archive@"+data["host"],
"host": ip_address,
"port": int(os.environ['TCP_PORT_ARCHIVE']),
"mandatory_tls": False,
Expand All @@ -89,7 +89,7 @@ if providers:
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']
"bcc": "archive@"+data["host"]
})
agent.assert_exp(response['exit_code'] == 0)

Expand Down
3 changes: 1 addition & 2 deletions imageroot/actions/destroy-module/20destroy
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ rdb = agent.redis_connect()
providers_old = agent.list_service_providers(rdb, 'imap', 'tcp', {
'module_uuid': os.environ.get("MAIL_SERVER")
})

if providers_old:
mail_id_old = providers_old[0]["module_id"]
response = agent.tasks.run(f"module/{mail_id_old}", action='remove-relay-rule', data={
"rule_subject": "archive@"+os.environ['MODULE_ID']})
"rule_subject": "archive@"+os.environ.get("TRAEFIK_HOST")})
# we need to set bcc address for the mail server
response = agent.tasks.run(f"module/{mail_id_old}", action='set-always-bcc', data={
"bcc": ""
Expand Down

0 comments on commit 636bb9a

Please sign in to comment.