Skip to content

feature/basic-setup#5

Closed
mutairibassam wants to merge 3 commits into
Voulnet:masterfrom
mutairibassam:feature/basic-setup
Closed

feature/basic-setup#5
mutairibassam wants to merge 3 commits into
Voulnet:masterfrom
mutairibassam:feature/basic-setup

Conversation

@mutairibassam
Copy link
Copy Markdown

@mutairibassam mutairibassam commented Nov 19, 2022

General enhancements:

- 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
Comment thread barq/main.py
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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread barq/main.py
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 = ''

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread barq/main.py
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()
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed since there is no use anywhere.

@mutairibassam mutairibassam closed this by deleting the head repository Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant