Skip to content

Commit

Permalink
common: Handle aliases correctly
Browse files Browse the repository at this point in the history
Fixed get_api_client API to handle `aliases` that
are passed via inventory configuration or module parameters.

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
  • Loading branch information
Akasurde committed Apr 20, 2021
1 parent b68bf7c commit 4ef08ab
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/honor_aliases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- common - handle ``aliases`` passed from inventory or module params.
14 changes: 14 additions & 0 deletions molecule/default/tasks/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@
debug:
var: output

- name: Use aliases and check if those values are picked up
k8s:
name: testing
kind: Namespace
validate_certs: yes
ssl_ca_cert: /dev/null # invalid CA certificate
ignore_errors: yes
register: output

- name: assert that ssl_ca_cert caused a failure (and therefore was correctly translated to ssl_ca_cert)
assert:
that:
- output is failed

- name: Setting validate_certs to true causes a failure
k8s:
name: testing
Expand Down
11 changes: 9 additions & 2 deletions plugins/module_utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,15 @@ def _raise_or_fail(exc, msg):

# If authorization variables aren't defined, look for them in environment variables
for true_name, arg_name in AUTH_ARG_MAP.items():
if module and module.params.get(arg_name):
auth[true_name] = module.params.get(arg_name)
if module:
if arg_name in module.params and module.params.get(arg_name) is not None:
auth[true_name] = module.params.get(arg_name)
elif true_name in module.params and module.params.get(true_name) is not None:
# Aliases
auth[true_name] = module.params.get(true_name)
elif true_name in kwargs and kwargs.get(true_name) is not None:
# Aliases
auth[true_name] = kwargs.get(true_name)
elif arg_name in kwargs and kwargs.get(arg_name) is not None:
auth[true_name] = kwargs.get(arg_name)
else:
Expand Down

0 comments on commit 4ef08ab

Please sign in to comment.