pact_broker-client 1.18.0 → 1.19.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 +20 -0
- data/README.md +2 -1
- data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +4 -4
- data/lib/pact_broker/client/git.rb +8 -0
- data/lib/pact_broker/client/hal/authorization_header_redactor.rb +34 -0
- data/lib/pact_broker/client/hal/http_client.rb +11 -4
- data/lib/pact_broker/client/merge_pacts.rb +3 -4
- data/lib/pact_broker/client/version.rb +1 -1
- data/lib/pact_broker/client/webhooks/create.rb +1 -3
- data/script/publish-pact.sh +1 -1
- data/spec/lib/pact_broker/client/hal/authorization_header_redactor_spec.rb +17 -0
- data/spec/lib/pact_broker/client/hal/http_client_spec.rb +4 -4
- data/spec/lib/pact_broker/client/merge_pacts_spec.rb +1 -1
- data/spec/lib/pact_broker/client/webhooks/create_spec.rb +9 -3
- data/spec/pacts/pact_broker_client-pact_broker.json +5 -8
- data/spec/service_providers/pact_broker_client_matrix_spec.rb +6 -6
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 254d1374fb868966c77ccff58753e8d53d96f577
|
4
|
+
data.tar.gz: fe50c5757ad5e4e10efda0aa144e63e167fec078
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9104dcc0ffcd52808781158d8ec862314063b18fbd5338ac535e8baba140030e833af899b1af00056f3822933790f9631214a01be04bfa0d48228b366b344856
|
7
|
+
data.tar.gz: c251c838c5379b259120af768652493d05184d812157b6b3d44963116016707709c2216138c21b74109038291f0c3d102ecc200f83c856e1ec995bf924f9a540
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
<a name="v1.19.0"></a>
|
2
|
+
### v1.19.0 (2019-06-25)
|
3
|
+
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
* **hal client**
|
8
|
+
* update from pact-ruby ([f8b3432](/../../commit/f8b3432))
|
9
|
+
|
10
|
+
* update pact with broker for scenario where version does not exist ([27b744f](/../../commit/27b744f))
|
11
|
+
|
12
|
+
|
13
|
+
#### Bug Fixes
|
14
|
+
|
15
|
+
* **create webhook**
|
16
|
+
* pass in token from command line ([9d3170e](/../../commit/9d3170e))
|
17
|
+
|
18
|
+
* correct pact merge error message ([5ebe808](/../../commit/5ebe808))
|
19
|
+
|
20
|
+
|
1
21
|
<a name="v1.18.0"></a>
|
2
22
|
### v1.18.0 (2019-03-05)
|
3
23
|
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Pact Broker Client
|
2
2
|
|
3
|
-
A client for the Pact Broker. Publishes pacts to, and retrieves pacts from,
|
3
|
+
A client for the Pact Broker. Publishes pacts to, and retrieves pacts from, a Pact Broker. The functionality is available via a CLI, or via Ruby Rake tasks. You can also use the [Pact CLI Docker image][docker].
|
4
4
|
|
5
5
|
[![Build Status](https://travis-ci.org/pact-foundation/pact_broker-client.svg?branch=master)](https://travis-ci.org/pact-foundation/pact_broker-client)
|
6
6
|
|
@@ -231,3 +231,4 @@ bundle exec rake pact:publish
|
|
231
231
|
|
232
232
|
[wiki-tags]: https://github.com/pact-foundation/pact_broker/wiki/Using-tags
|
233
233
|
[pact-ruby-standalone]: https://github.com/pact-foundation/pact-ruby-standalone/releases
|
234
|
+
[docker]: https://cloud.docker.com/u/pactfoundation/repository/docker/pactfoundation/pact-cli
|
@@ -417,14 +417,14 @@ Given **the pact for Foo version 1.2.3 has been verified by Bar version 4.5.6**,
|
|
417
417
|
Pact Broker will respond with:
|
418
418
|
```json
|
419
419
|
{
|
420
|
-
"status":
|
420
|
+
"status": 200,
|
421
421
|
"headers": {
|
422
422
|
"Content-Type": "application/hal+json;charset=utf-8"
|
423
423
|
},
|
424
424
|
"body": {
|
425
|
-
"
|
426
|
-
"an error message"
|
427
|
-
|
425
|
+
"summary": {
|
426
|
+
"reason": "an error message"
|
427
|
+
}
|
428
428
|
}
|
429
429
|
}
|
430
430
|
```
|
@@ -1,5 +1,13 @@
|
|
1
1
|
require 'pact_broker/client/error'
|
2
2
|
|
3
|
+
# BUILDKITE_BRANCH BUILDKITE_COMMIT https://buildkite.com/docs/pipelines/environment-variables
|
4
|
+
# CIRCLE_BRANCH CIRCLE_SHA1 https://circleci.com/docs/2.0/env-vars/
|
5
|
+
# TRAVIS_COMMIT TRAVIS_BRANCH - TRAVIS_PULL_REQUEST_BRANCH TRAVIS_PULL_REQUEST_SHA https://docs.travis-ci.com/user/environment-variables/
|
6
|
+
# GIT_COMMIT GIT_BRANCH https://wiki.jenkins.io/display/JENKINS/Building+a+software+project
|
7
|
+
# GIT_COMMIT GIT_LOCAL_BRANCH https://hudson.eclipse.org/webtools/env-vars.html/
|
8
|
+
# APPVEYOR_REPO_COMMIT APPVEYOR_REPO_BRANCH https://www.appveyor.com/docs/environment-variables/
|
9
|
+
# bamboo.repository.git.branch https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html
|
10
|
+
|
3
11
|
module PactBroker
|
4
12
|
module Client
|
5
13
|
module Git
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Client
|
5
|
+
module Hal
|
6
|
+
class AuthorizationHeaderRedactor < SimpleDelegator
|
7
|
+
def puts(*args)
|
8
|
+
__getobj__().puts(*redact_args(args))
|
9
|
+
end
|
10
|
+
|
11
|
+
def print(*args)
|
12
|
+
__getobj__().puts(*redact_args(args))
|
13
|
+
end
|
14
|
+
|
15
|
+
def <<(*args)
|
16
|
+
__getobj__().send(:<<, *redact_args(args))
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :redactions
|
22
|
+
|
23
|
+
def redact_args(args)
|
24
|
+
args.collect{ | s| redact(s) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def redact(string)
|
28
|
+
return string unless string.is_a?(String)
|
29
|
+
string.gsub(/Authorization: .*\\r\\n/, "Authorization: [redacted]\\r\\n")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,15 +1,18 @@
|
|
1
1
|
require 'pact_broker/client/retry'
|
2
|
+
require 'pact_broker/client/hal/authorization_header_redactor'
|
3
|
+
require 'net/http'
|
2
4
|
|
3
5
|
module PactBroker
|
4
6
|
module Client
|
5
7
|
module Hal
|
6
8
|
class HttpClient
|
7
|
-
attr_accessor :username, :password, :verbose
|
9
|
+
attr_accessor :username, :password, :verbose, :token
|
8
10
|
|
9
11
|
def initialize options
|
10
12
|
@username = options[:username]
|
11
13
|
@password = options[:password]
|
12
14
|
@verbose = options[:verbose]
|
15
|
+
@token = options[:token]
|
13
16
|
end
|
14
17
|
|
15
18
|
def get href, params = {}, headers = {}
|
@@ -39,13 +42,14 @@ module PactBroker
|
|
39
42
|
|
40
43
|
request.body = body if body
|
41
44
|
request.basic_auth username, password if username
|
45
|
+
request['Authorization'] = "Bearer #{token}" if token
|
42
46
|
request
|
43
47
|
end
|
44
48
|
|
45
49
|
def perform_request request, uri
|
46
|
-
response = Retry.
|
50
|
+
response = Retry.until_truthy_or_max_times do
|
47
51
|
http = Net::HTTP.new(uri.host, uri.port, :ENV)
|
48
|
-
http.set_debug_output(
|
52
|
+
http.set_debug_output(output_stream) if verbose
|
49
53
|
http.use_ssl = (uri.scheme == 'https')
|
50
54
|
http.start do |http|
|
51
55
|
http.request request
|
@@ -54,6 +58,10 @@ module PactBroker
|
|
54
58
|
Response.new(response)
|
55
59
|
end
|
56
60
|
|
61
|
+
def output_stream
|
62
|
+
AuthorizationHeaderRedactor.new($stdout)
|
63
|
+
end
|
64
|
+
|
57
65
|
class Response < SimpleDelegator
|
58
66
|
def body
|
59
67
|
bod = raw_body
|
@@ -77,7 +85,6 @@ module PactBroker
|
|
77
85
|
end
|
78
86
|
end
|
79
87
|
end
|
80
|
-
|
81
88
|
end
|
82
89
|
end
|
83
90
|
end
|
@@ -42,10 +42,9 @@ module PactBroker
|
|
42
42
|
private
|
43
43
|
|
44
44
|
def almost_duplicate_message(original, new_interaction)
|
45
|
-
"
|
46
|
-
"Please use a different description or provider state, or hard-code any random data.\n" +
|
47
|
-
original.to_json + "\n\n"
|
48
|
-
new_interaction.to_json
|
45
|
+
"Two interactions have been found with same description (#{new_interaction[:description].inspect}) and provider state (#{new_interaction[:providerState].inspect}) but a different request or response. " +
|
46
|
+
"Please use a different description or provider state, or hard-code any random data.\n\n" +
|
47
|
+
original.to_json + "\n\n" + new_interaction.to_json
|
49
48
|
end
|
50
49
|
|
51
50
|
def same_description_and_state? original, additional
|
@@ -20,9 +20,7 @@ module PactBroker
|
|
20
20
|
def initialize(params, pact_broker_base_url, pact_broker_client_options)
|
21
21
|
@params = OpenStruct.new(params)
|
22
22
|
@pact_broker_base_url = pact_broker_base_url
|
23
|
-
@
|
24
|
-
@verbose = pact_broker_client_options[:verbose]
|
25
|
-
@http_client = PactBroker::Client::Hal::HttpClient.new(basic_auth_options.merge(verbose: verbose))
|
23
|
+
@http_client = PactBroker::Client::Hal::HttpClient.new(pact_broker_client_options.merge(pact_broker_client_options[:basic_auth] || {}))
|
26
24
|
end
|
27
25
|
|
28
26
|
def call
|
data/script/publish-pact.sh
CHANGED
@@ -1 +1 @@
|
|
1
|
-
bundle exec bin/pact-broker publish spec/pacts/pact_broker_client-pact_broker.json --consumer-app-version 1.2.3 --broker-base-url http://localhost:9292 --tag-with-git-branch
|
1
|
+
bundle exec bin/pact-broker publish spec/pacts/pact_broker_client-pact_broker.json --consumer-app-version 1.2.3 --broker-base-url http://localhost:9292 --tag-with-git-branch --broker-username localhost --broker-password localhost
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'pact_broker/client/hal/authorization_header_redactor'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Client
|
5
|
+
module Hal
|
6
|
+
describe AuthorizationHeaderRedactor do
|
7
|
+
let(:stream) { StringIO.new }
|
8
|
+
let(:stream_redactor) { AuthorizationHeaderRedactor.new(stream) }
|
9
|
+
|
10
|
+
it "redacts the authorizaton header" do
|
11
|
+
stream_redactor << "\\r\\nAuthorization: Bearer TOKEN\\r\\n"
|
12
|
+
expect(stream.string).to eq "\\r\\nAuthorization: [redacted]\\r\\n"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -4,7 +4,7 @@ module PactBroker::Client
|
|
4
4
|
module Hal
|
5
5
|
describe HttpClient do
|
6
6
|
before do
|
7
|
-
allow(Retry).to receive(:
|
7
|
+
allow(Retry).to receive(:until_truthy_or_max_times) { |&block| block.call }
|
8
8
|
end
|
9
9
|
|
10
10
|
subject { HttpClient.new(username: 'foo', password: 'bar') }
|
@@ -43,7 +43,7 @@ module PactBroker::Client
|
|
43
43
|
|
44
44
|
|
45
45
|
it "retries on failure" do
|
46
|
-
expect(Retry).to receive(:
|
46
|
+
expect(Retry).to receive(:until_truthy_or_max_times)
|
47
47
|
do_get
|
48
48
|
end
|
49
49
|
|
@@ -74,8 +74,8 @@ module PactBroker::Client
|
|
74
74
|
expect(request).to have_been_made
|
75
75
|
end
|
76
76
|
|
77
|
-
it "calls Retry.
|
78
|
-
expect(Retry).to receive(:
|
77
|
+
it "calls Retry.until_truthy_or_max_times" do
|
78
|
+
expect(Retry).to receive(:until_truthy_or_max_times)
|
79
79
|
do_post
|
80
80
|
end
|
81
81
|
|
@@ -15,7 +15,7 @@ module PactBroker
|
|
15
15
|
}.to_json
|
16
16
|
end
|
17
17
|
let!(:index_request) do
|
18
|
-
stub_request(:get, "http://broker").to_return(status: 200, body: index_body, headers: { "Content-Type" => "application/hal+json" } )
|
18
|
+
stub_request(:get, "http://broker").with(headers: { "Authorization" => /.*/}).to_return(status: 200, body: index_body, headers: { "Content-Type" => "application/hal+json" } )
|
19
19
|
end
|
20
20
|
|
21
21
|
let!(:webhook_request) do
|
@@ -34,10 +34,16 @@ module PactBroker
|
|
34
34
|
}.tap { |it| Pact::Fixture.add_fixture(:create_webhook_params, it) }
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
let(:pact_broker_client_options) do
|
38
|
+
{
|
39
|
+
token: 'token',
|
40
|
+
verbose: 'verbose'
|
41
|
+
}
|
42
|
+
end
|
38
43
|
|
39
|
-
|
44
|
+
subject { Create.call(params, "http://broker", pact_broker_client_options) }
|
40
45
|
|
46
|
+
context "when a 405 is returned from the webhook creation request" do
|
41
47
|
it "raises an error with a message to upgrade the Pact Broker" do
|
42
48
|
expect { subject }.to raise_error PactBroker::Client::Error, /This version of the Pact Broker/
|
43
49
|
end
|
@@ -345,20 +345,17 @@
|
|
345
345
|
"query": "q[][pacticipant]=Foo&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][version]=9.9.9&latestby=cvpv"
|
346
346
|
},
|
347
347
|
"response": {
|
348
|
-
"status":
|
348
|
+
"status": 200,
|
349
349
|
"headers": {
|
350
350
|
"Content-Type": "application/hal+json;charset=utf-8"
|
351
351
|
},
|
352
352
|
"body": {
|
353
|
-
"
|
354
|
-
"an error message"
|
355
|
-
|
353
|
+
"summary": {
|
354
|
+
"reason": "an error message"
|
355
|
+
}
|
356
356
|
},
|
357
357
|
"matchingRules": {
|
358
|
-
"$.body.
|
359
|
-
"min": 1
|
360
|
-
},
|
361
|
-
"$.body.errors[*].*": {
|
358
|
+
"$.body.summary.reason": {
|
362
359
|
"match": "type"
|
363
360
|
}
|
364
361
|
}
|
@@ -95,20 +95,20 @@ module PactBroker::Client
|
|
95
95
|
query: "q[][pacticipant]=Foo&q[][version]=1.2.3&q[][pacticipant]=Bar&q[][version]=9.9.9&latestby=cvpv"
|
96
96
|
).
|
97
97
|
will_respond_with(
|
98
|
-
status:
|
98
|
+
status: 200,
|
99
99
|
headers: pact_broker_response_headers,
|
100
100
|
body: {
|
101
|
-
|
101
|
+
summary: {
|
102
|
+
reason: Pact.like("an error message")
|
103
|
+
}
|
102
104
|
}
|
103
105
|
)
|
104
106
|
end
|
105
107
|
|
106
108
|
let(:selectors) { [{ pacticipant: "Foo", version: "1.2.3" }, { pacticipant: "Bar", version: "9.9.9" }] }
|
107
109
|
|
108
|
-
it '
|
109
|
-
|
110
|
-
pact_broker_client.matrix.get(selectors)
|
111
|
-
}.to raise_error PactBroker::Client::Error, "an error message"
|
110
|
+
it 'does not raise an error' do
|
111
|
+
pact_broker_client.matrix.get(selectors)
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
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.19.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: 2019-
|
11
|
+
date: 2019-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -207,6 +207,7 @@ files:
|
|
207
207
|
- lib/pact_broker/client/error.rb
|
208
208
|
- lib/pact_broker/client/git.rb
|
209
209
|
- lib/pact_broker/client/hal.rb
|
210
|
+
- lib/pact_broker/client/hal/authorization_header_redactor.rb
|
210
211
|
- lib/pact_broker/client/hal/entity.rb
|
211
212
|
- lib/pact_broker/client/hal/entry_point.rb
|
212
213
|
- lib/pact_broker/client/hal/http_client.rb
|
@@ -247,6 +248,7 @@ files:
|
|
247
248
|
- spec/lib/pact_broker/client/cli/broker_publish_spec.rb
|
248
249
|
- spec/lib/pact_broker/client/cli/custom_thor_spec.rb
|
249
250
|
- spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb
|
251
|
+
- spec/lib/pact_broker/client/hal/authorization_header_redactor_spec.rb
|
250
252
|
- spec/lib/pact_broker/client/hal/entity_spec.rb
|
251
253
|
- spec/lib/pact_broker/client/hal/http_client_spec.rb
|
252
254
|
- spec/lib/pact_broker/client/hal/link_spec.rb
|
@@ -320,6 +322,7 @@ test_files:
|
|
320
322
|
- spec/lib/pact_broker/client/cli/broker_publish_spec.rb
|
321
323
|
- spec/lib/pact_broker/client/cli/custom_thor_spec.rb
|
322
324
|
- spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb
|
325
|
+
- spec/lib/pact_broker/client/hal/authorization_header_redactor_spec.rb
|
323
326
|
- spec/lib/pact_broker/client/hal/entity_spec.rb
|
324
327
|
- spec/lib/pact_broker/client/hal/http_client_spec.rb
|
325
328
|
- spec/lib/pact_broker/client/hal/link_spec.rb
|