Compare privileges from before and after manipulation

This commit is contained in:
R. Sicart 2022-09-05 18:25:30 +02:00
commit 5fb85e9dda

View file

@ -385,7 +385,12 @@ def user_mod(cursor, user, host, host_all, password, encrypted,
privileges_revoke(cursor, user, host, db_table, revoke_privs, grant_option, maria_role) privileges_revoke(cursor, user, host, db_table, revoke_privs, grant_option, maria_role)
if len(grant_privs) > 0: if len(grant_privs) > 0:
privileges_grant(cursor, user, host, db_table, grant_privs, tls_requires, maria_role) privileges_grant(cursor, user, host, db_table, grant_privs, tls_requires, maria_role)
changed = True
# after privilege manipulation, compare privileges from before and now
changed = changed or not privileges_equal(
curr_priv,
privileges_get(cursor, user, host, maria_role)
)
if role: if role:
continue continue
@ -880,3 +885,15 @@ def get_impl(cursor):
else: else:
from ansible_collections.community.mysql.plugins.module_utils.implementations.mysql import user as mysqluser from ansible_collections.community.mysql.plugins.module_utils.implementations.mysql import user as mysqluser
impl = mysqluser impl = mysqluser
def privileges_equal(before_privs, after_privs):
"""Compare 2 priv dicts
Args:
before_privs (dict): contains privileges, built with privileges_get()
after_privs (dict): contains privileges, built with privileges_get()
Returns: True, if equal, False otherwise.
"""
return before_privs == after_privs