pact_broker-client 1.38.1 → 1.38.2

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
2
  SHA256:
3
- metadata.gz: e1c89727fa660ba02fd9ff0565b74bf269aada75bfe3b04bb6f117048b265ad9
4
- data.tar.gz: f6c946f2ab43c4cc69550b2fee0740a1782604e7843ae9b6a582664b6ecaee82
3
+ metadata.gz: 134d7fe9f87596c2b56d1edfb136bdff06c045cf1f6e2ef8a3f93b805d3e108d
4
+ data.tar.gz: 57acfb55120c41e97ec1397dceebdd6f9784b9a3ff50c47c6464735c11c6e5a1
5
5
  SHA512:
6
- metadata.gz: 8a9f685a78726d293dc5017f1a142aa1d981a020ff8bdeafa56666a378562cd6c6632449c9ae980dff634e5c5ee216b3eb867b221156d15437166421b8eb1c14
7
- data.tar.gz: 2ac71e6f98f361c1262e3190eb6e8b9ec588de4bb2ae51df6cd0e2bc8f44f4b5ee38270acb1ac670d772069eeaaaa1baea98ec34104c5fa9b91fa3ad5db315c3
6
+ metadata.gz: 235afd0d61e101c549795f7dec7ea22f7d282456d59e72d8f49d7b383e358742e75f6eb866154f99af21b73a34671af6bfc6337fd72fc08b44049d47daeef2f9
7
+ data.tar.gz: 23e3aa5306ce014268b287d7de00b200476cea6f7711821ee5dac95586a3d8ccd1f9152959409209349b0a9a3cc77febcba26d6c90be7b7aa165ef2a3ceb3b22
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ <a name="v1.38.2"></a>
2
+ ### v1.38.2 (2021-04-01)
3
+
4
+ #### Features
5
+
6
+ * allow SSL verification to be disabled ([eb2125b](/../../commit/eb2125b))
7
+ * automatically retry at the http client level for 50x responses ([a7343f8](/../../commit/a7343f8))
8
+
1
9
  <a name="v1.38.1"></a>
2
10
  ### v1.38.1 (2021-03-22)
3
11
 
data/bin/pact-broker CHANGED
@@ -1,4 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'pact_broker/client/cli/broker'
3
3
 
4
+ if ENV['PACT_BROKER_DISABLE_SSL_VERIFICATION'] == 'true' || ENV['PACT_DISABLE_SSL_VERIFICATION'] == 'true'
5
+ require 'openssl'
6
+ OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
7
+ $stderr.puts "WARN: SSL verification has been disabled by a dodgy hack (reassigning the VERIFY_PEER constant to VERIFY_NONE). You acknowledge that you do this at your own risk!"
8
+ end
9
+
4
10
  PactBroker::Client::CLI::Broker.start
@@ -39,6 +39,7 @@ module PactBroker
39
39
  can_i_deploy_options = { output: options.output, retry_while_unknown: options.retry_while_unknown, retry_interval: options.retry_interval }
40
40
  result = CanIDeploy.call(options.broker_base_url, selectors, { to_tag: options.to, to_environment: options.to_environment, limit: options.limit }, can_i_deploy_options, pact_broker_client_options)
41
41
  $stdout.puts result.message
42
+ $stdout.flush
42
43
  exit(can_i_deploy_exit_status) unless result.success
43
44
  end
44
45
 
@@ -7,6 +7,7 @@ module PactBroker
7
7
  module Client
8
8
  module Hal
9
9
  class HttpClient
10
+ RETRYABLE_ERRORS = [Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::EHOSTUNREACH, Net::ReadTimeout]
10
11
  attr_accessor :username, :password, :verbose, :token
11
12
 
12
13
  def initialize options
@@ -53,7 +54,7 @@ module PactBroker
53
54
  end
54
55
 
55
56
  def perform_request request, uri
56
- response = Retry.until_truthy_or_max_times do
57
+ response = until_truthy_or_max_times(times: 5, sleep: 5, condition: ->(resp) { resp.code.to_i < 500 }) do
57
58
  http = Net::HTTP.new(uri.host, uri.port, :ENV)
58
59
  http.set_debug_output(output_stream) if verbose
59
60
  http.use_ssl = (uri.scheme == 'https')
@@ -69,6 +70,37 @@ module PactBroker
69
70
  Response.new(response)
70
71
  end
71
72
 
