portertech-sensu-json 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +20 -0
- data/README.md +33 -0
- data/lib/sensu/json/jrjackson.rb +24 -0
- data/lib/sensu/json/oj.rb +29 -0
- data/lib/sensu/json/parse_error.rb +23 -0
- data/lib/sensu/json.rb +49 -0
- data/sensu-json.gemspec +28 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2147c1e0964c8c057c190e70e6115b0687c028b1c4b63fe8df3cbe9881441faf
|
4
|
+
data.tar.gz: 57f0b64bef059e32657a2d85a46ef699ebdbb5a1c98074c148006da5aa0c3fd2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 79cc7b29577b0c8f2da691fc6e6e877bc1fa8198f4e8b52bf4dee86993d80b8bdf6c051c209e2c813233d487cfd3a317f99d5576b4f8b0af7303fb843efa21b1
|
7
|
+
data.tar.gz: 061bd6377d93b06937dba6d297bb7f44e84078361bf8e82dfbe916c36cec7491582a36e1145a2758b4d1ec1086d028b725bec3959bdefdffc390e65b7e84e0b1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 Heavy Water Operations, LLC.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Sensu::JSON
|
2
|
+
|
3
|
+
[](https://travis-ci.org/sensu/sensu-json)
|
4
|
+

|
5
|
+

|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'sensu-json'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
This library provides the Sensu JSON parser abstraction, enabling
|
20
|
+
the use of platform specific JSON parsers. Its documentation can be
|
21
|
+
found [here](http://rubydoc.info/github/sensu/sensu-json/Sensu/JSON).
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
Please do not submit a pull request to add features that Sensu does
|
26
|
+
not nor will not require.
|
27
|
+
|
28
|
+
0. By contributing to this project you agree to abide by the [code of conduct](https://sensuapp.org/conduct).
|
29
|
+
1. [Fork it](https://github.com/sensu/sensu-json/fork)
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create a new Pull Request
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "jrjackson"
|
2
|
+
|
3
|
+
module Sensu
|
4
|
+
module JSON
|
5
|
+
# The Sensu JSON parser when running on JRuby.
|
6
|
+
class JrJackson
|
7
|
+
# Load (and parse) a JSON string. Sensu expects symbolized keys.
|
8
|
+
#
|
9
|
+
# @param string [String]
|
10
|
+
# @return [Object]
|
11
|
+
def load(string)
|
12
|
+
::JrJackson::Json.load(string, :symbolize_keys => true, :raw => true)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Dump (generate) a JSON string from a Ruby object.
|
16
|
+
#
|
17
|
+
# @param object [Object]
|
18
|
+
# @param options [Hash]
|
19
|
+
def dump(object, options={})
|
20
|
+
::JrJackson::Json.dump(object, options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
gem "oj", "3.16.1"
|
2
|
+
|
3
|
+
require "oj"
|
4
|
+
|
5
|
+
Oj.default_options = {:mode => :compat}
|
6
|
+
|
7
|
+
module Sensu
|
8
|
+
module JSON
|
9
|
+
# The Sensu JSON parser when running on MRI.
|
10
|
+
class Oj
|
11
|
+
# Load (and parse) a JSON string. Sensu expects symbolized keys.
|
12
|
+
#
|
13
|
+
# @param string [String]
|
14
|
+
# @return [Object]
|
15
|
+
def load(string)
|
16
|
+
::Oj.load(string, :symbol_keys => true)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Dump (generate) a JSON string from a Ruby object.
|
20
|
+
#
|
21
|
+
# @param object [Object]
|
22
|
+
# @param options [Hash]
|
23
|
+
def dump(object, options={})
|
24
|
+
options.merge!(:indent => 2) if options[:pretty]
|
25
|
+
::Oj.dump(object, options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Sensu
|
2
|
+
module JSON
|
3
|
+
# The Sensu JSON parser error abstraction.
|
4
|
+
class ParseError < StandardError
|
5
|
+
attr_reader :data, :cause
|
6
|
+
|
7
|
+
# Produce an encapsulating error for a parser error, maintaining
|
8
|
+
# the backtrace.
|
9
|
+
#
|
10
|
+
# @param original_error [Object]
|
11
|
+
# @param data [Object] (such as a JSON string).
|
12
|
+
def self.build(original_error, data)
|
13
|
+
new(original_error.message).tap do |error|
|
14
|
+
error.instance_eval do
|
15
|
+
@cause = original_error
|
16
|
+
set_backtrace original_error.backtrace
|
17
|
+
@data = data
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/sensu/json.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require "sensu/json/parse_error"
|
2
|
+
|
3
|
+
# Sensu, monitoring for today's infrastructure.
|
4
|
+
module Sensu
|
5
|
+
# The Sensu JSON parser abstraction library.
|
6
|
+
module JSON
|
7
|
+
# The Sensu JSON parser abstraction API.
|
8
|
+
class << self
|
9
|
+
# Set up the JSON parser. This method must be called before any
|
10
|
+
# attempt to use the parser. This method is currently called at
|
11
|
+
# the bottom of this file. The appropriate JSON parser will be
|
12
|
+
# loaded for the current platform.
|
13
|
+
#
|
14
|
+
# @return [Object] parser.
|
15
|
+
def setup!
|
16
|
+
@@parser = case
|
17
|
+
when RUBY_PLATFORM =~ /java/
|
18
|
+
require "sensu/json/jrjackson"
|
19
|
+
Sensu::JSON::JrJackson.new
|
20
|
+
else
|
21
|
+
require "sensu/json/oj"
|
22
|
+
Sensu::JSON::Oj.new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Load (and parse) a JSON string.
|
27
|
+
#
|
28
|
+
# @param string [String]
|
29
|
+
# @return [Object]
|
30
|
+
def load(string)
|
31
|
+
begin
|
32
|
+
@@parser.load(string)
|
33
|
+
rescue => error
|
34
|
+
raise Sensu::JSON::ParseError.build(error, string)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Dump (generate) a JSON string from a Ruby object.
|
39
|
+
#
|
40
|
+
# @param object [Object]
|
41
|
+
# @param options [Hash]
|
42
|
+
def dump(object, options={})
|
43
|
+
@@parser.dump(object, options)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Sensu::JSON.setup!
|
data/sensu-json.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "portertech-sensu-json"
|
5
|
+
spec.version = "2.2.0"
|
6
|
+
spec.platform = RUBY_PLATFORM =~ /java/ ? Gem::Platform::JAVA : Gem::Platform::RUBY
|
7
|
+
spec.authors = ["Sean Porter"]
|
8
|
+
spec.email = ["portertech@gmail.com", "engineering@sensu.io"]
|
9
|
+
spec.summary = "The Sensu JSON parser abstraction library"
|
10
|
+
spec.description = "The Sensu JSON parser abstraction library"
|
11
|
+
spec.homepage = "https://github.com/sensu/sensu-json"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = Dir.glob("lib/**/*") + %w[sensu-json.gemspec README.md LICENSE.txt]
|
15
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
if RUBY_PLATFORM =~ /java/
|
20
|
+
spec.add_dependency("jrjackson", "0.4.0")
|
21
|
+
else
|
22
|
+
spec.add_dependency("oj", "3.16.1")
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 2.4"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "rspec"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: portertech-sensu-json
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Porter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-10-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oj
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.16.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.16.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: The Sensu JSON parser abstraction library
|
70
|
+
email:
|
71
|
+
- portertech@gmail.com
|
72
|
+
- engineering@sensu.io
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- LICENSE.txt
|
78
|
+
- README.md
|
79
|
+
- lib/sensu/json.rb
|
80
|
+
- lib/sensu/json/jrjackson.rb
|
81
|
+
- lib/sensu/json/oj.rb
|
82
|
+
- lib/sensu/json/parse_error.rb
|
83
|
+
- sensu-json.gemspec
|
84
|
+
homepage: https://github.com/sensu/sensu-json
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubygems_version: 3.4.10
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: The Sensu JSON parser abstraction library
|
107
|
+
test_files: []
|