From 777a741d4d508a28502e49cbb8e652689ec20a6c Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Tue, 15 Dec 2020 06:39:47 +0100 Subject: [PATCH] keycloak: Provide meaningful error message to user (#1487) (#1489) When user provides auth URL value which does not startswith http or https protocol schema, provide a meaningful error message stating so. Fixes: #331 Signed-off-by: Abhijeet Kasurde (cherry picked from commit f37eb12580fc6309cc13db729ec4d37d640312e1) Co-authored-by: Abhijeet Kasurde --- changelogs/fragments/331_keycloak.yml | 2 ++ plugins/module_utils/identity/keycloak/keycloak.py | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 changelogs/fragments/331_keycloak.yml diff --git a/changelogs/fragments/331_keycloak.yml b/changelogs/fragments/331_keycloak.yml new file mode 100644 index 0000000000..99c6474212 --- /dev/null +++ b/changelogs/fragments/331_keycloak.yml @@ -0,0 +1,2 @@ +bugfixes: +- keycloak module_utils - provide meaningful error message to user when auth URL does not start with http or https (https://github.com/ansible-collections/community.general/issues/331). diff --git a/plugins/module_utils/identity/keycloak/keycloak.py b/plugins/module_utils/identity/keycloak/keycloak.py index 5cab048dc8..1859d37d0e 100644 --- a/plugins/module_utils/identity/keycloak/keycloak.py +++ b/plugins/module_utils/identity/keycloak/keycloak.py @@ -75,6 +75,8 @@ class KeycloakError(Exception): def get_token(base_url, validate_certs, auth_realm, client_id, auth_username, auth_password, client_secret): + if not base_url.lower().startswith(('http', 'https')): + raise KeycloakError("auth_url '%s' should either start with 'http' or 'https'." % base_url) auth_url = URL_TOKEN.format(url=base_url, realm=auth_realm) temp_payload = { 'grant_type': 'password',