Skip to content

Commit

Permalink
Use http_relative_path with keycloak_conn_validator (#278)
Browse files Browse the repository at this point in the history
Fixes #277
  • Loading branch information
treydock authored Mar 9, 2023
1 parent 02bf402 commit 12eb71f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ def create
#
# @api private
def validator
@validator ||= Puppet::Util::KeycloakValidator.new(resource[:keycloak_server], resource[:keycloak_port], resource[:use_ssl], resource[:test_url])
@validator ||= Puppet::Util::KeycloakValidator.new(resource[:keycloak_server], resource[:keycloak_port], resource[:use_ssl], resource[:test_url], resource[:relative_path])
end
end
7 changes: 6 additions & 1 deletion lib/puppet/type/keycloak_conn_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@

newparam(:test_url) do
desc 'URL to use for testing if the Keycloak database is up'
defaultto '/auth/admin/serverinfo'
defaultto '/realms/master/.well-known/openid-configuration'
end

newparam(:relative_path) do
desc 'URL relative path that is used by Keycloak'
defaultto '/'
end

newparam(:timeout) do
Expand Down
6 changes: 4 additions & 2 deletions lib/puppet/util/keycloak_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
class Puppet::Util::KeycloakValidator
attr_reader :keycloak_server, :keycloak_port, :use_ssl, :test_path

def initialize(keycloak_server, keycloak_port, use_ssl = false, test_path = '/auth/admin/serverinfo')
def initialize(keycloak_server, keycloak_port, use_ssl = false, test_path = '/realms/master/.well-known/openid-configuration', relative_path = '/')
@keycloak_server = keycloak_server
@keycloak_port = keycloak_port
@use_ssl = use_ssl
@test_path = test_path
@relative_path = relative_path
end

# Utility method; attempts to make an http/https connection to the keycloak server.
Expand All @@ -22,10 +23,11 @@ def attempt_connection
# All that we care about is that we are able to connect successfully via
# http(s), so here we're simpling hitting a somewhat arbitrary low-impact URL
# on the keycloak server.
path = "#{@relative_path}#{@test_path.sub(%r{^/}, '')}"
http = Net::HTTP.new(@keycloak_server, @keycloak_port)
http.use_ssl = @use_ssl
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(@test_path)
request = Net::HTTP::Get.new(path)
request.add_field('Accept', 'application/json')
response = http.request(request)

Expand Down
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@
use_ssl => $validator_ssl,
timeout => 60,
test_url => $validator_test_url,
relative_path => $http_relative_path,
require => Class['keycloak::service'],
}

Expand Down

0 comments on commit 12eb71f

Please sign in to comment.