From 4184f0572cec92b265db399e49a45632f1370a49 Mon Sep 17 00:00:00 2001 From: Snigdhajyoti Ghosh Date: Wed, 29 Nov 2023 20:04:49 +0530 Subject: [PATCH] fix editorconfig with proper indentation --- .editorconfig | 9 +++++ aws_fusion/commands/config_switch.py | 33 +++++-------------- .../generate_okta_device_auth_credentials.py | 1 + aws_fusion/commands/iam_user_credentials.py | 6 ++-- aws_fusion/commands/init.py | 8 +++-- aws_fusion/commands/open_browser.py | 1 + aws_fusion/okta/api.py | 1 + bin/_awsp | 2 +- bin/_awsr | 2 +- setup.py | 1 + 10 files changed, 30 insertions(+), 34 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..fbc0728 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +[*.py] +max_line_length = 999 +ij_visual_guides = 120 +ij_wrap_on_typing = false +ij_python_wrap_long_lines = false +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 diff --git a/aws_fusion/commands/config_switch.py b/aws_fusion/commands/config_switch.py index 6c1418d..6246d1f 100644 --- a/aws_fusion/commands/config_switch.py +++ b/aws_fusion/commands/config_switch.py @@ -22,17 +22,8 @@ def switch_profile(args): session = boto3.Session(region_name=os.getenv("AWS_REGION", os.getenv("AWS_DEFAULT_REGION")), profile_name=os.getenv("AWS_PROFILE")) available_profiles = session.available_profiles - questions = [ - inquirer.List( - "profile", - message="Choose a profile", - choices=available_profiles, - default=session.profile_name, - carousel=True - ), - ] - - answers = inquirer.prompt(questions, theme=inquirer.themes.GreenPassion()) + 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()) profile = answers.get('profile') if answers.get('profile') != 'default' else None __update_file('profile', profile) @@ -42,17 +33,8 @@ def switch_region(args): session = boto3.Session(region_name=os.getenv("AWS_REGION", os.getenv("AWS_DEFAULT_REGION")), profile_name=os.getenv("AWS_PROFILE")) available_regions = session.get_available_regions('ec2') - questions = [ - inquirer.List( - "region", - message="Choose a region", - choices=available_regions, - default=session.region_name, - carousel=True - ), - ] - - answers = inquirer.prompt(questions, theme=inquirer.themes.GreenPassion()) + 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()) region = answers.get('region') if answers.get('region') != session.region_name else None __update_file('region', region) @@ -60,12 +42,13 @@ def switch_region(args): def __update_file(file_name, value): config_dir = os.path.expanduser(os.path.join('~', '.aws', 'fusion')) + if not os.path.isdir(config_dir): os.makedirs(config_dir) + full_key = os.path.join(config_dir, file_name) - with os.fdopen( - os.open(full_key, os.O_WRONLY | os.O_CREAT, 0o600), 'w' - ) as f: + + with os.fdopen(os.open(full_key, os.O_WRONLY | os.O_CREAT, 0o600), 'w') as f: f.truncate() if value is not None: f.write(value) diff --git a/aws_fusion/commands/generate_okta_device_auth_credentials.py b/aws_fusion/commands/generate_okta_device_auth_credentials.py index bbe26b0..6ff8a5a 100644 --- a/aws_fusion/commands/generate_okta_device_auth_credentials.py +++ b/aws_fusion/commands/generate_okta_device_auth_credentials.py @@ -3,6 +3,7 @@ from ..aws.assume_role import AssumeRoleWithSamlCache from ..okta.api import device_auth, verification_and_token, session_and_token, saml_assertion + LOG = logging.getLogger(__name__) diff --git a/aws_fusion/commands/iam_user_credentials.py b/aws_fusion/commands/iam_user_credentials.py index ca646ac..26651b6 100644 --- a/aws_fusion/commands/iam_user_credentials.py +++ b/aws_fusion/commands/iam_user_credentials.py @@ -14,13 +14,13 @@ def setup(subparsers, parent_parser): store_parser = subparsers.add_parser('store-iam-user-credentials', description=store_summary, help=store_summary, parents=[parent_parser, common_parser]) store_parser.set_defaults(func=run_store) store_parser.add_argument('--secret-key', required=True, help='AWS secret key') - + get_summary = 'Retrieve IAM user credentials for AWS CLI profiles or application authentication' get_parser = subparsers.add_parser('get-iam-user-credentials', description=get_summary, help=get_summary, parents=[parent_parser, common_parser]) get_parser.set_defaults(func=run_get) get_parser.add_argument('--credential-process', action='store_true', help='Output the credential in AWS credential process syntax') - + def run_store(args): service_name = '-'.join(filter(None, ['aws', args.account_id, args.username])) keyring.set_password(service_name, args.access_key, args.secret_key) @@ -42,5 +42,3 @@ def run_get(args): print(f'{command}AWS_ACCESS_KEY_ID="{args.access_key}"') print(f'{command}AWS_SECRET_ACCESS_KEY="{secret_key}"') - - \ No newline at end of file diff --git a/aws_fusion/commands/init.py b/aws_fusion/commands/init.py index 2026f22..3f16940 100644 --- a/aws_fusion/commands/init.py +++ b/aws_fusion/commands/init.py @@ -3,14 +3,16 @@ import sys import logging + LOG = logging.getLogger(__name__) def setup(subparsers, parent_parser): - summary = 'Initilize fusion app with creation of aws fusion alias' + summary = 'Initialize fusion app with creation of aws fusion alias' parser = subparsers.add_parser('init', description=summary, help=summary, parents=[parent_parser]) parser.set_defaults(func=run) + def run(args): cli_dir = os.path.expanduser(os.path.join('~', '.aws', 'cli')) @@ -22,7 +24,7 @@ def create_alias(config: configparser.ConfigParser): def update_aws_cli_alias_file(): if not os.path.isdir(cli_dir): - LOG.debug(f"Path {cli_dir} doesn't exists, creating" ) + LOG.debug(f"Path {cli_dir} doesn't exists, creating") os.makedirs(cli_dir) cli_alias_full_path = os.path.join(cli_dir, 'alias') config = configparser.ConfigParser() @@ -38,4 +40,4 @@ def update_aws_cli_alias_file(): config.write(f) LOG.debug(f'Updated alias file {cli_alias_full_path}') - update_aws_cli_alias_file() + update_aws_cli_alias_file() diff --git a/aws_fusion/commands/open_browser.py b/aws_fusion/commands/open_browser.py index 8163f58..c7312d4 100644 --- a/aws_fusion/commands/open_browser.py +++ b/aws_fusion/commands/open_browser.py @@ -7,6 +7,7 @@ from ..aws.session import credentials from ..aws.api import signin_url + LOG = logging.getLogger(__name__) diff --git a/aws_fusion/okta/api.py b/aws_fusion/okta/api.py index 582c36c..eb9f374 100644 --- a/aws_fusion/okta/api.py +++ b/aws_fusion/okta/api.py @@ -8,6 +8,7 @@ from bs4 import BeautifulSoup + LOG = logging.getLogger(__name__) diff --git a/bin/_awsp b/bin/_awsp index 292c8f6..5bc1a75 100644 --- a/bin/_awsp +++ b/bin/_awsp @@ -1,6 +1,6 @@ #!/bin/bash -aws-fusion config-switch profile +$(dirname "$0")/aws-fusion config-switch profile selected_profile="$(cat ~/.aws/fusion/profile)" diff --git a/bin/_awsr b/bin/_awsr index eb26762..16ac2b7 100644 --- a/bin/_awsr +++ b/bin/_awsr @@ -1,6 +1,6 @@ #!/bin/bash -aws-fusion config-switch region +$(dirname "$0")aws-fusion config-switch region selected_region="$(cat ~/.aws/fusion/region)" diff --git a/setup.py b/setup.py index 71efcff..913157b 100755 --- a/setup.py +++ b/setup.py @@ -3,6 +3,7 @@ import os from setuptools import setup, find_packages + here = os.path.abspath(os.path.dirname(__file__))