precursor 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/argv_vault.rb +3 -0
- data/lib/config_key_builder.rb +1 -0
- data/lib/config_root.rb +12 -18
- data/lib/config_root_builder.rb +1 -0
- data/lib/env_vault.rb +4 -3
- data/lib/hash_vault.rb +2 -0
- data/lib/override_vault.rb +2 -0
- data/lib/precursor.rb +1 -0
- data/lib/thread_local_override_vault.rb +1 -0
- data/lib/vault.rb +2 -1
- data/lib/version.rb +3 -1
- data/lib/yaml_vault.rb +4 -2
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e3304cac9ee21759234bd745095460b9dc71573f4cb6a0f54ba8ca7862c0b0a
|
4
|
+
data.tar.gz: b1995f5395d1b767e08d61db569c40995b277f69f4b516646fed026a000acdb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b3bb038529d96de309c2cf16e7acf1918310944612bd002dfa272e612c2a584c42fdea929cfe1a06f19999dc7b01b4f805c607891cbfb2621eebdd11a3724b6
|
7
|
+
data.tar.gz: d73549d136b50202dd4b222a4e0145851ba78927f3677e9ff55259057a8599018e1494cee40941c7ceafdff745d79f41447aad01f7d7b13c2d1867bad7fc0a6d
|
data/lib/argv_vault.rb
CHANGED
@@ -11,6 +11,8 @@ module Precursor
|
|
11
11
|
# Vault that parses command line arguments
|
12
12
|
class ArgvVault < Vault
|
13
13
|
def initialize(argv)
|
14
|
+
super()
|
15
|
+
|
14
16
|
@vault_data = {}
|
15
17
|
@parser = OptionParser.new do |parser|
|
16
18
|
parser.on('-h', '--help', 'Prints this help') do
|
@@ -34,6 +36,7 @@ module Precursor
|
|
34
36
|
@vault_data
|
35
37
|
end
|
36
38
|
|
39
|
+
# A builder to configure ArgvVault key options
|
37
40
|
class ArgvKeyBuilder
|
38
41
|
def initialize(key_name)
|
39
42
|
@key_name = key_name
|
data/lib/config_key_builder.rb
CHANGED
data/lib/config_root.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Precursor
|
4
|
+
# Root class to access config vaults
|
4
5
|
class ConfigRoot
|
5
6
|
def initialize(vaults, key_options)
|
6
7
|
@vaults = vaults
|
@@ -8,26 +9,12 @@ module Precursor
|
|
8
9
|
end
|
9
10
|
|
10
11
|
def [](key)
|
11
|
-
|
12
|
-
value = nil
|
13
|
-
@vaults.each do |v|
|
14
|
-
if v.key? key
|
15
|
-
found = true
|
16
|
-
value = v.value key
|
17
|
-
break
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
if !found && @key_options.key?(key) && @key_options[key].key?(:default)
|
22
|
-
found = true
|
23
|
-
value = @key_options[key][:default]
|
24
|
-
end
|
25
|
-
|
26
|
-
raise KeyError, "key #{key} not found" unless found
|
12
|
+
key_vault = @vaults.find { |v| v.key? key }
|
27
13
|
|
28
|
-
value =
|
14
|
+
value = key_vault.value key unless key_vault.nil?
|
15
|
+
value = get_default(key) if key_vault.nil?
|
29
16
|
|
30
|
-
value
|
17
|
+
value.is_a?(String) ? resolve_variables(value) : value
|
31
18
|
end
|
32
19
|
|
33
20
|
private
|
@@ -35,6 +22,13 @@ module Precursor
|
|
35
22
|
VAR_PATTERN = /\$\{(?<var_name>[a-zA-Z]+[\w.]+)\}/
|
36
23
|
MAX_DEPTH = 16
|
37
24
|
|
25
|
+
def get_default(key)
|
26
|
+
has_default = @key_options.key?(key) && @key_options[key].key?(:default)
|
27
|
+
raise KeyError, "key #{key} not found" unless has_default
|
28
|
+
|
29
|
+
@key_options[key][:default]
|
30
|
+
end
|
31
|
+
|
38
32
|
def resolve_variables(str)
|
39
33
|
res = str
|
40
34
|
until (m = res.match(VAR_PATTERN)).nil?
|
data/lib/config_root_builder.rb
CHANGED
data/lib/env_vault.rb
CHANGED
@@ -9,12 +9,13 @@ module Precursor
|
|
9
9
|
# @param separator [String] separator for hierarchical config entries
|
10
10
|
# @param allow_list [Array<String>] list of allowed env vars to prevent leaking of sensitive or unrelated vars
|
11
11
|
def initialize(separator: '__', allow_list: [])
|
12
|
-
|
12
|
+
super()
|
13
|
+
@separator = separator
|
13
14
|
|
14
15
|
allow_set = Set.new(allow_list)
|
15
16
|
|
16
|
-
@env_vars = ENV.select { |n, _| allow_set.empty? || allow_set.include?(n) }.
|
17
|
-
|
17
|
+
@env_vars = ENV.select { |n, _| allow_set.empty? || allow_set.include?(n) }.transform_keys do |name|
|
18
|
+
name.sub(@separator, '.').to_sym
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
data/lib/hash_vault.rb
CHANGED
data/lib/override_vault.rb
CHANGED
data/lib/precursor.rb
CHANGED
data/lib/vault.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Precursor
|
4
4
|
# Base class for config vaults
|
@@ -16,6 +16,7 @@ module Precursor
|
|
16
16
|
end
|
17
17
|
|
18
18
|
protected
|
19
|
+
|
19
20
|
# Replace this method in descendant classes to return Hash-like store
|
20
21
|
def store
|
21
22
|
{}
|
data/lib/version.rb
CHANGED
data/lib/yaml_vault.rb
CHANGED
@@ -5,9 +5,11 @@ require 'yaml'
|
|
5
5
|
require_relative 'vault'
|
6
6
|
|
7
7
|
module Precursor
|
8
|
+
# Vault that reads config data from a string with Yaml
|
8
9
|
class YamlVault < Vault
|
9
10
|
def initialize(src)
|
10
|
-
|
11
|
+
super()
|
12
|
+
@yaml = flat_hash(YAML.safe_load(src))
|
11
13
|
end
|
12
14
|
|
13
15
|
protected
|
@@ -27,7 +29,7 @@ module Precursor
|
|
27
29
|
{ k => v }
|
28
30
|
end
|
29
31
|
end
|
30
|
-
flat_hash.reduce(:merge).transform_keys
|
32
|
+
flat_hash.reduce(:merge).transform_keys(&:to_sym)
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: precursor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Maraev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: optparse
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description:
|
42
56
|
email:
|
43
57
|
- the_vk@thevk.net
|
@@ -60,7 +74,8 @@ files:
|
|
60
74
|
homepage: https://github.com/the-vk/precursor
|
61
75
|
licenses:
|
62
76
|
- MIT
|
63
|
-
metadata:
|
77
|
+
metadata:
|
78
|
+
rubygems_mfa_required: 'true'
|
64
79
|
post_install_message:
|
65
80
|
rdoc_options: []
|
66
81
|
require_paths:
|