Skip to content

Commit

Permalink
Allow cli flags to set logically False values (#64)
Browse files Browse the repository at this point in the history
During testing, `--disable-refresh False` failed to override the
default True value. This fix changes the logic so that properties
are overwritten as long as an argument is not None. Before it only
overwrote a property if an argument value was logically True. This
bug effects every command line argument that overrides a property.
  • Loading branch information
ddriddle authored Feb 3, 2021
1 parent 75b8cab commit 2d69ecf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
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

0 comments on commit 2d69ecf

Please sign in to comment.