73
+ def until_truthy_or_max_times options = {}
74
+ max_tries = options.fetch(:times, 3)
75
+ tries = 0
76
+ sleep_interval = options.fetch(:sleep, 5)
77
+ sleep(sleep_interval) if options[:sleep_first]
78
+ while true
79
+ begin
80
+ result = yield
81
+ return result if max_tries < 2
82
+ if options[:condition]
83
+ condition_result = options[:condition].call(result)
84
+ return result if condition_result
85
+ else
86
+ return result if result
87
+ end
88
+ tries += 1
89
+ return result if max_tries == tries
90
+ sleep sleep_interval
91
+ rescue *RETRYABLE_ERRORS => e
92
+ tries += 1
93
+ $stderr.puts "ERROR: Error making request - #{e.class} #{e.message} #{e.backtrace.find{|l| l.include?('pact_broker-client')}}, attempt #{tries} of #{max_tries}"
94
+ raise e if max_tries == tries
95
+ sleep sleep_interval
96
+ end
97
+ end
98
+ end
99
+
100
+ def sleep seconds
101
+ Kernel.sleep seconds
102
+ end
103
+
72
104
  def output_stream
73
105
  AuthorizationHeaderRedactor.new($stdout)
74
106
  end
@@ -1,5 +1,5 @@
1
1
  module PactBroker
2
2
  module Client
3
- VERSION = '1.38.1'
3
+ VERSION = '1.38.2'
4
4
  end
5
5
  end
@@ -3,13 +3,13 @@ require 'pact_broker/client/hal/http_client'
3
3
  module PactBroker::Client
4
4
  module Hal
5
5
  describe HttpClient do
6
- before do
7
- allow(Retry).to receive(:until_truthy_or_max_times) { |&block| block.call }
8
- end
9
-
10
6
  subject { HttpClient.new(username: 'foo', password: 'bar') }
11
7
 
12
8
  describe "get" do
9
+ before do
10
+ allow(subject).to receive(:until_truthy_or_max_times) { |&block| block.call }
11
+ end
12
+
13
13
  let!(:request) do
14
14
  stub_request(:get, "http://example.org/").
15
15
  with( headers: {
@@ -41,18 +41,22 @@ module PactBroker::Client
41
41
  end
42
42
  end
43
43
 
44
-
45
44
  it "retries on failure" do
46
- expect(Retry).to receive(:until_truthy_or_max_times)
45
+ expect(subject).to receive(:until_truthy_or_max_times)
47
46
  do_get
48
47
  end
49
48
 
50
49
  it "returns a response" do
51
50
  expect(do_get.body).to eq({"some" => "json"})
52
51
  end
52
+
53
53
  end
54
54
 
55
55
  describe "post" do
56
+ before do
57
+ allow(subject).to receive(:until_truthy_or_max_times) { |&block| block.call }
58
+ end
59
+
56
60
  let!(:request) do
57
61
  stub_request(:post, "http://example.org/").
58
62
  with( headers: {
@@ -75,7 +79,7 @@ module PactBroker::Client
75
79
  end
76
80
 
77
81
  it "calls Retry.until_truthy_or_max_times" do
78
- expect(Retry).to receive(:until_truthy_or_max_times)
82
+ expect(subject).to receive(:until_truthy_or_max_times)
79
83
  do_post
80
84
  end
81
85
 
@@ -100,6 +104,59 @@ module PactBroker::Client
100
104
  end
101
105
  end
102
106
  end
107
+
108
+ describe "integration test" do
109
+ before do
110
+ allow(subject).to receive(:sleep)
111
+ end
112
+
113
+ let(:do_get) { subject.get('http://example.org') }
114
+
115
+ context "with a 50x error is returned less than the max number of tries" do
116
+ let!(:request) do
117
+ stub_request(:get, "http://example.org").
118
+ to_return({ status: 500 }, { status: 502 }, { status: 503 }, { status: 200 })
119
+ end
120
+
121
+ it "retries" do
122
+ expect(do_get.status).to eq 200
123
+ end
124
+ end
125
+
126
+ context "with a 50x error is returned more than the max number of tries" do
127
+ let!(:request) do
128
+ stub_request(:get, "http://example.org").
129
+ to_return({ status: 500 }, { status: 501 }, { status: 502 }, { status: 503 }, { status: 504 })
130
+ end
131
+
132
+ it "retries and returns the last 50x response" do
133
+ expect(do_get.status).to eq 504
134
+ end
135
+ end
136
+
137
+ context "when exceptions are raised" do
138
+ before do
139
+ allow($stderr).to receive(:puts)
140
+ end
141
+
142
+ let!(:request) do
143
+ stub_request(:get, "http://example.org")
144
+ .to_raise(Errno::ECONNREFUSED)
145
+ end
146
+
147
+ it "logs the error" do
148
+ expect($stderr).to receive(:puts).with(/Errno::ECONNREFUSED/)
149
+ begin
150
+ do_get
151
+ rescue Errno::ECONNREFUSED
152
+ end
153
+ end
154
+
155
+ it "retries and raises the last exception" do
156
+ expect { do_get }.to raise_error(Errno::ECONNREFUSED)
157
+ end
158
+ end
159
+ end
103
160
  end
104
161
  end
105
162
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact_broker-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.38.1
4
+ version: 1.38.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beth Skurrie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-22 00:00:00.000000000 Z
11
+ date: 2021-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty