From 7f2f14127555e45539e616b39ede24feb78a09f7 Mon Sep 17 00:00:00 2001 From: Laurent Indermuehle Date: Wed, 13 Sep 2023 18:01:04 +0200 Subject: [PATCH] revert changes to get_grants() --- plugins/module_utils/user.py | 20 +++++++------------- plugins/modules/mysql_user.py | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/plugins/module_utils/user.py b/plugins/module_utils/user.py index 4f783a2..0c0c377 100644 --- a/plugins/module_utils/user.py +++ b/plugins/module_utils/user.py @@ -104,19 +104,13 @@ def get_tls_requires(cursor, user, host): return requires or None -def get_grants(module, cursor, user, host): +def get_grants(cursor, user, host): cursor.execute("SHOW GRANTS FOR %s@%s", (user, host)) - try: - c = cursor.fetchall() - # grants_line = list(filter(lambda x: "ON *.*" in x[0], cursor.fetchall()))[0] - module.warn("%s" % c) - except Exception as e: - module.fail_json(msg="Error %s" % e) + grants_line = list(filter(lambda x: "ON *.*" in x[0], cursor.fetchall()))[0] - # pattern = r"(?<=\bGRANT\b)(.*?)(?=(?:\bON\b))" - # grants = re.search(pattern, grants_line[0]).group().strip() - # return grants.split(", ") - return "test" + pattern = r"(?<=\bGRANT\b)(.*?)(?=(?:\bON\b))" + grants = re.search(pattern, grants_line[0]).group().strip() + return grants.split(", ") def get_existing_authentication(cursor, user): @@ -139,7 +133,7 @@ def get_existing_authentication(cursor, user): return None -def user_add(module, cursor, user, host, host_all, password, encrypted, +def user_add(cursor, user, host, host_all, password, encrypted, plugin, plugin_hash_string, plugin_auth_string, new_priv, tls_requires, check_mode, reuse_existing_password): # we cannot create users without a proper hostname @@ -194,7 +188,7 @@ def user_add(module, cursor, user, host, host_all, password, encrypted, for db_table, priv in iteritems(new_priv): privileges_grant(cursor, user, host, db_table, priv, tls_requires) if tls_requires is not None: - privileges_grant(cursor, user, host, "*.*", get_grants(module, cursor, user, host), tls_requires) + privileges_grant(cursor, user, host, "*.*", get_grants(cursor, user, host), tls_requires) return {'changed': True, 'password_changed': not used_existing_password} diff --git a/plugins/modules/mysql_user.py b/plugins/modules/mysql_user.py index 93d659b..3e914e6 100644 --- a/plugins/modules/mysql_user.py +++ b/plugins/modules/mysql_user.py @@ -525,7 +525,7 @@ def main(): if subtract_privs: priv = None # avoid granting unwanted privileges reuse_existing_password = update_password == 'on_new_username' - result = user_add(module, cursor, user, host, host_all, password, encrypted, + result = user_add(cursor, user, host, host_all, password, encrypted, plugin, plugin_hash_string, plugin_auth_string, priv, tls_requires, module.check_mode, reuse_existing_password) changed = result['changed']