Skip to content

Commit

Permalink
Avoid errors when prefetching realms (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock authored Apr 10, 2023
1 parent a6b49ac commit 978b360
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/puppet/provider/keycloak_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ def kcadm(*args)

def self.realms
output = kcadm('get', 'realms', nil, nil, ['realm'])
rescue Puppet::ExecutionFailure => e
Puppet.notice("Failed to get realms: #{e}")
[]
else
data = JSON.parse(output)
data.map { |r| r['realm'] }
end
Expand Down
7 changes: 5 additions & 2 deletions lib/puppet/provider/keycloak_realm/kcadm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,13 @@ def available_flows(realm)

def self.instances
realms = []
output = kcadm('get', 'realms')
Puppet.debug("Realms: #{output}")
begin
output = kcadm('get', 'realms')
Puppet.debug("Realms: #{output}")
data = JSON.parse(output)
rescue Puppet::ExecutionFailure => e
Puppet.notice("Failed to get realms: #{e}")
data = []
rescue JSON::ParserError
Puppet.debug('Unable to parse output from kcadm get realms')
data = []
Expand Down

0 comments on commit 978b360

Please sign in to comment.