Skip to content

Commit

Permalink
add aws cli alias for both console & credential-process-from-system
Browse files Browse the repository at this point in the history
  • Loading branch information
snigdhasjg committed Nov 12, 2023
1 parent 8c0b547 commit 32513a9
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import re
import os
from setuptools import setup, find_packages
from setuptools.command.develop import develop
import configparser

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

Expand All @@ -19,11 +21,40 @@ def find_version(*file_paths):
raise RuntimeError("Unable to find version string.")


class CustomDevelop(develop):
CLI_DIR = os.path.expanduser(os.path.join('~', '.aws', 'cli'))

def run(self):
self.update_aws_cli_alias_file()
develop.run(self)

def update_aws_cli_alias_file(self):
if not os.path.isdir(self.CLI_DIR):
os.makedirs(self.CLI_DIR)
cli_alias_full_path = os.path.join(self.CLI_DIR, 'alias')
config = configparser.ConfigParser()

if os.path.isfile(cli_alias_full_path):
config.read(cli_alias_full_path)

self.create_console_alias(config)

with os.fdopen(os.open(cli_alias_full_path, os.O_WRONLY | os.O_CREAT, 0o600), 'w') as f:
f.truncate()
config.write(f)

def create_console_alias(self, config: configparser.ConfigParser):
if not config.has_section('toplevel'):
config.add_section('toplevel')
config['toplevel']['console'] = '!aws-console'
config['toplevel']['credential-process-from-system'] = '!aws-credential-process-from-system'


setup(
name='aws_console',
version=find_version('aws_console', '__init__.py'),
description='AWS Console Login Utility',
keywords = [
keywords=[
'aws',
'aws-sdk',
'aws-cli',
Expand All @@ -33,6 +64,9 @@ def find_version(*file_paths):
],
long_description=read("README.md"),
packages=find_packages(),
cmdclass={
'develop': CustomDevelop
},
entry_points={
'console_scripts': [
'aws-console = aws_console:aws_console',
Expand Down

0 comments on commit 32513a9

Please sign in to comment.