hydraulic_brake 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,7 +12,16 @@ gem](https://github.com/airbrake/airbrake) and takes a different design
12
12
  approach. HydraulicBrake doesn't attempt to integrate with any
13
13
  frameworks and has few dependencies. HydraulicBrake doesn't change
14
14
  anything outside its own namespace. It doesn't do any automatic
15
- exception handling or configuration.
15
+ exception handling or configuration. HydraulicBrake doesn't ignore any
16
+ exceptions. If you don't want to send a notification, then don't call
17
+ HydraulicBrake#notify.
18
+
19
+ If you were previously using the Airbrake gem, and you want to use
20
+ HydraulicBrake instead, you'll need to install error handlers wherever
21
+ you intend to catch errors. The right place to do that depends entirely
22
+ on your application, but a good place to start would be
23
+ rescue_action_in_public for rails apps and Rack middleware for Rack
24
+ apps.
16
25
 
17
26
  Configuration
18
27
  -------------
@@ -20,13 +29,15 @@ Configuration
20
29
  Configure HydraulicBrake when your app starts with a configuration block
21
30
  like this one:
22
31
 
23
- HydraulicBrake.configure do |config|
24
- config.host = "api.airbrake.io"
25
- config.port = "443"
26
- config.secure = true
27
- config.environment_name = "staging"
28
- config.api_key = "<api-key-from-your-airbrake-server>"
29
- end
32
+ ```ruby
33
+ HydraulicBrake.configure do |config|
34
+ config.host = "api.airbrake.io"
35
+ config.port = "443"
36
+ config.secure = true
37
+ config.environment_name = "staging"
38
+ config.api_key = "<api-key-from-your-airbrake-server>"
39
+ end
40
+ ```
30
41
 
31
42
  Usage
32
43
  -----
@@ -34,70 +45,95 @@ Usage
34
45
  Wherever you want to notify an Airbrake server, just call
35
46
  HydraulicBrake#notify
36
47
 
37
- begin
38
- params = {
39
- # params that you pass to a method that can throw an exception
40
- }
41
- my_unpredicable_method(params)
42
- rescue => e
43
- HydraulicBrake.notify(
44
- :error_class => "Special Error",
45
- :error_message => "Special Error: #{e.message}",
46
- :parameters => params
47
- )
48
- end
48
+ ```ruby
49
+ begin
50
+ my_unpredicable_method
51
+ rescue => e
52
+ HydraulicBrake.notify(
53
+ :error_class => "Special Error",
54
+ :error_message => "Special Error: #{e.message}",
55
+ :parameters => params
56
+ )
57
+ end
58
+ ```
49
59
 
50
60
  HydraulicBrake merges the hash you pass with these default options:
51
61
 
52
- {
53
- :api_key => HydraulicBrake.api_key,
54
- :error_message => 'Notification',
55
- :backtrace => caller,
56
- :parameters => {},
57
- :session => {}
58
- }
62
+ ```ruby
63
+ {
64
+ :api_key => HydraulicBrake.api_key,
65
+ :error_message => 'Notification',
66
+ :backtrace => caller,
67
+ :parameters => {},
68
+ :session => {}
69
+ }
70
+ ```
59
71
 
60
- You can override any of those parameters.
72
+ You can override any of those parameters and there are many other
73
+ parameters you can add. See the inline documentation for
74
+ HydraulicBrake#notify.
61
75
 
62
76
  Async Notifications
63
77
  -------------------
64
78
 
65
- HydraulicBrake doesn't provide anything for async notifications, and
66
- that's a good thing. Just wrap your calls to Airbrake#notify in the
67
- async library of your choice.
79
+ HydraulicBrake doesn't provide anything special for async notifications.
80
+ Just wrap your calls to Airbrake#notify in the async library of your
81
+ choice if you want to.
68
82
 
69
83
  Proxy Support
70
84
  -------------
71
85
 
72
- The notifier supports using a proxy, if your server is not able to
73
- directly reach the Airbrake servers. To configure the proxy settings,
74
- added the following information to your HydraulicBrake configuration
75
- block.
76
-
77
- HydraulicBrake.configure do |config|
78
- config.proxy_host = proxy.host.com
79
- config.proxy_port = 4038
80
- config.proxy_user = foo # optional
81
- config.proxy_pass = bar # optional
86
+ The notifier supports using a proxy. To configure a proxy, add the
87
+ configuration to HydraulicBrake#configure:
88
+
89
+ ```ruby
90
+ HydraulicBrake.configure do |config|
91
+ config.proxy_host = proxy.host.com
92
+ config.proxy_port = 4038
93
+ config.proxy_user = foo # optional
94
+ config.proxy_pass = bar # optional
95
+ end
96
+ ```
82
97
 
83
98
  Logging
84
99
  ------------
85
100
 
86
- HydraulicBrake uses STDOUT by default. If you don't like HydraulicBrake
87
- scribbling to your standard output, just pass another `Logger` instance
88
- inside your configuration:
101
+ HydraulicBrake uses STDOUT by default. If you want to use a different
102
+ logger, just pass another `Logger` instance inside your configuration:
103
+
104
+ ```ruby
105
+ HydraulicBrake.configure do |config|
106
+ config.logger = Logger.new("path/to/your/log/file")
107
+ end
108
+ ```
109
+
110
+ Deploy Hook
111
+ -----------
112
+
113
+ HydraulicBrake can notify Airbrake whenever you deploy your app. Just
114
+ call HydraulicBrake::Hook#deploy whenever you deploy:
89
115
 
90
- HydraulicBrake.configure do |config|
91
- ...
92
- config.logger = Logger.new("path/to/your/log/file")
93
- end
116
+ ```ruby
117
+ HydraulicBrake::Hook.deploy({
118
+ :scm_revision => "cd6b969f66ad0794c7117d5030f926b49f82b038",
119
+ :scm_repository => "stevecrozz/hydraulic_brake",
120
+ :local_username => "stevecrozz",
121
+ :rails_env => "production", # everything is rails, right?
122
+ :message => "Another deployment hook brought to you by HydraulicBrake"
123
+ })
124
+ ```
94
125
 
95
126
  Credits
96
127
  -------
97
128
 
98
- Thank you to all [the airbrake contributors](https://github.com/airbrake/airbrake/contributors)!
129
+ Thank you to all [the airbrake
130
+ contributors](https://github.com/airbrake/airbrake/contributors) for
131
+ making HydraulicBrake possible.
99
132
 
100
133
  License
101
134
  -------
102
135
 
103
- Airbrake is Copyright © 2008-2012 Airbrake. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
136
+ Airbrake is Copyright © 2008-2012 Airbrake.
137
+ HydraulicBrake is CopyRight © 2013 Stephen Crosby. It is free software,
138
+ and may be redistributed under the terms specified in the MIT-LICENSE
139
+ file.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "hydraulic_brake"
8
- s.version = "0.0.0"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Stephen Crosby"]
12
- s.date = "2013-07-14"
12
+ s.date = "2013-07-19"
13
13
  s.description = "Sends notifications to an Airbrake server"
14
14
  s.email = "stevecrozz@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -34,13 +34,16 @@ Gem::Specification.new do |s|
34
34
  "lib/hydraulic_brake.rb",
35
35
  "lib/hydraulic_brake/backtrace.rb",
36
36
  "lib/hydraulic_brake/configuration.rb",
37
+ "lib/hydraulic_brake/hook.rb",
37
38
  "lib/hydraulic_brake/notice.rb",
38
39
  "lib/hydraulic_brake/sender.rb",
40
+ "lib/hydraulic_brake/test_notification.rb",
39
41
  "lib/hydraulic_brake/version.rb",
40
42
  "lib/hydraulic_brake_tasks.rb",
41
43
  "resources/README.md",
42
44
  "resources/ca-bundle.crt",
43
- "script/integration_test.rb",
45
+ "script/deploy_integration_test.rb",
46
+ "script/notify_integration_test.rb",
44
47
  "test/airbrake_2_3.xsd",
45
48
  "test/backtrace_test.rb",
46
49
  "test/configuration_test.rb",
@@ -1,11 +1,13 @@
1
1
  require 'net/http'
2
2
  require 'net/https'
3
3
  require 'rubygems'
4
- require 'hydraulic_brake/version'
4
+ require 'hydraulic_brake/backtrace'
5
5
  require 'hydraulic_brake/configuration'
6
+ require 'hydraulic_brake/hook'
6
7
  require 'hydraulic_brake/notice'
7
8
  require 'hydraulic_brake/sender'
8
- require 'hydraulic_brake/backtrace'
9
+ require 'hydraulic_brake/test_notification'
10
+ require 'hydraulic_brake/version'
9
11
 
10
12
  module HydraulicBrake
11
13
  API_VERSION = "2.3"
@@ -0,0 +1,53 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
4
+ module HydraulicBrake
5
+ module Hook
6
+
7
+ # Alerts Airbrake of a deploy.
8
+ #
9
+ # @param [Hash] opts Data about the deploy that is set to Airbrake
10
+ #
11
+ # @option opts [String] :api_key Api key of you Airbrake application
12
+ # @option opts [String] :scm_revision The given revision/sha that is being deployed
13
+ # @option opts [String] :scm_repository Address of your repository to help with code lookups
14
+ # @option opts [String] :local_username Who is deploying
15
+ def self.deploy(opts = {})
16
+ api_key = opts.delete(:api_key) || HydraulicBrake.configuration.api_key
17
+ if api_key.empty?
18
+ puts "I don't seem to be configured with an API key. Please check your configuration."
19
+ return false
20
+ end
21
+
22
+ params = {'api_key' => api_key}
23
+ opts.each {|k,v| params["deploy[#{k}]"] = v }
24
+
25
+ host = HydraulicBrake.configuration.host
26
+ port = HydraulicBrake.configuration.port
27
+
28
+ proxy = Net::HTTP.Proxy(HydraulicBrake.configuration.proxy_host,
29
+ HydraulicBrake.configuration.proxy_port,
30
+ HydraulicBrake.configuration.proxy_user,
31
+ HydraulicBrake.configuration.proxy_pass)
32
+ http = proxy.new(host, port)
33
+
34
+ # Handle Security
35
+ if HydraulicBrake.configuration.secure?
36
+ http.use_ssl = true
37
+ http.ca_file = HydraulicBrake.configuration.ca_bundle_path
38
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
39
+ end
40
+
41
+ post = Net::HTTP::Post.new("/deploys.txt")
42
+ post.set_form_data(params)
43
+
44
+ response = http.request(post)
45
+
46
+ puts response.body
47
+ return Net::HTTPSuccess === response
48
+ end
49
+
50
+ end
51
+ end
52
+
53
+
@@ -0,0 +1,19 @@
1
+ module HydraulicBrake
2
+ module TestNotification
3
+
4
+ def self.send
5
+ begin
6
+ raise "Testing hydraulic brake notifier. If you can see this, it works."
7
+ rescue Exception => e
8
+ puts "Configuration:"
9
+ HydraulicBrake.configuration.to_hash.each do |key, value|
10
+ puts sprintf("%25s: %s", key.to_s, value.inspect.slice(0, 55))
11
+ end
12
+ print "Sending notification... "
13
+ HydraulicBrake.notify(e)
14
+ print "done\n"
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ require 'hydraulic_brake'
5
+
6
+ fail "Please supply an API Key as the first argument" if ARGV.empty?
7
+
8
+ host = ARGV[1]
9
+
10
+ secure = (ARGV[2] == "secure")
11
+
12
+ HydraulicBrake.configure do |config|
13
+ config.secure = secure
14
+ config.host = host
15
+ config.api_key = ARGV.first
16
+ end
17
+
18
+ HydraulicBrake::Hook.deploy({
19
+ :api_key => ARGV.first,
20
+ :scm_revision => "cd6b969f66ad0794c7117d5030f926b49f82b038",
21
+ :scm_repository => "stevecrozz/hydraulic_brake",
22
+ :local_username => "stevecrozz",
23
+ :rails_env => "production", # everything is rails, right?
24
+ :message => "Another deployment hook brought to you by HydraulicBrake"
25
+ })
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ require 'hydraulic_brake'
5
+
6
+ fail "Please supply an API Key as the first argument" if ARGV.empty?
7
+
8
+ host = ARGV[1]
9
+
10
+ secure = (ARGV[2] == "secure")
11
+
12
+ HydraulicBrake.configure do |config|
13
+ config.secure = secure
14
+ config.host = host
15
+ config.api_key = ARGV.first
16
+ end
17
+
18
+ HydraulicBrake::TestNotification.send
19
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydraulic_brake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-14 00:00:00.000000000 Z
12
+ date: 2013-07-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder
@@ -212,13 +212,16 @@ files:
212
212
  - lib/hydraulic_brake.rb
213
213
  - lib/hydraulic_brake/backtrace.rb
214
214
  - lib/hydraulic_brake/configuration.rb
215
+ - lib/hydraulic_brake/hook.rb
215
216
  - lib/hydraulic_brake/notice.rb
216
217
  - lib/hydraulic_brake/sender.rb
218
+ - lib/hydraulic_brake/test_notification.rb
217
219
  - lib/hydraulic_brake/version.rb
218
220
  - lib/hydraulic_brake_tasks.rb
219
221
  - resources/README.md
220
222
  - resources/ca-bundle.crt
221
- - script/integration_test.rb
223
+ - script/deploy_integration_test.rb
224
+ - script/notify_integration_test.rb
222
225
  - test/airbrake_2_3.xsd
223
226
  - test/backtrace_test.rb
224
227
  - test/configuration_test.rb
@@ -243,7 +246,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
243
246
  version: '0'
244
247
  segments:
245
248
  - 0
246
- hash: 1855083520706619311
249
+ hash: -2276683694056635469
247
250
  required_rubygems_version: !ruby/object:Gem::Requirement
248
251
  none: false
249
252
  requirements:
@@ -1,36 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'logger'
4
- require 'fileutils'
5
-
6
- RAILS_ENV = "production"
7
- RAILS_ROOT = FileUtils.pwd
8
- RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
9
-
10
- $: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
11
- require 'hydraulic_brake'
12
-
13
- fail "Please supply an API Key as the first argument" if ARGV.empty?
14
-
15
- host = ARGV[1]
16
-
17
- secure = (ARGV[2] == "secure")
18
-
19
- exception = begin
20
- raise "Testing hydraulic brake notifier with secure = #{secure}. If you can see this, it works."
21
- rescue => foo
22
- foo
23
- end
24
-
25
- HydraulicBrake.configure do |config|
26
- config.secure = secure
27
- config.host = host
28
- config.api_key = ARGV.first
29
- end
30
- puts "Configuration:"
31
- HydraulicBrake.configuration.to_hash.each do |key, value|
32
- puts sprintf("%25s: %s", key.to_s, value.inspect.slice(0, 55))
33
- end
34
- puts "Sending #{secure ? "" : "in"}secure notification to project with key #{ARGV.first}"
35
- HydraulicBrake.notify(exception)
36
-