hoodoo 1.17.0 → 1.18.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a11d0bed3dc977f5aab127f4ed139e715a9f2431
4
- data.tar.gz: 42706658a33e920162e734ad3f0891a8e703e845
3
+ metadata.gz: 33592f5c0f6228a5253592dff50c587e70319ae8
4
+ data.tar.gz: 3f7c50f2d5935c5758c2efd61a650b96335be4bf
5
5
  SHA512:
6
- metadata.gz: d3f795bff6b580fe090f46a624461fac52939941e18564074e68c37e5d3fc757c5da9a34efbbad6ce3c435e0701c021e07c8a157f77f0e268541bbe78180c1f9
7
- data.tar.gz: f3fec8a2305e6c815d309c0442724f4fee7a6541606058421a1e473797f50e666dbe40b7540cc34cbb12baa1e8af2cdaa2052c13601e69b182a303feca31bc7e
6
+ metadata.gz: b5ccdb3765ae191bed76db43c25bbcf674dea032bd8d6ed2b6ff01fdc53ed811748e68ef34dcc1f2f1e89ce2d9f494e2323d31c0292bcf905fd3201661b4ff21
7
+ data.tar.gz: 3196db1484495a18006ce741da581e77bbce7b3aecf4deb829bb8b96f8005226c486c523d6c1374849323c8241d68cb70cc3dcdbe696f4e6678a723ad5360281
@@ -33,12 +33,13 @@ module Hoodoo
33
33
  raise "Hoodoo::Client::Endpoint::HTTP must be configured with a Hoodoo::Services::Discovery::ForHTTP instance - got '#{ @discovery_result.class.name }'"
34
34
  end
35
35
 
36
- @description = Hoodoo::Client::Endpoint::HTTPBased::DescriptionOfRequest.new
37
- @description.discovery_result = @discovery_result
38
- @description.endpoint_uri = @discovery_result.endpoint_uri
39
- @description.proxy_uri = @discovery_result.proxy_uri
40
- @description.ca_file = @discovery_result.ca_file
41
- @description.http_timeout = @discovery_result.http_timeout
36
+ @description = Hoodoo::Client::Endpoint::HTTPBased::DescriptionOfRequest.new
37
+ @description.discovery_result = @discovery_result
38
+ @description.endpoint_uri = @discovery_result.endpoint_uri
39
+ @description.proxy_uri = @discovery_result.proxy_uri
40
+ @description.ca_file = @discovery_result.ca_file
41
+ @description.http_timeout = @discovery_result.http_timeout
42
+ @description.http_open_timeout = @discovery_result.http_open_timeout
42
43
  end
43
44
 
44
45
  public
@@ -115,10 +116,11 @@ module Hoodoo
115
116
 
116
117
  data = get_data_for_request( description_of_request )
117
118
 
118
- action = description_of_request.action
119
- proxy = description_of_request.proxy_uri
120
- ca_file = description_of_request.ca_file
121
- http_timeout = description_of_request.http_timeout
119
+ action = description_of_request.action
120
+ proxy = description_of_request.proxy_uri
121
+ ca_file = description_of_request.ca_file
122
+ http_timeout = description_of_request.http_timeout
123
+ http_open_timeout = description_of_request.http_open_timeout
122
124
 
123
125
  proxy_host = :ENV
124
126
  proxy_port = proxy_user = proxy_pass = nil
@@ -157,6 +159,7 @@ module Hoodoo
157
159
  end
158
160
 
159
161
  http.read_timeout = http_timeout unless http_timeout.nil?
162
+ http.open_timeout = http_open_timeout unless http_open_timeout.nil?
160
163
 
161
164
  request_class = {
162
165
  :create => Net::HTTP::Post,
@@ -184,7 +187,7 @@ module Hoodoo
184
187
  description_of_response.http_status_code = 404
185
188
  description_of_response.raw_body_data = ''
186
189
 
187
- rescue Net::ReadTimeout => e
190
+ rescue Net::OpenTimeout, Net::ReadTimeout => e
188
191
  description_of_response.http_status_code = 408
189
192
  description_of_response.raw_body_data = ''
190
193
 
@@ -71,11 +71,37 @@ module Hoodoo
71
71
  attr_accessor :ca_file
72
72
 
73
73
  # Optional Float indicating the Net::HTTP read timeout value.
74
+ #
75
+ # This is a value in seconds (default 60) for which the client
76
+ # will wait while attempting to read data from a server in any
77
+ # individual TCP read operation. The timeout becomes active
78
+ # immediately after a server connection is established.
79
+ #
80
+ # If a read attempt is still running after the timeout, the
81
+ # request is aborted and a +platform.timeout+ error returned.
82
+ #
83
+ # See also #http_open_timeout.
84
+ #
74
85
  # This operates at the HTTP transport level and is independent
75
- # of any timeouts set within the API providing server.
86
+ # of any higher level timeouts that might be set up.
76
87
  #
77
88
  attr_accessor :http_timeout
78
89
 
90
+ # Optional Float indicating the Net::HTTP open timeout value.
91
+ #
92
+ # This is a value in seconds (default 60) for which the client
93
+ # will wait while attempting to connect to a server.
94
+ #
95
+ # If the connection attempt is still running after the timeout,
96
+ # the request is aborted and a +platform.timeout+ error returned.
97
+ #
98
+ # See also #http_timeout.
99
+ #
100
+ # This operates at the HTTP transport level and is independent
101
+ # of any higher level timeouts that might be set up.
102
+ #
103
+ attr_accessor :http_open_timeout
104
+
79
105
  # Optional Hash of query data.
80
106
  #
81
107
  attr_accessor :query_hash
@@ -36,47 +36,66 @@ module Hoodoo
36
36
  #
37
37
  # Options are:
38
38
  #
39
- # +base_uri+:: A String giving the base URI at which resource
40
- # endpoint implementations can be found. The
41
- # protocol (HTTP or HTTPS), host and port are of
42
- # interest. The path will be overwritten with
43
- # by-convention values for individual resources.
44
- #
45
- # +proxy_uri+:: An optional full URI of an HTTP proxy to use if
46
- # the base URI commands use of HTTP or HTTPS. Ruby
47
- # will itself read <tt>ENV['HTTP_PROXY']</tt> if
48
- # set; this option will _override_ that variable.
49
- # Set as a String, as with +base_uri+.
50
- #
51
- # +ca_file+:: An optional String indicating a relative or
52
- # absolute file path to the location of a +.pem+
53
- # format Certificate Authority file (trust store),
54
- # which may include multliple certificates. The
55
- # certificates in the file will be used by
56
- # Net::HTTP to validate the SSL ceritificate
57
- # chain presented by remote servers, when calling
58
- # endpoints over HTTPS with Hoodoo::Client.
59
- #
60
- # Default +nil+ value should be used in nearly all
61
- # cases and uses Ruby OpenSSL defaults which are
62
- # generally Operating System provided.
63
- #
64
- # +http_timeout+:: Optional Float indicating the Net::HTTP read
65
- # timeout value. This operates at the HTTP
66
- # transport level and is independent of any
67
- # timeouts set within the API providing server.
68
- #
69
- # +routing+:: An optional parameter which gives custom routing
70
- # for exception cases where the by-convention map
71
- # doesn't work. This is usually because there is a
72
- # resource singleton which lives logically at a
73
- # singular named route rather than plural route,
74
- # e.g. "/v1/health" rather than "/v1/healths".
39
+ # +base_uri+:: A String giving the base URI at which
40
+ # resource endpoint implementations can be
41
+ # found. The protocol (HTTP or HTTPS), host
42
+ # and port are of interest. The path will be
43
+ # overwritten with by-convention values for
44
+ # individual resources.
45
+ #
46
+ # +proxy_uri+:: An optional full URI of an HTTP proxy to
47
+ # use if the base URI commands use of HTTP or
48
+ # HTTPS. Ruby will itself read
49
+ # <tt>ENV['HTTP_PROXY']</tt> if set; this
50
+ # option _overrides_ that variable. Set as a
51
+ # String, as with +base_uri+.
52
+ #
53
+ # +ca_file+:: An optional String indicating a relative or
54
+ # absolute file path to the location of a
55
+ # +.pem+ format Certificate Authority file
56
+ # (trust store), which may include multliple
57
+ # certificates. The certificates in the file
58
+ # will be used by Net::HTTP to validate the
59
+ # SSL ceritificate chain presented by remote
60
+ # servers, when calling endpoints over HTTPS
61
+ # with Hoodoo::Client.
62
+ #
63
+ # The default +nil+ value should be used in
64
+ # nearly all cases and uses Ruby OpenSSL
65
+ # defaults which are generally Operating
66
+ # System provided.
67
+ #
68
+ # +http_timeout+:: Optional Float providing a Net::HTTP read
69
+ # timeout value, when calling endpoints over
70
+ # HTTPS with Hoodoo::Client. This is a value
71
+ # in seconds (default 60) that the client
72
+ # allows for any TCP read operation. It
73
+ # operates at the HTTP transport level and is
74
+ # independent of any higher level timeouts
75
+ # that might be set up.
76
+ #
77
+ # +http_open_timeout+:: Optional Float providing a Net::HTTP open
78
+ # timeout value, when calling endpoints over
79
+ # HTTPS with Hoodoo::Client. This is a value
80
+ # in seconds (default 60) that the client
81
+ # allows for any TCP connection attempt. It
82
+ # operates at the HTTP transport level and is
83
+ # independent of any higher level timeouts
84
+ # that might be set up.
85
+ #
86
+ # +routing+:: An optional parameter which gives custom
87
+ # routing for exception cases where the
88
+ # by-convention map doesn't work. This is
89
+ # usually because there is a resource
90
+ # singleton which lives logically at a
91
+ # singular named route rather than plural
92
+ # route, e.g. <tt>/v1/health</tt> rather than
93
+ # <tt>/v1/healths</tt>.
75
94
  #
76
95
  # The +routing+ parameter is a Hash of Resource names _as_
77
96
  # _Symbols_, then values which are Hash of API Version _as_
78
- # _Integers_ with values that are the Strings giving the
79
- # full alternative routing path.
97
+ # _Integers_ with values that are the Strings giving the full
98
+ # alternative routing path.
80
99
  #
81
100
  # For example, by convention API version 2 of a Health resource
82
101
  # would be routed to "/v2/healths". You would override this to a
@@ -99,11 +118,13 @@ module Hoodoo
99
118
  # actually Hoodoo itself but implemented in a compatible fashion.
100
119
  #
101
120
  def configure_with( options )
102
- @base_uri = URI.parse( options[ :base_uri ] )
103
- @proxy_uri = URI.parse( options[ :proxy_uri ] ) unless options[ :proxy_uri ].nil?
104
- @ca_file = options[ :ca_file ]
105
- @http_timeout = options[ :http_timeout ]
106
- @routing = options[ :routing ] || {}
121
+ @base_uri = URI.parse( options[ :base_uri ] )
122
+ @proxy_uri = URI.parse( options[ :proxy_uri ] ) unless options[ :proxy_uri ].nil?
123
+
124
+ @ca_file = options[ :ca_file ]
125
+ @http_timeout = options[ :http_timeout ]
126
+ @http_open_timeout = options[ :http_open_timeout ]
127
+ @routing = options[ :routing ] || {}
107
128
  end
108
129
 
109
130
  # Announce the location of an instance. This is really a no-op
@@ -154,12 +175,13 @@ module Hoodoo
154
175
  endpoint_uri.path = path
155
176
 
156
177
  return Hoodoo::Services::Discovery::ForHTTP.new(
157
- resource: resource,
158
- version: version,
159
- endpoint_uri: endpoint_uri,
160
- proxy_uri: @proxy_uri,
161
- ca_file: @ca_file,
162
- http_timeout: @http_timeout
178
+ resource: resource,
179
+ version: version,
180
+ endpoint_uri: endpoint_uri,
181
+ proxy_uri: @proxy_uri,
182
+ ca_file: @ca_file,
183
+ http_timeout: @http_timeout,
184
+ http_open_timeout: @http_open_timeout
163
185
  )
164
186
  end
165
187
 
@@ -51,33 +51,62 @@ module Hoodoo
51
51
  attr_accessor :ca_file
52
52
 
53
53
  # Optional Float indicating the Net::HTTP read timeout value.
54
+ #
55
+ # This is a value in seconds (default 60) for which the client
56
+ # will wait while attempting to read data from a server in any
57
+ # individual TCP read operation. The timeout becomes active
58
+ # immediately after a server connection is established.
59
+ #
60
+ # If a read attempt is still running after the timeout, the
61
+ # request is aborted and a +platform.timeout+ error returned.
62
+ #
63
+ # See also #http_open_timeout.
64
+ #
54
65
  # This operates at the HTTP transport level and is independent
55
- # of any timeouts set within the API providing server.
66
+ # of any higher level timeouts that might be set up.
56
67
  #
57
68
  attr_accessor :http_timeout
58
69
 
70
+ # Optional Float indicating the Net::HTTP open timeout value.
71
+ #
72
+ # This is a value in seconds (default 60) for which the client
73
+ # will wait while attempting to connect to a server.
74
+ #
75
+ # If the connection attempt is still running after the timeout,
76
+ # the request is aborted and a +platform.timeout+ error returned.
77
+ #
78
+ # See also #http_timeout.
79
+ #
80
+ # This operates at the HTTP transport level and is independent
81
+ # of any higher level timeouts that might be set up.
82
+ #
83
+ attr_accessor :http_open_timeout
84
+
59
85
  # Create an instance with named parameters as follows:
60
86
  #
61
- # +resource+:: See #resource.
62
- # +version+:: See #version.
63
- # +endpoint_uri+:: See #endpoint_uri.
64
- # +proxy_uri+:: See #proxy_uri. Optional.
65
- # +ca_file+:: See #ca_file. Optional.
66
- # +http_timeout+:: See #http_timeout. Optional.
87
+ # +resource+:: See #resource.
88
+ # +version+:: See #version.
89
+ # +endpoint_uri+:: See #endpoint_uri.
90
+ # +proxy_uri+:: See #proxy_uri. Optional.
91
+ # +ca_file+:: See #ca_file. Optional.
92
+ # +http_timeout+:: See #http_timeout. Optional.
93
+ # +http_open_timeout+:: See #http_open_timeout. Optional.
67
94
  #
68
95
  def initialize( resource:,
69
96
  version:,
70
97
  endpoint_uri:,
71
- proxy_uri: nil,
72
- ca_file: nil,
73
- http_timeout: nil )
98
+ proxy_uri: nil,
99
+ ca_file: nil,
100
+ http_timeout: nil,
101
+ http_open_timeout: nil )
74
102
 
75
- self.resource = resource.to_sym
76
- self.version = version.to_i
77
- self.endpoint_uri = endpoint_uri
78
- self.proxy_uri = proxy_uri
79
- self.ca_file = ca_file
80
- self.http_timeout = http_timeout
103
+ self.resource = resource.to_sym
104
+ self.version = version.to_i
105
+ self.endpoint_uri = endpoint_uri
106
+ self.proxy_uri = proxy_uri
107
+ self.ca_file = ca_file
108
+ self.http_timeout = http_timeout
109
+ self.http_open_timeout = http_open_timeout
81
110
  end
82
111
  end
83
112
  end
@@ -9,9 +9,14 @@
9
9
 
10
10
  module Hoodoo
11
11
 
12
- # The Hoodoo gem version. If this changes, ensure that the date in
13
- # "hoodoo.gemspec" is correct and run "bundle install" (or "update").
12
+ # The Hoodoo gem version. If this changes, be sure to re-run
13
+ # <tt>bundle install</tt> or <tt>bundle update</tt>.
14
14
  #
15
- VERSION = '1.17.0'
15
+ VERSION = '1.18.0'
16
+
17
+ # The Hoodoo gem date. If this changes, be sure to re-run
18
+ # <tt>bundle install</tt> or <tt>bundle update</tt>.
19
+ #
20
+ DATE = '2017-08-17'
16
21
 
17
22
  end
@@ -461,10 +461,11 @@ describe Hoodoo::Client do
461
461
 
462
462
  context 'and with a custom HTTP read timeout' do
463
463
  before :each do
464
+ timeout = 0.001
464
465
  base_uri = "http://localhost:#{ @port }"
465
466
  discoverer = Hoodoo::Services::Discovery::ByConvention.new(
466
467
  base_uri: base_uri,
467
- http_timeout: 0.0000001
468
+ http_timeout: timeout
468
469
  )
469
470
 
470
471
  set_vars_for(
@@ -473,6 +474,43 @@ describe Hoodoo::Client do
473
474
  session_id: @old_test_session.session_id,
474
475
  discoverer: discoverer
475
476
  )
477
+
478
+ expect_any_instance_of( Net::HTTP ).to receive( :read_timeout= ).with( timeout ).and_call_original
479
+ allow_any_instance_of( Net::BufferedIO ).to receive( :read ) do | instance, *args |
480
+ expect( instance.read_timeout ).to eq( timeout )
481
+ raise Net::ReadTimeout
482
+ end
483
+ end
484
+
485
+ it 'times out elegantly' do
486
+ mock_ident = Hoodoo::UUID.generate()
487
+ result = @endpoint.show( mock_ident )
488
+
489
+ expect( result.platform_errors.has_errors? ).to eq( true )
490
+ expect( result.platform_errors.errors[ 0 ][ 'code' ] ).to eq( 'platform.timeout' )
491
+ end
492
+ end
493
+
494
+ context 'and with a custom HTTP open timeout' do
495
+ before :each do
496
+ timeout = 0.001
497
+ base_uri = "http://localhost:#{ @port }"
498
+ discoverer = Hoodoo::Services::Discovery::ByConvention.new(
499
+ base_uri: base_uri,
500
+ http_open_timeout: timeout
501
+ )
502
+
503
+ set_vars_for(
504
+ base_uri: base_uri,
505
+ auto_session: false,
506
+ session_id: @old_test_session.session_id,
507
+ discoverer: discoverer
508
+ )
509
+
510
+ expect_any_instance_of( Net::HTTP ).to receive( :open_timeout= ).with( timeout ).and_call_original
511
+ expect( Timeout ).to receive( :timeout ).with( timeout, Net::OpenTimeout ).once do
512
+ raise Net::OpenTimeout
513
+ end
476
514
  end
