Skip to content

Commit

Permalink
Merge pull request #140 from treydock/check-theme
Browse files Browse the repository at this point in the history
Emit warning if configured theme does not exist
  • Loading branch information
treydock authored Jul 2, 2020
2 parents ee6894d + d23d2b8 commit 12ddcbe
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/puppet/provider/keycloak_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,11 @@ def self.name_uuid(name)
def name_uuid(*args)
self.class.name_uuid(*args)
end

def check_theme_exists(theme, res)
install_dir = self.class.install_dir || '/opt/keycloak'
path = File.join(install_dir, 'themes', theme)
return if File.exist?(path)
Puppet.warning("#{res}: Theme #{theme} not found at path #{path}.")
end
end
6 changes: 6 additions & 0 deletions lib/puppet/provider/keycloak_client/kcadm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ def create
t.close
Puppet.debug(IO.read(t.path))
begin
if resource[:login_theme]
check_theme_exists(resource[:login_theme], "Keycloak_client[#{resource[:name]}]")
end
output = kcadm('create', 'clients', resource[:realm], t.path)
Puppet.debug("create client output: #{output}")
rescue Puppet::ExecutionFailure => e
Expand Down Expand Up @@ -256,6 +259,9 @@ def flush
t.close
Puppet.debug(IO.read(t.path))
begin
if @property_flush[:login_theme]
check_theme_exists(@property_flush[:login_theme], "Keycloak_client[#{resource[:name]}]")
end
kcadm('update', "clients/#{id}", resource[:realm], t.path)
rescue Puppet::ExecutionFailure => e
raise Puppet::Error, "kcadm update client failed\nError message: #{e.message}"
Expand Down
20 changes: 20 additions & 0 deletions lib/puppet/provider/keycloak_realm/kcadm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ def create
t.close
Puppet.debug(IO.read(t.path))
begin
[
:login_theme,
:account_theme,
:admin_theme,
:email_theme,
].each do |theme|
if resource[theme]
check_theme_exists(resource[theme], "Keycloak_realm[#{resource[:name]}]")
end
end
kcadm('create', 'realms', nil, t.path)
rescue Puppet::ExecutionFailure => e
raise Puppet::Error, "kcadm create realm failed\nError message: #{e.message}"
Expand Down Expand Up @@ -291,6 +301,16 @@ def flush
t.close
Puppet.debug(IO.read(t.path))
begin
[
:login_theme,
:account_theme,
:admin_theme,
:email_theme,
].each do |theme|
if @property_flush[theme]
check_theme_exists(@property_flush[theme], "Keycloak_realm[#{resource[:name]}]")
end
end
kcadm('update', "realms/#{resource[:name]}", nil, t.path)
rescue Puppet::ExecutionFailure => e
raise Puppet::Error, "kcadm update realm failed\nError message: #{e.message}"
Expand Down

0 comments on commit 12ddcbe

Please sign in to comment.