sensu-settings 5.1.0 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sensu/settings.rb +1 -1
- data/lib/sensu/settings/loader.rb +7 -2
- data/sensu-settings.gemspec +1 -1
- data/spec/loader_spec.rb +8 -0
- data/spec/settings_spec.rb +10 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8924c88d3f2c09c838a8d63483dc5c5b43e4dfb
|
4
|
+
data.tar.gz: 6602361eb730baa005e103d0f916dc73c387febc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51c1f51bd223da49a9cf4221ae0504758841572628359d491dba61e5a091a77fbe51957f2aca71a4deb4a00c612982c485075a110239e6ecf5d8ebcd41166bc7
|
7
|
+
data.tar.gz: 343e7d524dc24d974007ee1bf190048084ab0005ed23ec1574bf801d31dc29f50083b62490f49991c80a0820c1ac54d2d68707278bbebd2ffefc17364032195e
|
data/lib/sensu/settings.rb
CHANGED
@@ -14,7 +14,7 @@ module Sensu
|
|
14
14
|
@loader = Loader.new
|
15
15
|
@loader.load_env
|
16
16
|
if options[:config_file]
|
17
|
-
@loader.load_file(options[:config_file])
|
17
|
+
@loader.load_file(options[:config_file], false)
|
18
18
|
end
|
19
19
|
if options[:config_dir]
|
20
20
|
@loader.load_directory(options[:config_dir])
|
@@ -99,7 +99,9 @@ module Sensu
|
|
99
99
|
# Load settings from a JSON file.
|
100
100
|
#
|
101
101
|
# @param [String] file path.
|
102
|
-
|
102
|
+
# @param must_exist [TrueClass, FalseClass] if the file must
|
103
|
+
# exist and is readable.
|
104
|
+
def load_file(file, must_exist=true)
|
103
105
|
if File.file?(file) && File.readable?(file)
|
104
106
|
begin
|
105
107
|
warning("loading config file", :file => file)
|
@@ -122,8 +124,11 @@ module Sensu
|
|
122
124
|
:error => error.to_s
|
123
125
|
})
|
124
126
|
end
|
125
|
-
|
127
|
+
elsif must_exist
|
126
128
|
load_error("config file does not exist or is not readable", :file => file)
|
129
|
+
else
|
130
|
+
warning("config file does not exist or is not readable", :file => file)
|
131
|
+
warning("ignoring config file", :file => file)
|
127
132
|
end
|
128
133
|
end
|
129
134
|
|
data/sensu-settings.gemspec
CHANGED
data/spec/loader_spec.rb
CHANGED
@@ -114,6 +114,14 @@ describe "Sensu::Settings::Loader" do
|
|
114
114
|
expect(error[:message]).to include("config file does not exist or is not readable")
|
115
115
|
end
|
116
116
|
|
117
|
+
it "can attempt to load settings from a nonexistent file and ignore it" do
|
118
|
+
@loader.load_file("/tmp/bananaphone", false)
|
119
|
+
expect(@loader.errors.length).to eq(0)
|
120
|
+
expect(@loader.warnings.length).to eq(2)
|
121
|
+
warning = @loader.warnings.last
|
122
|
+
expect(warning[:message]).to include("ignoring config file")
|
123
|
+
end
|
124
|
+
|
117
125
|
it "can attempt to load settings from a file with invalid JSON" do
|
118
126
|
expect {
|
119
127
|
@loader.load_file(File.join(@assets_dir, "invalid.json"))
|
data/spec/settings_spec.rb
CHANGED
@@ -51,9 +51,17 @@ describe "Sensu::Settings" do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it "can catch load errors" do
|
54
|
-
settings = Sensu::Settings.load(:config_file => "
|
54
|
+
settings = Sensu::Settings.load(:config_file => File.join(@assets_dir, "invalid.json"))
|
55
55
|
expect(settings.errors.length).to eq(1)
|
56
56
|
error = settings.errors.first
|
57
|
-
expect(error[:message]).to include("config file
|
57
|
+
expect(error[:message]).to include("config file must be valid json")
|
58
|
+
end
|
59
|
+
|
60
|
+
it "can handle a nonexistent config.json" do
|
61
|
+
settings = Sensu::Settings.load(:config_file => "/tmp/bananaphone")
|
62
|
+
expect(settings.errors.length).to eq(0)
|
63
|
+
expect(settings.warnings.length).to eq(2)
|
64
|
+
warning = settings.warnings.last
|
65
|
+
expect(warning[:message]).to include("ignoring config file")
|
58
66
|
end
|
59
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Porter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-json
|