Skip to content

Commit

Permalink
requested changes pt. 1
Browse files Browse the repository at this point in the history
  • Loading branch information
n-cc authored and n-cc committed Jan 16, 2024
1 parent 9a8b53d commit 9eb4cc3
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 53 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ Community MySQL Collection Release Notes

This changelog describes changes after version 2.0.0.

v3.9.0
======

This is the minor release of the ``community.mysql`` collection.
This changelog contains all changes to the modules and plugins in this
collection that have been made after the previous release.

Minor Changes
-------------

- mysql_user - add user attribute support via the ``attributes`` parameter and return value (https://github.com/ansible-collections/community.mysql/pull/604).

v3.8.0
======

Expand Down
9 changes: 4 additions & 5 deletions plugins/module_utils/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def user_add(cursor, user, host, host_all, password, encrypted,
attributes, tls_requires, reuse_existing_password, module):
# If attributes are set, perform a sanity check to ensure server supports user attributes before creating user
if attributes and not get_attribute_support(cursor):
module.fail_json(msg="user attributes were specified but the mysql server does not support user attributes")
module.fail_json(msg="user attributes were specified but the server does not support user attributes")

# we cannot create users without a proper hostname
if host_all:
Expand Down Expand Up @@ -431,15 +431,14 @@ def user_mod(cursor, user, host, host_all, password, encrypted,

if attributes:
if not attribute_support:
module.fail_json(msg="user attributes were specified but the mysql server does not support user attributes")
module.fail_json(msg="user attributes were specified but the server does not support user attributes")
else:
current_attributes = attributes_get(cursor, user, host)
attributes_to_change = {}

for key, value in attributes.items():
if key not in current_attributes or current_attributes[key] != value:
# The mysql null value (None in python) is used to delete an attribute; we use False to represent None in the attributes parameter
attributes_to_change[key] = None if not value else value
attributes_to_change[key] = value

if attributes_to_change:
msg = "Attributes updated: %s" % (", ".join(["%s: %s" % (key, value) for key, value in attributes_to_change.items()]))
Expand All @@ -451,7 +450,7 @@ def user_mod(cursor, user, host, host_all, password, encrypted,
else:
# Final if statements excludes items whose values are None in attributes_to_change, i.e. attributes that will be deleted
final_attributes = {k: v for d in (current_attributes, attributes_to_change) for k, v in d.items() if k not in attributes_to_change or
attributes_to_change[k]}
attributes_to_change[k] is not None}
changed = True
else:
final_attributes = current_attributes
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/mysql_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
description:
- "Create, update, or delete user attributes (arbitrary 'key: value' comments) for the user."
- MySQL server must support the INFORMATION_SCHEMA.USER_ATTRIBUTES table. Provided since MySQL 8.0.
- To delete an existing attribute, set its value to False.
- To delete an existing attribute, set its value to null.
type: dict
version_added: '3.9.0'
Expand Down Expand Up @@ -268,7 +268,7 @@
name: bob
attributes:
foo: "foo"
bar: False
bar: null
- name: Modify user to require TLS connection with a valid client certificate
community.mysql.mysql_user:
Expand Down
Loading

0 comments on commit 9eb4cc3

Please sign in to comment.