dd-vault 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +42 -0
- data/.rspec +2 -0
- data/.travis.yml +26 -0
- data/CHANGELOG.md +228 -0
- data/Gemfile +3 -0
- data/LICENSE +362 -0
- data/README.md +214 -0
- data/Rakefile +6 -0
- data/lib/vault/api/approle.rb +218 -0
- data/lib/vault/api/auth.rb +316 -0
- data/lib/vault/api/auth_tls.rb +92 -0
- data/lib/vault/api/auth_token.rb +242 -0
- data/lib/vault/api/help.rb +33 -0
- data/lib/vault/api/logical.rb +150 -0
- data/lib/vault/api/secret.rb +156 -0
- data/lib/vault/api/sys/audit.rb +91 -0
- data/lib/vault/api/sys/auth.rb +116 -0
- data/lib/vault/api/sys/health.rb +63 -0
- data/lib/vault/api/sys/init.rb +83 -0
- data/lib/vault/api/sys/leader.rb +48 -0
- data/lib/vault/api/sys/lease.rb +49 -0
- data/lib/vault/api/sys/mount.rb +103 -0
- data/lib/vault/api/sys/policy.rb +92 -0
- data/lib/vault/api/sys/seal.rb +81 -0
- data/lib/vault/api/sys.rb +25 -0
- data/lib/vault/api.rb +12 -0
- data/lib/vault/client.rb +447 -0
- data/lib/vault/configurable.rb +48 -0
- data/lib/vault/defaults.rb +197 -0
- data/lib/vault/encode.rb +19 -0
- data/lib/vault/errors.rb +72 -0
- data/lib/vault/persistent/connection.rb +42 -0
- data/lib/vault/persistent/pool.rb +48 -0
- data/lib/vault/persistent/timed_stack_multi.rb +70 -0
- data/lib/vault/persistent.rb +1158 -0
- data/lib/vault/request.rb +43 -0
- data/lib/vault/response.rb +89 -0
- data/lib/vault/vendor/connection_pool/timed_stack.rb +178 -0
- data/lib/vault/vendor/connection_pool/version.rb +5 -0
- data/lib/vault/vendor/connection_pool.rb +150 -0
- data/lib/vault/version.rb +3 -0
- data/lib/vault.rb +49 -0
- data/vault.gemspec +30 -0
- metadata +185 -0
data/lib/vault/errors.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
module Vault
|
2
|
+
class VaultError < RuntimeError; end
|
3
|
+
|
4
|
+
class MissingTokenError < VaultError
|
5
|
+
def initialize
|
6
|
+
super <<-EOH
|
7
|
+
Missing Vault token! I cannot make requests to Vault without a token. Please
|
8
|
+
set a Vault token in the client:
|
9
|
+
|
10
|
+
Vault.token = "42d1dee5-eb6e-102c-8d23-cc3ba875da51"
|
11
|
+
|
12
|
+
or authenticate with Vault using the Vault CLI:
|
13
|
+
|
14
|
+
$ vault auth ...
|
15
|
+
|
16
|
+
or set the environment variable $VAULT_TOKEN to the token value:
|
17
|
+
|
18
|
+
$ export VAULT_TOKEN="..."
|
19
|
+
|
20
|
+
Please refer to the documentation for more examples.
|
21
|
+
EOH
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class HTTPConnectionError < VaultError
|
26
|
+
attr_reader :address
|
27
|
+
|
28
|
+
def initialize(address, exception)
|
29
|
+
@address = address
|
30
|
+
@exception = exception
|
31
|
+
|
32
|
+
super <<-EOH
|
33
|
+
The Vault server at `#{address}' is not currently
|
34
|
+
accepting connections. Please ensure that the server is running and that your
|
35
|
+
authentication information is correct.
|
36
|
+
|
37
|
+
The original error was `#{exception.class}'. Additional information (if any) is
|
38
|
+
shown below:
|
39
|
+
|
40
|
+
#{exception.message}
|
41
|
+
|
42
|
+
Please refer to the documentation for more help.
|
43
|
+
EOH
|
44
|
+
end
|
45
|
+
|
46
|
+
def original_exception
|
47
|
+
@exception
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class HTTPError < VaultError
|
52
|
+
attr_reader :address, :response, :code, :errors
|
53
|
+
|
54
|
+
def initialize(address, response, errors = [])
|
55
|
+
@address, @response, @errors = address, response, errors
|
56
|
+
@code = response.code.to_i
|
57
|
+
errors = errors.map { |error| " * #{error}" }
|
58
|
+
|
59
|
+
super <<-EOH
|
60
|
+
The Vault server at `#{address}' responded with a #{code}.
|
61
|
+
Any additional information the server supplied is shown below:
|
62
|
+
|
63
|
+
#{errors.join("\n").rstrip}
|
64
|
+
|
65
|
+
Please refer to the documentation for help.
|
66
|
+
EOH
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class HTTPClientError < HTTPError; end
|
71
|
+
class HTTPServerError < HTTPError; end
|
72
|
+
end
|
@@ -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 PersistentHTTP::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 = PersistentHTTP::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 PersistentHTTP::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 = PersistentHTTP::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 PersistentHTTP::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
|