pixeltrix-prowler 1.1.0 → 1.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.
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ *1.1.1 (August 4th, 2009)
2
+
3
+ * Add support for verifying server certificate
4
+
5
+ * Add support for passing multiple API keys
6
+
7
+
1
8
  *1.1.0 (July 10th, 2009)
2
9
 
3
10
  * Add support for Delayed::Job background processing
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
@@ -62,7 +62,8 @@ require 'uri'
62
62
  class Prowler
63
63
 
64
64
  SERVICE_URL = "https://prowl.weks.net/publicapi"
65
- USER_AGENT = "Prowler/1.1.0"
65
+ USER_AGENT = "Prowler/1.1.1"
66
+ MULTIPLE_APIKEY_COMMANDS = %w(add)
66
67
 
67
68
  module Priority
68
69
  VERY_LOW = -2
@@ -93,7 +94,7 @@ class Prowler
93
94
  attr_accessor :api_key, :provider_key
94
95
  attr_accessor :application, :send_notifications
95
96
  attr_accessor :read_timeout, :open_timeout #:nodoc:
96
- attr_accessor :delayed
97
+ attr_accessor :delayed, :verify_certificate, :root_certificates
97
98
 
98
99
  # Call this method to configure your account details in an initializer.
99
100
  def configure
@@ -111,6 +112,7 @@ class Prowler
111
112
  # Reset configuration
112
113
  def reset_configuration
113
114
  @application = @api_key = @provider_key = nil
115
+ @delayed = @verify_certificate = @root_certificates = nil
114
116
  end
115
117
 
116
118
  # Whether the library has been configured
@@ -118,6 +120,17 @@ class Prowler
118
120
  !@application.nil? && !@api_key.nil?
119
121
  end
120
122
 
123
+ # Whether to verify the server's SSL certificate
124
+ def verify_certificate?
125
+ @verify_certificate ||= false
126
+ end
127
+
128
+ # Location of the root certificates file.
129
+ # Default: RAILS_ROOT/config/cacert.pem
130
+ def root_certificates
131
+ @root_certificates ||= File.join(RAILS_ROOT, "config", "cacert.pem")
132
+ end
133
+
121
134
  # Returns the default logger or a logger that prints to STDOUT.
122
135
  def logger
123
136
  ActiveRecord::Base.logger
@@ -163,7 +176,7 @@ class Prowler
163
176
  end
164
177
 
165
178
  def perform(command, api_key, provider_key, data = {}, method = :post) #:nodoc:
166
- params = { :apikey => api_key, :provider_key => provider_key }.merge(data).delete_if { |k,v| v.nil? }
179
+ params = { :apikey => format_api_key(command, api_key), :provider_key => provider_key }.merge(data).delete_if { |k,v| v.nil? }
167
180
  case method
168
181
  when :post
169
182
  perform_post(command, params)
@@ -205,7 +218,12 @@ class Prowler
205
218
  def perform_request(url, request) #:nodoc:
206
219
  http = Net::HTTP.new(url.host, url.port)
207
220
  http.use_ssl = true
208
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
221
+ if verify_certificate?
222
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
223
+ http.ca_file = root_certificates
224
+ else
225
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
226
+ end
209
227
  http.read_timeout = read_timeout
210
228
  http.open_timeout = open_timeout
211
229
  http.start do
@@ -226,6 +244,14 @@ class Prowler
226
244
  end
227
245
  end
228
246
  end
247
+
248
+ def format_api_key(command, api_key)
249
+ if api_key.is_a?(Array)
250
+ MULTIPLE_APIKEY_COMMANDS.include?(command.to_s) ? api_key.join(",") : api_key.first.to_s
251
+ else
252
+ api_key.to_s
253
+ end
254
+ end
229
255
  end
230
256
 
231
257
  attr_accessor :api_key, :provider_key #:nodoc:
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{prowler}
5
- s.version = "1.1.0"
5
+ s.version = "1.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Andrew White"]
9
- s.date = %q{2009-07-10}
9
+ s.date = %q{2009-08-04}
10
10
  s.description = %q{A simple wrapper class that provides basic access to the Prowl API.}
11
11
  s.email = %q{andyw@pixeltrix.co.uk}
12
12
  s.extra_rdoc_files = [
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  "lib/prowler.rb",
24
24
  "prowler.gemspec",
25
25
  "tasks/prowler.rake",
26
+ "test/config/cacert.pem",
26
27
  "test/prowler_test.rb"
27
28
  ]
28
29
  s.has_rdoc = true
@@ -0,0 +1,17 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDIDCCAomgAwIBAgIENd70zzANBgkqhkiG9w0BAQUFADBOMQswCQYDVQQGEwJVUzEQMA4GA1UE
3
+ ChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5
4
+ MB4XDTk4MDgyMjE2NDE1MVoXDTE4MDgyMjE2NDE1MVowTjELMAkGA1UEBhMCVVMxEDAOBgNVBAoT
5
+ B0VxdWlmYXgxLTArBgNVBAsTJEVxdWlmYXggU2VjdXJlIENlcnRpZmljYXRlIEF1dGhvcml0eTCB
6
+ nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwV2xWGcIYu6gmi0fCG2RFGiYCh7+2gRvE4RiIcPR
7
+ fM6fBeC4AfBONOziipUEZKzxa1NfBbPLZ4C/QgKO/t0BCezhABRP/PvwDN1Dulsr4R+AcJkVV5MW
8
+ 8Q+XarfCaCMczE1ZMKxRHjuvK9buY0V7xdlfUNLjUA86iOe/FP3gx7kCAwEAAaOCAQkwggEFMHAG
9
+ A1UdHwRpMGcwZaBjoGGkXzBdMQswCQYDVQQGEwJVUzEQMA4GA1UEChMHRXF1aWZheDEtMCsGA1UE
10
+ CxMkRXF1aWZheCBTZWN1cmUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MQ0wCwYDVQQDEwRDUkwxMBoG
11
+ A1UdEAQTMBGBDzIwMTgwODIyMTY0MTUxWjALBgNVHQ8EBAMCAQYwHwYDVR0jBBgwFoAUSOZo+SvS
12
+ spXXR9gjIBBPM5iQn9QwHQYDVR0OBBYEFEjmaPkr0rKV10fYIyAQTzOYkJ/UMAwGA1UdEwQFMAMB
13
+ Af8wGgYJKoZIhvZ9B0EABA0wCxsFVjMuMGMDAgbAMA0GCSqGSIb3DQEBBQUAA4GBAFjOKer89961
14
+ zgK5F7WF0bnj4JXMJTENAKaSbn+2kmOeUJXRmm/kEd5jhW6Y7qj/WsjTVbJmcVfewCHrPSqnI0kB
15
+ BIZCe/zuf6IWUrVnZ9NA2zsmWLIodz2uFHdh1voqZiegDfqnc1zqcPGUIWVEX/r87yloqaKHee95
16
+ 70+sB3c4
17
+ -----END CERTIFICATE-----
@@ -4,6 +4,8 @@ require 'mocha'
4
4
  require 'shoulda'
5
5
  require File.join(File.dirname(__FILE__), "..", "lib", "prowler")
6
6
 
7
+ RAILS_ROOT = File.dirname(__FILE__)
8
+
7
9
  class ProwlerTest < Test::Unit::TestCase
8
10
  context "Prowler configuration" do
9
11
  setup do
@@ -73,16 +75,40 @@ class ProwlerTest < Test::Unit::TestCase
73
75
  end
74
76
  end
75
77
 
76
- should "not verify SSL certificates" do
78
+ should "not verify SSL certificates by default" do
77
79
  Net::HTTP.any_instance.expects(:use_ssl=).with(true)
78
80
  Net::HTTP.any_instance.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
79
81
  Prowler.notify("Event Name", "Message Text", Prowler::Priority::NORMAL)
80
82
  end
81
83
 
84
+ should "verify SSL certificates if verification is turned on" do
85
+ Prowler.configure do |config|
86
+ config.verify_certificate = true
87
+ end
88
+ Net::HTTP.any_instance.expects(:use_ssl=).with(true)
89
+ Net::HTTP.any_instance.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
90
+ Net::HTTP.any_instance.expects(:ca_file=).with(File.join(RAILS_ROOT, "config", "cacert.pem"))
91
+ Prowler.notify("Event Name", "Message Text", Prowler::Priority::NORMAL)
92
+ end
93
+
82
94
  should "not send notifications if send_notifications is false" do
83
95
  Net::HTTP.any_instance.expects(:request).never
84
96
  Prowler.notify("Event Name", "Message Text", Prowler::Priority::NORMAL)
85
97
  end
98
+
99
+ should "send multiple API keys if configured" do
100
+ Prowler.configure do |config|
101
+ config.api_key = %w(apikey1 apikey2)
102
+ end
103
+ Net::HTTP::Post.any_instance.expects(:form_data=).with({
104
+ :apikey => "apikey1,apikey2",
105
+ :application => "Application Name",
106
+ :event => "Event Name",
107
+ :description => "Message Text",
108
+ :priority => Prowler::Priority::NORMAL
109
+ })
110
+ Prowler.notify("Event Name", "Message Text", Prowler::Priority::NORMAL)
111
+ end
86
112
  end
87
113
 
88
114
  context "Verifying an API key" do
@@ -107,12 +133,30 @@ class ProwlerTest < Test::Unit::TestCase
107
133
  end
108
134
  end
109
135
 
110
- should "not verify SSL certificates" do
136
+ should "only verify the first API key" do
137
+ Prowler.configure do |config|
138
+ config.api_key = %w(apikey1 apikey2)
139
+ end
140
+ Net::HTTP::Get.expects(:new).with("/publicapi/verify?apikey=apikey1", { 'User-Agent' => Prowler::USER_AGENT }).once
141
+ Prowler.verify
142
+ end
143
+
144
+ should "not verify SSL certificates by default" do
111
145
  Net::HTTP.any_instance.expects(:use_ssl=).with(true)
112
146
  Net::HTTP.any_instance.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
113
147
  Prowler.verify
114
148
  end
115
149
 
150
+ should "verify SSL certificates if verification is turned on" do
151
+ Prowler.configure do |config|
152
+ config.verify_certificate = true
153
+ end
154
+ Net::HTTP.any_instance.expects(:use_ssl=).with(true)
155
+ Net::HTTP.any_instance.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
156
+ Net::HTTP.any_instance.expects(:ca_file=).with(File.join(RAILS_ROOT, "config", "cacert.pem"))
157
+ Prowler.verify
158
+ end
159
+
116
160
  should "not send notifications if send_notifications is false" do
117
161
  Net::HTTP.any_instance.expects(:request).never
118
162
  Prowler.verify
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pixeltrix-prowler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew White
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-10 00:00:00 -07:00
12
+ date: 2009-08-04 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -32,9 +32,11 @@ files:
32
32
  - lib/prowler.rb
33
33
  - prowler.gemspec
34
34
  - tasks/prowler.rake
35
+ - test/config/cacert.pem
35
36
  - test/prowler_test.rb
36
37
  has_rdoc: true
37
38
  homepage: http://github.com/pixeltrix/prowler/
39
+ licenses:
38
40
  post_install_message:
39
41
  rdoc_options:
40
42
  - --charset=UTF-8
@@ -55,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
57
  requirements: []
56
58
 
57
59
  rubyforge_project:
58
- rubygems_version: 1.2.0
60
+ rubygems_version: 1.3.5
59
61
  signing_key:
60
62
  specification_version: 2
61
63
  summary: Provides access to the Prowl API.