mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-07-29 02:44:41 +00:00
k8s inventory - remove trailing slashes from hostname (#63)
When the user provides a hostname with trailing slashes like https://localhost:6443/, the openshift library fails to enumerate the APIs from the given cluster. This fix removes any extra trailing slashes before sending it to the openshift DynamicClient. Fixes: #52 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
2
changelogs/fragments/52_inventory.yml
Normal file
2
changelogs/fragments/52_inventory.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
bugfixes:
|
||||||
|
- k8s inventory - remove extra trailing slashes from the hostname (https://github.com/ansible-collections/kubernetes.core/issues/52).
|
||||||
@@ -124,8 +124,7 @@ def get_api_client(module=None, **kwargs):
|
|||||||
def _raise_or_fail(exc, msg):
|
def _raise_or_fail(exc, msg):
|
||||||
if module:
|
if module:
|
||||||
module.fail_json(msg % to_native(exc))
|
module.fail_json(msg % to_native(exc))
|
||||||
else:
|
raise exc
|
||||||
raise exc
|
|
||||||
|
|
||||||
# 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 true_name, arg_name in AUTH_ARG_MAP.items():
|
for true_name, arg_name in AUTH_ARG_MAP.items():
|
||||||
@@ -143,6 +142,10 @@ def get_api_client(module=None, **kwargs):
|
|||||||
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])
|
||||||
|
|
||||||
|
if auth_set('host'):
|
||||||
|
# Removing trailing slashes if any from hostname
|
||||||
|
auth['host'] = auth.get('host').rstrip('/')
|
||||||
|
|
||||||
if auth_set('username', 'password', 'host') or auth_set('api_key', 'host'):
|
if auth_set('username', 'password', 'host') or auth_set('api_key', 'host'):
|
||||||
# We have enough in the parameters to authenticate, no need to load incluster or kubeconfig
|
# We have enough in the parameters to authenticate, no need to load incluster or kubeconfig
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user