Class: Kybus::Client::Session::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty, BasicAuth
Defined in:
lib/kybus/client/session/base.rb

Overview

Used on http clients. It modifies the requests in order to implement credentials and other mechanism for session.

Instance Method Summary collapse

Methods included from BasicAuth

#basic_auth

Constructor Details

#initialize(config) ⇒ Base

Returns a new instance of Base.



20
21
22
23
24
# File 'lib/kybus/client/session/base.rb', line 20

def initialize(config)
  @config = config
  register_certificate
  register_ca
end

Instance Method Details

#configure_request(request) ⇒ Object

:nocov: #



43
44
45
46
# File 'lib/kybus/client/session/base.rb', line 43

def configure_request(request)
  basic_auth(request, **@config[:basic_auth]) if @config[:basic_auth]
  request[:verify] = @config[:verify] if @config.key?(:verify)
end

#perform_request(method, endpoint, data) ⇒ Object



48
49
50
51
# File 'lib/kybus/client/session/base.rb', line 48

def perform_request(method, endpoint, data)
  configure_request(data)
  self.class.send(method, endpoint, data)
end

#register_caObject

:nocov: #



36
37
38
39
40
# File 'lib/kybus/client/session/base.rb', line 36

def register_ca
  return unless @config[:ca_validate]

  self.class.ssl_ca_file(@config[:ca_validate])
end

#register_certificateObject

:nocov: #



27
28
29
30
31
32
# File 'lib/kybus/client/session/base.rb', line 27

def register_certificate
  return unless @config[:client_certificate]

  cert = File.read(@config[:client_certificate])
  self.class.pkcs12(cert, @config[:client_certificate_pass])
end