mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-04-08 19:50:31 -07:00
attempt to use privileges_get
This commit is contained in:
parent
7f2f141275
commit
028089da6d
2 changed files with 18 additions and 12 deletions
|
@ -324,7 +324,7 @@ def user_mod(cursor, user, host, host_all, password, encrypted,
|
||||||
|
|
||||||
# Handle privileges
|
# Handle privileges
|
||||||
if new_priv is not None:
|
if new_priv is not None:
|
||||||
curr_priv = privileges_get(cursor, user, host, maria_role)
|
curr_priv = privileges_get(module, cursor, user, host, maria_role)
|
||||||
|
|
||||||
# If the user has privileges on a db.table that doesn't appear at all in
|
# If the user has privileges on a db.table that doesn't appear at all in
|
||||||
# the new specification, then revoke all privileges on it.
|
# the new specification, then revoke all privileges on it.
|
||||||
|
@ -396,7 +396,7 @@ 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
|
||||||
after_priv = privileges_get(cursor, user, host, maria_role)
|
after_priv = privileges_get(module, cursor, user, host, maria_role)
|
||||||
changed = changed or (curr_priv != after_priv)
|
changed = changed or (curr_priv != after_priv)
|
||||||
|
|
||||||
if role:
|
if role:
|
||||||
|
@ -455,7 +455,7 @@ def user_get_hostnames(cursor, user):
|
||||||
return hostnames
|
return hostnames
|
||||||
|
|
||||||
|
|
||||||
def privileges_get(cursor, user, host, maria_role=False):
|
def privileges_get(module, cursor, user, host, maria_role=False):
|
||||||
""" MySQL doesn't have a better method of getting privileges aside from the
|
""" MySQL doesn't have a better method of getting privileges aside from the
|
||||||
SHOW GRANTS query syntax, which requires us to then parse the returned string.
|
SHOW GRANTS query syntax, which requires us to then parse the returned string.
|
||||||
Here's an example of the string that is returned from MySQL:
|
Here's an example of the string that is returned from MySQL:
|
||||||
|
@ -467,9 +467,10 @@ def privileges_get(cursor, user, host, maria_role=False):
|
||||||
"""
|
"""
|
||||||
output = {}
|
output = {}
|
||||||
if not maria_role:
|
if not maria_role:
|
||||||
cursor.execute("SHOW GRANTS FOR %s@%s", (user, host))
|
query = "SHOW GRANTS FOR '%s'@'%s'" % (user, host)
|
||||||
else:
|
else:
|
||||||
cursor.execute("SHOW GRANTS FOR %s", (user,))
|
query = "SHOW GRANTS FOR '%s'" % user
|
||||||
|
cursor.execute(query)
|
||||||
grants = cursor.fetchall()
|
grants = cursor.fetchall()
|
||||||
|
|
||||||
def pick(x):
|
def pick(x):
|
||||||
|
|
|
@ -249,7 +249,7 @@ from ansible_collections.community.mysql.plugins.module_utils.mysql import (
|
||||||
get_server_version,
|
get_server_version,
|
||||||
)
|
)
|
||||||
from ansible_collections.community.mysql.plugins.module_utils.user import (
|
from ansible_collections.community.mysql.plugins.module_utils.user import (
|
||||||
get_grants,
|
privileges_get,
|
||||||
)
|
)
|
||||||
from ansible.module_utils.six import iteritems
|
from ansible.module_utils.six import iteritems
|
||||||
from ansible.module_utils._text import to_native
|
from ansible.module_utils._text import to_native
|
||||||
|
@ -510,15 +510,20 @@ class MySQL_Info(object):
|
||||||
h = line['Host']
|
h = line['Host']
|
||||||
key = u + '_' + h
|
key = u + '_' + h
|
||||||
|
|
||||||
privs = get_grants(self.module, self.cursor, u, h)
|
user_priv = privileges_get(self.module, self.cursor, u, h)
|
||||||
|
|
||||||
if not privs:
|
if not user_priv:
|
||||||
self.module.warn(
|
self.module.warn("No privileges found for %s on host %s" % (u, h))
|
||||||
'Fail to get privileges for user %s on host %s.' % (u, h))
|
continue
|
||||||
privs = {}
|
|
||||||
|
|
||||||
|
# if not privs:
|
||||||
|
# self.module.warn(
|
||||||
|
# 'Fail to get privileges for user %s on host %s.' % (u, h))
|
||||||
|
# privs = {}
|
||||||
|
|
||||||
self.info['users_privs'][key] = {
|
self.info['users_privs'][key] = {
|
||||||
'user': u, 'host': h, 'privs': privs}
|
'user': u, 'host': h, 'privs': user_priv}
|
||||||
|
|
||||||
def __get_databases(self, exclude_fields, return_empty_dbs):
|
def __get_databases(self, exclude_fields, return_empty_dbs):
|
||||||
"""Get info about databases."""
|
"""Get info about databases."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue