pact_broker-client 1.28.4 → 1.32.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +41 -0
- data/Gemfile +0 -4
- data/README.md +8 -1
- data/lib/pact_broker/client/base_client.rb +11 -3
- data/lib/pact_broker/client/hal/http_client.rb +5 -0
- data/lib/pact_broker/client/matrix.rb +3 -1
- data/lib/pact_broker/client/pacts/list_latest_versions.rb +1 -1
- data/lib/pact_broker/client/publish_pacts.rb +11 -9
- data/lib/pact_broker/client/version.rb +1 -1
- data/pact-broker-client.gemspec +1 -1
- data/script/create-pacticipant.sh +2 -0
- data/spec/lib/pact_broker/client/base_client_spec.rb +62 -4
- data/spec/lib/pact_broker/client/publish_pacts_spec.rb +19 -0
- metadata +11 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fc996a2d95d7c3755d063cd244b273fa5924f6956cf18b26ebe9531fa59e304
|
4
|
+
data.tar.gz: '018d1d764a83f040d57d6ef504a6b4229f34f3fff38cf938c8c3f2202e03cc7a'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95944c92c42aa29803c5bd37b5b4c8526359cb910c4a983123379ac2f0482483aae75fc9179d2e6341e1931019c3f1588e1d7a385ffa628c203fd829d3137bfb
|
7
|
+
data.tar.gz: 5391400fa12118608718161c3ea286ffe1b3b7aebbe1eca074b999b1903b25f6a3f15e257459e35240e30faf768949d45c45a052616378507b0eaf970590ee1b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,44 @@
|
|
1
|
+
<a name="v1.32.0"></a>
|
2
|
+
### v1.32.0 (2020-10-26)
|
3
|
+
|
4
|
+
#### Features
|
5
|
+
|
6
|
+
* Improve HTTP errors handling (#76) ([d8eaf16](/../../commit/d8eaf16))
|
7
|
+
|
8
|
+
#### Bug Fixes
|
9
|
+
|
10
|
+
* **list-latest-pact-versions**
|
11
|
+
* correct json output ([cf77666](/../../commit/cf77666))
|
12
|
+
|
13
|
+
<a name="v1.31.0"></a>
|
14
|
+
### v1.31.0 (2020-10-22)
|
15
|
+
|
16
|
+
#### Features
|
17
|
+
|
18
|
+
* update thor dependancy (#75) ([2078f31](/../../commit/2078f31))
|
19
|
+
|
20
|
+
<a name="v1.30.0"></a>
|
21
|
+
### v1.30.0 (2020-10-09)
|
22
|
+
|
23
|
+
#### Features
|
24
|
+
|
25
|
+
* remove outdated comment from pact publishing output ([251b4df](/../../commit/251b4df))
|
26
|
+
|
27
|
+
<a name="v1.29.1"></a>
|
28
|
+
### v1.29.1 (2020-08-07)
|
29
|
+
|
30
|
+
#### Bug Fixes
|
31
|
+
|
32
|
+
* explicitly set the CA file and path from SSL_CERT_FILE and SSL_CERT_DIR for the pact-ruby-standalone ([27a0fe6](/../../commit/27a0fe6))
|
33
|
+
|
34
|
+
<a name="v1.29.0"></a>
|
35
|
+
### v1.29.0 (2020-08-05)
|
36
|
+
|
37
|
+
#### Features
|
38
|
+
|
39
|
+
* print out helpful error message for 403 ([5d5a18a](/../../commit/5d5a18a))
|
40
|
+
* support publishing pacts for multiple consumers at the same time ([573e97c](/../../commit/573e97c))
|
41
|
+
|
1
42
|
<a name="v1.28.4"></a>
|
2
43
|
### v1.28.4 (2020-07-31)
|
3
44
|
|
data/Gemfile
CHANGED
@@ -6,10 +6,6 @@ gemspec
|
|
6
6
|
# even thought it's in the development dependencies. Trying it here.
|
7
7
|
gem 'rake', '~> 13.0'
|
8
8
|
|
9
|
-
group :release do
|
10
|
-
gem 'bump', git: 'https://github.com/bethesque/bump.git'
|
11
|
-
end
|
12
|
-
|
13
9
|
if ENV['X_PACT_DEVELOPMENT'] == 'true'
|
14
10
|
gem 'pact-mock_service', path: '../pact-mock_service'
|
15
11
|
gem 'pact-support', path: '../pact-support'
|
data/README.md
CHANGED
@@ -153,7 +153,7 @@ Can I deploy the latest version of the application Foo that has the tag "test" t
|
|
153
153
|
|
154
154
|
If you are unable to use tags, or there is some other limitation that stops you from using the recommended approach, you can specify one or more of the dependencies explictly. You must also do this if you want to use the `--all TAG` option for any of the pacticipants.
|
155
155
|
|
156
|
-
You can specify as many application versions as you like, and you can even specify multiple versions of the same application (repeat the `--pacticipant` name and supply a different version.
|
156
|
+
You can specify as many application versions as you like, and you can even specify multiple versions of the same application (repeat the `--pacticipant` name and supply a different version). If you have a monorepo and you deploy a group of applications together, you can either call `can-i-deploy` once for each application, or you can group them all together by specifying a `--pacticipant` and `--version` for each sub-application.
|
157
157
|
|
158
158
|
You can use explictly declared dependencies with or without the `--to ENVIRONMENT`. For example, if you declare two (or more) application versions with no `--to ENVIRONMENT`, then only the applications you specify will be taken into account when determining if it is safe to deploy. If you declare two (or more) application versions _as well as_ a `--to ENVIRONMENT`, then the Pact Broker will work out what integrations your declared applications will have in that environment when determining if it safe to deploy. When using this script for a production release, and you are using tags, it is always the most future-proof option to use the `--to` if possible, as it will catch any newly added consumers or providers.
|
159
159
|
|
@@ -182,6 +182,13 @@ Can I deploy the latest version of Foo with tag "master" and the latest version
|
|
182
182
|
--pacticipant Bar --latest master \
|
183
183
|
--broker-base-url BROKER_BASE_URL
|
184
184
|
|
185
|
+
Can I deploy all the applications in my monorepo to prod?
|
186
|
+
|
187
|
+
$ pact-broker can-i-deploy --pacticipant A --version a7e28207 \
|
188
|
+
--pacticipant B --version a7e28207 \
|
189
|
+
--pacticipant C --version a7e28207 \
|
190
|
+
--to prod \
|
191
|
+
--broker-base-url BROKER_BASE_URL
|
185
192
|
|
186
193
|
Mobile provider use case - can I deploy version b80e7b1b of Bar, all versions of Foo with tag "prod", and the latest version tagged "prod" of any other automatically calculated dependencies together? (Eg. where Bar is a provider and Foo is a mobile consumer with multiple versions in production, and Bar also has its own providers it needs to be compatible with.)
|
187
194
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'erb'
|
2
4
|
require 'httparty'
|
3
5
|
require 'pact_broker/client/error'
|
@@ -30,6 +32,12 @@ module PactBroker
|
|
30
32
|
end
|
31
33
|
|
32
34
|
class BaseClient
|
35
|
+
ERROR_CODE_MAPPING = {
|
36
|
+
401 => "Authentication failed",
|
37
|
+
403 => "Authorization failed (insufficient permissions)",
|
38
|
+
409 => "Potential duplicate pacticipants"
|
39
|
+
}.freeze
|
40
|
+
|
33
41
|
include UrlHelpers
|
34
42
|
include HTTParty
|
35
43
|
include StringToSymbol
|
@@ -69,8 +77,8 @@ module PactBroker
|
|
69
77
|
yield response
|
70
78
|
elsif response.code == 404
|
71
79
|
nil
|
72
|
-
elsif response.code
|
73
|
-
message =
|
80
|
+
elsif ERROR_CODE_MAPPING.key?(response.code)
|
81
|
+
message = ERROR_CODE_MAPPING.fetch(response.code)
|
74
82
|
if response.body && response.body.size > 0
|
75
83
|
message = message + ": #{response.body}"
|
76
84
|
end
|
@@ -87,7 +95,7 @@ module PactBroker
|
|
87
95
|
response.body
|
88
96
|
end
|
89
97
|
rescue
|
90
|
-
raise Error.new(response.body)
|
98
|
+
raise Error.new("status=#{response.code} #{response.body}")
|
91
99
|
end
|
92
100
|
raise Error.new(error_message)
|
93
101
|
end
|
@@ -57,6 +57,11 @@ module PactBroker
|
|
57
57
|
http = Net::HTTP.new(uri.host, uri.port, :ENV)
|
58
58
|
http.set_debug_output(output_stream) if verbose
|
59
59
|
http.use_ssl = (uri.scheme == 'https')
|
60
|
+
# Need to manually set the ca_file and ca_path for the pact-ruby-standalone.
|
61
|
+
# The env vars seem to be picked up automatically in later Ruby versions.
|
62
|
+
# See https://github.com/pact-foundation/pact-ruby-standalone/issues/57
|
63
|
+
http.ca_file = ENV['SSL_CERT_FILE'] if ENV['SSL_CERT_FILE'] && ENV['SSL_CERT_FILE'] != ''
|
64
|
+
http.ca_path = ENV['SSL_CERT_DIR'] if ENV['SSL_CERT_DIR'] && ENV['SSL_CERT_DIR'] != ''
|
60
65
|
http.start do |http|
|
61
66
|
http.request request
|
62
67
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'base_client'
|
2
4
|
require 'pact_broker/client/matrix/resource'
|
3
5
|
|
@@ -39,7 +41,7 @@ module PactBroker
|
|
39
41
|
response.body
|
40
42
|
end
|
41
43
|
rescue
|
42
|
-
raise Error.new(response.body)
|
44
|
+
raise Error.new("status=#{response.code} #{response.body}")
|
43
45
|
end
|
44
46
|
raise Error.new(error_message)
|
45
47
|
end
|
@@ -52,6 +52,10 @@ module PactBroker
|
|
52
52
|
@pact_files ||= pact_file_paths.collect{ |pact_file_path| PactFile.new(pact_file_path) }
|
53
53
|
end
|
54
54
|
|
55
|
+
def consumer_names
|
56
|
+
pact_files.collect(&:consumer_name).uniq
|
57
|
+
end
|
58
|
+
|
55
59
|
def publish_pact pact
|
56
60
|
begin
|
57
61
|
$stdout.puts "Publishing #{pact.pact_name} to pact broker at #{pact_broker_base_url}"
|
@@ -72,12 +76,14 @@ module PactBroker
|
|
72
76
|
def tag_consumer_version tag
|
73
77
|
versions = pact_broker_client.pacticipants.versions
|
74
78
|
Retry.while_error do
|
75
|
-
|
76
|
-
|
77
|
-
|
79
|
+
consumer_names.collect do | consumer_name |
|
80
|
+
versions.tag(pacticipant: consumer_name, version: consumer_version, tag: tag)
|
81
|
+
$stdout.puts "Tagged version #{consumer_version} of #{consumer_name} as #{tag.inspect}"
|
82
|
+
true
|
83
|
+
end
|
78
84
|
end
|
79
85
|
rescue => e
|
80
|
-
$stderr.puts "Failed to tag version
|
86
|
+
$stderr.puts "Failed to tag version due to error: #{e.class} - #{e}"
|
81
87
|
false
|
82
88
|
end
|
83
89
|
|
@@ -89,15 +95,11 @@ module PactBroker
|
|
89
95
|
end
|
90
96
|
|
91
97
|
latest_pact_url = pacts.publish(pact_hash: pact, consumer_version: consumer_version)
|
92
|
-
$stdout.puts "The latest version of this pact can be accessed at the following URL
|
98
|
+
$stdout.puts "The latest version of this pact can be accessed at the following URL:\n#{latest_pact_url}"
|
93
99
|
true
|
94
100
|
end
|
95
101
|
end
|
96
102
|
|
97
|
-
def consumer_name
|
98
|
-
pact_files.first.consumer_name
|
99
|
-
end
|
100
|
-
|
101
103
|
def validate
|
102
104
|
raise PactBroker::Client::Error.new("Please specify the consumer_version") unless (consumer_version && consumer_version.to_s.strip.size > 0)
|
103
105
|
raise PactBroker::Client::Error.new("Please specify the pact_broker_base_url") unless (pact_broker_base_url && pact_broker_base_url.to_s.strip.size > 0)
|
data/pact-broker-client.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |gem|
|
|
24
24
|
gem.add_runtime_dependency 'httparty', '~>0.18'
|
25
25
|
gem.add_runtime_dependency 'term-ansicolor', '~> 1.7'
|
26
26
|
gem.add_runtime_dependency 'table_print', '~> 1.5'
|
27
|
-
gem.add_runtime_dependency 'thor', '
|
27
|
+
gem.add_runtime_dependency 'thor', '>= 0.20', '< 2.0'
|
28
28
|
gem.add_runtime_dependency 'rake', '~> 13.0' #For FileList
|
29
29
|
|
30
30
|
gem.add_development_dependency 'fakefs', '~> 0.4'
|
@@ -2,10 +2,11 @@ require 'pact_broker/client/base_client'
|
|
2
2
|
module PactBroker
|
3
3
|
module Client
|
4
4
|
describe BaseClient do
|
5
|
-
|
6
|
-
|
5
|
+
subject { BaseClient.new(base_url: base_url) }
|
6
|
+
|
7
|
+
let(:base_url) { 'http://pact_broker_base_url'}
|
7
8
|
|
8
|
-
|
9
|
+
describe '#initialize' do
|
9
10
|
let(:username) { 'pact_repo_username'}
|
10
11
|
let(:password) { 'pact_repo_password'}
|
11
12
|
let(:token) { '123456789' }
|
@@ -119,6 +120,63 @@ module PactBroker
|
|
119
120
|
end
|
120
121
|
end
|
121
122
|
end
|
123
|
+
|
124
|
+
describe '#handle_response' do
|
125
|
+
let(:response) { double('Response', success?: true) }
|
126
|
+
|
127
|
+
it 'yields response object' do
|
128
|
+
expect { |block| subject.handle_response(response, &block) }.to yield_with_args(response)
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'with 404 response' do
|
132
|
+
let(:response) { double('Response', success?: false, code: 404) }
|
133
|
+
it 'returns nil' do
|
134
|
+
expect(subject.handle_response(response)).to be_nil
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'with 401 response' do
|
139
|
+
let(:response) { double('Response', success?: false, code: 401, body: 'body') }
|
140
|
+
it 'raise an exception with meaningful message' do
|
141
|
+
expect { subject.handle_response(response) }
|
142
|
+
.to raise_error(PactBroker::Client::Error, "Authentication failed: body")
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'with 403 response' do
|
147
|
+
let(:response) { double('Response', success?: false, code: 403, body: 'body') }
|
148
|
+
it 'raise an exception with meaningful message' do
|
149
|
+
expect { subject.handle_response(response) }
|
150
|
+
.to raise_error(PactBroker::Client::Error, "Authorization failed (insufficient permissions): body")
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'with 409 response' do
|
155
|
+
let(:response) { double('Response', success?: false, code: 409, body: 'body') }
|
156
|
+
it 'raise an exception with meaningful message' do
|
157
|
+
expect { subject.handle_response(response) }
|
158
|
+
.to raise_error(PactBroker::Client::Error, "Potential duplicate pacticipants: body")
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'with unsuccessful JSON response' do
|
163
|
+
let(:response) do
|
164
|
+
double('Response', success?: false, code: 500, body: '{"errors": ["Internal server error"]}')
|
165
|
+
end
|
166
|
+
it 'raise an exception with meaningful message' do
|
167
|
+
expect { subject.handle_response(response) }
|
168
|
+
.to raise_error(PactBroker::Client::Error, "Internal server error")
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'with unsucessful nono-JSON response ' do
|
173
|
+
let(:response) { double('Response', success?: false, code: 500, body: 'Internal server error') }
|
174
|
+
it 'raise an exception with meaningful message' do
|
175
|
+
expect { subject.handle_response(response) }
|
176
|
+
.to raise_error(PactBroker::Client::Error, "status=500 Internal server error")
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
122
180
|
end
|
123
181
|
end
|
124
|
-
end
|
182
|
+
end
|
@@ -81,6 +81,25 @@ module PactBroker
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
+
context "when publishing multiple files with different consumers" do
|
85
|
+
let(:pact_file_paths) { ['spec/pacts/consumer-provider.json','spec/pacts/foo-bar.json']}
|
86
|
+
let(:tags) { ['dev'] }
|
87
|
+
|
88
|
+
it "tags each consumer" do
|
89
|
+
expect(pact_versions_client).to receive(:tag).with(
|
90
|
+
pacticipant: "Consumer",
|
91
|
+
version: consumer_version,
|
92
|
+
tag: "dev"
|
93
|
+
)
|
94
|
+
expect(pact_versions_client).to receive(:tag).with(
|
95
|
+
pacticipant: "Foo",
|
96
|
+
version: consumer_version,
|
97
|
+
tag: "dev"
|
98
|
+
)
|
99
|
+
subject.call
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
84
103
|
context "when publishing one or more pacts fails" do
|
85
104
|
let(:pact_file_paths) { ['spec/pacts/consumer-provider.json','spec/pacts/foo-bar.json']}
|
86
105
|
|
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.
|
4
|
+
version: 1.32.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Beth Skurrie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -56,16 +56,22 @@ dependencies:
|
|
56
56
|
name: thor
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0.20'
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '2.0'
|
62
65
|
type: :runtime
|
63
66
|
prerelease: false
|
64
67
|
version_requirements: !ruby/object:Gem::Requirement
|
65
68
|
requirements:
|
66
|
-
- - "
|
69
|
+
- - ">="
|
67
70
|
- !ruby/object:Gem::Version
|
68
71
|
version: '0.20'
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '2.0'
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
76
|
name: rake
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -216,6 +222,7 @@ files:
|
|
216
222
|
- lib/pact_broker/client/webhooks/test.rb
|
217
223
|
- lib/pact_broker_client.rb
|
218
224
|
- pact-broker-client.gemspec
|
225
|
+
- script/create-pacticipant.sh
|
219
226
|
- script/generate-cli-usage.sh
|
220
227
|
- script/publish-pact.sh
|
221
228
|
- script/release.sh
|