Skip to content

Commit

Permalink
fix editorconfig with proper indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
snigdhasjg committed Nov 29, 2023
1 parent 3c63345 commit 4184f05
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 34 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
33 changes: 8 additions & 25 deletions aws_fusion/commands/config_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -42,30 +33,22 @@ 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)


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)
Original file line number Diff line number Diff line change
Expand Up @@ -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__)


Expand Down
6 changes: 2 additions & 4 deletions aws_fusion/commands/iam_user_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}"')


8 changes: 5 additions & 3 deletions aws_fusion/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand All @@ -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()
Expand All @@ -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()
1 change: 1 addition & 0 deletions aws_fusion/commands/open_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ..aws.session import credentials
from ..aws.api import signin_url


LOG = logging.getLogger(__name__)


Expand Down
1 change: 1 addition & 0 deletions aws_fusion/okta/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from bs4 import BeautifulSoup


LOG = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion bin/_awsp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

aws-fusion config-switch profile
$(dirname "$0")/aws-fusion config-switch profile

selected_profile="$(cat ~/.aws/fusion/profile)"

Expand Down
2 changes: 1 addition & 1 deletion bin/_awsr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

aws-fusion config-switch region
$(dirname "$0")aws-fusion config-switch region

selected_region="$(cat ~/.aws/fusion/region)"

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
from setuptools import setup, find_packages


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


Expand Down

0 comments on commit 4184f05

Please sign in to comment.