tripwire_notifier 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +33 -20
- data/Rakefile +3 -3
- data/lib/tripwire_notifier/configuration.rb +5 -1
- data/lib/tripwire_notifier/rails/action_controller_monitor.rb +5 -17
- data/lib/tripwire_notifier/sender.rb +43 -0
- data/lib/tripwire_notifier/version.rb +1 -1
- data/lib/tripwire_notifier.rb +17 -3
- data/test/sender_test.rb +75 -0
- data/test/{test_tripwire.rb → tripwire_test.rb} +10 -7
- data/tripwire_notifier.gemspec +8 -5
- metadata +10 -7
data/README.rdoc
CHANGED
@@ -4,33 +4,42 @@ Stop hurting your users!
|
|
4
4
|
|
5
5
|
Tripwire captures validation errors from your Ruby on Rails application to help you identify and fix user experience issues. The TripwireNotifier gem makes it easy to hook up your app to the Tripwire web service.
|
6
6
|
|
7
|
-
If you haven't already signed up for a Tripwire account
|
7
|
+
If you haven't already signed up for a Tripwire account, visit http://tripwireapp.com.
|
8
8
|
|
9
9
|
|
10
|
-
=
|
10
|
+
= Installation
|
11
|
+
|
12
|
+
=== Rails 3
|
13
|
+
|
14
|
+
* Add the following line to Gemfile:
|
15
|
+
|
16
|
+
gem 'tripwire_notifier'
|
11
17
|
|
12
18
|
* Install the gem:
|
13
19
|
|
14
|
-
|
20
|
+
bundle install
|
15
21
|
|
16
|
-
|
22
|
+
=== Rails 2.3
|
23
|
+
|
24
|
+
* Add the following line to config/environment.rb:
|
17
25
|
|
18
26
|
config.gem 'tripwire_notifier'
|
19
27
|
|
20
|
-
*
|
28
|
+
* Install the gem:
|
29
|
+
|
30
|
+
[sudo] rake gems:install GEM=tripwire_notifier
|
21
31
|
|
22
|
-
|
32
|
+
= Configuration
|
23
33
|
|
24
|
-
|
34
|
+
In your Rails app, create config/initializers/tripwire_notifier.rb and add the following line with the API key for your Tripwire project:
|
25
35
|
|
26
36
|
TripwireNotifier.configure do |config|
|
27
37
|
config.api_key = "<YOUR API KEY>"
|
28
38
|
end
|
29
39
|
|
30
|
-
|
31
|
-
|
40
|
+
Validation errors will now be submitted to the Tripwire service on your create and update actions in production mode.
|
32
41
|
|
33
|
-
=
|
42
|
+
= Advanced Usage
|
34
43
|
|
35
44
|
=== Tracking custom actions
|
36
45
|
|
@@ -38,23 +47,27 @@ TripwireNotifier assumes your app is RESTful, so it only monitors the create and
|
|
38
47
|
|
39
48
|
after_filter :log_validation_failures_to_tripwire, :only => [:create, :update, :my_custom_action]
|
40
49
|
|
41
|
-
===
|
50
|
+
=== Running in other environments
|
42
51
|
|
43
|
-
TripwireNotifier
|
52
|
+
TripwireNotifier is only enabled in the production environment by default. If you want to enable it in additional environments, such as staging, you'll need to add the following line to your Tripwire initializer:
|
44
53
|
|
45
|
-
|
46
|
-
filter_parameter_logging :password, :secret
|
54
|
+
config.monitored_environments << 'staging'
|
47
55
|
|
48
|
-
|
56
|
+
=== SSL
|
49
57
|
|
50
|
-
|
58
|
+
TripwireNotifier does not use SSL by default, but you can enable it easily:
|
51
59
|
|
52
|
-
|
60
|
+
config.secure = true
|
53
61
|
|
54
|
-
|
62
|
+
=== Filtering params
|
63
|
+
|
64
|
+
TripwireNotifier records the parameters submitted in actions that cause validation errors. Because your app may handle sensitive data, like passwords, credit card numbers, and nuclear launch codes, TripwireNotifier respects the built-in Rails parameter filtering that you enable with filter_parameter_logging in your ApplicationController. For example:
|
65
|
+
|
66
|
+
# Scrub sensitive parameters from your log
|
67
|
+
filter_parameter_logging :password, :secret
|
55
68
|
|
69
|
+
Per Rails convention, those params will show up as "[FILTERED]" in the data submitted to Tripwire.
|
56
70
|
|
57
|
-
We plan to streamline the setup process in the future and provide additional detailed configuration options and documentation. Please feel free to contact us with feedback, questions, or suggestions about this process. Thanks!
|
58
71
|
|
59
72
|
== Contact information
|
60
73
|
|
@@ -68,7 +81,7 @@ We plan to streamline the setup process in the future and provide additional det
|
|
68
81
|
* Make your feature addition or bug fix.
|
69
82
|
* Add tests for it. This is important so I don't break it in a
|
70
83
|
future version unintentionally.
|
71
|
-
* Commit, do not mess with
|
84
|
+
* Commit, do not mess with Rakefile, version, or history.
|
72
85
|
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
73
86
|
* Send me a pull request. Bonus points for topic branches.
|
74
87
|
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ begin
|
|
9
9
|
gem.name = "tripwire_notifier"
|
10
10
|
gem.summary = %Q{Tripwire (http://tripwireapp.com) captures validation errors from your Ruby on Rails application.}
|
11
11
|
gem.description = %Q{Tripwire captures validation errors from your Ruby on Rails application to help you identify and fix user experience issues. The TripwireNotifier gem makes it easy to hook up your app to the Tripwire web service.}
|
12
|
-
gem.email = ""
|
12
|
+
gem.email = "support@tripwireapp.com"
|
13
13
|
gem.homepage = "http://github.com/jeremyw/tripwire_notifier"
|
14
14
|
gem.authors = ["Jeffrey Chupp", "Jeremy Weiskotten"]
|
15
15
|
gem.add_development_dependency "shoulda", ">= 0"
|
@@ -23,7 +23,7 @@ end
|
|
23
23
|
require 'rake/testtask'
|
24
24
|
Rake::TestTask.new(:test) do |test|
|
25
25
|
test.libs << 'lib' << 'test'
|
26
|
-
test.pattern = 'test
|
26
|
+
test.pattern = 'test/**/*_test.rb'
|
27
27
|
test.verbose = true
|
28
28
|
end
|
29
29
|
|
@@ -31,7 +31,7 @@ begin
|
|
31
31
|
require 'rcov/rcovtask'
|
32
32
|
Rcov::RcovTask.new do |test|
|
33
33
|
test.libs << 'test'
|
34
|
-
test.pattern = 'test
|
34
|
+
test.pattern = 'test/**/*_test.rb'
|
35
35
|
test.verbose = true
|
36
36
|
end
|
37
37
|
rescue LoadError
|
@@ -1,14 +1,18 @@
|
|
1
1
|
module TripwireNotifier
|
2
2
|
class Configuration
|
3
|
-
|
3
|
+
attr_reader :notifier_version
|
4
4
|
attr_accessor :api_key
|
5
5
|
attr_accessor :monitored_environments
|
6
6
|
attr_accessor :timeout_in_seconds
|
7
|
+
attr_accessor :secure
|
8
|
+
|
9
|
+
alias_method :secure?, :secure
|
7
10
|
|
8
11
|
def initialize
|
9
12
|
@notifier_version = VERSION
|
10
13
|
@timeout_in_seconds = 5
|
11
14
|
@monitored_environments = ['production']
|
15
|
+
@secure = false
|
12
16
|
end
|
13
17
|
end
|
14
18
|
end
|
@@ -11,16 +11,7 @@ module TripwireNotifier
|
|
11
11
|
|
12
12
|
def log_validation_failures_to_tripwire
|
13
13
|
if should_log_failures_to_tripwire? && records_with_errors.present?
|
14
|
-
|
15
|
-
timeout(TripwireNotifier.configuration.timeout_in_seconds) do
|
16
|
-
Net::HTTP.post_form(
|
17
|
-
URI.parse(TripwireNotifier::API_URL),
|
18
|
-
tripwire_params
|
19
|
-
)
|
20
|
-
end
|
21
|
-
rescue Exception => ex
|
22
|
-
warn "Could not submit tripwireapp notification: #{ex.class} - #{ex.message}"
|
23
|
-
end
|
14
|
+
TripwireNotifier.notify(tripwire_params)
|
24
15
|
end
|
25
16
|
end
|
26
17
|
|
@@ -47,13 +38,10 @@ module TripwireNotifier
|
|
47
38
|
|
48
39
|
def tripwire_params
|
49
40
|
{}.tap do |query|
|
50
|
-
query[:
|
51
|
-
query[:
|
52
|
-
query[:
|
53
|
-
query[:
|
54
|
-
query[:_action] = params['action']
|
55
|
-
query[:path] = request.path
|
56
|
-
query[:data] = request_data.to_json
|
41
|
+
query[:_controller] = params['controller']
|
42
|
+
query[:_action] = params['action']
|
43
|
+
query[:path] = request.path
|
44
|
+
query[:data] = request_data.to_json
|
57
45
|
|
58
46
|
query[:failures] = records_with_errors.map do |record|
|
59
47
|
error_hashes(record)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module TripwireNotifier
|
2
|
+
class Sender
|
3
|
+
attr_reader :configuration
|
4
|
+
|
5
|
+
def initialize(configuration)
|
6
|
+
@configuration = configuration
|
7
|
+
end
|
8
|
+
|
9
|
+
def protocol
|
10
|
+
self.configuration.secure? ? 'https' : 'http'
|
11
|
+
end
|
12
|
+
|
13
|
+
def port
|
14
|
+
self.configuration.secure? ? 443 : 80
|
15
|
+
end
|
16
|
+
|
17
|
+
def host
|
18
|
+
'api.tripwireapp.com'
|
19
|
+
end
|
20
|
+
|
21
|
+
def uri
|
22
|
+
URI.parse("#{protocol}://#{host}:#{port}").merge('/')
|
23
|
+
end
|
24
|
+
|
25
|
+
def send_to_tripwire(data)
|
26
|
+
uri = self.uri
|
27
|
+
|
28
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
29
|
+
http.open_timeout = self.configuration.timeout_in_seconds
|
30
|
+
http.use_ssl = self.configuration.secure?
|
31
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
32
|
+
|
33
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
34
|
+
request.set_form_data(data)
|
35
|
+
|
36
|
+
begin
|
37
|
+
response = http.request(request)
|
38
|
+
rescue Exception => ex
|
39
|
+
warn "Could not submit tripwireapp notification: #{ex.class} - #{ex.message}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/tripwire_notifier.rb
CHANGED
@@ -1,20 +1,34 @@
|
|
1
1
|
require 'net/http'
|
2
|
+
require 'net/https'
|
2
3
|
require 'uri'
|
3
|
-
require 'timeout'
|
4
4
|
require 'tripwire_notifier/version'
|
5
5
|
require 'tripwire_notifier/configuration'
|
6
|
+
require 'tripwire_notifier/sender'
|
6
7
|
require 'tripwire_notifier/rails/action_controller_monitor'
|
7
8
|
|
8
9
|
module TripwireNotifier
|
9
10
|
API_VERSION = "alpha 1"
|
10
|
-
API_URL = 'http://api.tripwireapp.com/'
|
11
11
|
|
12
12
|
class << self
|
13
13
|
attr_accessor :configuration
|
14
|
+
attr_accessor :sender
|
14
15
|
|
15
16
|
def configure
|
16
17
|
self.configuration ||= Configuration.new
|
17
|
-
yield(configuration)
|
18
|
+
yield(self.configuration)
|
19
|
+
self.sender = Sender.new(self.configuration)
|
20
|
+
end
|
21
|
+
|
22
|
+
def notify(data)
|
23
|
+
self.sender.send_to_tripwire(data.merge(notifier_params))
|
24
|
+
end
|
25
|
+
|
26
|
+
def notifier_params
|
27
|
+
{}.tap do |params|
|
28
|
+
params[:notifier_version] = self.configuration.notifier_version
|
29
|
+
params[:api_key] = self.configuration.api_key
|
30
|
+
params[:api_version] = API_VERSION
|
31
|
+
end
|
18
32
|
end
|
19
33
|
end
|
20
34
|
end
|
data/test/sender_test.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class SenderTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
TripwireNotifier.configure do |c|
|
6
|
+
c.api_key = 'API_KEY'
|
7
|
+
end
|
8
|
+
@sender = TripwireNotifier::Sender.new(TripwireNotifier.configuration)
|
9
|
+
end
|
10
|
+
|
11
|
+
context "initialize" do
|
12
|
+
should "set configuration" do
|
13
|
+
assert_same TripwireNotifier.configuration, @sender.configuration
|
14
|
+
assert_equal 'API_KEY', @sender.configuration.api_key
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when not configured to be secure" do
|
19
|
+
setup do
|
20
|
+
TripwireNotifier.configuration.secure = false
|
21
|
+
end
|
22
|
+
|
23
|
+
should "return 'http' for #protocol" do
|
24
|
+
assert_equal 'http', @sender.protocol
|
25
|
+
end
|
26
|
+
|
27
|
+
should "return 80 for #port" do
|
28
|
+
assert_equal 80, @sender.port
|
29
|
+
end
|
30
|
+
|
31
|
+
should "post data without ssl on insecure port" do
|
32
|
+
assert_sends_to_tripwire(false, 80)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when configured to be secure" do
|
37
|
+
setup do
|
38
|
+
TripwireNotifier.configuration.secure = true
|
39
|
+
end
|
40
|
+
|
41
|
+
should "return 'https' for protocol" do
|
42
|
+
assert_equal 'https', @sender.protocol
|
43
|
+
end
|
44
|
+
|
45
|
+
should "return 443 for #port" do
|
46
|
+
assert_equal 443, @sender.port
|
47
|
+
end
|
48
|
+
|
49
|
+
should "post data with ssl on secure port" do
|
50
|
+
assert_sends_to_tripwire(true, 443)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
should "return api.tripwireapp.com for #host" do
|
55
|
+
assert_equal 'api.tripwireapp.com', @sender.host
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def assert_sends_to_tripwire(use_ssl, port)
|
60
|
+
data = {:key => :value}
|
61
|
+
|
62
|
+
mock_request = mock()
|
63
|
+
mock_request.expects(:set_form_data).with(data)
|
64
|
+
Net::HTTP::Post.stubs(:new => mock_request)
|
65
|
+
|
66
|
+
mock_http = mock()
|
67
|
+
mock_http.expects(:open_timeout=)
|
68
|
+
mock_http.expects(:use_ssl=).with(use_ssl)
|
69
|
+
mock_http.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
|
70
|
+
mock_http.expects(:request).with(mock_request)
|
71
|
+
Net::HTTP.stubs(:new => mock_http)
|
72
|
+
|
73
|
+
@sender.send_to_tripwire(data)
|
74
|
+
end
|
75
|
+
end
|
@@ -17,7 +17,7 @@ class TestTripwire < Test::Unit::TestCase
|
|
17
17
|
|
18
18
|
@foo_controller = fake_controller(FooController)
|
19
19
|
|
20
|
-
FakeWeb.register_uri(:post,
|
20
|
+
FakeWeb.register_uri(:post, 'http://api.tripwireapp.com', :body => "")
|
21
21
|
|
22
22
|
TripwireNotifier.configure do |config|
|
23
23
|
config.api_key = "SOME API KEY"
|
@@ -40,6 +40,11 @@ class TestTripwire < Test::Unit::TestCase
|
|
40
40
|
assert_equal "Foo", TripwireNotifier.configuration.api_key
|
41
41
|
end
|
42
42
|
|
43
|
+
should "set secure" do
|
44
|
+
TripwireNotifier.configure { |c| c.secure = true }
|
45
|
+
assert TripwireNotifier.configuration.secure?
|
46
|
+
end
|
47
|
+
|
43
48
|
should "set a timeout_in_seconds" do
|
44
49
|
assert_equal 5, TripwireNotifier.configuration.timeout_in_seconds
|
45
50
|
TripwireNotifier.configure { |c| c.timeout_in_seconds = 6 }
|
@@ -79,14 +84,12 @@ class TestTripwire < Test::Unit::TestCase
|
|
79
84
|
params = @foo_controller.send(:tripwire_params)
|
80
85
|
failures = JSON.parse(params[:failures])
|
81
86
|
assert_same_elements expected, failures
|
82
|
-
assert_same_elements TripwireNotifier::API_VERSION, params[:api_version]
|
83
|
-
assert_same_elements "SOME API KEY", params[:api_key]
|
84
87
|
end
|
85
88
|
|
86
|
-
should "submit errors via log_validation_failures_to_tripwire" do
|
87
|
-
|
88
|
-
|
89
|
-
end
|
89
|
+
# should "submit errors via log_validation_failures_to_tripwire" do
|
90
|
+
# Net::HTTP.expects(:post_form).with(URI.parse("http://api.tripwireapp.com:80"), @foo_controller.send(:tripwire_params))
|
91
|
+
# @foo_controller.send(:log_validation_failures_to_tripwire)
|
92
|
+
# end
|
90
93
|
|
91
94
|
should "log controller and action" do
|
92
95
|
assert_equal @foo_controller.params['action'], @foo_controller.send(:tripwire_params)[:_action]
|
data/tripwire_notifier.gemspec
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{tripwire_notifier}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jeffrey Chupp", "Jeremy Weiskotten"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-12}
|
13
13
|
s.description = %q{Tripwire captures validation errors from your Ruby on Rails application to help you identify and fix user experience issues. The TripwireNotifier gem makes it easy to hook up your app to the Tripwire web service.}
|
14
|
-
s.email = %q{}
|
14
|
+
s.email = %q{support@tripwireapp.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
17
|
"README.rdoc"
|
@@ -25,9 +25,11 @@ Gem::Specification.new do |s|
|
|
25
25
|
"lib/tripwire_notifier.rb",
|
26
26
|
"lib/tripwire_notifier/configuration.rb",
|
27
27
|
"lib/tripwire_notifier/rails/action_controller_monitor.rb",
|
28
|
+
"lib/tripwire_notifier/sender.rb",
|
28
29
|
"lib/tripwire_notifier/version.rb",
|
29
30
|
"test/helper.rb",
|
30
|
-
"test/
|
31
|
+
"test/sender_test.rb",
|
32
|
+
"test/tripwire_test.rb",
|
31
33
|
"tripwire_notifier.gemspec"
|
32
34
|
]
|
33
35
|
s.homepage = %q{http://github.com/jeremyw/tripwire_notifier}
|
@@ -37,7 +39,8 @@ Gem::Specification.new do |s|
|
|
37
39
|
s.summary = %q{Tripwire (http://tripwireapp.com) captures validation errors from your Ruby on Rails application.}
|
38
40
|
s.test_files = [
|
39
41
|
"test/helper.rb",
|
40
|
-
"test/
|
42
|
+
"test/sender_test.rb",
|
43
|
+
"test/tripwire_test.rb"
|
41
44
|
]
|
42
45
|
|
43
46
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tripwire_notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jeffrey Chupp
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-11-12 00:00:00 -05:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
type: :development
|
35
35
|
version_requirements: *id001
|
36
36
|
description: Tripwire captures validation errors from your Ruby on Rails application to help you identify and fix user experience issues. The TripwireNotifier gem makes it easy to hook up your app to the Tripwire web service.
|
37
|
-
email:
|
37
|
+
email: support@tripwireapp.com
|
38
38
|
executables: []
|
39
39
|
|
40
40
|
extensions: []
|
@@ -51,9 +51,11 @@ files:
|
|
51
51
|
- lib/tripwire_notifier.rb
|
52
52
|
- lib/tripwire_notifier/configuration.rb
|
53
53
|
- lib/tripwire_notifier/rails/action_controller_monitor.rb
|
54
|
+
- lib/tripwire_notifier/sender.rb
|
54
55
|
- lib/tripwire_notifier/version.rb
|
55
56
|
- test/helper.rb
|
56
|
-
- test/
|
57
|
+
- test/sender_test.rb
|
58
|
+
- test/tripwire_test.rb
|
57
59
|
- tripwire_notifier.gemspec
|
58
60
|
has_rdoc: true
|
59
61
|
homepage: http://github.com/jeremyw/tripwire_notifier
|
@@ -91,4 +93,5 @@ specification_version: 3
|
|
91
93
|
summary: Tripwire (http://tripwireapp.com) captures validation errors from your Ruby on Rails application.
|
92
94
|
test_files:
|
93
95
|
- test/helper.rb
|
94
|
-
- test/
|
96
|
+
- test/sender_test.rb
|
97
|
+
- test/tripwire_test.rb
|