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

Allow cli flags to set logically False values #64

Merged
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: 2 additions & 1 deletion src/awscli_login/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def _set_attrs_from_args(self) -> None:
for option in options:
value = getattr(self._args, option)

if value:
# Allow False, empty strings, zero, etc.
if value is not None:
setattr(self, option, value)

def _set_override_attrs(self) -> None:
Expand Down
34 changes: 34 additions & 0 deletions src/tests/config/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ def setUp(self) -> None:
enable_keyring = True
passcode = secret_code
refresh = 1500
duration = 900
disable_refresh = True
http_header_factor = X_Foo
http_header_passcode = X_Bar
"""

def test_full_config(self) -> None:
Expand All @@ -236,6 +240,10 @@ def test_full_config(self) -> None:
"enable_keyring": True,
"passcode": "secret_code",
"refresh": 1500,
"duration": 900,
"disable_refresh": True,
"http_header_factor": "X_Foo",
"http_header_passcode": "X_Bar",
}

self.assertProfileHasAttrs(**expected_attr_vals)
Expand All @@ -254,6 +262,32 @@ def test_full_config(self) -> None:
"role_arn": "arn:aws:iam::account-id:role/role-name2",
"passcode": "secret",
"refresh": 1000,
"duration": 1500,
"disable_refresh": True,
"http_header_factor": "X_Bar",
"http_header_passcode": "X_Foo",
} # Dict[str, Any]
expected_attr_vals = copy(args)
expected_attr_vals.update({'enable_keyring': False})
args.update({'ask_password': True})

self.Profile(profile='default', no_args=False, **args)
self.assertProfileHasAttrs(**expected_attr_vals)

def test_logically_false_args_full_config(self) -> None:
""" Testing logically False command line args override config. """
args = {
"ecp_endpoint_url": '',
"username": '',
"password": '',
"factor": '',
"role_arn": "",
"passcode": "",
"refresh": 0,
"duration": 0,
"disable_refresh": False,
"http_header_factor": "",
"http_header_passcode": "",
} # Dict[str, Any]
expected_attr_vals = copy(args)
expected_attr_vals.update({'enable_keyring': False})
Expand Down