Skip to content

Commit

Permalink
Fix #306 - Retrieve parentId by realm name
Browse files Browse the repository at this point in the history
  • Loading branch information
TuningYourCode committed Apr 3, 2024
1 parent 7d93588 commit 351d5f7
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/puppet/provider/keycloak_ldap_user_provider/kcadm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,29 @@ def self.prefetch(resources)
end
end

def get_parent_id(realm)
parent_id = nil
output = kcadm('get', 'realms', realm, nil, ['id'])
Puppet.debug("#{realm} realms: #{output}")
begin
data = JSON.parse(output)
rescue JSON::ParserError
Puppet.debug('Unable to parse output from kcadm get realms')
data = []
end
data.each do |d|
parent_id = d['id']
end
parent_id
end

def create
raise(Puppet::Error, "Realm is mandatory for #{resource.type} #{resource.name}") if resource[:realm].nil?

data = {}
data[:id] = resource[:id] || name_uuid(resource[:name])
data[:name] = resource[:resource_name]
data[:parentId] = resource[:realm]
data[:parentId] = get_parent_id(resource[:realm]) || resource[:realm]
data[:providerId] = 'ldap'
data[:providerType] = 'org.keycloak.storage.UserStorageProvider'
data[:config] = {}
Expand Down

0 comments on commit 351d5f7

Please sign in to comment.