rubyconfig-vault 1.0.3 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/config/vault/vault_error.rb +7 -0
- data/lib/config/vault/vault_source.rb +37 -8
- data/lib/config/vault/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8983ba9504c855d75c19d322a3d3c501749f8f076a9e10c9ebc00b31b3d3167
|
4
|
+
data.tar.gz: 9dc89fac7bcabde9c1327ee1dc1f17f6f14ee1cf145acce4449b4a256c6594b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75ff199594c448bd6976efee7dda5a71d2d75806f98d3b9156bf01c28b7598f30a797141f7cb58ddf791a2abedcd0dc38b748361fb00b07e4eaf919d1e2d7dd8
|
7
|
+
data.tar.gz: c4e4bdc78601d67d8f853ac31ddfd4eabc5739a66e1df8380ad68dc47895fc3802035143dffba9544ac688bcb28c95da43e4e318e51fd8c4d79b258615b60b12
|
@@ -1,4 +1,6 @@
|
|
1
|
+
require 'config'
|
1
2
|
require 'vault'
|
3
|
+
require_relative 'vault_error'
|
2
4
|
|
3
5
|
module Config
|
4
6
|
module Sources
|
@@ -27,7 +29,7 @@ module Config
|
|
27
29
|
@root = client_opts.delete(:root)
|
28
30
|
@flatten = client_opts.delete(:flatten)
|
29
31
|
@paths << client_opts.delete(:paths) if client_opts.key?(:paths)
|
30
|
-
|
32
|
+
map({})
|
31
33
|
@paths.map! do |p|
|
32
34
|
if p.is_a?(Array)
|
33
35
|
p
|
@@ -56,6 +58,7 @@ module Config
|
|
56
58
|
# @param hsh [Hash] mappings for keys
|
57
59
|
def map(hsh)
|
58
60
|
@map = hsh
|
61
|
+
@map.transform_keys! { |k| k.to_sym }
|
59
62
|
end
|
60
63
|
|
61
64
|
# Remove added paths
|
@@ -67,10 +70,10 @@ module Config
|
|
67
70
|
#
|
68
71
|
# @return [Hash]
|
69
72
|
def load
|
70
|
-
Vault.with_retries(
|
71
|
-
|
72
|
-
|
73
|
-
|
73
|
+
::Vault.with_retries(RecoverableVaultError,
|
74
|
+
attempts: @attempts,
|
75
|
+
base: @base,
|
76
|
+
max_wait: @max_wait) do
|
74
77
|
process_paths
|
75
78
|
end
|
76
79
|
end
|
@@ -85,10 +88,34 @@ module Config
|
|
85
88
|
end
|
86
89
|
end
|
87
90
|
|
91
|
+
def read_at_path(query_path)
|
92
|
+
client_ops.read(query_path)&.data || {}
|
93
|
+
rescue ::Vault::HTTPClientError => e
|
94
|
+
if e.code.to_i == 403
|
95
|
+
raise VaultError, "Attempting to read at path #{query_path}\n#{e.response}", caller
|
96
|
+
else
|
97
|
+
raise RecoverableVaultError, e.response, caller
|
98
|
+
end
|
99
|
+
rescue ::Vault::HTTPError => e
|
100
|
+
raise RecoverableVaultError, e.response, caller
|
101
|
+
end
|
102
|
+
|
103
|
+
def list_at_path(query_path)
|
104
|
+
client_ops.list(query_path)
|
105
|
+
rescue ::Vault::HTTPClientError => e
|
106
|
+
if e.code == 403
|
107
|
+
raise VaultError, "Attempting to list at path #{query_path}\n#{e.response}", caller
|
108
|
+
else
|
109
|
+
raise RecoverableVaultError, e.response, caller
|
110
|
+
end
|
111
|
+
rescue ::Vault::HTTPError => e
|
112
|
+
raise RecoverableVaultError, e.response, caller
|
113
|
+
end
|
114
|
+
|
88
115
|
def process_paths
|
89
116
|
root = {}
|
90
117
|
parsed_paths = @paths.map { |p| process_path(p) }
|
91
|
-
parsed_paths.each { |p| root.
|
118
|
+
parsed_paths.each { |p| root.deep_merge!(p) }
|
92
119
|
|
93
120
|
root
|
94
121
|
end
|
@@ -103,7 +130,7 @@ module Config
|
|
103
130
|
query_path, idx, parent = stack.pop
|
104
131
|
sp = subpaths[idx]
|
105
132
|
if sp.nil? || sp.eql?('*')
|
106
|
-
data =
|
133
|
+
data = read_at_path(query_path)
|
107
134
|
node = root if @flatten
|
108
135
|
node = parent unless @flatten
|
109
136
|
node.merge!(data)
|
@@ -112,7 +139,7 @@ module Config
|
|
112
139
|
end
|
113
140
|
|
114
141
|
if sp.eql?('**') || sp.eql?('*')
|
115
|
-
subtrees =
|
142
|
+
subtrees = list_at_path(query_path)
|
116
143
|
subtrees.each do |st|
|
117
144
|
new_parent = {}
|
118
145
|
new_key = st.split('/').last.downcase.to_sym
|
@@ -130,6 +157,8 @@ module Config
|
|
130
157
|
end
|
131
158
|
|
132
159
|
if path.last
|
160
|
+
{ path.last => root }
|
161
|
+
elsif @root
|
133
162
|
{ @root => root }
|
134
163
|
else
|
135
164
|
root
|
data/lib/config/vault/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyconfig-vault
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Young
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: vault
|
@@ -88,6 +88,7 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- lib/config/vault.rb
|
91
|
+
- lib/config/vault/vault_error.rb
|
91
92
|
- lib/config/vault/vault_source.rb
|
92
93
|
- lib/config/vault/version.rb
|
93
94
|
homepage: https://github.com/CrunchwrapSupreme/rubyconfig-vault
|