From b2129157df99eb7e1863b91e95166f70950a21dd Mon Sep 17 00:00:00 2001 From: Snigdhajyoti Ghosh Date: Wed, 15 Nov 2023 21:15:18 +0530 Subject: [PATCH] format imports and add some logging --- aws_fusion/app.py | 8 ++----- aws_fusion/aws/api.py | 4 ++-- aws_fusion/aws/assume_role.py | 4 ++-- aws_fusion/aws/session.py | 3 ++- .../generate_okta_device_auth_credentials.py | 3 +-- aws_fusion/commands/open_browser.py | 21 ++++++++++--------- setup.py | 13 +++++++----- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/aws_fusion/app.py b/aws_fusion/app.py index 8ebcf23..a3ed5b9 100644 --- a/aws_fusion/app.py +++ b/aws_fusion/app.py @@ -1,18 +1,14 @@ import argparse from importlib.metadata import version - from .commands import open_browser, iam_user_credentials, generate_okta_device_auth_credentials def main(): global_parser = argparse.ArgumentParser(add_help=False) - global_parser.add_argument('-v', '--version', action='version', help="Display the version of this tool", - version=version("aws_fusion")) + global_parser.add_argument('-v', '--version', action='version', help="Display the version of this tool", version=version("aws_fusion")) - main_parser = argparse.ArgumentParser(prog='aws-fusion', - description='Unified CLI tool for streamlined AWS operations, enhancing developer productivity', - parents=[global_parser]) + main_parser = argparse.ArgumentParser(prog='aws-fusion', description='Unified CLI tool for streamlined AWS operations, enhancing developer productivity', parents=[global_parser]) subparsers = main_parser.add_subparsers(dest='command', required=True, help='Available commands') open_browser.setup(subparsers, global_parser) diff --git a/aws_fusion/aws/api.py b/aws_fusion/aws/api.py index 9d7ce55..9312652 100644 --- a/aws_fusion/aws/api.py +++ b/aws_fusion/aws/api.py @@ -1,7 +1,7 @@ -from urllib import parse, request - import json +from urllib import parse, request + ISSUER = "aws-console-python-script" SESSION_DURATION_IN_SECONDS = 43200 diff --git a/aws_fusion/aws/assume_role.py b/aws_fusion/aws/assume_role.py index cdf6276..ca1196b 100644 --- a/aws_fusion/aws/assume_role.py +++ b/aws_fusion/aws/assume_role.py @@ -3,11 +3,11 @@ import hashlib import datetime import logging +import json + from botocore.exceptions import ClientError from botocore.utils import JSONFileCache -import json - LOG = logging.getLogger(__name__) diff --git a/aws_fusion/aws/session.py b/aws_fusion/aws/session.py index a868844..032d97b 100644 --- a/aws_fusion/aws/session.py +++ b/aws_fusion/aws/session.py @@ -1,6 +1,7 @@ -from botocore.utils import JSONFileCache import boto3 +from botocore.utils import JSONFileCache + class TokenGenerationException(Exception): """Exception for credential not having token""" diff --git a/aws_fusion/commands/generate_okta_device_auth_credentials.py b/aws_fusion/commands/generate_okta_device_auth_credentials.py index 03431ef..4c6e1cd 100644 --- a/aws_fusion/commands/generate_okta_device_auth_credentials.py +++ b/aws_fusion/commands/generate_okta_device_auth_credentials.py @@ -1,4 +1,3 @@ -import os import logging from ..aws.assume_role import AssumeRoleWithSamlCache @@ -24,7 +23,7 @@ def run(args): assume_role_with_cache = AssumeRoleWithSamlCache(args.aws_iam_role) if not assume_role_with_cache.does_valid_token_cache_exists(): - LOG.debug('Credential cache not found, invloking SAML') + LOG.debug('Credential cache not found, invoking SAML') device_code = device_auth(args.org_domain, args.oidc_client_id) access_token, id_token = verification_and_token(args.org_domain, args.oidc_client_id, device_code) session_token = session_and_token(args.org_domain, args.oidc_client_id, access_token, id_token, args.aws_acct_fed_app_id) diff --git a/aws_fusion/commands/open_browser.py b/aws_fusion/commands/open_browser.py index 0c921ec..8163f58 100644 --- a/aws_fusion/commands/open_browser.py +++ b/aws_fusion/commands/open_browser.py @@ -2,35 +2,36 @@ import pyperclip import webbrowser import sys +import logging from ..aws.session import credentials from ..aws.api import signin_url +LOG = logging.getLogger(__name__) + def setup(subparsers, parent_parser): summary = 'Open a web browser for graphical access to the AWS Console' parser = subparsers.add_parser('open-browser', description=summary, help=summary, parents=[parent_parser]) parser.set_defaults(func=run) - parser.add_argument('-P', '--profile', default=os.getenv("AWS_PROFILE"), - help="The AWS profile to create the pre-signed URL with") - parser.add_argument('-R', '--region', default=os.getenv("AWS_REGION", os.getenv("AWS_DEFAULT_REGION")), - help="The AWS Region to send the request to") + parser.add_argument('-P', '--profile', default=os.getenv("AWS_PROFILE"), help="The AWS profile to create the pre-signed URL with") + parser.add_argument('-R', '--region', default=os.getenv("AWS_REGION", os.getenv("AWS_DEFAULT_REGION")), help="The AWS Region to send the request to") - group1 = parser.add_mutually_exclusive_group() - group1.add_argument('--clip', action='store_true', - help="don't open the web browser, but copy the signin URL to clipboard") - group1.add_argument('--stdout', action='store_true', - help="don't open the web browser, but echo the signin URL to stdout") + no_browser_group = parser.add_mutually_exclusive_group() + no_browser_group.add_argument('--clip', action='store_true', help="don't open the web browser, but copy the signin URL to clipboard") + no_browser_group.add_argument('--stdout', action='store_true', help="don't open the web browser, but echo the signin URL to stdout") def run(args): creds, region_name = credentials(args.profile, args.region) url = signin_url(creds, region_name) + LOG.debug(f'Generated aws console URL: {url}') if args.clip: pyperclip.copy(url) elif args.stdout: print(url) elif not webbrowser.open_new_tab(url): - sys.exit("No browser found. Try --help for other options") \ No newline at end of file + LOG.error('No browser found on the system') + sys.exit("No browser found. Try --help for other options") diff --git a/setup.py b/setup.py index fc8be71..bf450f3 100755 --- a/setup.py +++ b/setup.py @@ -70,7 +70,7 @@ class CustomInstallScriptsCommand(install_scripts): setup( - name='aws_fusion', + name='aws-fusion', version=find_version('aws_fusion', '__init__.py'), description='Unified CLI tool for streamlined AWS operations', keywords=[ @@ -93,9 +93,12 @@ class CustomInstallScriptsCommand(install_scripts): ] }, install_requires=[ - 'boto3>=1.28', - 'pyperclip>=1.8,<1.9', - 'keyring>=24.2,<24.3' + 'boto3>=1.29', + 'botocore>=1.32', + 'pyperclip>=1.8', + 'keyring>=24.3', + 'beautifulsoup4>=4.12', + 'requests>=2.31' ], author='Snigdhajyoti Ghosh', author_email='snigdhajyotighos.h@gmail.com', @@ -107,7 +110,7 @@ class CustomInstallScriptsCommand(install_scripts): 'Intended Audience :: Developers', 'Intended Audience :: System Administrators', 'Operating System :: OS Independent', - 'Development Status :: 5 - Production/Stable', + 'Development Status :: 4 - Beta', 'Topic :: Utilities' ], )