From 55bb5b426de921e1791174b3b9ed0083047d858c Mon Sep 17 00:00:00 2001 From: konsthol Date: Sun, 26 Mar 2023 00:37:47 +0200 Subject: [PATCH] The dog is eating my code --- assets/pages/usage/usage.md | 2 +- secdep.py | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/assets/pages/usage/usage.md b/assets/pages/usage/usage.md index 99de6f3..83ead8b 100644 --- a/assets/pages/usage/usage.md +++ b/assets/pages/usage/usage.md @@ -6,7 +6,7 @@ You can also run `python3 secdep.py --init ` where `` is eit ### Configuration ⚙️ -Should you ever change your mind you can always edit the `.env` file manually or run `python3 secdep.py -v` or `python3 secdep.py --values` to change the values you want. +Should you ever change your mind you can always edit the `.env` file manually or run `python3 secdep.py -e` or `python3 secdep.py --edit` to change the values you want. ### Key Creation 🔐 diff --git a/secdep.py b/secdep.py index 712f066..57e7174 100755 --- a/secdep.py +++ b/secdep.py @@ -55,7 +55,8 @@ parser = argparse.ArgumentParser( description='Manage cloud instances', ) parser.add_argument('-l', '--list', help='List all instances or with -P PROVIDER list a provider\'s instances', action='store_true') -parser.add_argument('-v', '--values', help='Change credential values', action='store_true') +parser.add_argument('-e', '--edit', help='Change credential values', action='store_true') +parser.add_argument('-v', '--version', help='Show secdep\'s version', action='store_true') parser.add_argument('-P', '--provider', help='Cloud provider', choices=['gce', 'azure', 'aws']) parser.add_argument('-a', '--action', help='Action to perform on a single provider with -P PROVIDER or all instances. Valid options are delete[all] start[all] stop[all] reboot[all]', choices=action_choices, metavar='ACTION') parser.add_argument('-c', '--create', help='Create an instance', action='store_true') @@ -75,6 +76,13 @@ parser.add_argument('-ssh', '--ssh', help='Connect to an instance using ssh with parser.add_argument('-init', '--init', help='Initialize a specific provider\'s values' , choices=['gce', 'azure', 'aws']) args = parser.parse_args() +def show_version(): + print("SecDep - Automated secure docker services deployment\nVersion: v1.0.0\nRepo: https://git.konsthol.eu/konsthol/SecDep") + +if args.version: + show_version() + exit(0) + # If one or both keys don't exist we create them if not os.path.exists(SECDEP_SSH_PUBLIC_KEY) or not os.path.exists(SECDEP_SSH_PRIVATE_KEY): # Generate a new SSH key pair @@ -143,10 +151,10 @@ if os.stat(ENV_FILE).st_size == 0: case _: print("Invalid provider") else: - print('You will be asked for each needed value\nIf you want to skip a provider press enter on each of their values because they are all needed for authentication\nIf at some point you delete the provider\'s value entry you will once again be asked to enter it\nIf you pressed enter by mistake or inserted an incorrect value just edit the file directly or delete the corresponding line\nThere is also the choice of using the -v option to have that done interactively') + print('You will be asked for each needed value\nIf you want to skip a provider press enter on each of their values because they are all needed for authentication\nIf at some point you delete the provider\'s value entry you will once again be asked to enter it\nIf you pressed enter by mistake or inserted an incorrect value just edit the file directly or delete the corresponding line\nThere is also the choice of using the -e option to have that done interactively') if os.stat(ENV_FILE).st_size != 0 and args.init: - print("The init flag was only meant to be optionally run once and only in the first run if you knew you were going to be using only one provider. If you need to change or populate a provider\'s needed values use the --values or -v flag instead") + print("The init flag was only meant to be optionally run once and only in the first run if you knew you were going to be using only one provider. If you need to change or populate a provider\'s needed values use the --edit or -e flag instead") exit(0) # We search for these values in the ENV_FILE and for each not found, we prompt the user to enter it @@ -276,9 +284,10 @@ def update_env_file(): load_dotenv(ENV_FILE) get_env_vars() -# If -v or --values is passed, call the update_env_file function -if args.values: +# If -e or --edit is passed, call the update_env_file function +if args.edit: update_env_file() + exit(0) # AWS and AZURE have thousands of image choice so we hardcode the ones we want in order to not wait forever during the input validation AWS_ubuntu22_04_images = {