Skip to content

common: Handle aliases correctly #71

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

Open
wants to merge 1 commit into
base: main
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may need to cover all aliases cert_file, key_file, verify_ssl

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
6 changes: 6 additions & 0 deletions plugins/module_utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ def _raise_or_fail(exc, msg):
for true_name, arg_name in AUTH_ARG_MAP.items():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest some validation step to avoid having both alias and true name set as input, otherwise the behavior of the api will be undefined. for instance using

k8s:
  ...
  validate_certs: yes
  verify_ssl: no

the process will the k8s configuration item with the first value in alpha num ?

if module and module.params.get(arg_name):
auth[true_name] = module.params.get(arg_name)
elif module and 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