philae 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/philae/etcd_probe.rb +22 -14
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52665bd2cc49aad1dfdc3c7c53661e886ecb2960
4
- data.tar.gz: c995b59612c527541139225798d1e58d654e15e6
3
+ metadata.gz: 364566be0ba5f86c671be8dfc919961eb333675c
4
+ data.tar.gz: 861a74eea37e7b5a4dd39f18f04165028df0727d
5
5
  SHA512:
6
- metadata.gz: 35be4d2d3316b3992a852b4b51192e7ed153919fffc30ca489cc81e1be0912d7b46cf8784b90636df6100565a0cd5bf2c38b56e22500dc95caef3ffe802571fb
7
- data.tar.gz: 7bf212df4572ce144eb9cb2d8b7bf3a0a080539194a2e9c05ad61a0e6b7f0e1788d8c8c329aa692d780dbaaadbceb2951fe5b0ac28aae8796846a4e1779edc63
6
+ metadata.gz: 8a75abb6a2a71b648d25386e1e269c77326589084211b32d2fdf2d8bfa1228c9947ea4467cda1b3b5a4f4b03a452385d9c3c28764c6a2260338cfeacb032d73b
7
+ data.tar.gz: fd7c6875ef6784f9654f79b3c692eedcdfee804f73bcc4043564a65f68601ea98f43448dadf463bf75186548c456b453c284449e0d7e0777f1c31f77d0997a93
@@ -6,13 +6,22 @@ require 'etcd'
6
6
  # If you need to connect to etcd using a custom CA cert, you can give it along with the SSL cert and
7
7
  # key to the constructor.
8
8
  module Philae
9
+ class InvalidSSLConfig < RuntimeError
10
+ end
11
+
9
12
  class EtcdProbe
10
13
  attr_reader :name
11
14
 
12
15
  # @param [Integer] read_timeout Timeout in second for the HTTP request
13
- def initialize(name, host, port, read_timeout=1, cacert=nil, ssl_cert=nil, ssl_key=nil)
14
- if not cacert.nil? and (ssl_cert.nil? or ssl_key.nil?)
15
- raise ArgumentError
16
+ def initialize(name, host, port, read_timeout: 1, cacert: nil, ssl_cert: nil, ssl_key: nil)
17
+ if not cacert.nil?
18
+ if !File.exists? cacert
19
+ raise InvalidSSLConfig, "cacert"
20
+ elsif ssl_cert.nil? or !File.exists? ssl_cert
21
+ raise InvalidSSLConfig, "ssl_cert"
22
+ elsif ssl_key.nil? or !File.exists? ssl_key
23
+ raise InvalidSSLConfig, "ssl_key"
24
+ end
16
25
  end
17
26
  @name = name
18
27
  @host = host
@@ -25,20 +34,19 @@ module Philae
25
34
 
26
35
  def check
27
36
  begin
28
- opts = {
29
- host: @host,
30
- port: @port,
31
- read_timeout: @read_timeout,
32
- }
33
37
  if not @cacert.nil?
34
- opts[:cacert] = @cacert
35
- opts[:ssl_cert] = @ssl_cert
36
- opts[:ssl_key] = @ssl_key
38
+ client = Etcd.client host: @host, port: @port, read_timeout: @read_timeout do |c|
39
+ c.use_ssl = true
40
+ c.ca_file = @cacert
41
+ c.ssl_cert = OpenSSL::X509::Certificate.new(File.read(@ssl_cert))
42
+ c.ssl_key = OpenSSL::PKey::RSA.new(File.read(@ssl_key))
43
+ end
44
+ else
45
+ client = Etcd.client host: @host, port: @port, read_timeout: @read_timeout
37
46
  end
38
- client = Etcd.client(opts)
39
47
  client.get '/'
40
- rescue
41
- return { healthy: false, comment: 'Unable to contact etcd' }
48
+ rescue Exception => e
49
+ return { healthy: false, comment: "Unable to contact etcd (#{e.message})" }
42
50
  end
43
51
  { healthy: true, comment: '' }
44
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philae
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - leo@scalingo.com
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-06-14 00:00:00.000000000 Z
13
+ date: 2017-07-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: docker-api