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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8724bfa38843c122d4c3f0b0b711eb58c75dfe3b
4
- data.tar.gz: 4513614a55e3e89a05b601ae812ad7a3c2b7d12e
3
+ metadata.gz: 25d64e131590e9ad8c0422ffac256c7d58b96534
4
+ data.tar.gz: f8e4095b4f3697d0684387bc8d5d25d2f92451cf
5
5
  SHA512:
6
- metadata.gz: 5a9a06c82bdce804a8a49e1d424670c31e32c5516ba5a8ddeaa80aa08c96c566a03aab8bd2bbc7c1b7765dc34583cccf8585326c3c753d5ef76b17e6001aba41
7
- data.tar.gz: 26207cb67afa386675b265b0035e08c2560594e023ce5037cf6c9ee475823291086de66da9e9a12e0e97624fec04ddc57a77c47777e1c985e3cf588c8c6c92ef
6
+ metadata.gz: b0c560de6157c8454bc3b640460fe8edf408c1b188f416d99784e1f0b013713bb6527b76cc17edd4448c9e05d311a928b7ac21e9e51c572a5b834b3d9b0e3c81
7
+ data.tar.gz: 180058d0339579b553fd5ae8aa9d4ff82cfc49106afaf7ebd01c571fc69ff6a321ab206adc38ad07f2231ecd5785c919ccad6f0becab9d99c4c5d976c3156fc0
data/.travis.yml CHANGED
@@ -6,7 +6,7 @@ rvm:
6
6
  - 2.2.0
7
7
  - 2.2.3
8
8
  - 2.3.0
9
- - jruby-1.7.23
9
+ - jruby-9.0.5.0
10
10
  notifications:
11
11
  irc:
12
12
  - "irc.freenode.net#sensu"
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:
@@ -24,7 +24,11 @@ module Sensu
24
24
  @loader.load_directory(directory)
25
25
  end
26
26
  end
27
- @loader.set_env!
27
+ if @loader.validate.empty?
28
+ @loader.set_env!
29
+ end
30
+ @loader
31
+ rescue Loader::Error
28
32
  @loader
29
33
  end
30
34
 
@@ -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
- warning("config file must be valid json", {
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
- warning("config file does not exist or is not readable", :file => file)
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "sensu-settings"
5
- spec.version = "3.4.0"
5
+ spec.version = "4.0.0"
6
6
  spec.authors = ["Sean Porter"]
7
7
  spec.email = ["portertech@gmail.com"]
8
8
  spec.summary = "The Sensu settings library, loader and validator"
@@ -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
- @loader.load_file("/tmp/bananaphone")
110
- warnings = @loader.warnings
111
- expect(warnings.size).to eq(2)
112
- messages = warnings.map do |warning|
113
- warning[:message]
114
- end
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
- @loader.load_file(File.join(@assets_dir, "invalid.json"))
121
- warnings = @loader.warnings
122
- expect(warnings.size).to eq(3)
123
- messages = warnings.map do |warning|
124
- warning[:message]
125
- end
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
@@ -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: 3.4.0
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-22 00:00:00.000000000 Z
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.4.5.1
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: