secret_config 0.7.1 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,19 +15,19 @@ class SecretConfigTest < Minitest::Test
15
15
  SecretConfig.use :file, path: path, file_name: file_name
16
16
  end
17
17
 
18
- describe "#configuration" do
18
+ describe ".configuration" do
19
19
  it "returns a copy of the config" do
20
20
  assert_equal "127.0.0.1", SecretConfig.configuration.dig("mysql", "host")
21
21
  end
22
22
  end
23
23
 
24
- describe "#key?" do
24
+ describe ".key?" do
25
25
  it "has key" do
26
26
  assert SecretConfig.key?("mysql/database")
27
27
  end
28
28
  end
29
29
 
30
- describe "#[]" do
30
+ describe ".[]" do
31
31
  it "returns values" do
32
32
  assert_equal "secret_config_test", SecretConfig["mysql/database"]
33
33
  end
@@ -37,7 +37,7 @@ class SecretConfigTest < Minitest::Test
37
37
  end
38
38
  end
39
39
 
40
- describe "#fetch" do
40
+ describe ".fetch" do
41
41
  after do
42
42
  ENV["MYSQL_DATABASE"] = nil
43
43
  SecretConfig.check_env_var = true
@@ -66,5 +66,36 @@ class SecretConfigTest < Minitest::Test
66
66
  assert_equal "secret_config_test", SecretConfig.fetch("mysql/database")
67
67
  end
68
68
  end
69
+
70
+ describe ".configure" do
71
+ before do
72
+ SecretConfig.use :file, path: path, file_name: file_name
73
+ end
74
+
75
+ it "#fetch" do
76
+ database = nil
77
+ SecretConfig.configure("mysql") do |config|
78
+ database = config.fetch("database")
79
+ end
80
+ assert_equal "secret_config_test", database
81
+ end
82
+
83
+ it "#[]" do
84
+ database = nil
85
+ SecretConfig.configure("mysql") do |config|
86
+ database = config["database"]
87
+ end
88
+ assert_equal "secret_config_test", database
89
+ end
90
+
91
+ it "#key?" do
92
+ database = nil
93
+ SecretConfig.configure("mysql") do |config|
94
+ database = config.key?("database")
95
+ end
96
+ assert_equal true, database
97
+ end
98
+ end
99
+
69
100
  end
70
101
  end
@@ -1,28 +1,28 @@
1
- require_relative 'test_helper'
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 '#parse' do
7
+ describe "#parse" do
8
8
  it "handles good key" do
9
- string = "Set a date of %{date} here."
10
- expected = string.gsub("%{date}", Date.today.strftime("%Y%m%d"))
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 = "%{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)
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 %{blah} here."
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 'interpolates date only' do
34
- string = "%{date}"
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 'interpolates date' do
41
- string = "Set a date of %{date} here."
42
- expected = string.gsub("%{date}", Date.today.strftime("%Y%m%d"))
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 '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"))
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 'interpolates time only' do
57
- string = "%{time}"
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 'interpolates time' do
67
- string = "Set a time of %{time} here."
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("%{time}", Time.now.strftime("%Y%m%d%H%M%S%L"))
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 '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"))
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 'fetches existing ENV var' do
90
- string = "%{env:TEST_SETTING}"
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 'fetches existing ENV var into a larger string' do
96
- string = "Hello %{env:TEST_SETTING}. How are you?"
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("%{env:TEST_SETTING}", "Secret")
98
+ expected = string.gsub("${env:TEST_SETTING}", "Secret")
99
99
  assert_equal expected, actual, string
100
100
  end
101
101
 
102
- it 'handles missing ENV var' do
103
- string = "%{env:OTHER_TEST_SETTING}"
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 'returns hostname' do
111
- string = "%{hostname}"
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 'returns short hostname' do
117
- string = "%{hostname:short}"
116
+ it "returns short hostname" do
117
+ string = "${hostname:short}"
118
118
  actual = interpolator.parse(string)
119
- assert_equal Socket.gethostname.split('.')[0], actual, string
119
+ assert_equal Socket.gethostname.split(".")[0], actual, string
120
120
  end
121
121
  end
122
122
 
123
123
  describe "#pid" do
124
- it 'returns process id' do
125
- string = "%{pid}"
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 'interpolates random 32 byte string' do
133
- string = "%{random}"
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 'interpolates custom length random string' do
142
- string = "%{random:64}"
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)
@@ -1,9 +1,9 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
2
2
 
3
- require 'yaml'
4
- require 'minitest/autorun'
5
- require 'minitest/reporters'
6
- require 'secret_config'
7
- require 'awesome_print'
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
@@ -1,4 +1,4 @@
1
- require_relative 'test_helper'
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 '.flatten' do
21
- it 'returns a copy of the config' do
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.7.1
4
+ version: 0.10.2
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-03-10 00:00:00.000000000 Z
11
+ date: 2020-06-12 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
- - secret_config
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/secret_config
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.6
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