Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USE of AWS_PROFILE #20

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions awsudo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def set(key, value):
if value:
env[key] = value

if profile:
set('AWS_PROFILE', profile)

set('AWS_ACCESS_KEY_ID', creds.access_key)
set('AWS_SECRET_ACCESS_KEY', creds.secret_key)

Expand Down
2 changes: 1 addition & 1 deletion awsudo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def parseArgs():
if not (args):
usage()

profile = None
profile = os.environ.get('AWS_PROFILE')
for (option, value) in options:
if option == '-u':
profile = value
Expand Down
39 changes: 39 additions & 0 deletions awsudo/test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,45 @@ def test_no_args(capsys, monkeypatch):
assert 'Usage:' in err


def test_only_option(capsys, monkeypatch):
'''With only options, awsudo exits with usage.'''
monkeypatch.setattr(sys, 'argv', ['awsudo', '-u', 'default'])

with pytest.raises(SystemExit):
main.main()

out, err = capsys.readouterr()
assert 'Usage:' in err


def test_parseArgs_env_profile(monkeypatch):
'''Env vars is taken if no option are given.'''
environ = {
'AWS_PROFILE': 'profile'
}
monkeypatch.setattr(os, 'environ', environ)
monkeypatch.setattr(sys, 'argv', ['awsudo', 'command'])

profile, args = main.parseArgs()

assert profile == 'profile'
assert args == ['command']


def test_parseArgs_option_over_environ(monkeypatch):
'''Options values are taken even if environment variables are set.'''
environ = {
'AWS_PROFILE': 'profile-environ'
}
monkeypatch.setattr(os, 'environ', environ)
monkeypatch.setattr(sys, 'argv', ['awsudo', '-u', 'profile-option', 'command'])

profile, args = main.parseArgs()

assert profile == 'profile-option'
assert args == ['command']


def test_cleanEnvironment(monkeypatch):
'''cleanEnvironment strips AWS and boto configuration.'''
environ = {
Expand Down