Class: KeycloakApiRails::HTTPClient

Inherits:
Object
  • Object
show all
Defined in:
lib/keycloak-api-rails/http_client.rb

Constant Summary collapse

UNREACHABLE_ERRORS =
[
  Timeout::Error,
  SocketError,
  SystemCallError,
  IOError,
  OpenSSL::SSL::SSLError,
  Net::ProtocolError
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(configuration, logger) ⇒ HTTPClient

Returns a new instance of HTTPClient.



23
24
25
26
27
28
29
# File 'lib/keycloak-api-rails/http_client.rb', line 23

def initialize(configuration, logger)
  @configuration = configuration
  @logger        = logger
  @x509_store    = OpenSSL::X509::Store.new
  @x509_store.set_default_paths
  @x509_store.add_file(configuration.ca_certificate_file) if configuration.ca_certificate_file
end

Instance Method Details

#get(realm_id, path) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/keycloak-api-rails/http_client.rb', line 31

def get(realm_id, path)
  @configuration.validate_server!

  uri      = build_uri(realm_id, path)
  response = request(uri)

  unless response.is_a?(Net::HTTPSuccess)
    @logger.error("KeycloakApiRails: Keycloak responded with an error when calling '#{path}'. Status #{response.code}. Payload: #{response.body}")
    raise HTTPError.new("Keycloak responded with a #{response.code} status when calling '#{path}'", response.code)
  end

  parse(response, path)
end