rubyconfig-vault 1.0.1 → 1.0.4

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: 46de173dcd36067470c87796ac1767b87b0dfa8a45deccab555e3f4e46f27eba
4
- data.tar.gz: a46241218beef3db50686fdd504804c0996b3a773dc7d5fdf0c6cffe2250ae8e
3
+ metadata.gz: 161ede1df26b9ba941d4e64dd921b4c4f98f9c66ed443b5f83d3ebeb55bc7ae3
4
+ data.tar.gz: 54e80ec49323dbbf1540dd39ce99623ff3acf86968ca3dcf4ba9122e099ee364
5
5
  SHA512:
6
- metadata.gz: 2714a2880f99e0adfa77bbcdfb1b0bc00fe26ecc087846d47dce9d1c644f37c39ce459c1474810f4d6b9200094b197dab593f80e26023643854eb27d3b828859
7
- data.tar.gz: d31a1275c69520b68ed8d3c7bb6bb68fbd852ac50e8337899ab310114c76d4086697407067cfb13d6c391b98bb3f96fbcf40202bb7a8a322a13a4176c35962b5
6
+ metadata.gz: 617735e0edf543dfed976f9b07a090414b47f4ec218e28e7821762da19ffbf44aa447072c205d3ab79db68b619de946d4d962385cdd50f74bd5ceac5c886f4a6
7
+ data.tar.gz: c96b23a0ae4b45daaf688b39d65948bbee01909ad3866bacfd78eb91aa1c1c97a53bfd2961c17dbe31f4e6b330a8606120dbced79b403410a9ed8b5378824f46
@@ -1,10 +1,11 @@
1
+ require 'config'
1
2
  require 'vault'
2
3
 
3
4
  module Config
4
5
  module Sources
5
6
  # A vault source for Config
6
7
  class VaultSource
7
- attr_accessor :kv, :root
8
+ attr_accessor :kv, :root, :flatten
8
9
  attr_reader :paths, :client
9
10
 
10
11
  # Create a new Config source, all Vault::Client parameters supported
@@ -27,6 +28,7 @@ module Config
27
28
  @root = client_opts.delete(:root)
28
29
  @flatten = client_opts.delete(:flatten)
29
30
  @paths << client_opts.delete(:paths) if client_opts.key?(:paths)
31
+ @map = {}
30
32
  @paths.map! do |p|
31
33
  if p.is_a?(Array)
32
34
  p
@@ -34,7 +36,7 @@ module Config
34
36
  [p, @root]
35
37
  end
36
38
  end
37
- @client = Vault::Client.new(client_opts)
39
+ @client = ::Vault::Client.new(client_opts)
38
40
  end
39
41
 
40
42
  # Add a path to Config source
@@ -50,6 +52,13 @@ module Config
50
52
  @paths << [path, root]
51
53
  end
52
54
 
55
+ # Re-map individual key names
56
+ #
57
+ # @param hsh [Hash] mappings for keys
58
+ def map(hsh)
59
+ @map = hsh
60
+ end
61
+
53
62
  # Remove added paths
54
63
  def clear_paths
55
64
  @paths = []
@@ -59,10 +68,10 @@ module Config
59
68
  #
60
69
  # @return [Hash]
61
70
  def load
62
- Vault.with_retries(Vault::HTTPError,
63
- attempts: @attempts,
64
- base: @base,
65
- max_wait: @max_wait) do
71
+ ::Vault.with_retries(::Vault::HTTPError,
72
+ attempts: @attempts,
73
+ base: @base,
74
+ max_wait: @max_wait) do
66
75
  process_paths
67
76
  end
68
77
  end
@@ -95,9 +104,12 @@ module Config
95
104
  query_path, idx, parent = stack.pop
96
105
  sp = subpaths[idx]
97
106
  if sp.nil? || sp.eql?('*')
98
- data = client_ops.read(query_path)&.data
99
- parent.merge!(data || {})
100
- parent.compact!
107
+ data = client_ops.read(query_path)&.data || {}
108
+ node = root if @flatten
109
+ node = parent unless @flatten
110
+ node.merge!(data)
111
+ node.transform_keys! { |key| @map[key] || key }
112
+ node.compact!
101
113
  end
102
114
 
103
115
  if sp.eql?('**') || sp.eql?('*')
@@ -106,19 +118,18 @@ module Config
106
118
  new_parent = {}
107
119
  new_key = st.split('/').last.downcase.to_sym
108
120
  new_query_path = [query_path, st].join('/')
109
- parent[new_key] = new_parent
121
+ parent[new_key] = new_parent unless @flatten
110
122
  stack.push([new_query_path, idx + 1, new_parent])
111
123
  end
112
124
  elsif sp
113
125
  query_path = [query_path, sp].compact.join('/')
114
126
  idx += 1
115
127
  new_parent = {}
116
- parent[sp.downcase.to_sym] = new_parent
128
+ parent[sp.downcase.to_sym] = new_parent unless @flatten
117
129
  stack.push([query_path, idx, new_parent])
118
130
  end
119
131
  end
120
132
 
121
- root = root.flatten if @flatten
122
133
  if path.last
123
134
  { @root => root }
124
135
  else
@@ -1,5 +1,5 @@
1
1
  module Config
2
2
  module Vault
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.4"
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.1
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Young
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-15 00:00:00.000000000 Z
11
+ date: 2022-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vault
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description:
83
+ description:
84
84
  email:
85
85
  - da.young@f5.com
86
86
  executables: []
@@ -97,7 +97,7 @@ metadata:
97
97
  homepage_uri: https://github.com/CrunchwrapSupreme/rubyconfig-vault
98
98
  source_code_uri: https://github.com/CrunchwrapSupreme/rubyconfig-vault
99
99
  documentation_uri: https://www.rubydoc.info/gems/rubyconfig-vault/index
100
- post_install_message:
100
+ post_install_message:
101
101
  rdoc_options: []
102
102
  require_paths:
103
103
  - lib
@@ -112,8 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  - !ruby/object:Gem::Version
113
113
  version: '0'
114
114
  requirements: []
115
- rubygems_version: 3.0.3.1
116
- signing_key:
115
+ rubygems_version: 3.1.2
116
+ signing_key:
117
117
  specification_version: 4
118
118
  summary: Implements a ruby config source from vault
119
119
  test_files: []