class Philae::EtcdProbe
Attributes
name[R]
Public Class Methods
new(name, host, port, read_timeout: 1, cacert: nil, ssl_cert: nil, ssl_key: nil)
click to toggle source
@param [Integer] read_timeout Timeout in second for the HTTP request
# File lib/philae/etcd_probe.rb, line 16 def initialize(name, host, port, read_timeout: 1, cacert: nil, ssl_cert: nil, ssl_key: nil) if !cacert.nil? raise InvalidSSLConfig, 'cacert' if !File.exist?(cacert) raise InvalidSSLConfig, 'ssl_cert' if ssl_cert.nil? || !File.exist?(ssl_cert) raise InvalidSSLConfig, 'ssl_key' if ssl_key.nil? || !File.exist?(ssl_key) end @name = name @host = host @port = port @read_timeout = read_timeout @cacert = cacert @ssl_cert = ssl_cert @ssl_key = ssl_key end
Public Instance Methods
check()
click to toggle source
# File lib/philae/etcd_probe.rb, line 32 def check begin etcd_client.get '/' rescue StandardError => e return { healthy: false, comment: "Unable to contact etcd (#{e.message})" } end return { healthy: true, comment: '' } end
Protected Instance Methods
etcd_client()
click to toggle source
# File lib/philae/etcd_probe.rb, line 44 def etcd_client return Etcd.client host: @host, port: @port, read_timeout: @read_timeout do |c| next if @cacert.nil? c.use_ssl = true c.ca_file = @cacert c.ssl_cert = OpenSSL::X509::Certificate.new(File.read(@ssl_cert)) c.ssl_key = OpenSSL::PKey::RSA.new(File.read(@ssl_key)) end end