Skip to content

Commit

Permalink
Fixing column uppercasing
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenny Marse committed Sep 6, 2023
1 parent 21e42b5 commit fcc8a87
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
15 changes: 10 additions & 5 deletions plugins/module_utils/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def sort_column_order(statement):
return '%s(%s)' % (priv_name, ', '.join(columns))


def privileges_unpack(priv, mode, ensure_usage=True):
def privileges_unpack(priv, mode, column_case_sensitive, ensure_usage=True):
""" Take a privileges string, typically passed as a parameter, and unserialize
it into a dictionary, the same format as privileges_get() above. We have this
custom format to avoid using YAML/JSON strings inside YAML playbooks. Example
Expand Down Expand Up @@ -663,11 +663,16 @@ def privileges_unpack(priv, mode, ensure_usage=True):
pieces[0] = object_type + '.'.join(dbpriv)

if '(' in pieces[1]:
output[pieces[0]] = re.split(r',\s*(?=[^)]*(?:\(|$))', pieces[1].upper())
for i in output[pieces[0]]:
privs.append(re.sub(r'\s*\(.*\)', '', i))
if column_case_sensitive == True:
output[pieces[0]] = re.split(r',\s*(?=[^)]*(?:\(|$))', pieces[1])

Check warning on line 667 in plugins/module_utils/user.py

View check run for this annotation

Codecov / codecov/patch

plugins/module_utils/user.py#L667

Added line #L667 was not covered by tests
for i in output[pieces[0]]:
privs.append(re.sub(r'\s*\(.*\)', '', i))

Check warning on line 669 in plugins/module_utils/user.py

View check run for this annotation

Codecov / codecov/patch

plugins/module_utils/user.py#L669

Added line #L669 was not covered by tests
else:
output[pieces[0]] = re.split(r',\s*(?=[^)]*(?:\(|$))', pieces[1].upper())
for i in output[pieces[0]]:
privs.append(re.sub(r'\s*\(.*\)', '', i))
else:
output[pieces[0]] = pieces[1].upper().split(',')
output[pieces[0]] = pieces[1].split(',')
privs = output[pieces[0]]

# Handle cases when there's privs like GRANT SELECT (colA, ...) in privs.
Expand Down
6 changes: 4 additions & 2 deletions plugins/modules/mysql_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,8 @@ def main():
detach_members=dict(type='bool', default=False),
check_implicit_admin=dict(type='bool', default=False),
set_default_role_all=dict(type='bool', default=True),
members_must_exist=dict(type='bool', default=True)
members_must_exist=dict(type='bool', default=True),
column_case_sensitive=dict(type='bool', default=False)
)
module = AnsibleModule(
argument_spec=argument_spec,
Expand Down Expand Up @@ -989,6 +990,7 @@ def main():
db = ''
set_default_role_all = module.params['set_default_role_all']
members_must_exist = module.params['members_must_exist']
column_case_sensitive = module.boolean(module.params['column_case_sensitive'])

if priv and not isinstance(priv, (str, dict)):
msg = ('The "priv" parameter must be str or dict '
Expand Down Expand Up @@ -1038,7 +1040,7 @@ def main():
module.fail_json(msg=to_native(e))

try:
priv = privileges_unpack(priv, mode, ensure_usage=not subtract_privs)
priv = privileges_unpack(priv, mode, column_case_sensitive, ensure_usage=not subtract_privs)

Check warning on line 1043 in plugins/modules/mysql_role.py

View check run for this annotation

Codecov / codecov/patch

plugins/modules/mysql_role.py#L1043

Added line #L1043 was not covered by tests
except Exception as e:
module.fail_json(msg='Invalid privileges string: %s' % to_native(e))

Expand Down
4 changes: 3 additions & 1 deletion plugins/modules/mysql_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ def main():
resource_limits=dict(type='dict'),
force_context=dict(type='bool', default=False),
session_vars=dict(type='dict'),
column_case_sensitive=dict(type='bool', default=False)
)
module = AnsibleModule(
argument_spec=argument_spec,
Expand Down Expand Up @@ -434,6 +435,7 @@ def main():
plugin_auth_string = module.params["plugin_auth_string"]
resource_limits = module.params["resource_limits"]
session_vars = module.params["session_vars"]
column_case_sensitive = module.boolean(module.params["column_case_sensitive"])

if priv and not isinstance(priv, (str, dict)):
module.fail_json(msg="priv parameter must be str or dict but %s was passed" % type(priv))
Expand Down Expand Up @@ -473,7 +475,7 @@ def main():
mode = get_mode(cursor)
except Exception as e:
module.fail_json(msg=to_native(e))
priv = privileges_unpack(priv, mode, ensure_usage=not subtract_privs)
priv = privileges_unpack(priv, mode, column_case_sensitive, ensure_usage=not subtract_privs)

Check warning on line 478 in plugins/modules/mysql_user.py

View check run for this annotation

Codecov / codecov/patch

plugins/modules/mysql_user.py#L478

Added line #L478 was not covered by tests
password_changed = False
if state == "present":
if user_exists(cursor, user, host, host_all):
Expand Down

0 comments on commit fcc8a87

Please sign in to comment.