hoodoo 1.17.0 → 1.18.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 +4 -4
- data/lib/hoodoo/client/endpoint/endpoints/http.rb +14 -11
- data/lib/hoodoo/client/endpoint/endpoints/http_based.rb +27 -1
- data/lib/hoodoo/services/discovery/discoverers/by_convention.rb +71 -49
- data/lib/hoodoo/services/discovery/results/for_http.rb +45 -16
- data/lib/hoodoo/version.rb +8 -3
- data/spec/client/client_spec.rb +39 -1
- data/spec/services/discovery/results/for_http_spec.rb +9 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33592f5c0f6228a5253592dff50c587e70319ae8
|
4
|
+
data.tar.gz: 3f7c50f2d5935c5758c2efd61a650b96335be4bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
37
|
-
@description.discovery_result
|
38
|
-
@description.endpoint_uri
|
39
|
-
@description.proxy_uri
|
40
|
-
@description.ca_file
|
41
|
-
@description.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
|
119
|
-
proxy
|
120
|
-
ca_file
|
121
|
-
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
|
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+::
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
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
|
-
#
|
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
|
103
|
-
@proxy_uri
|
104
|
-
|
105
|
-
@
|
106
|
-
@
|
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:
|
158
|
-
version:
|
159
|
-
endpoint_uri:
|
160
|
-
proxy_uri:
|
161
|
-
ca_file:
|
162
|
-
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
|
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+::
|
62
|
-
# +version+::
|
63
|
-
# +endpoint_uri+::
|
64
|
-
# +proxy_uri+::
|
65
|
-
# +ca_file+::
|
66
|
-
# +http_timeout+::
|
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:
|
72
|
-
ca_file:
|
73
|
-
http_timeout:
|
98
|
+
proxy_uri: nil,
|
99
|
+
ca_file: nil,
|
100
|
+
http_timeout: nil,
|
101
|
+
http_open_timeout: nil )
|
74
102
|
|
75
|
-
self.resource
|
76
|
-
self.version
|
77
|
-
self.endpoint_uri
|
78
|
-
self.proxy_uri
|
79
|
-
self.ca_file
|
80
|
-
self.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
|
data/lib/hoodoo/version.rb
CHANGED
@@ -9,9 +9,14 @@
|
|
9
9
|
|
10
10
|
module Hoodoo
|
11
11
|
|
12
|
-
# The Hoodoo gem version. If this changes,
|
13
|
-
#
|
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.
|
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
|
data/spec/client/client_spec.rb
CHANGED
@@ -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:
|
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
|
31
|
-
expect( r.version
|
32
|
-
expect( r.endpoint_uri
|
33
|
-
expect( r.proxy_uri
|
34
|
-
expect( r.ca_file
|
35
|
-
expect( r.http_timeout
|
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.
|
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-
|
11
|
+
date: 2017-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dalli
|