Skip to content

Commit

Permalink
format imports and add some logging
Browse files Browse the repository at this point in the history
  • Loading branch information
snigdhasjg committed Nov 15, 2023
1 parent a8c29f9 commit b212915
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 28 deletions.
8 changes: 2 additions & 6 deletions aws_fusion/app.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions aws_fusion/aws/api.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions aws_fusion/aws/assume_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)


Expand Down
3 changes: 2 additions & 1 deletion aws_fusion/aws/session.py
Original file line number Diff line number Diff line change
@@ -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"""
Expand Down
3 changes: 1 addition & 2 deletions aws_fusion/commands/generate_okta_device_auth_credentials.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import logging

from ..aws.assume_role import AssumeRoleWithSamlCache
Expand All @@ -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)
Expand Down
21 changes: 11 additions & 10 deletions aws_fusion/commands/open_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
LOG.error('No browser found on the system')
sys.exit("No browser found. Try --help for other options")
13 changes: 8 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand All @@ -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='[email protected]',
Expand All @@ -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'
],
)

0 comments on commit b212915

Please sign in to comment.