mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-08-03 12:44:25 -07:00
Replace privileges_equal() by a comparison
This commit is contained in:
parent
e2b7d0e29b
commit
b195e71e7c
2 changed files with 2 additions and 46 deletions
|
@ -387,10 +387,8 @@ def user_mod(cursor, user, host, host_all, password, encrypted,
|
||||||
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)
|
||||||
|
|
||||||
# after privilege manipulation, compare privileges from before and now
|
# after privilege manipulation, compare privileges from before and now
|
||||||
changed = changed or not privileges_equal(
|
after_priv = privileges_get(cursor, user, host, maria_role)
|
||||||
curr_priv,
|
changed = changed or not (curr_priv == after_priv)
|
||||||
privileges_get(cursor, user, host, maria_role)
|
|
||||||
)
|
|
||||||
|
|
||||||
if role:
|
if role:
|
||||||
continue
|
continue
|
||||||
|
@ -885,15 +883,3 @@ 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
|
|
||||||
|
|
|
@ -98,33 +98,3 @@ def test_handle_grant_on_col(privileges, start, end, output):
|
||||||
def test_normalize_col_grants(input_, expected):
|
def test_normalize_col_grants(input_, expected):
|
||||||
"""Tests normalize_col_grants function."""
|
"""Tests normalize_col_grants function."""
|
||||||
assert normalize_col_grants(input_) == expected
|
assert normalize_col_grants(input_) == expected
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
'before_privileges,after_privileges,output',
|
|
||||||
[
|
|
||||||
(
|
|
||||||
{'*.*': ['INSERT', 'UPDATE', 'GRANT'], '`mysql`.*': ['SELECT']},
|
|
||||||
{'*.*': ['INSERT', 'UPDATE', 'GRANT'], '`mysql`.*': ['SELECT']},
|
|
||||||
True
|
|
||||||
),
|
|
||||||
(
|
|
||||||
{'`mysql`.*': ['SELECT'], '`sys`.*': ['SELECT']},
|
|
||||||
{'`mysql`.*': ['SELECT'], '`sys`.*': ['SELECT']},
|
|
||||||
True
|
|
||||||
),
|
|
||||||
(
|
|
||||||
{'`sys`.*': ['SELECT'], '`mysql`.*': ['SELECT']},
|
|
||||||
{'`mysql`.*': ['SELECT'], '`sys`.*': ['SELECT']},
|
|
||||||
True
|
|
||||||
),
|
|
||||||
(
|
|
||||||
{'`mysql`.*': ['UPDATE'], '`sys`.*': ['SELECT']},
|
|
||||||
{'`mysql`.*': ['SELECT'], '`sys`.*': ['SELECT']},
|
|
||||||
False
|
|
||||||
),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
def test_privileges_equal(before_privileges, after_privileges, output):
|
|
||||||
"""Tests privileges_equal function."""
|
|
||||||
assert privileges_equal(before_privileges, after_privileges) == output
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue