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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a737c714f6c9e6cdff7bc6ea5ad1cdb864929ea00552b49c0a711bf7985571e
4
- data.tar.gz: 54d1b1055a1272b021c3b9411fefd41c2c6ee2e6ec2469fec1382e7becbd4502
3
+ metadata.gz: c8983ba9504c855d75c19d322a3d3c501749f8f076a9e10c9ebc00b31b3d3167
4
+ data.tar.gz: 9dc89fac7bcabde9c1327ee1dc1f17f6f14ee1cf145acce4449b4a256c6594b1
5
5
  SHA512:
6
- metadata.gz: d6810e8ed8954833fd7de46c76f1ff0102ab8240d7c25b9eed16eee421bd73703c1ae2b6ac75b1a5b36b25c5857e763ef7c73c8641a6aa305702b9716f3ba1ca
7
- data.tar.gz: f4b0a4031bff1d623978064ddef59656b60ae9cf7071ee0a2e31665d7397b4c15ed63462a9a356b5ee7e82b2b671d2daf6a94b2969f24fb3c7e402f85e005cd6
6
+ metadata.gz: 75ff199594c448bd6976efee7dda5a71d2d75806f98d3b9156bf01c28b7598f30a797141f7cb58ddf791a2abedcd0dc38b748361fb00b07e4eaf919d1e2d7dd8
7
+ data.tar.gz: c4e4bdc78601d67d8f853ac31ddfd4eabc5739a66e1df8380ad68dc47895fc3802035143dffba9544ac688bcb28c95da43e4e318e51fd8c4d79b258615b60b12
@@ -0,0 +1,7 @@
1
+ module Config
2
+ module Sources
3
+ class RecoverableVaultError < Exception; end
4
+
5
+ class VaultError < Exception; end
6
+ end
7
+ end
@@ -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
- @map = {}
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(Vault::HTTPError,
71
- attempts: @attempts,
72
- base: @base,
73
- max_wait: @max_wait) do
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.merge!(p) }
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 = client_ops.read(query_path)&.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 = client_ops.list(query_path)
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
@@ -1,5 +1,5 @@
1
1
  module Config
2
2
  module Vault
3
- VERSION = "1.0.3"
3
+ VERSION = "1.0.6"
4
4
  end
5
5
  end
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.3
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-19 00:00:00.000000000 Z
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