exception_notification-squash_notifier 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c430db5ff29ad03510cbf68c9522c52fac229732
4
+ data.tar.gz: 2f4b0a4858cba1c1bad75cfb15c87cd1e4bfa20d
5
+ SHA512:
6
+ metadata.gz: 4f5093d0882cd1e6ca3d686b368e8f1844f81ff9c73547d6b1b0e87097075fa4638287b38dd692ec46db04b8060ae8116bfa5676a716c5f4b67eac3454d00697
7
+ data.tar.gz: 45c57a3fa5bd0169bf1e11c5e59bd120bc2dfd0a8f862199eafa10a1abdc71040c53aecca29753c15b85ef8b7c9b71f6feaecb63334751aca26ec5cf22ba9c27
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in exception-notifier-squash-notifier.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Powershop
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # ExceptionNotifier::SquashNotifier
2
+
3
+ This is a plugin for the ExceptionNotification gem to allow it to use the SquareSquash/ruby gem
4
+ for cpaturing and forwarding exceptions to SquareSquash/web server
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'exception-notifier-squash-notifier'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install exception-notifier-squash-notifer
21
+
22
+ ## Usage
23
+
24
+ Simply configure Squash client as normal (see SquareSquash/ruby gem for details).
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it ( https://github.com/powershop/exception-notifier-squash-notifier/fork )
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
data/TODO.org ADDED
@@ -0,0 +1,2 @@
1
+ * Tasks
2
+ * Checklist
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'exception_notifier/squash'
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'exception_notifier/squash_notifier/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "exception_notification-squash_notifier"
8
+ spec.version = ExceptionNotifier::SquashNotifier::VERSION
9
+ spec.authors = ["Will Robertson"]
10
+ spec.email = ["will.robertson@powershop.co.nz"]
11
+ spec.summary = %q{Exception Notifier plugin for Squash}
12
+ spec.description = %q{Plugin to use Squash with ExceptionNotification}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.2"
24
+ spec.add_development_dependency "pry-byebug", "~> 3.0"
25
+ spec.add_development_dependency "simplecov", "~> 0.9"
26
+ spec.add_development_dependency "exception_notification", "~> 4.0"
27
+
28
+ spec.add_dependency "activesupport", ">= 3.0.4"
29
+ spec.add_dependency "squash_ruby", "~> 2.0"
30
+ end
@@ -0,0 +1,5 @@
1
+ module ExceptionNotifier
2
+ class SquashNotifier
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,84 @@
1
+ require "exception_notifier/squash_notifier/version"
2
+
3
+ require "active_support/core_ext/module/attribute_accessors"
4
+ require "exception_notifier"
5
+
6
+ require "exception_notifier/squash_ruby"
7
+
8
+ module ExceptionNotifier
9
+ class SquashNotifier
10
+ @@whitelisted_env_vars = [
11
+ 'action_dispatch.request.parameters',
12
+ 'action_dispatch.request.path_parameters',
13
+ 'action_dispatch.request.query_parameters',
14
+ 'action_dispatch.request.request_parameters',
15
+ 'BUNDLE_BIN_PATH',
16
+ 'BUNDLE_GEMFILE',
17
+ 'CONTENT_LENGTH',
18
+ 'CONTENT_TYPE',
19
+ 'DOCUMENT_ROOT',
20
+ 'GEM_HOME',
21
+ 'HOME',
22
+ /HTTP_/,
23
+ 'ORIGINAL_FULLPATH',
24
+ 'PASSENGER_APP_TYPE',
25
+ 'PASSENGER_ENV',
26
+ 'PASSENGER_RUBY',
27
+ 'PASSENGER_SPAWN_METHOD',
28
+ 'PASSENGER_USER',
29
+ 'PATH',
30
+ 'PATH_INFO',
31
+ 'PWD',
32
+ 'RAILS_ENV',
33
+ 'REMOTE_ADDR',
34
+ 'REMOTE_PORT',
35
+ 'REQUEST_METHOD',
36
+ 'REQUEST_URI',
37
+ 'RUBYOPT',
38
+ 'SERVER_ADDR',
39
+ 'SERVER_NAME',
40
+ 'SERVER_PORT',
41
+ 'SERVER_PROTOCOL',
42
+ 'SERVER_SOFTWARE',
43
+ 'TMPDIR',
44
+ 'USER',
45
+ ]
46
+ cattr_accessor :whitelisted_env_vars
47
+
48
+ def self.default_options
49
+ {
50
+ filter_env_vars: self.whitelist_env_filter
51
+ }
52
+ end
53
+
54
+ def default_options
55
+ self.class.default_options
56
+ end
57
+
58
+ def self.whitelist_env_filter
59
+ # Remove any entries from the 'env' var that are not in the 'whitelisted_env_var' list
60
+ lambda do |env|
61
+ env.select do |key, val|
62
+ #NB: we want to close-over `self` so we can access the class var
63
+ #NB:
64
+ # - When `allowed` is a Regexp, === is like ((a =~ b) ? true : false)
65
+ # - When `allowed` is a String, === is like (a == b.to_str)
66
+ # - When `allowed` is a Symbol, === is (a == b)
67
+ self.whitelisted_env_vars.any? {|allowed| allowed === key }
68
+ end
69
+ end
70
+ end
71
+
72
+ #####
73
+
74
+ def initialize(options)
75
+ Squash::Ruby.configure default_options.merge(options)
76
+ Squash::Ruby.configure disabled: !Squash::Ruby.configuration(:api_key)
77
+ end
78
+
79
+ def call(exception, options={})
80
+ #NB: You can pass a `user_data` hash to #notify, and most attr's will be placed into a `user_data` field
81
+ Squash::Ruby.notify(exception, options)
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,25 @@
1
+ require "squash/ruby"
2
+
3
+ module Squash::Ruby
4
+
5
+ # You need to set a configuration :filter_env_vars and :filter_argv
6
+ # These are supposed to contain lambdas/procs that will filter the contents of these arrays before sending them up to the Squash server
7
+
8
+ class << self
9
+ private
10
+
11
+ alias :environment_data__original :environment_data
12
+
13
+ def environment_data
14
+ no_filtering = lambda {|val| val }
15
+ filter_env_vars = configuration(:filter_env_vars) || no_filtering
16
+ filter_argv = configuration(:filter_argv) || no_filtering
17
+
18
+ ev_orig = environment_data__original
19
+ ev_orig.merge({
20
+ 'env_vars' => filter_env_vars.call(ev_orig['env_vars']), # The original "valueifies" ENV for us
21
+ 'arguments' => filter_argv.call(ARGV).join(' ') # The original munges into a string, which is less-easy to filter
22
+ })
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.shared_context "squash_ruby" do
4
+ let(:squash_ruby) do
5
+ class_double("Squash::Ruby").
6
+ as_stubbed_const(:transfer_nested_constants => true)
7
+ end
8
+ end
9
+
10
+ describe ExceptionNotifier::SquashNotifier do
11
+ include_context "squash_ruby"
12
+
13
+ let(:squash_notifier) { ExceptionNotifier.registered_exception_notifier(:squash) }
14
+
15
+ describe "with a valid instance" do
16
+ before(:context) do
17
+ @squash_config_options = {
18
+ api_host: 'https://no-such-host.noncom',
19
+ api_key: '00000000-0000-0000-0000-000000000000',
20
+ environment: 'development'
21
+ }
22
+
23
+ env = ExceptionNotifier::SquashNotifier.whitelisted_env_vars.map do |k|
24
+ k = k.to_s.sub(/^(\(.*:)(.*)(\))$/, '\2') if k.is_a? Regexp
25
+ [k.to_s, "val #{k}"]
26
+ end
27
+ @captured_env_vars = Hash[env]
28
+ end
29
+
30
+ describe "created directly" do
31
+ it "can create a SquashNotifier from a const" do
32
+ expect(squash_ruby).to receive(:configure).with(
33
+ @squash_config_options.merge(filter_env_vars: duck_type(:call))
34
+ )
35
+ expect(squash_ruby).to receive(:configuration).with(:api_key).and_return(true)
36
+ expect(squash_ruby).to receive(:configure).with(disabled: false)
37
+ expect(ExceptionNotifier::SquashNotifier.new(@squash_config_options)).to be_an ExceptionNotifier::SquashNotifier
38
+ end
39
+
40
+ end
41
+
42
+ describe "created via ExceptionNotifier" do
43
+ around(:context) do |eg|
44
+ ExceptionNotification.configure {|c| c.add_notifier :squash, @squash_config_options }
45
+ eg.run
46
+ ExceptionNotification.configure {|c| c.unregister_exception_notifier :squash }
47
+ end
48
+ let(:squash_notifier) { ExceptionNotifier.registered_exception_notifier(:squash) }
49
+
50
+ #Time.stubs(:current).returns('Sat, 20 Apr 2013 20:58:55 UTC +00:00')
51
+
52
+ it "has a version number" do
53
+ expect(ExceptionNotifier::SquashNotifier::VERSION).not_to be_nil
54
+ end
55
+
56
+ it "notifies Squash of an exception" do
57
+ begin
58
+ 1/0
59
+ rescue => e
60
+ expect(squash_ruby).to receive(:notify).with(e, {})
61
+ ExceptionNotifier.notify_exception(e, {})
62
+ end
63
+ end
64
+
65
+ context "whitelisting" do
66
+ it "should be the same at class and instance level" do
67
+ #NB: Need to use #class_eval, as the underlying is dynamically extended
68
+ expect(squash_notifier.whitelisted_env_vars).to eq(ExceptionNotifier::SquashNotifier.class_eval { self.whitelisted_env_vars })
69
+ end
70
+
71
+ context "with faked ENV" do
72
+ around do |eg|
73
+ ENV["NOSUCHVAR"] = "Test"
74
+ eg.run
75
+ ENV.delete("NOSUCHVAR")
76
+ end
77
+
78
+ it do
79
+ expect(Squash::Ruby.class_eval { environment_data['env_vars'] }).to include("HOME" => String)
80
+ end
81
+
82
+ it do
83
+ expect(Squash::Ruby.class_eval { environment_data['env_vars'] }).not_to include("NOSUCHVAR" => "Test")
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ describe "with Squash unregistered" do
91
+ it "should note find a Squash notifier" do
92
+ expect(squash_notifier).to be_nil
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Squash::Ruby do
4
+ describe "with a valid instance" do
5
+ context "with a key-replacement env-var filter" do
6
+ around(:all) do |eg|
7
+ @key_prefix = '@@ '
8
+ @val_prefix = '== '
9
+ filter_env_vars = lambda do |env_vars|
10
+ Hash[env_vars.map {|h, v| [@key_prefix + h.to_s, @val_prefix + v.to_s] }]
11
+ end
12
+
13
+ Squash::Ruby.configure(filter_env_vars: filter_env_vars)
14
+ eg.run
15
+ Squash::Ruby.configure(filter_env_vars: nil)
16
+ end
17
+
18
+ it "should return prefaced keys and val's for ENV" do
19
+ Squash::Ruby.class_eval { environment_data['env_vars'] }.each do |k, v|
20
+ expect(k).to match(/^#{@key_prefix}/),
21
+ "expected ENV[#{k}].key to start with #{@key_prefix.inspect}"
22
+ expect(v).to match(/^#{@val_prefix}/),
23
+ "expected ENV[#{k}].val to start with #{@val_prefix.inspect}"
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,13 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter "/.bundle/"
4
+ end
5
+
6
+ require 'pry'
7
+
8
+ #####
9
+
10
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
11
+
12
+ require 'exception_notification'
13
+ require 'exception_notifier/squash_notifier'
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exception_notification-squash_notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Will Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: exception_notification
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: activesupport
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.4
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.4
111
+ - !ruby/object:Gem::Dependency
112
+ name: squash_ruby
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.0'
125
+ description: Plugin to use Squash with ExceptionNotification
126
+ email:
127
+ - will.robertson@powershop.co.nz
128
+ executables:
129
+ - exception-notifier-squash-notifier
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - TODO.org
140
+ - bin/exception-notifier-squash-notifier
141
+ - exception-notification-squash-notifier.gemspec
142
+ - lib/exception_notifier/squash_notifier.rb
143
+ - lib/exception_notifier/squash_notifier/version.rb
144
+ - lib/exception_notifier/squash_ruby.rb
145
+ - spec/exception_notifier/squash_notifier_spec.rb
146
+ - spec/exception_notifier/squash_ruby_spec.rb
147
+ - spec/spec_helper.rb
148
+ homepage: ''
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.4.5
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: Exception Notifier plugin for Squash
172
+ test_files:
173
+ - spec/exception_notifier/squash_notifier_spec.rb
174
+ - spec/exception_notifier/squash_ruby_spec.rb
175
+ - spec/spec_helper.rb
176
+ has_rdoc: