feature/basic-setup#5
Closed
mutairibassam wants to merge 3 commits into
Closed
Conversation
- add flake test automation - repackage the project to be as a python module - add test directory for unittest - replace args with yml file as the args uses if statements which bring more complixity in the future (prefer to use click package) - code enhancements
mutairibassam
commented
Nov 19, 2022
Comment on lines
-195
to
-207
| global menu_stack | ||
| try: | ||
| current_menu = menu_stack.pop() | ||
| next_menu = menu_stack[-1] | ||
| if next_menu == 'main': | ||
| go_to_menu(next_menu) | ||
| elif next_menu == 'training': | ||
| go_to_menu(next_menu) | ||
| elif next_menu == 'ec2instances': | ||
| go_to_menu(next_menu) | ||
| except Exception as e: | ||
| print(e) | ||
| pass |
Author
There was a problem hiding this comment.
always navigate back to main menu as the stack has only 2 cases
- ['main', 'training]
- ['main', 'ec2instances']
so, menu_stack.pop() removes the last element in both cases return to main. However, dynamic navigation should be written based on stack complexity and supported features.
Comment on lines
-125
to
-163
| myargs = dict(args.grouped) | ||
| if '--help' in myargs or '-h' in myargs: | ||
| help = """ | ||
| barq framework options: | ||
| -h --help - This menu | ||
| -k --keyid - The AWS access key id | ||
| -s --secretkey - The AWS secret access key. (Needs --keyid, mandatory) | ||
| -r --region - The default region to use. (Needs --keyid) | ||
| -t --token - The AWS session token to use. (Needs --keyid, optional) | ||
| """ | ||
| print(help) | ||
| exit(0) | ||
| if '--keyid' in myargs or '-k' in myargs: | ||
| try: | ||
| aws_access_key_id = myargs['--keyid'][0] | ||
| except: | ||
| aws_access_key_id = myargs['-k'][0] | ||
| if '--secretkey' not in myargs and '-s' not in myargs: | ||
| puts(color("[!] using --secretkey is mandatory with --keyid")) | ||
| exit() | ||
| try: | ||
| aws_secret_access_key = myargs['--secretkey'][0] | ||
| except: | ||
| aws_secret_access_key = myargs['-s'][0] | ||
| if '--region' not in myargs and '-r' not in myargs: | ||
| puts(color("[!] using --region is mandatory with --keyid")) | ||
| exit() | ||
| try: | ||
| region_name = myargs['--region'][0] | ||
| except: | ||
| region_name = myargs['-r'][0] | ||
| if '--token' in myargs or '-t' in myargs: | ||
| try: | ||
| aws_session_token = myargs['--token'][0] | ||
| except: | ||
| aws_session_token = myargs['-t'][0] | ||
| else: | ||
| aws_session_token = '' | ||
|
|
Author
There was a problem hiding this comment.
The goal here is to accept arguments and assign them to global variables and establish new amazon session. If arguments are empty the user can later setup new profile.
I replaced terminal args with config file to contain all keys not limited to only amazon and simplified the logic to one if statement.
# config file
amazon:
id: "value"
key: "value"
region: "value"
token: "value"
# future if needed
digital_ocean:
id: "value"
...# unpack secret keys from config file
aws_access_key_id , aws_secret_access_key, region_name, aws_session_token = get_secret()
# if values are empty, print warning...
# if not empty establish a new amazon session
if not aws_access_key_id or aws_secret_access_key or region_name:
puts(color('[!] You haven\'t set your AWS credentials yet. Run command setprofile to set them'))
else:
set_aws_creds_inline(aws_access_key_id, aws_secret_access_key, region_name, aws_session_token)
Comment on lines
-225
to
-243
| def handle_menu(): | ||
| """ | ||
| Pop the top menu from the stack and go to it. | ||
| :return: None | ||
| """ | ||
| global menu_stack | ||
| try: | ||
| current_menu = menu_stack.pop() | ||
| if current_menu == 'main': | ||
| main_loop() | ||
| elif current_menu == 'ec2instances': | ||
| instances_loop() | ||
| elif current_menu == 'training': | ||
| training_loop() | ||
| else: | ||
| main_loop() | ||
| except Exception as e: | ||
| print(e) | ||
| main_loop() |
Author
There was a problem hiding this comment.
removed since there is no use anywhere.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
General enhancements: