Skip to content

Commit

Permalink
Refactor configure-module action to use 'always-bcc' rule type for re…
Browse files Browse the repository at this point in the history
…lay and set BCC address using os.environ['MODULE_ID']
  • Loading branch information
stephdl committed Apr 25, 2024
1 parent fae8fe3 commit ebf0dd5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
6 changes: 1 addition & 5 deletions imageroot/actions/configure-module/02_validate_bcc_server
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ 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 @@ -44,5 +41,4 @@ def get_always_bcc(email):

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

get_always_bcc('archive@'+os.environ['MODULE_ID'])
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@"+data["host"],
"rule_subject": "archive@"+os.environ['MODULE_ID'],
"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@"+data["host"]
"bcc": "archive@"+os.environ['MODULE_ID']
})
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@"+data["host"]})
"rule_subject": "archive@"+os.environ['MODULE_ID']})
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@"+data["host"],
"rule_subject": "archive@"+os.environ['MODULE_ID'],
"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@"+data["host"]
"bcc": "archive@"+os.environ['MODULE_ID']
})
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@"+data["host"],
"rule_subject": "archive@"+os.environ['MODULE_ID'],
"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@"+data["host"]
"bcc": "archive@"+os.environ['MODULE_ID']
})
agent.assert_exp(response['exit_code'] == 0)

Expand Down
3 changes: 2 additions & 1 deletion imageroot/actions/destroy-module/20destroy
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ 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.get("TRAEFIK_HOST")})
"rule_subject": "archive@"+os.environ['MODULE_ID']})
# 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 ebf0dd5

Please sign in to comment.