477
515
 
478
516
  it 'times out elegantly' do
@@ -24,14 +24,16 @@ describe Hoodoo::Services::Discovery::ForHTTP do
24
24
  endpoint_uri: endpoint_uri(),
25
25
  proxy_uri: proxy_uri(),
26
26
  ca_file: 'foo.pem',
27
- http_timeout: 0.25
27
+ http_timeout: 0.25,
28
+ http_open_timeout: 2.5
28
29
  )
29
30
 
30
- expect( r.resource ).to eq( :Bar ) # Also Symbol
31
- expect( r.version ).to eq( 2 )
32
- expect( r.endpoint_uri ).to eq( endpoint_uri() )
33
- expect( r.proxy_uri ).to eq( proxy_uri() )
34
- expect( r.ca_file ).to eq( 'foo.pem' )
35
- expect( r.http_timeout ).to eq( 0.25 )
31
+ expect( r.resource ).to eq( :Bar ) # Also Symbol
32
+ expect( r.version ).to eq( 2 )
33
+ expect( r.endpoint_uri ).to eq( endpoint_uri() )
34
+ expect( r.proxy_uri ).to eq( proxy_uri() )
35
+ expect( r.ca_file ).to eq( 'foo.pem' )
36
+ expect( r.http_timeout ).to eq( 0.25 )
37
+ expect( r.http_open_timeout ).to eq( 2.5 )
36
38
  end
37
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hoodoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.17.0
4
+ version: 1.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Loyalty New Zealand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-01 00:00:00.000000000 Z
11
+ date: 2017-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dalli