Skip to content

Commit

Permalink
Add settings_profile_elements (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksvagachev authored Sep 16, 2024
1 parent 272ffa2 commit 49798dd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/2-info_add_all_settings_profiles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- clickhouse_info - add the ``settings_profile_elements`` returns all settings for users, profiles and roles.
55 changes: 55 additions & 0 deletions plugins/modules/clickhouse_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@
type: dict
sample: { "roles": {"..."}, "users": {"..."} }
version_added: '0.7.0'
settings_profile_elements:
description:
- The content of the system.settings_profile_elements table for users, roles, profiles as keys.
returned: success
type: dict
sample: { "roles": {"..."}, "users": {"..."}, "profiles": {"..."} }
version_added: '0.7.0'
'''

from ansible.module_utils.basic import AnsibleModule
Expand Down Expand Up @@ -581,6 +588,53 @@ def get_all_grants(module, client):
return grants_info


def get_settings_profile_elements(module, client):
"""Get settings_profile_elements.
Returns a dictionary with roles, profiles and users names as keys.
"""
query = ("SELECT profile_name, user_name, role_name, "
"index, setting_name, value, min, max, "
"inherit_profile FROM system.settings_profile_elements")
result = execute_query(module, client, query)

if result == PRIV_ERR_CODE:
return {PRIV_ERR_CODE: "Not enough privileges"}

settings_profile_elements = {'profiles': {},
'users': {},
'roles': {},
}

for row in result:
if row[0] is not None:
dict_name = 'profiles'
name = row[0]
if row[0] not in settings_profile_elements[dict_name]:
settings_profile_elements[dict_name][name] = []
elif row[1] is not None:
dict_name = 'users'
name = row[1]
if row[1] not in settings_profile_elements[dict_name]:
settings_profile_elements[dict_name][name] = []
else:
dict_name = 'roles'
name = row[2]
if row[2] not in settings_profile_elements[dict_name]:
settings_profile_elements[dict_name][name] = []

settings_profile_elements[dict_name][name].append({
"index": row[3],
"setting_name": row[4],
"value": row[5],
"min": row[6],
"max": row[7],
"inherit_profile": row[8],
})

return settings_profile_elements


def get_functions(module, client):
"""Get functions.
Expand Down Expand Up @@ -708,6 +762,7 @@ def main():
'merge_tree_settings': get_merge_tree_settings,
'quotas': get_quotas,
'settings_profiles': get_settings_profiles,
'settings_profile_elements': get_settings_profile_elements,
'functions': get_functions,
'storage_policies': get_storage_policies,
'grants': get_all_grants,
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/targets/clickhouse_info/tasks/initial.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
- name: Create user eva
community.clickhouse.clickhouse_user:
name: eva
settings:
- max_memory_usage = 15000 MIN 15000 MAX 16000 READONLY

- name: Grant to INSERT for user eva
community.clickhouse.clickhouse_client:
Expand Down Expand Up @@ -58,6 +60,8 @@
- result["settings_profiles"]["default"] != {}
- result["storage_policies"] != {}
- result["grants"]["users"]["eva"][0]["access_type"] == "INSERT"
- result["settings_profile_elements"]["users"]["eva"][0]["setting_name"] == "max_memory_usage"
- result["settings_profile_elements"]["users"]["eva"][0]["value"] == "15000"

- name: Debug
ansible.builtin.debug:
Expand Down

0 comments on commit 49798dd

Please sign in to comment.