vault 0.10.0 → 0.16.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 +5 -5
- data/CHANGELOG.md +68 -0
- data/README.md +31 -7
- data/lib/vault/api.rb +2 -0
- data/lib/vault/api/auth.rb +113 -8
- data/lib/vault/api/auth_token.rb +2 -2
- data/lib/vault/api/kv.rb +207 -0
- data/lib/vault/api/secret.rb +12 -0
- data/lib/vault/api/sys.rb +3 -0
- data/lib/vault/api/sys/audit.rb +18 -1
- data/lib/vault/api/sys/health.rb +63 -0
- data/lib/vault/api/sys/mount.rb +7 -2
- data/lib/vault/api/sys/namespace.rb +83 -0
- data/lib/vault/api/sys/quota.rb +107 -0
- data/lib/vault/api/transform.rb +29 -0
- data/lib/vault/api/transform/alphabet.rb +43 -0
- data/lib/vault/api/transform/role.rb +42 -0
- data/lib/vault/api/transform/template.rb +54 -0
- data/lib/vault/api/transform/transformation.rb +61 -0
- data/lib/vault/client.rb +19 -5
- data/lib/vault/configurable.rb +2 -0
- data/lib/vault/defaults.rb +27 -2
- data/lib/vault/persistent.rb +2 -7
- data/lib/vault/persistent/pool.rb +1 -1
- data/lib/vault/request.rb +1 -0
- data/lib/vault/version.rb +1 -1
- metadata +40 -24
- data/.gitignore +0 -41
- data/.rspec +0 -2
- data/.travis.yml +0 -24
- data/Gemfile +0 -3
- data/Rakefile +0 -6
- data/vault.gemspec +0 -28
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative '../../request'
|
2
|
+
require_relative '../../response'
|
3
|
+
|
4
|
+
module Vault
|
5
|
+
class Transform < Request
|
6
|
+
class Template < Response
|
7
|
+
# @!attribute [r] alphabet
|
8
|
+
# Name of the alphabet to be used in the template
|
9
|
+
# @return [String]
|
10
|
+
field :alphabet
|
11
|
+
|
12
|
+
# @!attribute [r] pattern
|
13
|
+
# Regex string to detect and match for the template
|
14
|
+
# @return [String]
|
15
|
+
field :pattern
|
16
|
+
|
17
|
+
# @!attribute [r] type
|
18
|
+
# Type of the template, currently, only "regex" is supported
|
19
|
+
# @return [String]
|
20
|
+
field :type
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_template(name, type:, pattern:, **opts)
|
24
|
+
opts ||= {}
|
25
|
+
opts[:type] = type
|
26
|
+
opts[:pattern] = pattern
|
27
|
+
client.post("/v1/transform/template/#{encode_path(name)}", JSON.fast_generate(opts))
|
28
|
+
return true
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_template(name)
|
32
|
+
json = client.get("/v1/transform/template/#{encode_path(name)}")
|
33
|
+
if data = json.dig(:data)
|
34
|
+
Template.decode(data)
|
35
|
+
else
|
36
|
+
json
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete_template(name)
|
41
|
+
client.delete("/v1/transform/template/#{encode_path(name)}")
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
45
|
+
def templates
|
46
|
+
json = client.list("/v1/transform/template")
|
47
|
+
if keys = json.dig(:data, :keys)
|
48
|
+
keys
|
49
|
+
else
|
50
|
+
json
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require_relative '../../request'
|
2
|
+
require_relative '../../response'
|
3
|
+
|
4
|
+
module Vault
|
5
|
+
class Transform < Request
|
6
|
+
class Transformation < Response
|
7
|
+
# @!attribute [r] allowed_roles
|
8
|
+
# Array of role names that are allowed to use this transformation
|
9
|
+
# @return [Array<String>]
|
10
|
+
field :allowed_roles
|
11
|
+
|
12
|
+
# @!attribute [r] templates
|
13
|
+
# Array of template names accessible to this transformation
|
14
|
+
# @return [Array<String>]
|
15
|
+
field :templates
|
16
|
+
|
17
|
+
# @!attribute [r] tweak_source
|
18
|
+
# String representing how a tweak is provided for this transformation.
|
19
|
+
# Available tweaks are "supplied", "generated", and "internal"
|
20
|
+
# @return [String]
|
21
|
+
field :tweak_source
|
22
|
+
|
23
|
+
# @!attribute [r] type
|
24
|
+
# String representing the type of transformation this is.
|
25
|
+
# Available types are "fpe", and "masking"
|
26
|
+
# @return [String]
|
27
|
+
field :type
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_transformation(name, type:, template:, **opts)
|
31
|
+
opts ||= {}
|
32
|
+
opts[:type] = type
|
33
|
+
opts[:template] = template
|
34
|
+
client.post("/v1/transform/transformation/#{encode_path(name)}", JSON.fast_generate(opts))
|
35
|
+
return true
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_transformation(name)
|
39
|
+
json = client.get("/v1/transform/transformation/#{encode_path(name)}")
|
40
|
+
if data = json.dig(:data)
|
41
|
+
Transformation.decode(data)
|
42
|
+
else
|
43
|
+
json
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def delete_transformation(name)
|
48
|
+
client.delete("/v1/transform/transformation/#{encode_path(name)}")
|
49
|
+
true
|
50
|
+
end
|
51
|
+
|
52
|
+
def transformations
|
53
|
+
json = client.list("/v1/transform/transformation")
|
54
|
+
if keys = json.dig(:data, :keys)
|
55
|
+
keys
|
56
|
+
else
|
57
|
+
json
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/vault/client.rb
CHANGED
@@ -16,6 +16,9 @@ module Vault
|
|
16
16
|
# The name of the header used to hold the Vault token.
|
17
17
|
TOKEN_HEADER = "X-Vault-Token".freeze
|
18
18
|
|
19
|
+
# The name of the header used to hold the Namespace.
|
20
|
+
NAMESPACE_HEADER = "X-Vault-Namespace".freeze
|
21
|
+
|
19
22
|
# The name of the header used to hold the wrapped request ttl.
|
20
23
|
WRAP_TTL_HEADER = "X-Vault-Wrap-TTL".freeze
|
21
24
|
|
@@ -83,11 +86,7 @@ module Vault
|
|
83
86
|
@lock.synchronize do
|
84
87
|
return @nhp if @nhp
|
85
88
|
|
86
|
-
@nhp = PersistentHTTP.new("vault-ruby", nil, pool_size)
|
87
|
-
|
88
|
-
if hostname
|
89
|
-
@nhp.hostname = hostname
|
90
|
-
end
|
89
|
+
@nhp = PersistentHTTP.new("vault-ruby", nil, pool_size, pool_timeout)
|
91
90
|
|
92
91
|
if proxy_address
|
93
92
|
proxy_uri = URI.parse "http://#{proxy_address}"
|
@@ -158,6 +157,12 @@ module Vault
|
|
158
157
|
|
159
158
|
private :pool
|
160
159
|
|
160
|
+
# Shutdown any open pool connections. Pool will be recreated upon next request.
|
161
|
+
def shutdown
|
162
|
+
@nhp.shutdown()
|
163
|
+
@nhp = nil
|
164
|
+
end
|
165
|
+
|
161
166
|
# Creates and yields a new client object with the given token. This may be
|
162
167
|
# used safely in a threadsafe manner because the original client remains
|
163
168
|
# unchanged. The value of the block is returned.
|
@@ -236,6 +241,9 @@ module Vault
|
|
236
241
|
# Build the URI and request object from the given information
|
237
242
|
uri = build_uri(verb, path, data)
|
238
243
|
request = class_for_request(verb).new(uri.request_uri)
|
244
|
+
if uri.userinfo()
|
245
|
+
request.basic_auth uri.user, uri.password
|
246
|
+
end
|
239
247
|
|
240
248
|
if proxy_address and uri.scheme.downcase == "https"
|
241
249
|
raise SecurityError, "no direct https connection to vault"
|
@@ -250,6 +258,12 @@ module Vault
|
|
250
258
|
headers[TOKEN_HEADER] ||= token
|
251
259
|
end
|
252
260
|
|
261
|
+
# Add the Vault Namespace header - users could still override this on a
|
262
|
+
# per-request basis
|
263
|
+
if !namespace.nil?
|
264
|
+
headers[NAMESPACE_HEADER] ||= namespace
|
265
|
+
end
|
266
|
+
|
253
267
|
# Add headers
|
254
268
|
headers.each do |key, value|
|
255
269
|
request.add_field(key, value)
|
data/lib/vault/configurable.rb
CHANGED
@@ -7,12 +7,14 @@ module Vault
|
|
7
7
|
:address,
|
8
8
|
:token,
|
9
9
|
:hostname,
|
10
|
+
:namespace,
|
10
11
|
:open_timeout,
|
11
12
|
:proxy_address,
|
12
13
|
:proxy_password,
|
13
14
|
:proxy_port,
|
14
15
|
:proxy_username,
|
15
16
|
:pool_size,
|
17
|
+
:pool_timeout,
|
16
18
|
:read_timeout,
|
17
19
|
:ssl_ciphers,
|
18
20
|
:ssl_pem_contents,
|
data/lib/vault/defaults.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "pathname"
|
2
|
+
require "base64"
|
2
3
|
|
3
4
|
module Vault
|
4
5
|
module Defaults
|
@@ -29,6 +30,9 @@ module Vault
|
|
29
30
|
# The default size of the connection pool
|
30
31
|
DEFAULT_POOL_SIZE = 16
|
31
32
|
|
33
|
+
# The default timeout in seconds for retrieving a connection from the connection pool
|
34
|
+
DEFAULT_POOL_TIMEOUT = 0.5
|
35
|
+
|
32
36
|
# The set of exceptions that are detect and retried by default
|
33
37
|
# with `with_retries`
|
34
38
|
RETRIED_EXCEPTIONS = [HTTPServerError]
|
@@ -60,6 +64,13 @@ module Vault
|
|
60
64
|
nil
|
61
65
|
end
|
62
66
|
|
67
|
+
|
68
|
+
# Vault Namespace, if any.
|
69
|
+
# @return [String, nil]
|
70
|
+
def namespace
|
71
|
+
ENV["VAULT_NAMESPACE"]
|
72
|
+
end
|
73
|
+
|
63
74
|
# The SNI host to use when connecting to Vault via TLS.
|
64
75
|
# @return [String, nil]
|
65
76
|
def hostname
|
@@ -77,12 +88,22 @@ module Vault
|
|
77
88
|
# @return Integer
|
78
89
|
def pool_size
|
79
90
|
if var = ENV["VAULT_POOL_SIZE"]
|
80
|
-
|
91
|
+
var.to_i
|
81
92
|
else
|
82
93
|
DEFAULT_POOL_SIZE
|
83
94
|
end
|
84
95
|
end
|
85
96
|
|
97
|
+
# The timeout for getting a connection from the connection pool that communicates with Vault
|
98
|
+
# @return Float
|
99
|
+
def pool_timeout
|
100
|
+
if var = ENV["VAULT_POOL_TIMEOUT"]
|
101
|
+
var.to_f
|
102
|
+
else
|
103
|
+
DEFAULT_POOL_TIMEOUT
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
86
107
|
# The HTTP Proxy server address as a string
|
87
108
|
# @return [String, nil]
|
88
109
|
def proxy_address
|
@@ -126,7 +147,11 @@ module Vault
|
|
126
147
|
# the value for {#ssl_pem_file}, if set.
|
127
148
|
# @return [String, nil]
|
128
149
|
def ssl_pem_contents
|
129
|
-
ENV["
|
150
|
+
if ENV["VAULT_SSL_PEM_CONTENTS_BASE64"]
|
151
|
+
Base64.decode64(ENV["VAULT_SSL_PEM_CONTENTS_BASE64"])
|
152
|
+
else
|
153
|
+
ENV["VAULT_SSL_PEM_CONTENTS"]
|
154
|
+
end
|
130
155
|
end
|
131
156
|
|
132
157
|
# The path to a pem on disk to use with custom SSL verification
|
data/lib/vault/persistent.rb
CHANGED
@@ -202,11 +202,6 @@ class PersistentHTTP
|
|
202
202
|
|
203
203
|
HAVE_OPENSSL = defined? OpenSSL::SSL # :nodoc:
|
204
204
|
|
205
|
-
##
|
206
|
-
# The default connection pool size is 1/4 the allowed open files.
|
207
|
-
|
208
|
-
DEFAULT_POOL_SIZE = 16
|
209
|
-
|
210
205
|
##
|
211
206
|
# The version of PersistentHTTP you are using
|
212
207
|
|
@@ -505,7 +500,7 @@ class PersistentHTTP
|
|
505
500
|
# Defaults to 1/4 the number of allowed file handles. You can have no more
|
506
501
|
# than this many threads with active HTTP transactions.
|
507
502
|
|
508
|
-
def initialize name=nil, proxy=nil, pool_size=DEFAULT_POOL_SIZE
|
503
|
+
def initialize name=nil, proxy=nil, pool_size=Vault::Defaults::DEFAULT_POOL_SIZE, pool_timeout=Vault::Defaults::DEFAULT_POOL_TIMEOUT
|
509
504
|
@name = name
|
510
505
|
|
511
506
|
@debug_output = nil
|
@@ -525,7 +520,7 @@ class PersistentHTTP
|
|
525
520
|
@socket_options << [Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1] if
|
526
521
|
Socket.const_defined? :TCP_NODELAY
|
527
522
|
|
528
|
-
@pool = PersistentHTTP::Pool.new size: pool_size do |http_args|
|
523
|
+
@pool = PersistentHTTP::Pool.new size: pool_size, timeout: pool_timeout do |http_args|
|
529
524
|
PersistentHTTP::Connection.new Net::HTTP, http_args, @ssl_generation
|
530
525
|
end
|
531
526
|
|
@@ -31,7 +31,7 @@ class PersistentHTTP::Pool < Vault::ConnectionPool # :nodoc:
|
|
31
31
|
stack = stacks[net_http_args]
|
32
32
|
|
33
33
|
if stack.empty? then
|
34
|
-
conn = @available.pop connection_args: net_http_args
|
34
|
+
conn = @available.pop @timeout, connection_args: net_http_args
|
35
35
|
else
|
36
36
|
conn = stack.last
|
37
37
|
end
|
data/lib/vault/request.rb
CHANGED
data/lib/vault/version.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vault
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.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:
|
11
|
+
date: 2021-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: aws-sigv4
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
|
-
type: :
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: pry
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - "
|
45
|
+
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
47
|
+
version: 0.13.1
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - "
|
52
|
+
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
54
|
+
version: 0.13.1
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,30 +84,30 @@ dependencies:
|
|
70
84
|
name: yard
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- - "
|
87
|
+
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
89
|
+
version: 0.9.24
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- - "
|
94
|
+
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
96
|
+
version: 0.9.24
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: webmock
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
103
|
+
version: 3.8.3
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
110
|
+
version: 3.8.3
|
97
111
|
description: Vault is a Ruby API client for interacting with a Vault server.
|
98
112
|
email:
|
99
113
|
- sethvargo@gmail.com
|
@@ -101,14 +115,9 @@ executables: []
|
|
101
115
|
extensions: []
|
102
116
|
extra_rdoc_files: []
|
103
117
|
files:
|
104
|
-
- ".gitignore"
|
105
|
-
- ".rspec"
|
106
|
-
- ".travis.yml"
|
107
118
|
- CHANGELOG.md
|
108
|
-
- Gemfile
|
109
119
|
- LICENSE
|
110
120
|
- README.md
|
111
|
-
- Rakefile
|
112
121
|
- lib/vault.rb
|
113
122
|
- lib/vault/api.rb
|
114
123
|
- lib/vault/api/approle.rb
|
@@ -116,17 +125,26 @@ files:
|
|
116
125
|
- lib/vault/api/auth_tls.rb
|
117
126
|
- lib/vault/api/auth_token.rb
|
118
127
|
- lib/vault/api/help.rb
|
128
|
+
- lib/vault/api/kv.rb
|
119
129
|
- lib/vault/api/logical.rb
|
120
130
|
- lib/vault/api/secret.rb
|
121
131
|
- lib/vault/api/sys.rb
|
122
132
|
- lib/vault/api/sys/audit.rb
|
123
133
|
- lib/vault/api/sys/auth.rb
|
134
|
+
- lib/vault/api/sys/health.rb
|
124
135
|
- lib/vault/api/sys/init.rb
|
125
136
|
- lib/vault/api/sys/leader.rb
|
126
137
|
- lib/vault/api/sys/lease.rb
|
127
138
|
- lib/vault/api/sys/mount.rb
|
139
|
+
- lib/vault/api/sys/namespace.rb
|
128
140
|
- lib/vault/api/sys/policy.rb
|
141
|
+
- lib/vault/api/sys/quota.rb
|
129
142
|
- lib/vault/api/sys/seal.rb
|
143
|
+
- lib/vault/api/transform.rb
|
144
|
+
- lib/vault/api/transform/alphabet.rb
|
145
|
+
- lib/vault/api/transform/role.rb
|
146
|
+
- lib/vault/api/transform/template.rb
|
147
|
+
- lib/vault/api/transform/transformation.rb
|
130
148
|
- lib/vault/client.rb
|
131
149
|
- lib/vault/configurable.rb
|
132
150
|
- lib/vault/defaults.rb
|
@@ -142,10 +160,9 @@ files:
|
|
142
160
|
- lib/vault/vendor/connection_pool/timed_stack.rb
|
143
161
|
- lib/vault/vendor/connection_pool/version.rb
|
144
162
|
- lib/vault/version.rb
|
145
|
-
- vault.gemspec
|
146
163
|
homepage: https://github.com/hashicorp/vault-ruby
|
147
164
|
licenses:
|
148
|
-
-
|
165
|
+
- MPL-2.0
|
149
166
|
metadata: {}
|
150
167
|
post_install_message:
|
151
168
|
rdoc_options: []
|
@@ -155,15 +172,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
172
|
requirements:
|
156
173
|
- - ">="
|
157
174
|
- !ruby/object:Gem::Version
|
158
|
-
version: '0'
|
175
|
+
version: '2.0'
|
159
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
177
|
requirements:
|
161
178
|
- - ">="
|
162
179
|
- !ruby/object:Gem::Version
|
163
180
|
version: '0'
|
164
181
|
requirements: []
|
165
|
-
|
166
|
-
rubygems_version: 2.5.1
|
182
|
+
rubygems_version: 3.2.3
|
167
183
|
signing_key:
|
168
184
|
specification_version: 4
|
169
185
|
summary: Vault is a Ruby API client for interacting with a Vault server.
|