mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
email_server: action: Refactor for simplicity
- Parse arguments in a readable way. - Convert decorator into simple call. - Make a simple call instead of looking for subcommand. - Don't setup logging in global scope. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
1 parent
220149e6e0
commit
a2038e98d6
8 files changed
+38
-45
No files matched your search
@@ -98,7 +98,7 @@ def _set_status(uid, aliases, status):
|
||||
|
||||
def first_setup():
|
||||
"""Create the database file and schema inside it."""
|
||||
actions.superuser_run('email_server', ['-i', 'aliases', 'setup'])
|
||||
actions.superuser_run('email_server', ['aliases', 'setup'])
|
||||
|
||||
# Create schema if not exists
|
||||
query = '''
|
||||
|
||||
@@ -42,14 +42,14 @@ def get():
|
||||
|
||||
|
||||
def repair():
|
||||
superuser_run('email_server', ['-i', 'domain', 'set_up'])
|
||||
superuser_run('email_server', ['domain', 'set_up'])
|
||||
|
||||
|
||||
def repair_component(action_name):
|
||||
allowed_actions = {'set_up': ['postfix']}
|
||||
if action_name not in allowed_actions:
|
||||
return
|
||||
superuser_run('email_server', ['-i', 'domain', action_name])
|
||||
superuser_run('email_server', ['domain', action_name])
|
||||
return allowed_actions[action_name]
|
||||
|
||||
|
||||
@@ -199,7 +199,7 @@ def set_keys(raw):
|
||||
raise ClientError('POST data exceeds max line length')
|
||||
|
||||
try:
|
||||
superuser_run('email_server', ['-i', 'domain', 'set_keys'], input=ipc)
|
||||
superuser_run('email_server', ['domain', 'set_keys'], input=ipc)
|
||||
except ActionError as e:
|
||||
stdout = e.args[1]
|
||||
if not stdout.startswith('ClientError:'):
|
||||
|
||||
@@ -49,8 +49,7 @@ def put_uid(uid_number):
|
||||
|
||||
def _put(arg_type, user_info):
|
||||
try:
|
||||
args = ['-i', 'home', 'mk', arg_type, user_info]
|
||||
superuser_run('email_server', args)
|
||||
superuser_run('email_server', ['home', 'mk', arg_type, user_info])
|
||||
except ActionError as e:
|
||||
raise RuntimeError('Action script failure') from e
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ def repair():
|
||||
POST /audit/ldap/repair
|
||||
"""
|
||||
aliases.first_setup()
|
||||
actions.superuser_run('email_server', ['-i', 'ldap', 'set_up'])
|
||||
actions.superuser_run('email_server', ['ldap', 'set_up'])
|
||||
|
||||
|
||||
def action_set_up():
|
||||
|
||||
@@ -32,7 +32,7 @@ def get():
|
||||
'rc_config_header': _('RoundCube configured for FreedomBox email'),
|
||||
}
|
||||
|
||||
output = actions.superuser_run('email_server', ['-i', 'rcube', 'check'])
|
||||
output = actions.superuser_run('email_server', ['rcube', 'check'])
|
||||
results = json.loads(output)
|
||||
for i in range(0, len(results)):
|
||||
results[i] = models.Diagnosis.from_json(results[i], translation.get)
|
||||
@@ -41,14 +41,14 @@ def get():
|
||||
|
||||
|
||||
def repair():
|
||||
actions.superuser_run('email_server', ['-i', 'rcube', 'set_up'])
|
||||
actions.superuser_run('email_server', ['rcube', 'set_up'])
|
||||
|
||||
|
||||
def repair_component(action):
|
||||
action_to_services = {'set_up': []}
|
||||
if action not in action_to_services:
|
||||
return
|
||||
actions.superuser_run('email_server', ['-i', 'rcube', action])
|
||||
actions.superuser_run('email_server', ['rcube', action])
|
||||
return action_to_services[action]
|
||||
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ def get():
|
||||
|
||||
|
||||
def repair():
|
||||
actions.superuser_run('email_server', ['-i', 'spam', 'set_filter'])
|
||||
actions.superuser_run('email_server', ['spam', 'set_filter'])
|
||||
|
||||
|
||||
def check_filter(title=''):
|
||||
|
||||
@@ -90,20 +90,20 @@ def _get_superuser_results(results):
|
||||
translation = {
|
||||
'cert_availability': _('Has a TLS certificate'),
|
||||
}
|
||||
dump = actions.superuser_run('email_server', ['-i', 'tls', 'check'])
|
||||
dump = actions.superuser_run('email_server', ['tls', 'check'])
|
||||
for jmap in json.loads(dump):
|
||||
results.append(models.Diagnosis.from_json(jmap, translation.get))
|
||||
|
||||
|
||||
def repair():
|
||||
actions.superuser_run('email_server', ['-i', 'tls', 'set_up'])
|
||||
actions.superuser_run('email_server', ['tls', 'set_up'])
|
||||
|
||||
|
||||
def repair_component(action):
|
||||
action_to_services = {'set_cert': ['dovecot', 'postfix']}
|
||||
if action not in action_to_services: # action not allowed
|
||||
return
|
||||
actions.superuser_run('email_server', ['-i', 'tls', action])
|
||||
actions.superuser_run('email_server', ['tls', action])
|
||||
return action_to_services[action]
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user