vault 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,42 @@
1
+ ##
2
+ # A Net::HTTP connection wrapper that holds extra information for managing the
3
+ # connection's lifetime.
4
+
5
+ module Vault
6
+ class Net::HTTP::Persistent::Connection # :nodoc:
7
+
8
+ attr_accessor :http
9
+
10
+ attr_accessor :last_use
11
+
12
+ attr_accessor :requests
13
+
14
+ attr_accessor :ssl_generation
15
+
16
+ def initialize http_class, http_args, ssl_generation
17
+ @http = http_class.new(*http_args)
18
+ @ssl_generation = ssl_generation
19
+
20
+ reset
21
+ end
22
+
23
+ def finish
24
+ @http.finish
25
+ rescue IOError
26
+ ensure
27
+ reset
28
+ end
29
+
30
+ def reset
31
+ @last_use = Net::HTTP::Persistent::EPOCH
32
+ @requests = 0
33
+ end
34
+
35
+ def ressl ssl_generation
36
+ @ssl_generation = ssl_generation
37
+
38
+ finish
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,48 @@
1
+ module Vault
2
+ class Net::HTTP::Persistent::Pool < Vault::ConnectionPool # :nodoc:
3
+
4
+ attr_reader :available # :nodoc:
5
+ attr_reader :key # :nodoc:
6
+
7
+ def initialize(options = {}, &block)
8
+ super
9
+
10
+ @available = Net::HTTP::Persistent::TimedStackMulti.new(@size, &block)
11
+ @key = :"current-#{@available.object_id}"
12
+ end
13
+
14
+ def checkin net_http_args
15
+ stack = Thread.current[@key][net_http_args]
16
+
17
+ raise ConnectionPool::Error, 'no connections are checked out' if
18
+ stack.empty?
19
+
20
+ conn = stack.pop
21
+
22
+ if stack.empty?
23
+ @available.push conn, connection_args: net_http_args
24
+ end
25
+
26
+ nil
27
+ end
28
+
29
+ def checkout net_http_args
30
+ stacks = Thread.current[@key] ||= Hash.new { |h, k| h[k] = [] }
31
+ stack = stacks[net_http_args]
32
+
33
+ if stack.empty? then
34
+ conn = @available.pop connection_args: net_http_args
35
+ else
36
+ conn = stack.last
37
+ end
38
+
39
+ stack.push conn
40
+
41
+ conn
42
+ end
43
+
44
+ end
45
+ end
46
+
47
+ require_relative 'timed_stack_multi'
48
+
@@ -0,0 +1,70 @@
1
+ module Vault
2
+ class Net::HTTP::Persistent::TimedStackMulti < ConnectionPool::TimedStack # :nodoc:
3
+
4
+ def initialize(size = 0, &block)
5
+ super
6
+
7
+ @enqueued = 0
8
+ @ques = Hash.new { |h, k| h[k] = [] }
9
+ @lru = {}
10
+ @key = :"connection_args-#{object_id}"
11
+ end
12
+
13
+ def empty?
14
+ (@created - @enqueued) >= @max
15
+ end
16
+
17
+ def length
18
+ @max - @created + @enqueued
19
+ end
20
+
21
+ private
22
+
23
+ def connection_stored? options = {} # :nodoc:
24
+ !@ques[options[:connection_args]].empty?
25
+ end
26
+
27
+ def fetch_connection options = {} # :nodoc:
28
+ connection_args = options[:connection_args]
29
+
30
+ @enqueued -= 1
31
+ lru_update connection_args
32
+ @ques[connection_args].pop
33
+ end
34
+
35
+ def lru_update connection_args # :nodoc:
36
+ @lru.delete connection_args
37
+ @lru[connection_args] = true
38
+ end
39
+
40
+ def shutdown_connections # :nodoc:
41
+ @ques.each_key do |key|
42
+ super connection_args: key
43
+ end
44
+ end
45
+
46
+ def store_connection obj, options = {} # :nodoc:
47
+ @ques[options[:connection_args]].push obj
48
+ @enqueued += 1
49
+ end
50
+
51
+ def try_create options = {} # :nodoc:
52
+ connection_args = options[:connection_args]
53
+
54
+ if @created >= @max && @enqueued >= 1
55
+ oldest, = @lru.first
56
+ @lru.delete oldest
57
+ @ques[oldest].pop
58
+
59
+ @created -= 1
60
+ end
61
+
62
+ if @created < @max
63
+ @created += 1
64
+ lru_update connection_args
65
+ return @create_block.call(connection_args)
66
+ end
67
+ end
68
+
69
+ end
70
+ end
@@ -1,3 +1,3 @@
1
1
  module Vault
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vault
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Vargo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-30 00:00:00.000000000 Z
11
+ date: 2016-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -111,6 +111,7 @@ files:
111
111
  - Rakefile
112
112
  - lib/vault.rb
113
113
  - lib/vault/api.rb
114
+ - lib/vault/api/approle.rb
114
115
  - lib/vault/api/auth.rb
115
116
  - lib/vault/api/auth_tls.rb
116
117
  - lib/vault/api/auth_token.rb
@@ -129,9 +130,17 @@ files:
129
130
  - lib/vault/client.rb
130
131
  - lib/vault/configurable.rb
131
132
  - lib/vault/defaults.rb
133
+ - lib/vault/encode.rb
132
134
  - lib/vault/errors.rb
133
135
  - lib/vault/request.rb
134
136
  - lib/vault/response.rb
137
+ - lib/vault/vendor/connection_pool.rb
138
+ - lib/vault/vendor/connection_pool/timed_stack.rb
139
+ - lib/vault/vendor/connection_pool/version.rb
140
+ - lib/vault/vendor/net/http/persistent.rb
141
+ - lib/vault/vendor/net/http/persistent/connection.rb
142
+ - lib/vault/vendor/net/http/persistent/pool.rb
143
+ - lib/vault/vendor/net/http/persistent/timed_stack_multi.rb
135
144
  - lib/vault/version.rb
136
145
  - vault.gemspec
137
146
  homepage: https://github.com/hashicorp/vault-ruby
@@ -154,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
163
  version: '0'
155
164
  requirements: []
156
165
  rubyforge_project:
157
- rubygems_version: 2.4.5.1
166
+ rubygems_version: 2.5.1
158
167
  signing_key:
159
168
  specification_version: 4
160
169
  summary: Vault is a Ruby API client for interacting with a Vault server.