From 84ed0ae70708305aa3c66eb04722820d21c7fb26 Mon Sep 17 00:00:00 2001 From: Drew Short Date: Mon, 7 Oct 2019 15:30:34 -0500 Subject: [PATCH] Refactor: Added base64 decode tooling --- server/manage.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/server/manage.py b/server/manage.py index 49262d6..0e08875 100644 --- a/server/manage.py +++ b/server/manage.py @@ -15,6 +15,9 @@ from corvus.service import user_service logging.basicConfig() +ENCODING = 'utf-8' + + @click.group() def main(): pass @@ -25,6 +28,11 @@ def user_command_group(): pass +@click.group(name='base64') +def base64_command_group(): + pass + + @click.command(name='delete') @click.argument('name') def delete_user(name: str): @@ -112,14 +120,24 @@ def list_users(): [click.echo(user.name) for user in all_users] -@click.command(name='base64') +@click.command(name='encode') @click.argument('text') def convert_to_base64(text: str): - print(base64.b64encode(text.encode('utf8')).decode('utf8')) + encoded_text = base64.standard_b64encode(text.encode(ENCODING)).decode(ENCODING) + logging.info('Encoded base64: \'%s\'', encoded_text) + + +@click.command(name='decode') +@click.argument('text') +def convert_from_base64(text: str): + decoded_text = base64.standard_b64decode(text.encode(ENCODING)).decode(ENCODING) + logging.info('Decoded base64: \'%s\'', decoded_text) +main.add_command(base64_command_group) +base64_command_group.add_command(convert_to_base64) +base64_command_group.add_command(convert_from_base64) main.add_command(user_command_group) -main.add_command(convert_to_base64) user_command_group.add_command(register_user) user_command_group.add_command(register_admin_user) user_command_group.add_command(delete_user)