secret_config 0.7.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -756
- data/Rakefile +7 -7
- data/bin/{secret_config → secret-config} +1 -1
- data/lib/secret_config.rb +31 -2
- data/lib/secret_config/cli.rb +154 -97
- data/lib/secret_config/config.rb +44 -0
- data/lib/secret_config/parser.rb +76 -0
- data/lib/secret_config/providers/file.rb +17 -4
- data/lib/secret_config/providers/ssm.rb +9 -2
- data/lib/secret_config/registry.rb +46 -33
- data/lib/secret_config/setting_interpolator.rb +14 -27
- data/lib/secret_config/string_interpolator.rb +10 -9
- data/lib/secret_config/utils.rb +1 -1
- data/lib/secret_config/version.rb +1 -1
- data/test/config/application.yml +35 -5
- data/test/parser_test.rb +82 -0
- data/test/providers/file_test.rb +5 -5
- data/test/providers/ssm_test.rb +37 -12
- data/test/registry_test.rb +56 -26
- data/test/secret_config_test.rb +35 -4
- data/test/setting_interpolator_test.rb +43 -43
- data/test/test_helper.rb +6 -6
- data/test/utils_test.rb +4 -4
- metadata +9 -5
@@ -1,28 +1,28 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "test_helper"
|
2
2
|
module SecretConfig
|
3
3
|
class SettingInterpolatorTest < Minitest::Test
|
4
4
|
describe SettingInterpolator do
|
5
5
|
let(:interpolator) { SettingInterpolator.new }
|
6
6
|
|
7
|
-
describe
|
7
|
+
describe "#parse" do
|
8
8
|
it "handles good key" do
|
9
|
-
string = "Set a date of
|
10
|
-
expected = string.gsub("
|
9
|
+
string = "Set a date of ${date} here."
|
10
|
+
expected = string.gsub("${date}", Date.today.strftime("%Y%m%d"))
|
11
11
|
actual = interpolator.parse(string)
|
12
12
|
assert_equal expected, actual, string
|
13
13
|
end
|
14
14
|
|
15
15
|
it "handles multiple keys" do
|
16
|
-
string = "
|
17
|
-
expected = string.gsub("
|
18
|
-
expected = expected.gsub("
|
19
|
-
expected = expected.gsub("
|
16
|
+
string = "${pid}: Set a date of ${date} here and a ${time:%H%M} here and for luck ${pid}"
|
17
|
+
expected = string.gsub("${date}", Date.today.strftime("%Y%m%d"))
|
18
|
+
expected = expected.gsub("${time:%H%M}", Time.now.strftime("%H%M"))
|
19
|
+
expected = expected.gsub("${pid}", $$.to_s)
|
20
20
|
actual = interpolator.parse(string)
|
21
21
|
assert_equal expected, actual, string
|
22
22
|
end
|
23
23
|
|
24
24
|
it "handles bad key" do
|
25
|
-
string = "Set a date of
|
25
|
+
string = "Set a date of ${blah} here."
|
26
26
|
assert_raises InvalidInterpolation do
|
27
27
|
interpolator.parse(string)
|
28
28
|
end
|
@@ -30,31 +30,31 @@ module SecretConfig
|
|
30
30
|
end
|
31
31
|
|
32
32
|
describe "#date" do
|
33
|
-
it
|
34
|
-
string = "
|
33
|
+
it "interpolates date only" do
|
34
|
+
string = "${date}"
|
35
35
|
expected = Date.today.strftime("%Y%m%d")
|
36
36
|
actual = interpolator.parse(string)
|
37
37
|
assert_equal expected, actual, string
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
41
|
-
string = "Set a date of
|
42
|
-
expected = string.gsub("
|
40
|
+
it "interpolates date" do
|
41
|
+
string = "Set a date of ${date} here."
|
42
|
+
expected = string.gsub("${date}", Date.today.strftime("%Y%m%d"))
|
43
43
|
actual = interpolator.parse(string)
|
44
44
|
assert_equal expected, actual, string
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
48
|
-
string = "Set a custom
|
49
|
-
expected = string.gsub("
|
47
|
+
it "interpolates date with custom format" do
|
48
|
+
string = "Set a custom ${date:%m%d%Y} here."
|
49
|
+
expected = string.gsub("${date:%m%d%Y}", Date.today.strftime("%m%d%Y"))
|
50
50
|
actual = interpolator.parse(string)
|
51
51
|
assert_equal expected, actual, string
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
describe "#time" do
|
56
|
-
it
|
57
|
-
string = "
|
56
|
+
it "interpolates time only" do
|
57
|
+
string = "${time}"
|
58
58
|
time = Time.now
|
59
59
|
Time.stub(:now, time) do
|
60
60
|
expected = Time.now.strftime("%Y%m%d%H%M%S%L")
|
@@ -63,19 +63,19 @@ module SecretConfig
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
it
|
67
|
-
string = "Set a time of
|
66
|
+
it "interpolates time" do
|
67
|
+
string = "Set a time of ${time} here."
|
68
68
|
time = Time.now
|
69
69
|
Time.stub(:now, time) do
|
70
|
-
expected = string.gsub("
|
70
|
+
expected = string.gsub("${time}", Time.now.strftime("%Y%m%d%H%M%S%L"))
|
71
71
|
actual = interpolator.parse(string)
|
72
72
|
assert_equal expected, actual, string
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
it
|
77
|
-
string = "Set a custom time of
|
78
|
-
expected = string.gsub("
|
76
|
+
it "interpolates time with custom format" do
|
77
|
+
string = "Set a custom time of ${time:%H%M} here."
|
78
|
+
expected = string.gsub("${time:%H%M}", Time.now.strftime("%H%M"))
|
79
79
|
actual = interpolator.parse(string)
|
80
80
|
assert_equal expected, actual, string
|
81
81
|
end
|
@@ -86,51 +86,51 @@ module SecretConfig
|
|
86
86
|
ENV["TEST_SETTING"] = "Secret"
|
87
87
|
end
|
88
88
|
|
89
|
-
it
|
90
|
-
string = "
|
89
|
+
it "fetches existing ENV var" do
|
90
|
+
string = "${env:TEST_SETTING}"
|
91
91
|
actual = interpolator.parse(string)
|
92
92
|
assert_equal "Secret", actual, string
|
93
93
|
end
|
94
94
|
|
95
|
-
it
|
96
|
-
string = "Hello
|
95
|
+
it "fetches existing ENV var into a larger string" do
|
96
|
+
string = "Hello ${env:TEST_SETTING}. How are you?"
|
97
97
|
actual = interpolator.parse(string)
|
98
|
-
expected = string.gsub("
|
98
|
+
expected = string.gsub("${env:TEST_SETTING}", "Secret")
|
99
99
|
assert_equal expected, actual, string
|
100
100
|
end
|
101
101
|
|
102
|
-
it
|
103
|
-
string = "
|
102
|
+
it "handles missing ENV var" do
|
103
|
+
string = "${env:OTHER_TEST_SETTING}"
|
104
104
|
actual = interpolator.parse(string)
|
105
105
|
assert_equal "", actual, string
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
109
|
describe "#hostname" do
|
110
|
-
it
|
111
|
-
string = "
|
110
|
+
it "returns hostname" do
|
111
|
+
string = "${hostname}"
|
112
112
|
actual = interpolator.parse(string)
|
113
113
|
assert_equal Socket.gethostname, actual, string
|
114
114
|
end
|
115
115
|
|
116
|
-
it
|
117
|
-
string = "
|
116
|
+
it "returns short hostname" do
|
117
|
+
string = "${hostname:short}"
|
118
118
|
actual = interpolator.parse(string)
|
119
|
-
assert_equal Socket.gethostname.split(
|
119
|
+
assert_equal Socket.gethostname.split(".")[0], actual, string
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
123
|
describe "#pid" do
|
124
|
-
it
|
125
|
-
string = "
|
124
|
+
it "returns process id" do
|
125
|
+
string = "${pid}"
|
126
126
|
actual = interpolator.parse(string)
|
127
127
|
assert_equal $$.to_s, actual, string
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
131
|
describe "#random" do
|
132
|
-
it
|
133
|
-
string = "
|
132
|
+
it "interpolates random 32 byte string" do
|
133
|
+
string = "${random}"
|
134
134
|
random = SecureRandom.urlsafe_base64(32)
|
135
135
|
SecureRandom.stub(:urlsafe_base64, random) do
|
136
136
|
actual = interpolator.parse(string)
|
@@ -138,8 +138,8 @@ module SecretConfig
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
-
it
|
142
|
-
string = "
|
141
|
+
it "interpolates custom length random string" do
|
142
|
+
string = "${random:64}"
|
143
143
|
random = SecureRandom.urlsafe_base64(64)
|
144
144
|
SecureRandom.stub(:urlsafe_base64, random) do
|
145
145
|
actual = interpolator.parse(string)
|
data/test/test_helper.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) +
|
1
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
3
|
+
require "yaml"
|
4
|
+
require "minitest/autorun"
|
5
|
+
require "minitest/reporters"
|
6
|
+
require "secret_config"
|
7
|
+
require "awesome_print"
|
8
8
|
|
9
9
|
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
data/test/utils_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "test_helper"
|
2
2
|
|
3
3
|
class UtilsTest < Minitest::Test
|
4
4
|
describe SecretConfig::Utils do
|
@@ -9,7 +9,7 @@ class UtilsTest < Minitest::Test
|
|
9
9
|
"test/my_application/mysql/username" => "secret_config",
|
10
10
|
"test/my_application/mysql/host" => "127.0.0.1",
|
11
11
|
"test/my_application/secrets" => "both_a_path_and_a_value",
|
12
|
-
"test/my_application/secrets/secret_key_base" => "somereallylongteststring"
|
12
|
+
"test/my_application/secrets/secret_key_base" => "somereallylongteststring"
|
13
13
|
}
|
14
14
|
end
|
15
15
|
|
@@ -17,8 +17,8 @@ class UtilsTest < Minitest::Test
|
|
17
17
|
SecretConfig::Utils.hierarchical(flat_registry)
|
18
18
|
end
|
19
19
|
|
20
|
-
describe
|
21
|
-
it
|
20
|
+
describe ".flatten" do
|
21
|
+
it "returns a copy of the config" do
|
22
22
|
h = SecretConfig::Utils.flatten(hash_registry, path = nil)
|
23
23
|
assert_equal(flat_registry, h)
|
24
24
|
end
|
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.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -28,17 +28,19 @@ description:
|
|
28
28
|
email:
|
29
29
|
- reidmo@gmail.com
|
30
30
|
executables:
|
31
|
-
-
|
31
|
+
- secret-config
|
32
32
|
extensions: []
|
33
33
|
extra_rdoc_files: []
|
34
34
|
files:
|
35
35
|
- LICENSE
|
36
36
|
- README.md
|
37
37
|
- Rakefile
|
38
|
-
- bin/
|
38
|
+
- bin/secret-config
|
39
39
|
- lib/secret_config.rb
|
40
40
|
- lib/secret_config/cli.rb
|
41
|
+
- lib/secret_config/config.rb
|
41
42
|
- lib/secret_config/errors.rb
|
43
|
+
- lib/secret_config/parser.rb
|
42
44
|
- lib/secret_config/providers/file.rb
|
43
45
|
- lib/secret_config/providers/provider.rb
|
44
46
|
- lib/secret_config/providers/ssm.rb
|
@@ -49,6 +51,7 @@ files:
|
|
49
51
|
- lib/secret_config/utils.rb
|
50
52
|
- lib/secret_config/version.rb
|
51
53
|
- test/config/application.yml
|
54
|
+
- test/parser_test.rb
|
52
55
|
- test/providers/file_test.rb
|
53
56
|
- test/providers/ssm_test.rb
|
54
57
|
- test/registry_test.rb
|
@@ -75,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
78
|
- !ruby/object:Gem::Version
|
76
79
|
version: '0'
|
77
80
|
requirements: []
|
78
|
-
rubygems_version: 3.0.
|
81
|
+
rubygems_version: 3.0.8
|
79
82
|
signing_key:
|
80
83
|
specification_version: 4
|
81
84
|
summary: Centralized Configuration and Secrets Management for Ruby and Rails applications.
|
@@ -85,6 +88,7 @@ test_files:
|
|
85
88
|
- test/providers/file_test.rb
|
86
89
|
- test/registry_test.rb
|
87
90
|
- test/setting_interpolator_test.rb
|
91
|
+
- test/parser_test.rb
|
88
92
|
- test/test_helper.rb
|
89
93
|
- test/utils_test.rb
|
90
94
|
- test/secret_config_test.rb
|