papertrail 0.10.4 → 0.11.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 78e1cee299b431dfb6467aa16086c5b9fa4ac651
4
- data.tar.gz: a82f9f3341af1811328d45b89b87d59162da11f7
2
+ SHA256:
3
+ metadata.gz: 19f8502944f2149f181050b434539d27f5a01a72682c787beaad70f07aa3fe60
4
+ data.tar.gz: f1c37f9ad6d77dc618174becd614c4c185493fef917d12f74b7df2f050271c22
5
5
  SHA512:
6
- metadata.gz: 2ca1e90d8afe8f6750694dcea9a0b31954b1d3f4912ad5f2a6e8377f85f4409d1e6c2f1e1be3c52279dd678c83c2e75f13e07c3dab9fe76b763b9e7591157be4
7
- data.tar.gz: 2ac0f36dc3a4e52496a35cae9904b7d206dd8c997c0d0e04ba984640f6c41ee3f124c4ad9ef2569529d0fe08158bb82926136918079db2be0922e49aba6b700d
6
+ metadata.gz: bffe601811d165aa07ef028bd74304babf322c518e7fbf492d2453974363f7e26ad9a2e73ce2c871f583fbf961765004f2371eceeb5575f762bddf7645d26450
7
+ data.tar.gz: 7b43d937751f7cdb8b46dc95dac721b4625b70f3a1fab0019ec3f1ea94ef34d95f7ab2271fea9684477120fe247501ccb3c00483eb43fa682001005a5f5d5dae
@@ -1,5 +1,5 @@
1
1
  module Papertrail
2
- VERSION = '0.10.4'
2
+ VERSION = '0.11.0'
3
3
  end
4
4
 
5
5
  require 'papertrail/connection'
@@ -95,6 +95,9 @@ module Papertrail
95
95
 
96
96
  @connection = Papertrail::Connection.new(options)
97
97
 
98
+ # Use HTTP Keep-Alive unless delay is too long
99
+ connection.start if options[:delay] < 10
100
+
98
101
  if options[:system]
99
102
  query_options[:system_id] = connection.find_id_for_source(options[:system])
100
103
  unless query_options[:system_id]
@@ -46,15 +46,15 @@ module Papertrail
46
46
 
47
47
  raise OptionParser::MissingArgument, 'group' if options[:group].nil?
48
48
 
49
- connection = Papertrail::Connection.new(options)
50
-
51
- # Bail if group already exists
52
- if connection.show_group(options[:group])
53
- exit 0
54
- end
49
+ Papertrail::Connection.new(options).start do |connection|
50
+ # Bail if group already exists
51
+ if connection.show_group(options[:group])
52
+ exit 0
53
+ end
55
54
 
56
- if connection.create_group(options[:group], options[:wildcard])
57
- exit 0
55
+ if connection.create_group(options[:group], options[:wildcard])
56
+ exit 0
57
+ end
58
58
  end
59
59
 
60
60
  exit 1
@@ -84,19 +84,19 @@ module Papertrail
84
84
  error 'Either --ip-address or --destination-port most be provided'
85
85
  end
86
86
 
87
- connection = Papertrail::Connection.new(options)
88
-
89
- # Bail if system already exists
90
- if connection.show_source(options[:system])
91
- exit 0
92
- end
87
+ Papertrail::Connection.new(options).start do |connection|
88
+ # Bail if system already exists
89
+ if connection.show_source(options[:system])
90
+ exit 0
91
+ end
93
92
 
94
- if options[:destination_port] && !options[:hostname]
95
- options[:hostname] = options[:system]
96
- end
93
+ if options[:destination_port] && !options[:hostname]
94
+ options[:hostname] = options[:system]
95
+ end
97
96
 
98
- if connection.register_source(options[:system], options)
99
- exit 0
97
+ if connection.register_source(options[:system], options)
98
+ exit 0
99
+ end
100
100
  end
101
101
 
102
102
  exit 1
@@ -38,6 +38,19 @@ module Papertrail
38
38
  end
39
39
  end
40
40
 
41
+ def start
42
+ if block_given?
43
+ @connection.start { yield self }
44
+ else
45
+ @connection.start
46
+ self
47
+ end
48
+ end
49
+
50
+ def finish
51
+ @connection.finish
52
+ end
53
+
41
54
  def find_id_for_source(name)
42
55
  response = @connection.get('systems.json', :system_name => name)
43
56
 
@@ -37,6 +37,19 @@ module Papertrail
37
37
  @headers = {}
38
38
  end
39
39
 
40
+ def start
41
+ if block_given?
42
+ https.start { yield self }
43
+ else
44
+ https.start
45
+ self
46
+ end
47
+ end
48
+
49
+ def finish
50
+ https.finish
51
+ end
52
+
40
53
  def basic_auth(login, pass)
41
54
  @headers['Authorization'] = 'Basic ' + ["#{login}:#{pass}"].pack('m').delete("\r\n")
42
55
  end
@@ -72,7 +85,7 @@ module Papertrail
72
85
  else
73
86
  on_complete(https.send(http_method, uri, build_nested_query(params), @headers))
74
87
  end
75
- rescue SystemCallError, Net::HTTPFatalError => e
88
+ rescue IOError, SystemCallError, Net::HTTPFatalError => e
76
89
  attempts += 1
77
90
  retry if (attempts < 3)
78
91
  raise e
