Skip to content

Commit

Permalink
Added new role management features (#59)
Browse files Browse the repository at this point in the history
* Added new role management features

* Fixed test
  • Loading branch information
aleksvagachev authored Apr 15, 2024
1 parent abc9593 commit d4cadbf
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
35 changes: 35 additions & 0 deletions plugins/modules/clickhouse_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
author:
- Don Naro (@oranod)
- Aleksandr Vagachev (@aleksvagachev)
extends_documentation_fragment:
- community.clickhouse.client_inst_opts
Expand All @@ -44,6 +45,17 @@
- Role name to add or remove.
type: str
required: true
cluster:
description:
- Run the command on all cluster hosts.
- If the cluster is not configured, the command will crash with an error.
type: str
settings:
description:
- Settings with their limitations that apply to the role.
- You can also specify the profile from which the settings will be inherited.
type: list
elements: str
"""

EXAMPLES = r"""
Expand All @@ -52,6 +64,15 @@
name: test_role
state: present
- name: Create a role with settings
community.clickhouse.clickhouse_role:
name: test_role
state: present
settings:
- max_memory_usage = 15000 MIN 15000 MAX 16000 READONLY
- PROFILE restricted
cluster: test_cluster
- name: Remove role
community.clickhouse.clickhouse_role:
name: test_role
Expand Down Expand Up @@ -95,6 +116,18 @@ def check_exists(self):
def create(self):
if not self.exists:
query = "CREATE ROLE %s" % self.name

if self.module.params['cluster']:
query += " ON CLUSTER %s" % self.module.params['cluster']

list_settings = self.module.params['settings']
if list_settings:
query += " SETTINGS"
for index, value in enumerate(list_settings):
query += " %s" % value
if index < len(list_settings) - 1:
query += ","

executed_statements.append(query)

if not self.module.check_mode:
Expand Down Expand Up @@ -128,6 +161,8 @@ def main():
argument_spec.update(
state=dict(type="str", choices=["present", "absent"], default="present"),
name=dict(type="str", required=True),
cluster=dict(type='str', default=None),
settings=dict(type='list', elements='str'),
)

# Instantiate an object of module class
Expand Down
1 change: 1 addition & 0 deletions plugins/modules/clickhouse_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
- You can also specify the profile from which the settings will be inherited.
type: list
elements: str
version_added: '0.5.0'
'''

EXAMPLES = r'''
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/targets/clickhouse_role/tasks/initial.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@
community.clickhouse.clickhouse_role:
state: present
name: test_role
settings:
- max_memory_usage = 15000 READONLY
- max_memory_usage_for_all_queries = 15000 MIN 15000 MAX 16000 WRITABLE

- name: Test 2 - Check the return values
ansible.builtin.assert:
that:
- result is changed
- result.executed_statements == ['CREATE ROLE test_role']
- result.executed_statements == ['CREATE ROLE test_role SETTINGS max_memory_usage = 15000 READONLY, max_memory_usage_for_all_queries = 15000 MIN 15000 MAX 16000 WRITABLE']

- name: Test 2 - Check the role was created
register: result
Expand Down

0 comments on commit d4cadbf

Please sign in to comment.