Skip to content

Commit

Permalink
export AWS_PROFILE=my-profile-name
Browse files Browse the repository at this point in the history
This is usefull to be displayed at shell command prompts and is e.g.
already implemented by oh-my-zsh themes.

ignore .idea
  • Loading branch information
Max Berndt committed Aug 14, 2019
1 parent 8c18170 commit 6619a8e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/.installed.cfg
/.python-version
/.vagrant
/.idea

__pycache__
*.pyc
Expand Down
6 changes: 4 additions & 2 deletions src/awsenv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,14 @@ def format(self, export=True):
return "\n".join([
"{}AWS_ACCESS_KEY_ID={}".format("export " if export else "", self.aws_access_key_id),
"{}AWS_SECRET_ACCESS_KEY={}".format("export " if export else "", self.aws_secret_access_key),
"{}AWS_SESSION_TOKEN={}".format("export " if export else "", self.aws_session_token)
"{}AWS_SESSION_TOKEN={}".format("export " if export else "", self.aws_session_token),
"{}AWS_PROFILE={}".format("export " if export else "", self.name)
])
else:
return "\n".join([
"{}AWS_ACCESS_KEY_ID={}".format("export " if export else "", self.aws_access_key_id),
"{}AWS_SECRET_ACCESS_KEY={}".format("export " if export else "", self.aws_secret_access_key)
"{}AWS_SECRET_ACCESS_KEY={}".format("export " if export else "", self.aws_secret_access_key),
"{}AWS_PROFILE={}".format("export " if export else "", self.name)
])
@property
def aws_access_key_id(self):
Expand Down
6 changes: 3 additions & 3 deletions src/awsenv/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ def test_constructor(self):
self.assertEqual('session token', fixture.session_token)

def test_format(self):
fixture = AWSProfile(None, 'a', 'b', 'c')
result_export = "export AWS_ACCESS_KEY_ID=a\nexport AWS_SECRET_ACCESS_KEY=b\nexport AWS_SESSION_TOKEN=c"
result_no_export = "AWS_ACCESS_KEY_ID=a\nAWS_SECRET_ACCESS_KEY=b\nAWS_SESSION_TOKEN=c"
fixture = AWSProfile('p', 'a', 'b', 'c')
result_export = "export AWS_ACCESS_KEY_ID=a\nexport AWS_SECRET_ACCESS_KEY=b\nexport AWS_SESSION_TOKEN=c\nexport AWS_PROFILE=p"
result_no_export = "AWS_ACCESS_KEY_ID=a\nAWS_SECRET_ACCESS_KEY=b\nAWS_SESSION_TOKEN=c\nAWS_PROFILE=p"

self.assertEqual(result_export, fixture.format())
self.assertEqual(result_no_export, fixture.format(export=False))
Expand Down

0 comments on commit 6619a8e

Please sign in to comment.