vault 0.18.2 → 0.19.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 476b00af55107f31b54a20b77e1f451aef3d463908a457d7026fe669d0948547
4
- data.tar.gz: 0072055306b85967a9a49abc230f2b1d5ed67521378825bfa2d7c849948cbc29
3
+ metadata.gz: f8cca2d8b21c19833848eb69819c8157663bcb8cde2320764640ab8c096bbdc9
4
+ data.tar.gz: 7d9789a8d34fd04b041e564c19a8a37b38c411941d3052b094a6e8316c6d3843
5
5
  SHA512:
6
- metadata.gz: 7d0619e6569b4f7ca9543f04545be9aa2bd0fe89c531eac135458b80b51d0d55a2667eae79290a7aecb389a4893d9fb6841505faffe623e056ff50889633490e
7
- data.tar.gz: ef620f96b924e63b51deab4021c97d3f1f548722028b41a55a8c9b3f5beca930369b2a7c6f7f3c5b561f4dfc98fd6c4b5e3ed66660bdc053aa8b2c4af316a439
6
+ metadata.gz: 8e75e89576231aa7fb88b1ed0aef7772578afcb0ee68ef8b4f7e558950602be4ca1c6f88f699e7623e3931679f84256e312c7c6d27f04785dac3cdae077c70ff
7
+ data.tar.gz: cd00de0b622d9b4f792cdae6f2b7660470fa3a925447fe1a3979f2ca35b7255fa8dabfc6d723b723f8aea074e18ebb68f8ae37f41850539845873a17570d21bb
data/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  ## v?.??.? (Unreleased)
4
4
 
5
+ ## v0.19.0 (December 3, 2025)
6
+
7
+ BREAKING CHANGES
8
+
9
+ - Set minimum Ruby version to 3.1. All EOL Ruby versions are no longer supported. [GH-352]
10
+
11
+ IMPROVEMENTS
12
+
13
+ - Upgraded vendored `net-http-persistent` from 3.0.0 to upstream gem 4.0.2+, which includes:
14
+ - Fixes compatibility with `connection-pool` 2.4
15
+ - Supports TLS min/max and IPv6
16
+ - Fixes a memory leak in connection pooling
17
+ - Many bugfixes [GH-345]
18
+ - Upgraded vendored `connection-pool` from 2.2.0 to upstream gem 2.4+, which includes:
19
+ - Fixes argument forwarding for Ruby 2.7+
20
+ - Automatically drops all connections after fork [GH-345]
21
+ - Added dependency on `base64` gem for Ruby 3.4 compatibility [GH-352]
22
+ - Added Ruby 3.3 and 3.4 to CI matrix [GH-352]
23
+ - Added modern Vault versions (1.16, 1.19, 1.20, 1.21) to CI matrix [GH-352]
24
+ - Replaced deprecated `JSON.fast_generate` with `JSON.generate` [GH-349]
25
+
26
+ BUG FIXES
27
+
28
+ - Fixed HTTP client shutdown to be lock-protected, ensuring thread-safe access to `@nhp` [GH-329]
29
+
5
30
  ## v0.18.1 (September 14, 2023)
6
31
 
7
32
  BUG FIXES
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Vault Ruby Client [![Build Status](https://circleci.com/gh/hashicorp/vault-ruby.svg?style=shield)](https://circleci.com/gh/hashicorp/vault-ruby)
1
+ Vault Ruby Client [![Build Status](https://github.com/hashicorp/vault-ruby/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/hashicorp/vault-ruby/actions/workflows/run-tests.yml)
2
2
  =================
3
3
 
4
4
  Vault is the official Ruby client for interacting with [Vault](https://vaultproject.io) by HashiCorp.
@@ -9,9 +9,9 @@ Vault Ruby client for the proper documentation.**
9
9
 
10
10
  Quick Start
11
11
  -----------
12
- Install Ruby 2.0+: [Guide](https://www.ruby-lang.org/en/documentation/installation/).
12
+ Install Ruby 3.1+: [Guide](https://www.ruby-lang.org/en/documentation/installation/).
13
13
 
14
- > Please note that as of Vault Ruby version 0.14.0 versions of Ruby prior to 2.0 are no longer supported.
14
+ > Please note that as of Vault Ruby version 0.19.0, the minimum required Ruby version is 3.1. All EOL Ruby versions are no longer supported.
15
15
 
16
16
  Install via Rubygems:
17
17
 
@@ -61,7 +61,7 @@ module Vault
61
61
  # @return [true]
62
62
  def set_role(name, options = {})
63
63
  headers = extract_headers!(options)
64
- client.post("/v1/auth/approle/role/#{encode_path(name)}", JSON.fast_generate(options), headers)
64
+ client.post("/v1/auth/approle/role/#{encode_path(name)}", JSON.generate(options), headers)
65
65
  return true
66
66
  end
67
67
 
@@ -118,7 +118,7 @@ module Vault
118
118
  # @return [true]
119
119
  def set_role_id(name, role_id)
120
120
  options = { role_id: role_id }
121
- client.post("/v1/auth/approle/role/#{encode_path(name)}/role-id", JSON.fast_generate(options))
121
+ client.post("/v1/auth/approle/role/#{encode_path(name)}/role-id", JSON.generate(options))
122
122
  return true
123
123
  end
124
124
 
@@ -163,9 +163,9 @@ module Vault
163
163
  def create_secret_id(role_name, options = {})
164
164
  headers = extract_headers!(options)
165
165
  if options[:secret_id]
166
- json = client.post("/v1/auth/approle/role/#{encode_path(role_name)}/custom-secret-id", JSON.fast_generate(options), headers)
166
+ json = client.post("/v1/auth/approle/role/#{encode_path(role_name)}/custom-secret-id", JSON.generate(options), headers)
167
167
  else
168
- json = client.post("/v1/auth/approle/role/#{encode_path(role_name)}/secret-id", JSON.fast_generate(options), headers)
168
+ json = client.post("/v1/auth/approle/role/#{encode_path(role_name)}/secret-id", JSON.generate(options), headers)
169
169
  end
170
170
  return Secret.decode(json)
171
171
  end
@@ -184,7 +184,7 @@ module Vault
184
184
  # @return [Secret, nil]
185
185
  def secret_id(role_name, secret_id)
186
186
  opts = { secret_id: secret_id }
187
- json = client.post("/v1/auth/approle/role/#{encode_path(role_name)}/secret-id/lookup", JSON.fast_generate(opts), {})
187
+ json = client.post("/v1/auth/approle/role/#{encode_path(role_name)}/secret-id/lookup", JSON.generate(opts), {})
188
188
  return nil unless json
189
189
  return Secret.decode(json)
190
190
  rescue HTTPError => e
@@ -71,7 +71,7 @@ module Vault
71
71
  # @return [Secret]
72
72
  def app_id(app_id, user_id, options = {})
73
73
  payload = { app_id: app_id, user_id: user_id }.merge(options)
74
- json = client.post("/v1/auth/app-id/login", JSON.fast_generate(payload))
74
+ json = client.post("/v1/auth/app-id/login", JSON.generate(payload))
75
75
  secret = Secret.decode(json)
76
76
  client.token = secret.auth.client_token
77
77
  return secret
@@ -95,7 +95,7 @@ module Vault
95
95
  def approle(role_id, secret_id=nil)
96
96
  payload = { role_id: role_id }
97
97
  payload[:secret_id] = secret_id if secret_id
98
- json = client.post("/v1/auth/approle/login", JSON.fast_generate(payload))
98
+ json = client.post("/v1/auth/approle/login", JSON.generate(payload))
99
99
  secret = Secret.decode(json)
100
100
  client.token = secret.auth.client_token
101
101
  return secret
@@ -120,7 +120,7 @@ module Vault
120
120
  # @return [Secret]
121
121
  def userpass(username, password, options = {})
122
122
  payload = { password: password }.merge(options)
123
- json = client.post("/v1/auth/userpass/login/#{encode_path(username)}", JSON.fast_generate(payload))
123
+ json = client.post("/v1/auth/userpass/login/#{encode_path(username)}", JSON.generate(payload))
124
124
  secret = Secret.decode(json)
125
125
  client.token = secret.auth.client_token
126
126
  return secret
@@ -142,7 +142,7 @@ module Vault
142
142
  # @return [Secret]
143
143
  def ldap(username, password, options = {})
144
144
  payload = { password: password }.merge(options)
145
- json = client.post("/v1/auth/ldap/login/#{encode_path(username)}", JSON.fast_generate(payload))
145
+ json = client.post("/v1/auth/ldap/login/#{encode_path(username)}", JSON.generate(payload))
146
146
  secret = Secret.decode(json)
147
147
  client.token = secret.auth.client_token
148
148
  return secret
@@ -160,7 +160,7 @@ module Vault
160
160
  # @return [Secret]
161
161
  def github(github_token, path="/v1/auth/github/login")
162
162
  payload = {token: github_token}
163
- json = client.post(path, JSON.fast_generate(payload))
163
+ json = client.post(path, JSON.generate(payload))
164
164
  secret = Secret.decode(json)
165
165
  client.token = secret.auth.client_token
166
166
  return secret
@@ -185,7 +185,7 @@ module Vault
185
185
  payload = { role: role, pkcs7: pkcs7 }
186
186
  # Set a custom nonce if client is providing one
187
187
  payload[:nonce] = nonce if nonce
188
- json = client.post(route, JSON.fast_generate(payload))
188
+ json = client.post(route, JSON.generate(payload))
189
189
  secret = Secret.decode(json)
190
190
  client.token = secret.auth.client_token
191
191
  return secret
@@ -242,7 +242,7 @@ module Vault
242
242
  iam_request_body: Base64.strict_encode64(request_body)
243
243
  }
244
244
 
245
- json = client.post(route, JSON.fast_generate(payload))
245
+ json = client.post(route, JSON.generate(payload))
246
246
  secret = Secret.decode(json)
247
247
  client.token = secret.auth.client_token
248
248
  return secret
@@ -264,7 +264,7 @@ module Vault
264
264
  # @return [Secret]
265
265
  def gcp(role, jwt, path = 'gcp')
266
266
  payload = { role: role, jwt: jwt }
267
- json = client.post("/v1/auth/#{CGI.escape(path)}/login", JSON.fast_generate(payload))
267
+ json = client.post("/v1/auth/#{CGI.escape(path)}/login", JSON.generate(payload))
268
268
  secret = Secret.decode(json)
269
269
  client.token = secret.auth.client_token
270
270
  return secret
@@ -45,7 +45,7 @@ module Vault
45
45
  # @return [true]
46
46
  def set_certificate(name, options = {})
47
47
  headers = extract_headers!(options)
48
- client.post("/v1/auth/cert/certs/#{encode_path(name)}", JSON.fast_generate(options), headers)
48
+ client.post("/v1/auth/cert/certs/#{encode_path(name)}", JSON.generate(options), headers)
49
49
  return true
50
50
  end
51
51
 
@@ -69,7 +69,7 @@ module Vault
69
69
  # @return [Secret]
70
70
  def create(options = {})
71
71
  headers = extract_headers!(options)
72
- json = client.post("/v1/auth/token/create", JSON.fast_generate(options), headers)
72
+ json = client.post("/v1/auth/token/create", JSON.generate(options), headers)
73
73
  return Secret.decode(json)
74
74
  end
75
75
 
@@ -84,7 +84,7 @@ module Vault
84
84
  # @return [Secret]
85
85
  def create_orphan(options = {})
86
86
  headers = extract_headers!(options)
87
- json = client.post("/v1/auth/token/create-orphan", JSON.fast_generate(options), headers)
87
+ json = client.post("/v1/auth/token/create-orphan", JSON.generate(options), headers)
88
88
  return Secret.decode(json)
89
89
  end
90
90
 
@@ -98,7 +98,7 @@ module Vault
98
98
  # @return [Secret]
99
99
  def create_with_role(name, options = {})
100
100
  headers = extract_headers!(options)
101
- json = client.post("/v1/auth/token/create/#{encode_path(name)}", JSON.fast_generate(options), headers)
101
+ json = client.post("/v1/auth/token/create/#{encode_path(name)}", JSON.generate(options), headers)
102
102
  return Secret.decode(json)
103
103
  end
104
104
 
@@ -113,7 +113,7 @@ module Vault
113
113
  # @return [Secret]
114
114
  def lookup(token, options = {})
115
115
  headers = extract_headers!(options)
116
- json = client.post("/v1/auth/token/lookup", JSON.fast_generate(
116
+ json = client.post("/v1/auth/token/lookup", JSON.generate(
117
117
  token: token,
118
118
  ), headers)
119
119
  return Secret.decode(json)
@@ -128,7 +128,7 @@ module Vault
128
128
  # @param [Hash] options
129
129
  def lookup_accessor(accessor, options = {})
130
130
  headers = extract_headers!(options)
131
- json = client.post("/v1/auth/token/lookup-accessor", JSON.fast_generate(
131
+ json = client.post("/v1/auth/token/lookup-accessor", JSON.generate(
132
132
  accessor: accessor,
133
133
  ), headers)
134
134
  return Secret.decode(json)
@@ -157,7 +157,7 @@ module Vault
157
157
  # @return [Secret]
158
158
  def renew(token, increment = 0, options = {})
159
159
  headers = extract_headers!(options)
160
- json = client.put("/v1/auth/token/renew", JSON.fast_generate(
160
+ json = client.put("/v1/auth/token/renew", JSON.generate(
161
161
  token: token,
162
162
  increment: increment,
163
163
  ), headers)
@@ -174,7 +174,7 @@ module Vault
174
174
  # @return [Secret]
175
175
  def renew_self(increment = 0, options = {})
176
176
  headers = extract_headers!(options)
177
- json = client.put("/v1/auth/token/renew-self", JSON.fast_generate(
177
+ json = client.put("/v1/auth/token/renew-self", JSON.generate(
178
178
  increment: increment,
179
179
  ), headers)
180
180
  return Secret.decode(json)
@@ -201,7 +201,7 @@ module Vault
201
201
  # @return [true]
202
202
  def revoke_orphan(token, options = {})
203
203
  headers = extract_headers!(options)
204
- client.put("/v1/auth/token/revoke-orphan", JSON.fast_generate(
204
+ client.put("/v1/auth/token/revoke-orphan", JSON.generate(
205
205
  token: token,
206
206
  ), headers)
207
207
  return true
@@ -218,7 +218,7 @@ module Vault
218
218
  # @return [true]
219
219
  def revoke_accessor(accessor, options = {})
220
220
  headers = extract_headers!(options)
221
- client.put("/v1/auth/token/revoke-accessor", JSON.fast_generate(
221
+ client.put("/v1/auth/token/revoke-accessor", JSON.generate(
222
222
  accessor: accessor,
223
223
  ), headers)
224
224
  return true
@@ -235,7 +235,7 @@ module Vault
235
235
  # @return [true]
236
236
  def revoke(token, options = {})
237
237
  headers = extract_headers!(options)
238
- client.put("/v1/auth/token/revoke", JSON.fast_generate(
238
+ client.put("/v1/auth/token/revoke", JSON.generate(
239
239
  token: token,
240
240
  ), headers)
241
241
  return true
data/lib/vault/api/kv.rb CHANGED
@@ -99,7 +99,7 @@ module Vault
99
99
  # @return [Secret]
100
100
  def write(path, data = {}, options = {})
101
101
  headers = extract_headers!(options)
102
- json = client.post("/v1/#{mount}/data/#{encode_path(path)}", JSON.fast_generate(:data => data), headers)
102
+ json = client.post("/v1/#{mount}/data/#{encode_path(path)}", JSON.generate(:data => data), headers)
103
103
  if json.nil?
104
104
  return true
105
105
  else
@@ -120,7 +120,27 @@ module Vault
120
120
  #
121
121
  # @return [true]
122
122
  def write_metadata(path, metadata = {})
123
- client.post("/v1/#{mount}/metadata/#{encode_path(path)}", JSON.fast_generate(metadata))
123
+ client.post("/v1/#{mount}/metadata/#{encode_path(path)}", JSON.generate(metadata))
124
+
125
+ true
126
+ end
127
+
128
+ # Patch the metadata of a secret at the given path. Note that the data must
129
+ # be a {Hash}.
130
+ #
131
+ # @example
132
+ # Vault.kv("secret").patch_metadata("password", custom_metadata: { my_custom_key: "my_value" }, max_versions: 3)
133
+ #
134
+ # @param [String] path
135
+ # the path to patch
136
+ # @param [Hash] metadata
137
+ # the metadata to patch
138
+ #
139
+ # @return [true]
140
+ def patch_metadata(path, metadata = {}, options = {})
141
+ headers = extract_headers!(options)
142
+ headers["Content-Type"] = "application/merge-patch+json"
143
+ client.patch("/v1/#{mount}/metadata/#{encode_path(path)}", JSON.generate(metadata), headers)
124
144
 
125
145
  true
126
146
  end
@@ -153,7 +173,7 @@ module Vault
153
173
  #
154
174
  # @return [true]
155
175
  def delete_versions(path, versions)
156
- client.post("/v1/#{mount}/delete/#{encode_path(path)}", JSON.fast_generate(versions: versions))
176
+ client.post("/v1/#{mount}/delete/#{encode_path(path)}", JSON.generate(versions: versions))
157
177
 
158
178
  true
159
179
  end
@@ -170,7 +190,7 @@ module Vault
170
190
  #
171
191
  # @return [true]
172
192
  def undelete_versions(path, versions)
173
- client.post("/v1/#{mount}/undelete/#{encode_path(path)}", JSON.fast_generate(versions: versions))
193
+ client.post("/v1/#{mount}/undelete/#{encode_path(path)}", JSON.generate(versions: versions))
174
194
 
175
195
  true
176
196
  end
@@ -202,7 +222,7 @@ module Vault
202
222
  #
203
223
  # @return [true]
204
224
  def destroy_versions(path, versions)
205
- client.post("/v1/#{mount}/destroy/#{encode_path(path)}", JSON.fast_generate(versions: versions))
225
+ client.post("/v1/#{mount}/destroy/#{encode_path(path)}", JSON.generate(versions: versions))
206
226
 
207
227
  true
208
228
  end
@@ -68,7 +68,7 @@ module Vault
68
68
  # @return [Secret]
69
69
  def write(path, data = {}, options = {})
70
70
  headers = extract_headers!(options)
71
- json = client.put("/v1/#{encode_path(path)}", JSON.fast_generate(data), headers)
71
+ json = client.put("/v1/#{encode_path(path)}", JSON.generate(data), headers)
72
72
  if json.nil?
73
73
  return true
74
74
  else
@@ -54,7 +54,7 @@ module Vault
54
54
  #
55
55
  # @return [true]
56
56
  def enable_audit(path, type, description, options = {})
57
- client.put("/v1/sys/audit/#{encode_path(path)}", JSON.fast_generate(
57
+ client.put("/v1/sys/audit/#{encode_path(path)}", JSON.generate(
58
58
  type: type,
59
59
  description: description,
60
60
  options: options,
@@ -86,7 +86,7 @@ module Vault
86
86
  #
87
87
  # @return [String]
88
88
  def audit_hash(path, input)
89
- json = client.post("/v1/sys/audit-hash/#{encode_path(path)}", JSON.fast_generate(input: input))
89
+ json = client.post("/v1/sys/audit-hash/#{encode_path(path)}", JSON.generate(input: input))
90
90
  json = json[:data] if json[:data]
91
91
  json[:hash]
92
92
  end
@@ -60,7 +60,7 @@ module Vault
60
60
  payload = { type: type }
61
61
  payload[:description] = description if !description.nil?
62
62
 
63
- client.post("/v1/sys/auth/#{encode_path(path)}", JSON.fast_generate(payload))
63
+ client.post("/v1/sys/auth/#{encode_path(path)}", JSON.generate(payload))
64
64
  return true
65
65
  end
66
66
 
@@ -108,7 +108,7 @@ module Vault
108
108
  # @return [AuthConfig]
109
109
  # configuration of the given auth path
110
110
  def put_auth_tune(path, config = {})
111
- json = client.put("/v1/sys/auth/#{encode_path(path)}/tune", JSON.fast_generate(config))
111
+ json = client.put("/v1/sys/auth/#{encode_path(path)}/tune", JSON.generate(config))
112
112
  if json.nil?
113
113
  return true
114
114
  else
@@ -70,7 +70,7 @@ module Vault
70
70
  #
71
71
  # @return [InitResponse]
72
72
  def init(options = {})
73
- json = client.put("/v1/sys/init", JSON.fast_generate(
73
+ json = client.put("/v1/sys/init", JSON.generate(
74
74
  root_token_pgp_key: options.fetch(:root_token_pgp_key, nil),
75
75
  secret_shares: options.fetch(:secret_shares, options.fetch(:shares, 5)),
76
76
  secret_threshold: options.fetch(:secret_threshold, options.fetch(:threshold, 3)),
@@ -14,7 +14,7 @@ module Vault
14
14
  #
15
15
  # @return [Secret]
16
16
  def renew(id, increment = 0)
17
- json = client.put("/v1/sys/renew/#{id}", JSON.fast_generate(
17
+ json = client.put("/v1/sys/renew/#{id}", JSON.generate(
18
18
  increment: increment,
19
19
  ))
20
20
  return Secret.decode(json)
@@ -98,7 +98,7 @@ module Vault
98
98
  payload = options.merge type: type
99
99
  payload[:description] = description if !description.nil?
100
100
 
101
- client.post("/v1/sys/mounts/#{encode_path(path)}", JSON.fast_generate(payload))
101
+ client.post("/v1/sys/mounts/#{encode_path(path)}", JSON.generate(payload))
102
102
  return true
103
103
  end
104
104
 
@@ -124,7 +124,7 @@ module Vault
124
124
  # @param [Hash] data
125
125
  # the data to write
126
126
  def mount_tune(path, data = {})
127
- json = client.post("/v1/sys/mounts/#{encode_path(path)}/tune", JSON.fast_generate(data))
127
+ json = client.post("/v1/sys/mounts/#{encode_path(path)}/tune", JSON.generate(data))
128
128
  return true
129
129
  end
130
130
 
@@ -155,7 +155,7 @@ module Vault
155
155
  #
156
156
  # @return [true]
157
157
  def remount(from, to)
158
- client.post("/v1/sys/remount", JSON.fast_generate(
158
+ client.post("/v1/sys/remount", JSON.generate(
159
159
  from: from,
160
160
  to: to,
161
161
  ))
@@ -73,7 +73,7 @@ module Vault
73
73
  #
74
74
  # @return [true]
75
75
  def put_policy(name, rules)
76
- client.put("/v1/sys/policy/#{encode_path(name)}", JSON.fast_generate(
76
+ client.put("/v1/sys/policy/#{encode_path(name)}", JSON.generate(
77
77
  rules: rules,
78
78
  ))
79
79
  return true
@@ -60,7 +60,7 @@ module Vault
60
60
 
61
61
  def create_quota(type, name, opts={})
62
62
  path = generate_path(type, name)
63
- client.post(path, JSON.fast_generate(opts))
63
+ client.post(path, JSON.generate(opts))
64
64
  return true
65
65
  end
66
66
 
@@ -83,7 +83,7 @@ module Vault
83
83
  end
84
84
 
85
85
  def update_quota_config(opts={})
86
- client.post("v1/sys/quotas/config", JSON.fast_generate(opts))
86
+ client.post("v1/sys/quotas/config", JSON.generate(opts))
87
87
  return true
88
88
  end
89
89
 
@@ -75,7 +75,7 @@ module Vault
75
75
  #
76
76
  # @return [SealStatus]
77
77
  def unseal(shard)
78
- json = client.put("/v1/sys/unseal", JSON.fast_generate(
78
+ json = client.put("/v1/sys/unseal", JSON.generate(
79
79
  key: shard,
80
80
  ))
81
81
  return SealStatus.decode(json)
@@ -16,7 +16,7 @@ module Vault
16
16
  def create_alphabet(name, alphabet:, **opts)
17
17
  opts ||= {}
18
18
  opts[:alphabet] = alphabet
19
- client.post("/v1/transform/alphabet/#{encode_path(name)}", JSON.fast_generate(opts))
19
+ client.post("/v1/transform/alphabet/#{encode_path(name)}", JSON.generate(opts))
20
20
  return true
21
21
  end
22
22
 
@@ -15,7 +15,7 @@ module Vault
15
15
 
16
16
  def create_role(name, **opts)
17
17
  opts ||= {}
18
- client.post("/v1/transform/role/#{encode_path(name)}", JSON.fast_generate(opts))
18
+ client.post("/v1/transform/role/#{encode_path(name)}", JSON.generate(opts))
19
19
  return true
20
20
  end
21
21
 
@@ -27,7 +27,7 @@ module Vault
27
27
  opts ||= {}
28
28
  opts[:type] = type
29
29
  opts[:pattern] = pattern
30
- client.post("/v1/transform/template/#{encode_path(name)}", JSON.fast_generate(opts))
30
+ client.post("/v1/transform/template/#{encode_path(name)}", JSON.generate(opts))
31
31
  return true
32
32
  end
33
33
 
@@ -34,7 +34,7 @@ module Vault
34
34
  opts ||= {}
35
35
  opts[:type] = type
36
36
  opts[:template] = template
37
- client.post("/v1/transform/transformation/#{encode_path(name)}", JSON.fast_generate(opts))
37
+ client.post("/v1/transform/transformation/#{encode_path(name)}", JSON.generate(opts))
38
38
  return true
39
39
  end
40
40
 
@@ -16,12 +16,12 @@ module Vault
16
16
  class Transform < Request
17
17
  def encode(role_name:, **opts)
18
18
  opts ||= {}
19
- client.post("/v1/transform/encode/#{encode_path(role_name)}", JSON.fast_generate(opts))
19
+ client.post("/v1/transform/encode/#{encode_path(role_name)}", JSON.generate(opts))
20
20
  end
21
21
 
22
22
  def decode(role_name:, **opts)
23
23
  opts ||= {}
24
- client.post("/v1/transform/decode/#{encode_path(role_name)}", JSON.fast_generate(opts))
24
+ client.post("/v1/transform/decode/#{encode_path(role_name)}", JSON.generate(opts))
25
25
  end
26
26
  end
27
27
  end
data/lib/vault/client.rb CHANGED
@@ -5,7 +5,8 @@ require "cgi"
5
5
  require "json"
6
6
  require "uri"
7
7
 
8
- require_relative "persistent"
8
+ require "net/http/persistent"
9
+
9
10
  require_relative "configurable"
10
11
  require_relative "errors"
11
12
  require_relative "version"
@@ -50,6 +51,14 @@ module Vault
50
51
  a << Errno::ECONNREFUSED
51
52
  a << Errno::EADDRNOTAVAIL
52
53
 
54
+ # Broken connection errors
55
+ a << Errno::ECONNRESET
56
+ a << Errno::ECONNABORTED
57
+ a << Errno::EPIPE
58
+ a << Errno::ETIMEDOUT
59
+ a << OpenSSL::SSL::SSLError
60
+ a << IOError
61
+
53
62
  # Failed to read body or no response body given
54
63
  a << EOFError
55
64
 
@@ -61,7 +70,7 @@ module Vault
61
70
  a << Net::ReadTimeout if defined?(Net::ReadTimeout)
62
71
  a << Net::OpenTimeout if defined?(Net::OpenTimeout)
63
72
 
64
- a << PersistentHTTP::Error
73
+ a << Net::HTTP::Persistent::Error
65
74
  end.freeze
66
75
 
67
76
  # Vault requires at least TLS1.2
@@ -92,7 +101,8 @@ module Vault
92
101
  @lock.synchronize do
93
102
  return @nhp if @nhp
94
103
 
95
- @nhp = PersistentHTTP.new("vault-ruby", nil, pool_size, pool_timeout)
104
+ @nhp = Net::HTTP::Persistent.new(name: "vault-ruby", pool_size:)
105
+ @nhp.pool.instance_variable_set(:@timeout, pool_timeout)
96
106
 
97
107
  if proxy_address
98
108
  proxy_uri = URI.parse "http://#{proxy_address}"
@@ -164,8 +174,10 @@ module Vault
164
174
 
165
175
  # Shutdown any open pool connections. Pool will be recreated upon next request.
166
176
  def shutdown
167
- @nhp.shutdown()
168
- @nhp = nil
177
+ @lock.synchronize do
178
+ @nhp.shutdown()
179
+ @nhp = nil
180
+ end
169
181
  end
170
182
 
171
183
  # Creates and yields a new client object with the given token. This may be
@@ -10,9 +10,9 @@ module Vault
10
10
  # @return [String]
11
11
  VAULT_ADDRESS = "https://127.0.0.1:8200".freeze
12
12
 
13
- # The path to the vault token on disk.
13
+ # The default path to the vault token on disk.
14
14
  # @return [String]
15
- VAULT_DISK_TOKEN = Pathname.new("#{ENV["HOME"]}/.vault-token").expand_path.freeze
15
+ DEFAULT_VAULT_DISK_TOKEN = Pathname.new("#{ENV["HOME"]}/.vault-token").expand_path.freeze
16
16
 
17
17
  # The list of SSL ciphers to allow. You should not change this value unless
18
18
  # you absolutely know what you are doing!
@@ -56,18 +56,16 @@ module Vault
56
56
  # The vault token to use for authentiation.
57
57
  # @return [String, nil]
58
58
  def token
59
- if !ENV["VAULT_TOKEN"].nil?
60
- return ENV["VAULT_TOKEN"]
61
- end
59
+ ENV["VAULT_TOKEN"] || fetch_from_disk("VAULT_TOKEN_FILE")
60
+ end
62
61
 
63
- if VAULT_DISK_TOKEN.exist? && VAULT_DISK_TOKEN.readable?
64
- return VAULT_DISK_TOKEN.read.chomp
62
+ def fetch_from_disk(env_var)
63
+ path = ENV[env_var] ? Pathname.new(ENV[env_var]) : DEFAULT_VAULT_DISK_TOKEN
64
+ if path.exist? && path.readable?
65
+ path.read.chomp
65
66
  end
66
-
67
- nil
68
67
  end
69
68
 
70
-
71
69
  # Vault Namespace, if any.
72
70
  # @return [String, nil]
73
71
  def namespace
data/lib/vault/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # SPDX-License-Identifier: MPL-2.0
3
3
 
4
4
  module Vault
5
- VERSION = "0.18.2"
5
+ VERSION = "0.19.0"
6
6
  end