Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Sorts group mappings in ldap.toml by org_role #467

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This file is used to list changes made in each version of grafana.

## Unreleased

- Fix: Sorts group mappings in ldap.toml by org_role

## 10.8.0 - *2024-09-27*

- Added org_ids to ldap_mapping functions
Expand Down
6 changes: 3 additions & 3 deletions libraries/ldap_config_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ def load_file_ldap_config_host_attributes(config_file, host)
# @param group_dn [String] The group DN to return configuration for
# @return [Hash] Host attribute configuration
#
def load_file_ldap_config_host_group_mapping(config_file, host, group_dn)
def load_file_ldap_config_host_group_mapping(config_file, host, org_id)
host_config = load_file_ldap_config_host(config_file, host)

return if nil_or_empty?(host_config)

group_mapping = host_config.fetch('group_mappings', []).select { |gm| gm['group_dn'].eql?(group_dn) }.first
Chef::Log.debug("load_file_ldap_config_host_group_mapping: #{config_file} host #{host} group #{group_dn} - [#{group_mapping.class}] #{group_mapping}")
group_mapping = host_config.fetch('group_mappings', []).select { |gm| gm['org_id'].eql?(org_id) }.first
Chef::Log.debug("load_file_ldap_config_host_group_mapping: #{config_file} host #{host} group #{org_id} - [#{group_mapping.class}] #{group_mapping}")

group_mapping
end
Expand Down
5 changes: 2 additions & 3 deletions resources/config_ldap_group_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,13 @@ def remove_group_mapping
converge_if_changed do
mapping = resource_properties.map do |rp|
next if nil_or_empty?(new_resource.send(rp))

[rp.to_s, new_resource.send(rp)]
end.compact.sort.to_h
end.compact.to_h

remove_group_mapping if group_mapping_exist?

ldap_server_config(new_resource.host)['group_mappings'] ||= []
ldap_server_config(new_resource.host)['group_mappings'].push(mapping)
ldap_server_config(new_resource.host)['group_mappings'].sort_by! { |gm| gm['org_id'] }
end
end

Expand Down
Loading