sensu-settings 1.6.0 → 1.7.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: 54d0111bccce26545cf3c41ed61ec4fbfd550ce4
4
- data.tar.gz: 5453d340333900902d7eab3fedae5438aa4b1718
3
+ metadata.gz: 1fdb6232d33121ec1fedbb3f3c8426371a89111b
4
+ data.tar.gz: 9b9d6896325f9f58982b25995d781cdcf5200fc8
5
5
  SHA512:
6
- metadata.gz: 22eeed17690307c1335e314fa8a69ef727c4685a4a6a5c0e12ee2c6c5aa868f5481d5ec2dc678e64db99c0475751fa064e4d97c5e276b3afa37adc75f0503080
7
- data.tar.gz: 7e89473c1889695fb5c238e73e0fc57026b4025291a7cc1932731b9e9485f3838687640011f23cb2b22b9cb85c67a4e9b33e19eb68e1a733b5ffa89e4dde9bb7
6
+ metadata.gz: 772d0f3421965e774bd7f2c33e56e081de4e1ba2592bbb7e8b4aad45b3d0601378b38cb76ae09148b3e7c6599d78efa58025113a2c9e925493d16c7487a86031
7
+ data.tar.gz: 501534272b7fc5c0a0c70634e1f6fdac842931fb4198b35cee587b120c61bd1d45b76e1ec59692af215f6bca5efd35dc58fb084b74ebbc370e6efcb2300aa82d
@@ -86,7 +86,7 @@ module Sensu
86
86
  if File.file?(file) && File.readable?(file)
87
87
  begin
88
88
  warning("loading config file", :file => file)
89
- contents = IO.read(file)
89
+ contents = read_config_file(file)
90
90
  config = MultiJson.load(contents, :symbolize_keys => true)
91
91
  merged = deep_merge(@settings, config)
92
92
  unless @loaded_files.empty?
@@ -190,10 +190,32 @@ module Sensu
190
190
  @indifferent_access = true
191
191
  end
192
192
 
193
+ # Read a configuration file and force its encoding to 8-bit
194
+ # ASCII, ignoring invalid characters. If there is a UTF-8 BOM,
195
+ # it will be removed. Some JSON parsers force ASCII but do not
196
+ # remove the UTF-8 BOM if present, causing encoding conversion
197
+ # errors. This method is for consistency across MultiJson
198
+ # adapters and system platforms.
199
+ #
200
+ # @param [String] file path to read.
201
+ # @return [String] file contents.
202
+ def read_config_file(file)
203
+ contents = IO.read(file)
204
+ if contents.respond_to?(:force_encoding)
205
+ encoding = ::Encoding::ASCII_8BIT
206
+ contents = contents.force_encoding(encoding)
207
+ contents.sub!("\xEF\xBB\xBF".force_encoding(encoding), "")
208
+ else
209
+ contents.sub!(/^\357\273\277/, "")
210
+ end
211
+ contents
212
+ end
213
+
193
214
  # Deep merge two hashes.
194
215
  #
195
216
  # @param [Hash] hash_one to serve as base.
196
217
  # @param [Hash] hash_two to merge in.
218
+ # @return [Hash] deep merged hash.
197
219
  def deep_merge(hash_one, hash_two)
198
220
  merged = hash_one.dup
199
221
  hash_two.each do |key, value|
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "sensu-settings"
5
- spec.version = "1.6.0"
5
+ spec.version = "1.7.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,7 @@
1
+ {
2
+ "client": {
3
+ "name": "bom",
4
+ "address": "utf-8",
5
+ "subscriptions": ["encoding"]
6
+ }
7
+ }
data/spec/loader_spec.rb CHANGED
@@ -97,6 +97,14 @@ describe "Sensu::Settings::Loader" do
97
97
  expect(messages).to include("ignoring config file")
98
98
  end
99
99
 
100
+ it "can load settings from a utf-8 encoded file with a bom" do
101
+ @loader.load_file(File.join(@assets_dir, "bom.json"))
102
+ warnings = @loader.warnings
103
+ failures = @loader.validate
104
+ expect(warnings.size).to eq(1)
105
+ expect(failures.size).to eq(0)
106
+ end
107
+
100
108
  it "can load settings from files in a directory" do
101
109
  @loader.load_directory(@config_dir)
102
110
  warnings = @loader.warnings
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: 1.6.0
4
+ version: 1.7.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: 2015-04-22 00:00:00.000000000 Z
11
+ date: 2015-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -109,6 +109,7 @@ files:
109
109
  - lib/sensu/settings/validators/transport.rb
110
110
  - sensu-settings.gemspec
111
111
  - spec/assets/app/config/sensu/app_http_endpoint.json
112
+ - spec/assets/bom.json
112
113
  - spec/assets/conf.d/merger.json
113
114
  - spec/assets/conf.d/nested/file.json
114
115
  - spec/assets/config.json
@@ -144,6 +145,7 @@ specification_version: 4
144
145
  summary: The Sensu settings library, loader and validator
145
146
  test_files:
146
147
  - spec/assets/app/config/sensu/app_http_endpoint.json
148
+ - spec/assets/bom.json
147
149
  - spec/assets/conf.d/merger.json
148
150
  - spec/assets/conf.d/nested/file.json
149
151
  - spec/assets/config.json