secret_config 0.10.2 → 0.10.3
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 +4 -4
- data/README.md +1 -3
- data/lib/secret_config/cli.rb +4 -4
- data/lib/secret_config/config.rb +14 -0
- data/lib/secret_config/errors.rb +3 -0
- data/lib/secret_config/parser.rb +4 -5
- data/lib/secret_config/providers/file.rb +2 -2
- data/lib/secret_config/setting_interpolator.rb +19 -12
- data/lib/secret_config/version.rb +1 -1
- data/test/registry_test.rb +2 -2
- data/test/secret_config_test.rb +0 -1
- data/test/setting_interpolator_test.rb +8 -1
- data/test/test_helper.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41c6e3154517787c40c77442238b3d4f62d03503924f51db586ff562a0975d2f
|
4
|
+
data.tar.gz: 985e416b9d9e480c8dc83e5988d896605329a93f5c854d0a05331209fb1e6fd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 417a5673810b55d39c9ae17c144da9528724ebf142a46ccdc5b02abf60a69bc6fe4ed8455007583d4bdada03fd2d27dc6e03207649df42495b84718c7bb84bd0
|
7
|
+
data.tar.gz: 3adae9bd474b45b0d4cc4b4780b3aaef41cdb5a52ea7dff2f4ea0261d34198f3ac7b8158dabe765b366b6a83d7e6dcc5c1a3fc798f7bec11c2366efa141ce012
|
data/README.md
CHANGED
@@ -5,11 +5,9 @@ Centralized Configuration and Secrets Management for Ruby and Rails applications
|
|
5
5
|
|
6
6
|
Securely store configuration information centrally, supporting multiple tenants of the same application.
|
7
7
|
|
8
|
-
Checkout https://config.rocketjob.io/
|
9
|
-
|
10
8
|
## Documentation
|
11
9
|
|
12
|
-
* [
|
10
|
+
* [Secret Config](https://config.rocketjob.io/)
|
13
11
|
|
14
12
|
## Support
|
15
13
|
|
data/lib/secret_config/cli.rb
CHANGED
@@ -359,16 +359,16 @@ module SecretConfig
|
|
359
359
|
# Ignore filtered values
|
360
360
|
if (value != target[key].to_s) && (value != FILTERED)
|
361
361
|
puts "#{Colors::KEY}#{key}:"
|
362
|
-
puts "#{Colors::REMOVE}#{prefix_lines(
|
363
|
-
puts "#{Colors::ADD}#{prefix_lines(
|
362
|
+
puts "#{Colors::REMOVE}#{prefix_lines('- ', target[key])}"
|
363
|
+
puts "#{Colors::ADD}#{prefix_lines('+ ', source[key])}#{Colors::CLEAR}\n\n"
|
364
364
|
end
|
365
365
|
else
|
366
366
|
puts "#{Colors::KEY}#{key}:"
|
367
|
-
puts "#{Colors::REMOVE}#{prefix_lines(
|
367
|
+
puts "#{Colors::REMOVE}#{prefix_lines('- ', target[key])}\n\n"
|
368
368
|
end
|
369
369
|
elsif source.key?(key)
|
370
370
|
puts "#{Colors::KEY}#{key}:"
|
371
|
-
puts "#{Colors::ADD}#{prefix_lines(
|
371
|
+
puts "#{Colors::ADD}#{prefix_lines('+ ', source[key])}#{Colors::CLEAR}\n\n"
|
372
372
|
end
|
373
373
|
end
|
374
374
|
end
|
data/lib/secret_config/config.rb
CHANGED
@@ -5,31 +5,45 @@ module SecretConfig
|
|
5
5
|
def_delegator :registry, :refresh!
|
6
6
|
|
7
7
|
def initialize(path, registry)
|
8
|
+
raise(ArgumentError, "path cannot be nil") if path.nil?
|
9
|
+
|
8
10
|
@path = path
|
9
11
|
@registry = registry
|
10
12
|
end
|
11
13
|
|
12
14
|
def fetch(sub_path, **options)
|
15
|
+
raise(ArgumentError, "sub_path cannot be nil") if sub_path.nil?
|
16
|
+
|
13
17
|
registry.fetch(join_path(sub_path), **options)
|
14
18
|
end
|
15
19
|
|
16
20
|
def [](sub_path)
|
21
|
+
raise(ArgumentError, "sub_path cannot be nil") if sub_path.nil?
|
22
|
+
|
17
23
|
registry[join_path(sub_path)]
|
18
24
|
end
|
19
25
|
|
20
26
|
def []=(sub_path, value)
|
27
|
+
raise(ArgumentError, "sub_path cannot be nil") if sub_path.nil?
|
28
|
+
|
21
29
|
registry[join_path(sub_path)] = value
|
22
30
|
end
|
23
31
|
|
24
32
|
def key?(sub_path)
|
33
|
+
raise(ArgumentError, "sub_path cannot be nil") if sub_path.nil?
|
34
|
+
|
25
35
|
registry.key?(join_path(sub_path))
|
26
36
|
end
|
27
37
|
|
28
38
|
def set(sub_path, value)
|
39
|
+
raise(ArgumentError, "sub_path cannot be nil") if sub_path.nil?
|
40
|
+
|
29
41
|
registry.set(join_path(sub_path), value)
|
30
42
|
end
|
31
43
|
|
32
44
|
def delete(sub_path)
|
45
|
+
raise(ArgumentError, "sub_path cannot be nil") if sub_path.nil?
|
46
|
+
|
33
47
|
registry.delete(join_path(sub_path))
|
34
48
|
end
|
35
49
|
|
data/lib/secret_config/errors.rb
CHANGED
data/lib/secret_config/parser.rb
CHANGED
@@ -38,11 +38,11 @@ module SecretConfig
|
|
38
38
|
# - Imports cannot reference other imports at this time.
|
39
39
|
def apply_imports
|
40
40
|
tree.keys.each do |key|
|
41
|
-
next unless (key =~
|
41
|
+
next unless (key =~ %r{/__import__\Z}) || (key == "__import__")
|
42
42
|
|
43
43
|
import_key = tree.delete(key)
|
44
|
-
key,
|
45
|
-
key
|
44
|
+
key, = ::File.split(key)
|
45
|
+
key = nil if key == "."
|
46
46
|
|
47
47
|
# binding.irb
|
48
48
|
|
@@ -51,7 +51,7 @@ module SecretConfig
|
|
51
51
|
|
52
52
|
if relative_key?(import_key)
|
53
53
|
tree.keys.each do |current_key|
|
54
|
-
match = current_key.match(
|
54
|
+
match = current_key.match(%r{\A#{import_key}/(.*)})
|
55
55
|
next unless match
|
56
56
|
|
57
57
|
imported_key = key.nil? ? match[1] : ::File.join(key, match[1])
|
@@ -71,6 +71,5 @@ module SecretConfig
|
|
71
71
|
def relative_key?(key)
|
72
72
|
!key.start_with?("/")
|
73
73
|
end
|
74
|
-
|
75
74
|
end
|
76
75
|
end
|
@@ -4,16 +4,19 @@ require "securerandom"
|
|
4
4
|
# * SecretConfig Interpolations
|
5
5
|
#
|
6
6
|
# Expanding values inline for date, time, hostname, pid and random values.
|
7
|
-
# ${date}
|
8
|
-
# ${date:format}
|
9
|
-
# ${time}
|
10
|
-
# ${time:format}
|
11
|
-
# ${env:name}
|
12
|
-
#
|
13
|
-
# ${
|
14
|
-
#
|
15
|
-
# ${
|
16
|
-
# ${
|
7
|
+
# ${date} # Current date in the format of "%Y%m%d" (CCYYMMDD)
|
8
|
+
# ${date:format} # Current date in the supplied format. See strftime
|
9
|
+
# ${time} # Current date and time down to ms in the format of "%Y%m%d%Y%H%M%S%L" (CCYYMMDDHHMMSSmmm)
|
10
|
+
# ${time:format} # Current date and time in the supplied format. See strftime
|
11
|
+
# ${env:name} # Extract value from the named environment value.
|
12
|
+
# # Raises SecretConfig::MissingEnvironmentVariable when the env var is not defined.
|
13
|
+
# ${env:name,default} # Extract value from the named environment value.
|
14
|
+
# # Returns the supplied default value when the env var is not defined.
|
15
|
+
# ${hostname} # Full name of this host.
|
16
|
+
# ${hostname:short} # Short name of this host. Everything up to the first period.
|
17
|
+
# ${pid} # Process Id for this process.
|
18
|
+
# ${random} # URL safe Random 32 byte value.
|
19
|
+
# ${random:size} # URL safe Random value of `size` bytes.
|
17
20
|
module SecretConfig
|
18
21
|
class SettingInterpolator < StringInterpolator
|
19
22
|
def date(format = "%Y%m%d")
|
@@ -24,8 +27,12 @@ module SecretConfig
|
|
24
27
|
Time.now.strftime(format)
|
25
28
|
end
|
26
29
|
|
27
|
-
def env(name)
|
28
|
-
ENV[name]
|
30
|
+
def env(name, default = :no_default_supplied)
|
31
|
+
return ENV[name] if ENV.key?(name)
|
32
|
+
|
33
|
+
return default unless default == :no_default_supplied
|
34
|
+
|
35
|
+
raise(MissingEnvironmentVariable, "Missing mandatory environment variable: #{name}")
|
29
36
|
end
|
30
37
|
|
31
38
|
def hostname(format = nil)
|
data/test/registry_test.rb
CHANGED
@@ -132,12 +132,12 @@ class RegistryTest < Minitest::Test
|
|
132
132
|
|
133
133
|
it "of integers" do
|
134
134
|
value = registry.fetch("mysql/ports", type: :integer, separator: ",")
|
135
|
-
assert_equal([
|
135
|
+
assert_equal([12_345, 5343, 26_815], value)
|
136
136
|
end
|
137
137
|
|
138
138
|
it "of integers with spaces" do
|
139
139
|
value = registry.fetch("mysql/ports2", type: :integer, separator: ",")
|
140
|
-
assert_equal([
|
140
|
+
assert_equal([12_345, 5343, 26_815], value)
|
141
141
|
end
|
142
142
|
|
143
143
|
it "accepts a default without requiring conversion" do
|
data/test/secret_config_test.rb
CHANGED
@@ -101,8 +101,15 @@ module SecretConfig
|
|
101
101
|
|
102
102
|
it "handles missing ENV var" do
|
103
103
|
string = "${env:OTHER_TEST_SETTING}"
|
104
|
+
assert_raises SecretConfig::MissingEnvironmentVariable do
|
105
|
+
interpolator.parse(string)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
it "uses default value for missing ENV var" do
|
110
|
+
string = "${env:OTHER_TEST_SETTING,My default value}"
|
104
111
|
actual = interpolator.parse(string)
|
105
|
-
assert_equal "", actual, string
|
112
|
+
assert_equal "My default value", actual, string
|
106
113
|
end
|
107
114
|
end
|
108
115
|
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: secret_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
description:
|
27
|
+
description:
|
28
28
|
email:
|
29
29
|
- reidmo@gmail.com
|
30
30
|
executables:
|
@@ -63,7 +63,7 @@ homepage: https://github.com/rocketjob/secret_config
|
|
63
63
|
licenses:
|
64
64
|
- Apache-2.0
|
65
65
|
metadata: {}
|
66
|
-
post_install_message:
|
66
|
+
post_install_message:
|
67
67
|
rdoc_options: []
|
68
68
|
require_paths:
|
69
69
|
- lib
|
@@ -78,17 +78,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
78
|
- !ruby/object:Gem::Version
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
|
-
rubygems_version: 3.
|
82
|
-
signing_key:
|
81
|
+
rubygems_version: 3.2.3
|
82
|
+
signing_key:
|
83
83
|
specification_version: 4
|
84
84
|
summary: Centralized Configuration and Secrets Management for Ruby and Rails applications.
|
85
85
|
test_files:
|
86
86
|
- test/config/application.yml
|
87
|
-
- test/
|
87
|
+
- test/parser_test.rb
|
88
88
|
- test/providers/file_test.rb
|
89
|
+
- test/providers/ssm_test.rb
|
89
90
|
- test/registry_test.rb
|
91
|
+
- test/secret_config_test.rb
|
90
92
|
- test/setting_interpolator_test.rb
|
91
|
-
- test/parser_test.rb
|
92
93
|
- test/test_helper.rb
|
93
94
|
- test/utils_test.rb
|
94
|
-
- test/secret_config_test.rb
|