config_hound 1.4.2 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/test.yaml +20 -0
- data/README.md +2 -2
- data/config_hound.gemspec +4 -2
- data/lib/config_hound/interpolation.rb +2 -1
- data/lib/config_hound/parser.rb +1 -1
- data/lib/config_hound/resource.rb +6 -6
- data/lib/config_hound/version.rb +1 -1
- data/spec/config_hound/resource_spec.rb +6 -6
- data/spec/features/expansion_spec.rb +32 -0
- data/spec/features/formats_spec.rb +12 -0
- data/spec/spec_helper.rb +5 -1
- metadata +13 -14
- data/.travis.yml +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 33f4e286668dbf7171c50d313cd9339cbb1ccbdc34d9b68c1e732c7a84d0acb9
|
4
|
+
data.tar.gz: 007b751b55b1b1463db129e754572e966f937a890636a16d3506d3b9ca2801b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdaa8f5cd09e6a5aee6c35b5a9116e2f7f28b7553472c1b10ece292028d5553ffdfeda9c4358a79729589c33f565b58a4439c42f431cd1a7e9ad0878bba376e4
|
7
|
+
data.tar.gz: b084ffc0661eaf04af3ff1c22bc762158e660a5a0ab0658d9b71b89b1700cb402515c5a2ea01520b2b8d61e0cbe682e5425939e5499e45b5cf0736b600fec0f1
|
@@ -0,0 +1,20 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
|
8
|
+
strategy:
|
9
|
+
matrix:
|
10
|
+
ruby: ['2.7', '3.0', '3.1']
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v3
|
15
|
+
- uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
bundler-cache: true
|
18
|
+
ruby-version: ${{ matrix.ruby }}
|
19
|
+
- run: bundle install
|
20
|
+
- run: bundle exec rake
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# ConfigHound
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/config_hound.
|
4
|
-
[![Build Status](https://
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/config_hound.svg)](http://badge.fury.io/rb/config_hound)
|
4
|
+
[![Build Status](https://github.com/mdub/config_hound/actions/workflows/test.yaml/badge.svg?branch=master)](https://github.com/mdub/config_hound/actions/workflows/test.yaml)
|
5
5
|
|
6
6
|
ConfigHound makes it easy to load configuration data.
|
7
7
|
|
data/config_hound.gemspec
CHANGED
@@ -19,9 +19,11 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^spec/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
+
spec.required_ruby_version = '>= 2.7'
|
23
|
+
|
22
24
|
spec.add_runtime_dependency "dig_rb"
|
23
25
|
|
24
|
-
spec.add_development_dependency "bundler", "~>
|
25
|
-
spec.add_development_dependency "rake", "~>
|
26
|
+
spec.add_development_dependency "bundler", "~> 2.2"
|
27
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
26
28
|
|
27
29
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "config_hound/error"
|
2
2
|
require "dig_rb"
|
3
|
+
require "set"
|
3
4
|
|
4
5
|
module ConfigHound
|
5
6
|
|
@@ -46,7 +47,7 @@ module ConfigHound
|
|
46
47
|
|
47
48
|
def expand_hash(input)
|
48
49
|
input.each_with_object({}) do |(k,v), a|
|
49
|
-
a[k] = expand(v)
|
50
|
+
a[expand(k)] = expand(v)
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
data/lib/config_hound/parser.rb
CHANGED
@@ -29,14 +29,16 @@ module ConfigHound
|
|
29
29
|
when %r{^\w+:/}
|
30
30
|
URI(arg)
|
31
31
|
when %r{^/}
|
32
|
-
URI("file
|
32
|
+
URI("file://#{arg}")
|
33
33
|
else
|
34
|
-
URI("file
|
34
|
+
URI("file://#{File.expand_path(arg)}")
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
39
39
|
|
40
|
+
attr_reader :uri
|
41
|
+
|
40
42
|
def to_s
|
41
43
|
uri.to_s
|
42
44
|
end
|
@@ -46,7 +48,7 @@ module ConfigHound
|
|
46
48
|
end
|
47
49
|
|
48
50
|
def read
|
49
|
-
open(uri.scheme == "file" ? uri.path : uri.to_s) do |io|
|
51
|
+
URI.open(uri.scheme == "file" ? uri.path : uri.to_s) do |io|
|
50
52
|
io.read
|
51
53
|
end
|
52
54
|
rescue Errno::ENOENT
|
@@ -54,7 +56,7 @@ module ConfigHound
|
|
54
56
|
end
|
55
57
|
|
56
58
|
def format
|
57
|
-
File.extname(uri.to_s)[1..-1]
|
59
|
+
File.extname(uri.path.to_s)[1..-1]
|
58
60
|
end
|
59
61
|
|
60
62
|
def load
|
@@ -67,8 +69,6 @@ module ConfigHound
|
|
67
69
|
@uri = uri
|
68
70
|
end
|
69
71
|
|
70
|
-
attr_reader :uri
|
71
|
-
|
72
72
|
end
|
73
73
|
|
74
74
|
end
|
data/lib/config_hound/version.rb
CHANGED
@@ -13,7 +13,7 @@ describe ConfigHound::Resource do
|
|
13
13
|
let(:path) { uri }
|
14
14
|
|
15
15
|
it "retains the URI" do
|
16
|
-
expect(resource.
|
16
|
+
expect(resource.uri).to eq uri
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
@@ -23,7 +23,7 @@ describe ConfigHound::Resource do
|
|
23
23
|
let(:path) { "/path/to/file" }
|
24
24
|
|
25
25
|
it "assumes it's a file" do
|
26
|
-
expect(resource.
|
26
|
+
expect(resource.uri).to eq URI("file:///path/to/file")
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "#resolve" do
|
@@ -32,21 +32,21 @@ describe ConfigHound::Resource do
|
|
32
32
|
it "resolves relatively" do
|
33
33
|
other_resource = resource.resolve("other_file")
|
34
34
|
expect(other_resource).to be_a(ConfigHound::Resource)
|
35
|
-
expect(other_resource.
|
35
|
+
expect(other_resource.uri).to eq URI("file:///path/to/other_file")
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
context "with an absolute file path" do
|
40
40
|
it "resolves relatively" do
|
41
41
|
other_resource = resource.resolve("/different/path")
|
42
|
-
expect(other_resource.
|
42
|
+
expect(other_resource.uri).to eq URI("file:///different/path")
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
context "with a fully-qualified URI" do
|
47
47
|
it "uses the URI provided" do
|
48
48
|
other_resource = resource.resolve("http://foo/bar")
|
49
|
-
expect(other_resource.
|
49
|
+
expect(other_resource.uri).to eq URI("http://foo/bar")
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -59,7 +59,7 @@ describe ConfigHound::Resource do
|
|
59
59
|
let(:path) { "config.yml" }
|
60
60
|
|
61
61
|
it "assumes it's a file relative to $CWD" do
|
62
|
-
expect(resource.
|
62
|
+
expect(resource.uri).to eq URI("file://#{Dir.pwd}/config.yml")
|
63
63
|
end
|
64
64
|
|
65
65
|
end
|
@@ -16,6 +16,38 @@ describe ConfigHound, "expansion" do
|
|
16
16
|
expect(config["address"]).to eq("host:5678")
|
17
17
|
end
|
18
18
|
|
19
|
+
context "with key expansion" do
|
20
|
+
|
21
|
+
given_resource "config-with-key-expansion.yml", %{
|
22
|
+
var:
|
23
|
+
account_id: "123"
|
24
|
+
<(var.account_id)>: value
|
25
|
+
}
|
26
|
+
|
27
|
+
let(:config) { ConfigHound.load("config-with-key-expansion.yml", :expand_refs => true) }
|
28
|
+
|
29
|
+
it "expands key references" do
|
30
|
+
expect(config["123"]).to eq("value")
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with key and value expansion" do
|
36
|
+
|
37
|
+
given_resource "config-with-key-and-value-expansion.yml", %{
|
38
|
+
var:
|
39
|
+
account_id: "123"
|
40
|
+
port: 5678
|
41
|
+
<(var.account_id)>: host:<(var.port)>
|
42
|
+
}
|
43
|
+
let(:config) { ConfigHound.load("config-with-key-and-value-expansion.yml", :expand_refs => true) }
|
44
|
+
|
45
|
+
it "expands key references" do
|
46
|
+
expect(config["123"]).to eq("host:5678")
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
19
51
|
context "with overrides" do
|
20
52
|
|
21
53
|
given_resource "overrides.yml", %{
|
@@ -20,6 +20,18 @@ describe ConfigHound, "formats" do
|
|
20
20
|
)
|
21
21
|
end
|
22
22
|
|
23
|
+
given_resource "s3://s3-test-bucket/config.yml?versionId=123456", %{
|
24
|
+
foo: 1
|
25
|
+
bar: 2
|
26
|
+
}
|
27
|
+
|
28
|
+
it "loads YAML from s3 with version id" do
|
29
|
+
expect(load("s3://s3-test-bucket/config.yml?versionId=123456")).to eq(
|
30
|
+
"foo" => 1,
|
31
|
+
"bar" => 2
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
23
35
|
given_resource "config-with-aliases.yml", %{
|
24
36
|
foo: &foo
|
25
37
|
bar: 1
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require "open-uri"
|
2
|
+
require "uri"
|
3
|
+
|
1
4
|
module GivenResource
|
2
5
|
|
3
6
|
def inputs
|
@@ -10,7 +13,7 @@ module GivenResource
|
|
10
13
|
end
|
11
14
|
content = undent(content)
|
12
15
|
before do
|
13
|
-
|
16
|
+
allow(URI).to receive(:open).with(path) do |_, _, &block|
|
14
17
|
block.call(StringIO.new(content.dup))
|
15
18
|
end
|
16
19
|
end
|
@@ -31,6 +34,7 @@ module GivenResource
|
|
31
34
|
end
|
32
35
|
|
33
36
|
RSpec.configure do |config|
|
37
|
+
config.warnings = true
|
34
38
|
|
35
39
|
config.extend(GivenResource)
|
36
40
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: config_hound
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Williams
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dig_rb
|
@@ -30,38 +30,38 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.2'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
-
description:
|
54
|
+
version: '13.0'
|
55
|
+
description:
|
56
56
|
email:
|
57
57
|
- mdub@dogbiscuit.org
|
58
58
|
executables: []
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".github/workflows/test.yaml"
|
62
63
|
- ".gitignore"
|
63
64
|
- ".rspec"
|
64
|
-
- ".travis.yml"
|
65
65
|
- Gemfile
|
66
66
|
- LICENSE.txt
|
67
67
|
- README.md
|
@@ -87,7 +87,7 @@ homepage: https://github.com/mdub/config_hound
|
|
87
87
|
licenses:
|
88
88
|
- MIT
|
89
89
|
metadata: {}
|
90
|
-
post_install_message:
|
90
|
+
post_install_message:
|
91
91
|
rdoc_options: []
|
92
92
|
require_paths:
|
93
93
|
- lib
|
@@ -95,16 +95,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
95
|
requirements:
|
96
96
|
- - ">="
|
97
97
|
- !ruby/object:Gem::Version
|
98
|
-
version: '
|
98
|
+
version: '2.7'
|
99
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
|
-
|
106
|
-
|
107
|
-
signing_key:
|
105
|
+
rubygems_version: 3.3.7
|
106
|
+
signing_key:
|
108
107
|
specification_version: 4
|
109
108
|
summary: Sniffs out config, wherever it may be.
|
110
109
|
test_files:
|
data/.travis.yml
DELETED