mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-27 23:21:22 -07:00
[k8s] Always check envvars when auth parameter is not provided (#51495)
* Always check envvars when auth parameter is not provided This will make it so that all code using the get_api_client method will make use of the environment variables, instead of silently ignoring them if default values haven't been set. This affects at least the k8s lookup plugin. * Add changelog
This commit is contained in:
parent
abb964a5a0
commit
0be66113d4
2 changed files with 7 additions and 4 deletions
3
changelogs/fragments/51495-k8s-load-envvars.yaml
Normal file
3
changelogs/fragments/51495-k8s-load-envvars.yaml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
bugfixes:
|
||||||
|
- All K8S_AUTH_* environment variables are now properly loaded by the k8s lookup plugin
|
|
@ -138,11 +138,11 @@ class K8sAnsibleMixin(object):
|
||||||
auth = copy.deepcopy(auth_params)
|
auth = copy.deepcopy(auth_params)
|
||||||
|
|
||||||
# If authorization variables aren't defined, look for them in environment variables
|
# If authorization variables aren't defined, look for them in environment variables
|
||||||
for key, value in iteritems(auth_params):
|
for arg in auth_args:
|
||||||
if key in auth_args and value is None:
|
if auth_params.get(arg) is None:
|
||||||
env_value = os.getenv('K8S_AUTH_{0}'.format(key.upper()), None)
|
env_value = os.getenv('K8S_AUTH_{0}'.format(arg.upper()), None)
|
||||||
if env_value is not None:
|
if env_value is not None:
|
||||||
auth[key] = env_value
|
auth[arg] = env_value
|
||||||
|
|
||||||
def auth_set(*names):
|
def auth_set(*names):
|
||||||
return all([auth.get(name) for name in names])
|
return all([auth.get(name) for name in names])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue