rubyconfig-vault 0.1.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 +7 -0
- data/lib/rubyconfig/vault/vault_source.rb +84 -0
- data/lib/rubyconfig/vault/version.rb +5 -0
- data/lib/rubyconfig/vault.rb +2 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9d90484b02d5150c6c0b8904b0a4900b3a0bb1d7e83a53f863c5aee656976ea1
|
4
|
+
data.tar.gz: f81e33ba21ff66e46ac33d9ec0fbb5a0cb6a795798dd4966d45be0945b9a1aa4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 804d3baeb799ca7880a2dc8d2bfa818c48b56cec25f183ff00fb55a08c2b04bd17b50b0f74127de7368cdb15a8b3aa1334a283b3fcc7b3e56777c4c2aac3f1c3
|
7
|
+
data.tar.gz: 1eacd15b46baba5f31449f083f7454057e0d63faffaf7df4a2484968cb5e4240e8b713a6f132be171d663b99472408f98f49ce519484250efe8ecdf2e48805c7
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'vault'
|
2
|
+
|
3
|
+
module Config
|
4
|
+
module Sources
|
5
|
+
class VaultSource
|
6
|
+
attr_accessor :kv
|
7
|
+
attr_reader :paths, :client
|
8
|
+
|
9
|
+
def initialize(opts = {})
|
10
|
+
client_opts = opts.clone
|
11
|
+
@kv = client_opts.delete(:kv) || ''
|
12
|
+
@paths = client_opts.delete(:paths) || []
|
13
|
+
@client = Vault::Client.new(client_opts)
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_path(path)
|
17
|
+
@paths << path
|
18
|
+
end
|
19
|
+
|
20
|
+
def clear_paths
|
21
|
+
@paths = []
|
22
|
+
end
|
23
|
+
|
24
|
+
def load
|
25
|
+
process_paths
|
26
|
+
end
|
27
|
+
|
28
|
+
def client
|
29
|
+
unless kv.empty?
|
30
|
+
@client.kv(@kv)
|
31
|
+
else
|
32
|
+
@client.logical
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def process_paths
|
39
|
+
root = {}
|
40
|
+
parsed_paths = @paths.map { |p| process_path(p) }
|
41
|
+
parsed_paths.each { |p| root.merge!(p) }
|
42
|
+
|
43
|
+
root
|
44
|
+
end
|
45
|
+
|
46
|
+
def process_path(path)
|
47
|
+
root = {}
|
48
|
+
subpaths = path.split('/')
|
49
|
+
stack = []
|
50
|
+
stack.push([nil, 0, root])
|
51
|
+
|
52
|
+
while !stack.empty? do
|
53
|
+
query_path, idx, parent = stack.pop
|
54
|
+
sp = subpaths[idx]
|
55
|
+
if sp.nil? || sp.eql?('*')
|
56
|
+
data = client.read(query_path)&.data
|
57
|
+
parent.merge!(data || {})
|
58
|
+
parent.compact!
|
59
|
+
end
|
60
|
+
|
61
|
+
if sp.eql?('**') || sp.eql?('*')
|
62
|
+
subtrees = client.list(query_path)
|
63
|
+
subtrees.each do |st|
|
64
|
+
new_parent = {}
|
65
|
+
new_key = st.split('/').last.downcase.to_sym
|
66
|
+
new_query_path = [query_path, st].join('/')
|
67
|
+
parent[new_key] = new_parent
|
68
|
+
stack.push([new_query_path, idx + 1, new_parent])
|
69
|
+
end
|
70
|
+
elsif sp
|
71
|
+
query_path = [query_path, sp].compact.join('/')
|
72
|
+
idx += 1
|
73
|
+
new_parent = {}
|
74
|
+
parent[sp.downcase.to_sym] = new_parent
|
75
|
+
stack.push([query_path, idx, new_parent])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
root
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubyconfig-vault
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Young
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-04-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: vault
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.16.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.16.0
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- da.young@f5.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/rubyconfig/vault.rb
|
35
|
+
- lib/rubyconfig/vault/vault_source.rb
|
36
|
+
- lib/rubyconfig/vault/version.rb
|
37
|
+
homepage: https://github.com/CrunchwrapSupreme/rubyconfig-vault
|
38
|
+
licenses: []
|
39
|
+
metadata:
|
40
|
+
allowed_push_host: https://rubygems.org
|
41
|
+
homepage_uri: https://github.com/CrunchwrapSupreme/rubyconfig-vault
|
42
|
+
source_code_uri: https://github.com/CrunchwrapSupreme/rubyconfig-vault
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: 2.3.0
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubygems_version: 3.0.3.1
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: Implements a ruby config source from vault
|
62
|
+
test_files: []
|