@@ -84,19 +97,20 @@ module Papertrail
84
97
  end
85
98
 
86
99
  def https
87
- http = Net::HTTP.new('papertrailapp.com', 443)
88
- http.use_ssl = true
89
- http.verify_mode = ssl_verify_mode
90
- http.cert_store = ssl_cert_store
91
-
92
- http.cert = @ssl[:client_cert] if @ssl[:client_cert]
93
- http.key = @ssl[:client_key] if @ssl[:client_key]
94
- http.ca_file = @ssl[:ca_file] if @ssl[:ca_file]
95
- http.ca_path = @ssl[:ca_path] if @ssl[:ca_path]
96
- http.verify_depth = @ssl[:verify_depth] if @ssl[:verify_depth]
97
- http.ssl_version = @ssl[:version] if @ssl[:version]
98
-
99
- http
100
+ @https ||= Net::HTTP.new('papertrailapp.com', 443).tap do |http|
101
+ http.use_ssl = true
102
+ http.verify_mode = ssl_verify_mode
103
+ http.cert_store = ssl_cert_store
104
+
105
+ http.cert = @ssl[:client_cert] if @ssl[:client_cert]
106
+ http.key = @ssl[:client_key] if @ssl[:client_key]
107
+ http.ca_file = @ssl[:ca_file] if @ssl[:ca_file]
108
+ http.ca_path = @ssl[:ca_path] if @ssl[:ca_path]
109
+ http.verify_depth = @ssl[:verify_depth] if @ssl[:verify_depth]
110
+ http.ssl_version = @ssl[:version] if @ssl[:version]
111
+
112
+ http.keep_alive_timeout = 10 if http.respond_to?(:keep_alive_timeout=)
113
+ end
100
114
  end
101
115
 
102
116
  def cli_version
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  ## If your rubyforge_project name is different, then edit it and comment out
10
10
  ## the sub! line in the Rakefile
11
11
  s.name = 'papertrail'
12
- s.version = '0.10.4'
13
- s.date = '2017-11-02'
12
+ s.version = '0.11.0'
13
+ s.date = '2018-05-16'
14
14
  s.rubyforge_project = 'papertrail'
15
15
 
16
16
  ## Make sure your summary is short. The description may be as long
@@ -4,6 +4,17 @@ class ConnectionTest < Minitest::Test
4
4
  let(:connection_options) { { :token => 'dummy' } }
5
5
  let(:connection) { Papertrail::Connection.new(connection_options) }
6
6
 
7
+ def test_start_finish
8
+ assert_same connection, connection.start
9
+ assert_nil connection.finish
10
+
11
+ block_args = nil
12
+ connection.start {|*args| block_args = args}
13
+ assert_equal [connection], block_args
14
+
15
+ assert_raises { connection.finish }
16
+ end
17
+
7
18
  def test_each_event
8
19
  skip
9
20
  end
@@ -2,7 +2,17 @@ require 'test_helper'
2
2
 
3
3
  class HttpClientTest < Minitest::Test
4
4
  let(:http) { Papertrail::HttpClient.new({}) }
5
- describe "http methods" do
5
+ describe 'http methods' do
6
+ def test_start_finish
7
+ assert_same http, http.start
8
+ assert_nil http.finish
9
+
10
+ block_args = nil
11
+ http.start {|*args| block_args = args}
12
+ assert_equal [http], block_args
13
+
14
+ assert_raises { http.finish }
15
+ end
6
16
 
7
17
  def test_cli_version_present_in_http_methods
8
18
  return if RUBY_VERSION < '2.0'
@@ -22,7 +32,8 @@ class HttpClientTest < Minitest::Test
22
32
  http.delete('some-path')
23
33
  end
24
34
  end
25
- describe "build_nested_query" do
35
+
36
+ describe 'build nested query' do
26
37
  def test_value_accepts_hash
27
38
  assert_equal(http.send(:build_nested_query, {}), "")
28
39
  assert_equal(http.send(:build_nested_query, {:a => 1}), "a=1")
@@ -32,4 +43,4 @@ class HttpClientTest < Minitest::Test
32
43
  assert_equal(http.send(:build_nested_query, [1,2]), "%5B%5D=1&%5B%5D=2")
33
44
  end
34
45
  end
35
- end
46
+ end
@@ -1,7 +1,7 @@
1
1
  gem "minitest"
2
2
  require 'minitest/autorun'
3
3
  require 'minitest/pride' # Color!
4
- require 'mocha/mini_test'
4
+ require 'mocha/minitest'
5
5
  unless RUBY_VERSION < '1.9'
6
6
  require 'webmock/minitest'
7
7
  WebMock.disable_net_connect!
@@ -13,4 +13,4 @@ class Minitest::Test
13
13
  extend Minitest::Spec::DSL # Add let blocks
14
14
  end
15
15
 
16
- require './lib/papertrail'
16
+ require './lib/papertrail'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: papertrail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.4
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Papertrail
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-02 00:00:00.000000000 Z
11
+ date: 2018-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chronic
@@ -202,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
202
  version: '0'
203
203
  requirements: []
204
204
  rubyforge_project: papertrail
205
- rubygems_version: 2.6.12
205
+ rubygems_version: 2.7.4
206
206
  signing_key:
207
207
  specification_version: 2
208
208
  summary: Command-line client for Papertrail hosted log management service.