sensu-settings 3.4.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +0 -3
- data/lib/sensu/settings.rb +5 -1
- data/lib/sensu/settings/loader.rb +21 -5
- data/sensu-settings.gemspec +1 -1
- data/spec/assets/alternative/conf.d/loop +1 -0
- data/spec/assets/conf.d/alternative +1 -0
- data/spec/loader_spec.rb +12 -17
- data/spec/settings_spec.rb +7 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25d64e131590e9ad8c0422ffac256c7d58b96534
|
4
|
+
data.tar.gz: f8e4095b4f3697d0684387bc8d5d25d2f92451cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0c560de6157c8454bc3b640460fe8edf408c1b188f416d99784e1f0b013713bb6527b76cc17edd4448c9e05d311a928b7ac21e9e51c572a5b834b3d9b0e3c81
|
7
|
+
data.tar.gz: 180058d0339579b553fd5ae8aa9d4ff82cfc49106afaf7ebd01c571fc69ff6a321ab206adc38ad07f2231ecd5785c919ccad6f0becab9d99c4c5d976c3156fc0
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,9 +2,6 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/sensu/sensu-settings.svg?branch=master)](https://travis-ci.org/sensu/sensu-settings)
|
4
4
|
|
5
|
-
[![Code Climate](https://codeclimate.com/github/sensu/sensu-settings.png)](https://codeclimate.com/github/sensu/sensu-settings)
|
6
|
-
[![Code Climate Coverage](https://codeclimate.com/github/sensu/sensu-settings/coverage.png)](https://codeclimate.com/github/sensu/sensu-settings)
|
7
|
-
|
8
5
|
## Installation
|
9
6
|
|
10
7
|
Add this line to your application's Gemfile:
|
data/lib/sensu/settings.rb
CHANGED
@@ -6,16 +6,23 @@ require "socket"
|
|
6
6
|
module Sensu
|
7
7
|
module Settings
|
8
8
|
class Loader
|
9
|
+
class Error < RuntimeError; end
|
10
|
+
|
9
11
|
# @!attribute [r] warnings
|
10
12
|
# @return [Array] loader warnings.
|
11
13
|
attr_reader :warnings
|
12
14
|
|
15
|
+
# @!attribute [r] errors
|
16
|
+
# @return [Array] loader errors.
|
17
|
+
attr_reader :errors
|
18
|
+
|
13
19
|
# @!attribute [r] loaded_files
|
14
20
|
# @return [Array] loaded config files.
|
15
21
|
attr_reader :loaded_files
|
16
22
|
|
17
23
|
def initialize
|
18
24
|
@warnings = []
|
25
|
+
@errors = []
|
19
26
|
@settings = default_settings
|
20
27
|
@indifferent_access = false
|
21
28
|
@loaded_files = []
|
@@ -105,15 +112,13 @@ module Sensu
|
|
105
112
|
@indifferent_access = false
|
106
113
|
@loaded_files << file
|
107
114
|
rescue Sensu::JSON::ParseError => error
|
108
|
-
|
115
|
+
load_error("config file must be valid json", {
|
109
116
|
:file => file,
|
110
117
|
:error => error.to_s
|
111
118
|
})
|
112
|
-
warning("ignoring config file", :file => file)
|
113
119
|
end
|
114
120
|
else
|
115
|
-
|
116
|
-
warning("ignoring config file", :file => file)
|
121
|
+
load_error("config file does not exist or is not readable", :file => file)
|
117
122
|
end
|
118
123
|
end
|
119
124
|
|
@@ -145,7 +150,7 @@ module Sensu
|
|
145
150
|
# @return [Array] validation failures.
|
146
151
|
def validate
|
147
152
|
validator = Validator.new
|
148
|
-
validator.run(@settings, sensu_service_name)
|
153
|
+
@errors += validator.run(@settings, sensu_service_name)
|
149
154
|
end
|
150
155
|
|
151
156
|
private
|
@@ -367,6 +372,17 @@ module Sensu
|
|
367
372
|
:message => message
|
368
373
|
}.merge(data)
|
369
374
|
end
|
375
|
+
|
376
|
+
# Record a load error and raise a load error exception.
|
377
|
+
#
|
378
|
+
# @param message [String] load error message.
|
379
|
+
# @param data [Hash] load error context.
|
380
|
+
def load_error(message, data={})
|
381
|
+
@errors << {
|
382
|
+
:message => message
|
383
|
+
}.merge(data)
|
384
|
+
raise(Error, message)
|
385
|
+
end
|
370
386
|
end
|
371
387
|
end
|
372
388
|
end
|
data/sensu-settings.gemspec
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
../conf.d
|
@@ -0,0 +1 @@
|
|
1
|
+
../alternative/conf.d/
|
data/spec/loader_spec.rb
CHANGED
@@ -106,26 +106,21 @@ describe "Sensu::Settings::Loader" do
|
|
106
106
|
end
|
107
107
|
|
108
108
|
it "can attempt to load settings from a nonexistent file" do
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
expect(messages).to include("config file does not exist or is not readable")
|
116
|
-
expect(messages).to include("ignoring config file")
|
109
|
+
expect {
|
110
|
+
@loader.load_file("/tmp/bananaphone")
|
111
|
+
}.to raise_error(Sensu::Settings::Loader::Error)
|
112
|
+
expect(@loader.errors.length).to eq(1)
|
113
|
+
error = @loader.errors.first
|
114
|
+
expect(error[:message]).to include("config file does not exist or is not readable")
|
117
115
|
end
|
118
116
|
|
119
117
|
it "can attempt to load settings from a file with invalid JSON" do
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
expect(messages).to include("loading config file")
|
127
|
-
expect(messages).to include("config file must be valid json")
|
128
|
-
expect(messages).to include("ignoring config file")
|
118
|
+
expect {
|
119
|
+
@loader.load_file(File.join(@assets_dir, "invalid.json"))
|
120
|
+
}.to raise_error(Sensu::Settings::Loader::Error)
|
121
|
+
expect(@loader.errors.length).to eq(1)
|
122
|
+
error = @loader.errors.first
|
123
|
+
expect(error[:message]).to include("config file must be valid json")
|
129
124
|
end
|
130
125
|
|
131
126
|
it "can load settings from a utf-8 encoded file with a bom" do
|
data/spec/settings_spec.rb
CHANGED
@@ -49,4 +49,11 @@ describe "Sensu::Settings" do
|
|
49
49
|
expect(settings[:checks][:merger][:command]).to eq("echo -n merger")
|
50
50
|
expect(settings[:checks][:app_http_endpoint][:command]).to eq("check-http.rb -u https://localhost/ping -q pong")
|
51
51
|
end
|
52
|
+
|
53
|
+
it "can catch load errors" do
|
54
|
+
settings = Sensu::Settings.load(:config_file => "/tmp/bananaphone")
|
55
|
+
expect(settings.errors.length).to eq(1)
|
56
|
+
error = settings.errors.first
|
57
|
+
expect(error[:message]).to include("config file does not exist or is not readable")
|
58
|
+
end
|
52
59
|
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:
|
4
|
+
version: 4.0.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-03
|
11
|
+
date: 2016-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-json
|
@@ -108,9 +108,11 @@ files:
|
|
108
108
|
- lib/sensu/settings/validators/subdue.rb
|
109
109
|
- lib/sensu/settings/validators/transport.rb
|
110
110
|
- sensu-settings.gemspec
|
111
|
+
- spec/assets/alternative/conf.d/loop
|
111
112
|
- spec/assets/alternative/conf.d/symlinked.json
|
112
113
|
- spec/assets/app/config/sensu/app_http_endpoint.json
|
113
114
|
- spec/assets/bom.json
|
115
|
+
- spec/assets/conf.d/alternative
|
114
116
|
- spec/assets/conf.d/merger.json
|
115
117
|
- spec/assets/conf.d/nested/file.json
|
116
118
|
- spec/assets/config.json
|
@@ -140,14 +142,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
142
|
version: '0'
|
141
143
|
requirements: []
|
142
144
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.
|
145
|
+
rubygems_version: 2.6.3
|
144
146
|
signing_key:
|
145
147
|
specification_version: 4
|
146
148
|
summary: The Sensu settings library, loader and validator
|
147
149
|
test_files:
|
150
|
+
- spec/assets/alternative/conf.d/loop
|
148
151
|
- spec/assets/alternative/conf.d/symlinked.json
|
149
152
|
- spec/assets/app/config/sensu/app_http_endpoint.json
|
150
153
|
- spec/assets/bom.json
|
154
|
+
- spec/assets/conf.d/alternative
|
151
155
|
- spec/assets/conf.d/merger.json
|
152
156
|
- spec/assets/conf.d/nested/file.json
|
153
157
|
- spec/assets/config.json
|
@@ -157,4 +161,3 @@ test_files:
|
|
157
161
|
- spec/rules_spec.rb
|
158
162
|
- spec/settings_spec.rb
|
159
163
|
- spec/validator_spec.rb
|
160
|
-
has_rdoc:
|