Skip to content

Commit

Permalink
error handling for keyboard interaption
Browse files Browse the repository at this point in the history
  • Loading branch information
snigdhasjg committed Nov 29, 2023
1 parent fa75ed7 commit e5285b3
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 28 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ ij_python_blank_lines_after_imports = 2
ij_python_optimize_imports_sort_imports = true
ij_python_call_parameters_wrap = off
ij_python_method_parameters_wrap = off
ij_python_optimize_imports_always_split_from_imports = true
2 changes: 1 addition & 1 deletion aws_fusion/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.5'
__version__ = '1.5.1'
8 changes: 6 additions & 2 deletions aws_fusion/app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import argparse
import logging

from importlib.metadata import version
from .commands import open_browser, iam_user_credentials, generate_okta_device_auth_credentials, init, config_switch

from .commands import config_switch
from .commands import generate_okta_device_auth_credentials
from .commands import iam_user_credentials
from .commands import init
from .commands import open_browser


def main():
Expand Down
3 changes: 2 additions & 1 deletion aws_fusion/aws/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from urllib import parse
from urllib import request

from urllib import parse, request

ISSUER = "aws-console-python-script"
SESSION_DURATION_IN_SECONDS = 43200
Expand Down
9 changes: 5 additions & 4 deletions aws_fusion/aws/assume_role.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import sys
import boto3
import hashlib
import datetime
import logging
import hashlib
import json
import logging
import os
import sys

import boto3
from botocore.exceptions import ClientError
from botocore.utils import JSONFileCache


LOG = logging.getLogger(__name__)


Expand Down
3 changes: 2 additions & 1 deletion aws_fusion/aws/session.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import boto3
import logging
import os

import boto3
from botocore.utils import JSONFileCache


LOG = logging.getLogger(__name__)


Expand Down
21 changes: 17 additions & 4 deletions aws_fusion/commands/config_switch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import inquirer
import boto3
import logging
import os

import boto3
import inquirer


LOG = logging.getLogger(__name__)


def setup(subparsers, parent_parser):
summary = 'Switching between AWS config'
Expand All @@ -22,7 +27,11 @@ def switch_profile(args):
available_profiles = session.available_profiles

profile_inquiry = inquirer.List("profile", message="Choose a profile", choices=available_profiles, default=session.profile_name, carousel=True)
answers = inquirer.prompt([profile_inquiry], theme=inquirer.themes.GreenPassion())
try:
answers = inquirer.prompt([profile_inquiry], theme=inquirer.themes.GreenPassion(), raise_keyboard_interrupt=True)
except KeyboardInterrupt:
LOG.warning('Cancelled by user')
exit(7)

profile = answers.get('profile') if answers.get('profile') != 'default' else None
__update_file('profile', profile)
Expand All @@ -33,7 +42,11 @@ def switch_region(args):
available_regions = session.get_available_regions('ec2')

region_inquery = inquirer.List("region", message="Choose a region", choices=available_regions, default=session.region_name, carousel=True)
answers = inquirer.prompt([region_inquery], theme=inquirer.themes.GreenPassion())
try:
answers = inquirer.prompt([region_inquery], theme=inquirer.themes.GreenPassion(), raise_keyboard_interrupt=True)
except KeyboardInterrupt:
LOG.warning('Cancelled by user')
exit(7)

region = answers.get('region') if answers.get('region') != session.region_name else None
__update_file('region', region)
Expand Down
5 changes: 4 additions & 1 deletion aws_fusion/commands/generate_okta_device_auth_credentials.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import logging

from ..aws.assume_role import AssumeRoleWithSamlCache
from ..okta.api import device_auth, verification_and_token, session_and_token, saml_assertion
from ..okta.api import device_auth
from ..okta.api import saml_assertion
from ..okta.api import session_and_token
from ..okta.api import verification_and_token


LOG = logging.getLogger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion aws_fusion/commands/iam_user_credentials.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import argparse
import json
import keyring
import sys

import keyring


def setup(subparsers, parent_parser):
common_parser = argparse.ArgumentParser(add_help=False)
Expand Down
4 changes: 2 additions & 2 deletions aws_fusion/commands/init.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import configparser
import sys
import logging
import os
import sys


LOG = logging.getLogger(__name__)
Expand Down
9 changes: 5 additions & 4 deletions aws_fusion/commands/open_browser.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import logging
import os
import pyperclip
import webbrowser
import sys
import logging
import webbrowser

import pyperclip

from ..aws.session import credentials
from ..aws.api import signin_url
from ..aws.session import credentials


LOG = logging.getLogger(__name__)
Expand Down
9 changes: 4 additions & 5 deletions aws_fusion/okta/api.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import json

import requests
import webbrowser
import time
import base64
import json
import logging
import time
import webbrowser

import requests
from bs4 import BeautifulSoup


Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env python
import re
import os
from setuptools import setup, find_packages
import re

from setuptools import find_packages
from setuptools import setup


here = os.path.abspath(os.path.dirname(__file__))
Expand Down

0 comments on commit e5285b3

Please sign in to comment.