mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-04-12 13:40:32 -07:00
Add user resources limit to the output
This commit is contained in:
parent
248b30cad6
commit
1c93c1bd66
1 changed files with 27 additions and 9 deletions
|
@ -250,6 +250,7 @@ from ansible_collections.community.mysql.plugins.module_utils.mysql import (
|
||||||
)
|
)
|
||||||
from ansible_collections.community.mysql.plugins.module_utils.user import (
|
from ansible_collections.community.mysql.plugins.module_utils.user import (
|
||||||
privileges_get,
|
privileges_get,
|
||||||
|
get_resource_limits,
|
||||||
)
|
)
|
||||||
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
|
||||||
|
@ -522,15 +523,15 @@ class MySQL_Info(object):
|
||||||
self.fail_json(
|
self.fail_json(
|
||||||
msg="mysql_info failed to retrieve the users: %s" % e)
|
msg="mysql_info failed to retrieve the users: %s" % e)
|
||||||
|
|
||||||
|
output = list()
|
||||||
for line in users:
|
for line in users:
|
||||||
u = line['User']
|
user = line['User']
|
||||||
h = line['Host']
|
host = line['Host']
|
||||||
key = u + '_' + h
|
|
||||||
|
|
||||||
user_priv = privileges_get(self.module, self.cursor, u, h)
|
user_priv = privileges_get(self.module, self.cursor, user, host)
|
||||||
|
|
||||||
if not user_priv:
|
if not user_priv:
|
||||||
self.module.warn("No privileges found for %s on host %s" % (u, h))
|
self.module.warn("No privileges found for %s on host %s" % (user, host))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
priv_string = list()
|
priv_string = list()
|
||||||
|
@ -539,16 +540,33 @@ class MySQL_Info(object):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# privileges_get returns "'''@''': 'PROXY,GRANT'". The % is missing
|
# privileges_get returns "'''@''': 'PROXY,GRANT'". The % is missing
|
||||||
# and there is too many quotes. So we rewrite this.
|
# and there is too many quotes. So we rewrite this. Also because we
|
||||||
if priv == ['PROXY', 'GRANT'] and u == 'root':
|
# wrap the db_table between single quotes, I use backticks to
|
||||||
|
# indicate an empty string.
|
||||||
|
if priv == ['PROXY', 'GRANT'] and user == 'root':
|
||||||
priv_string.append("'``@`%`: 'PROXY,GRANT'")
|
priv_string.append("'``@`%`: 'PROXY,GRANT'")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
unquote_db_table = db_table.replace('`', '').replace("'", '')
|
unquote_db_table = db_table.replace('`', '').replace("'", '')
|
||||||
priv_string.append("'%s': '%s'" % (unquote_db_table, ','.join(priv)))
|
priv_string.append("'%s': '%s'" % (unquote_db_table, ','.join(priv)))
|
||||||
|
|
||||||
self.info['users_privs'][key] = {
|
resource_limits = get_resource_limits(self.module, self.cursor, user, host)
|
||||||
'user': u, 'host': h, 'privs': '/'.join(priv_string)}
|
|
||||||
|
output_dict = {
|
||||||
|
'user': user,
|
||||||
|
'host': host,
|
||||||
|
'privs': '/'.join(priv_string),
|
||||||
|
'resource_limits': resource_limits
|
||||||
|
}
|
||||||
|
|
||||||
|
if not resource_limits:
|
||||||
|
del output_dict['resource_limits']
|
||||||
|
|
||||||
|
output.append(output_dict)
|
||||||
|
|
||||||
|
# TODO: Return passwords
|
||||||
|
|
||||||
|
self.info['users_privs'] = output
|
||||||
|
|
||||||
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