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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4dc04a5e5fea8efc7195b797bb23347e6a87eaa9a5b0eef6e8fa2e8e1882cdc1
4
- data.tar.gz: 287576509e9a80f0407771d53409efd00b28a2ce59e880719e1722a78eb85039
3
+ metadata.gz: 41c6e3154517787c40c77442238b3d4f62d03503924f51db586ff562a0975d2f
4
+ data.tar.gz: 985e416b9d9e480c8dc83e5988d896605329a93f5c854d0a05331209fb1e6fd7
5
5
  SHA512:
6
- metadata.gz: 2c40c7e1f92ef57be28cb714e3713169b4950abc2cc115d7dd73ea16e2e4aaf748911336bfba01c5d244ae4363f3f52d6676f240c3bdb365f6f7805684459610
7
- data.tar.gz: 860ad65cc9ab5ffe34ef5506c69158d3c5107e8f8b5c1e44a09011da11d018f3c1ed23a73f66e98cf4064955c071cd7cc89dcaee780dfc1c43e2ec0c2575a469
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
- * [Guide](https://config.rocketjob.io/)
10
+ * [Secret Config](https://config.rocketjob.io/)
13
11
 
14
12
  ## Support
15
13
 
@@ -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("- ", target[key])}"
363
- puts "#{Colors::ADD}#{prefix_lines("+ ", source[key])}#{Colors::CLEAR}\n\n"
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("- ", target[key])}\n\n"
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("+ ", source[key])}#{Colors::CLEAR}\n\n"
371
+ puts "#{Colors::ADD}#{prefix_lines('+ ', source[key])}#{Colors::CLEAR}\n\n"
372
372
  end
373
373
  end
374
374
  end
@@ -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
 
@@ -5,6 +5,9 @@ module SecretConfig
5
5
  class MissingMandatoryKey < Error
6
6
  end
7
7
 
8
+ class MissingEnvironmentVariable < Error
9
+ end
10
+
8
11
  class UndefinedRootError < Error
9
12
  end
10
13
 
@@ -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 =~ /\/__import__\Z/) || (key == "__import__")
41
+ next unless (key =~ %r{/__import__\Z}) || (key == "__import__")
42
42
 
43
43
  import_key = tree.delete(key)
44
- key, _ = ::File.split(key)
45
- key = nil if 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(/\A#{import_key}\/(.*)/)
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
@@ -23,9 +23,9 @@ module SecretConfig
23
23
  end
24
24
 
25
25
  # Returns the value or `nil` if not found
26
- def fetch(key)
26
+ def fetch(_key)
27
27
  values = fetch_path(path)
28
- value.is_a?(Hash) ? nil : value
28
+ values.is_a?(Hash) ? nil : values
29
29
  end
30
30
 
31
31
  private
@@ -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} # 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
- # ${hostname} # Full name of this host.
13
- # ${hostname:short} # Short name of this host. Everything up to the first period.
14
- # ${pid} # Process Id for this process.
15
- # ${random} # URL safe Random 32 byte value.
16
- # ${random:size} # URL safe Random value of `size` bytes.
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)
@@ -1,3 +1,3 @@
1
1
  module SecretConfig
2
- VERSION = "0.10.2".freeze
2
+ VERSION = "0.10.3".freeze
3
3
  end
@@ -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([12345, 5343, 26815], value)
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([12345, 5343, 26815], value)
140
+ assert_equal([12_345, 5343, 26_815], value)
141
141
  end
142
142
 
143
143
  it "accepts a default without requiring conversion" do
@@ -96,6 +96,5 @@ class SecretConfigTest < Minitest::Test
96
96
  assert_equal true, database
97
97
  end
98
98
  end
99
-
100
99
  end
101
100
  end
@@ -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
 
@@ -4,6 +4,6 @@ require "yaml"
4
4
  require "minitest/autorun"
5
5
  require "minitest/reporters"
6
6
  require "secret_config"
7
- require "awesome_print"
7
+ require "amazing_print"
8
8
 
9
9
  Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
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.2
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: 2020-06-12 00:00:00.000000000 Z
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.0.8
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/providers/ssm_test.rb
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