pact_broker-client 1.24.0 → 1.25.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
  SHA256:
3
- metadata.gz: b12cd2f4a46260bb9c9642e5ae8c402f36e99e876409eb5f5a5718c24ff705e7
4
- data.tar.gz: 79a2e1cea4055116b3b11017b8ee877f496a6b911107cdde0551a2eff944fd0b
3
+ metadata.gz: c23dc5746d9c229a4e357c8fe96273902ba48eb009a23feba13ec82e176bbb30
4
+ data.tar.gz: 482f212c6ed800809fe09ac51cc42b4bddf726fc0a1d37d9ad271cdbb12378d4
5
5
  SHA512:
6
- metadata.gz: d7488d1136e7153157c411c671a7c82309f1f1c1bd33afe1fbb1dc315bed1ddda5759b9b78363d2a8c1c6dcdc1b126d50a729fab23cf6744a122fb2264b864c0
7
- data.tar.gz: ab8cd8cb2f6ce39b9138440a1a065eb81b10c90cf926d557b5852f6aa1e677348b42491d02e1f601a08027b49990e4710dd3da979568ae0a6cd5978397f5c2ce
6
+ metadata.gz: b5dc6e9ffc7ee3d88711cc0a606d2616e00c826e6681bc84a652e37f18a944f8e402b7265a828a4ddbd16a7d5591fd9e40f8938761112411f58a08c2cc1cc3c6
7
+ data.tar.gz: c28296e8fc790b329061809abaa58af206765061fdb5d07bf2c1d60861408184b304f20c725faf2b3a4ebb59ca3e8cf23f8d8d992f9069da63b55ba60826b13d
@@ -1,3 +1,14 @@
1
+ <a name="v1.25.0"></a>
2
+ ### v1.25.0 (2020-02-18)
3
+
4
+
5
+ #### Features
6
+
7
+ * **cli**
8
+ * print any response body from the Pact Broker when authentication fails ([116f0d9](/../../commit/116f0d9))
9
+ * raise error if both basic auth credentials and bearer token are set ([163f56b](/../../commit/163f56b))
10
+
11
+
1
12
  <a name="v1.24.0"></a>
2
13
  ### v1.24.0 (2020-02-13)
3
14
 
@@ -70,7 +70,11 @@ module PactBroker
70
70
  elsif response.code == 404
71
71
  nil
72
72
  elsif response.code == 401
73
- raise Error.new("Authentication failed")
73
+ message = "Authentication failed"
74
+ if response.body && response.body.size > 0
75
+ message = message + ": #{response.body}"
76
+ end
77
+ raise Error.new(message)
74
78
  else
75
79
  error_message = nil
76
80
  begin
@@ -1,13 +1,5 @@
1
- require 'pact_broker/client/version'
2
- require 'pact_broker/client/can_i_deploy'
3
- require 'pact_broker/client/git'
4
- require 'pact_broker/client/cli/version_selector_options_parser'
5
1
  require 'pact_broker/client/cli/custom_thor'
6
- require 'pact_broker/client/publish_pacts'
7
- require 'rake/file_list'
8
2
  require 'thor/error'
9
- require 'pact_broker/client/create_tag'
10
- require 'pact_broker/client/versions/describe'
11
3
 
12
4
  module PactBroker
13
5
  module Client
@@ -15,6 +7,7 @@ module PactBroker
15
7
  # Thor::Error will have its backtrace hidden
16
8
  class PactPublicationError < ::Thor::Error; end
17
9
  class WebhookCreationError < ::Thor::Error; end
10
+ class AuthError < ::Thor::Error; end
18
11
 
19
12
  class Broker < CustomThor
20
13
  desc 'can-i-deploy', ''
@@ -36,6 +29,10 @@ module PactBroker
36
29
  method_option :limit, hide: true
37
30
 
38
31
  def can_i_deploy(*ignored_but_necessary)
32
+ require 'pact_broker/client/cli/version_selector_options_parser'
33
+ require 'pact_broker/client/can_i_deploy'
34
+
35
+ validate_credentials
39
36
  selectors = VersionSelectorOptionsParser.call(ARGV)
40
37
  validate_can_i_deploy_selectors(selectors)
41
38
  can_i_deploy_options = { output: options.output, retry_while_unknown: options.retry_while_unknown, retry_interval: options.retry_interval }
@@ -55,6 +52,7 @@ module PactBroker
55
52
  method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
56
53
 
57
54
  def publish(*pact_files)
55
+ validate_credentials
58
56
  validate_pact_files(pact_files)
59
57
  success = publish_pacts(pact_files)
60
58
  raise PactPublicationError, "One or more pacts failed to be published" unless success
@@ -74,6 +72,9 @@ module PactBroker
74
72
  method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
75
73
 
76
74
  def create_version_tag
75
+ require 'pact_broker/client/create_tag'
76
+
77
+ validate_credentials
77
78
  PactBroker::Client::CreateTag.call(
78
79
  options.broker_base_url,
79
80
  options.pacticipant,
@@ -94,6 +95,9 @@ module PactBroker
94
95
 
95
96
  desc 'describe-version', 'Describes a pacticipant version. If no version or tag is specified, the latest version is described.'
96
97
  def describe_version
98
+ require 'pact_broker/client/versions/describe'
99
+
100
+ validate_credentials
97
101
  latest = !options.latest.nil? || (options.latest.nil? && options.version.nil?)
98
102
  params = {
99
103
  pacticipant: options.pacticipant,
@@ -130,11 +134,15 @@ module PactBroker
130
134
  desc 'generate-uuid', 'Generate a UUID for use when calling create-or-update-webhook'
131
135
  def generate_uuid
132
136
  require 'securerandom'
137
+
133
138
  puts SecureRandom.uuid
134
139
  end
135
140
 
141
+ ignored_and_hidden_potential_options_from_environment_variables
136
142
  desc 'version', "Show the pact_broker-client gem version"
137
143
  def version
144
+ require 'pact_broker/client/version'
145
+
138
146
  $stdout.puts PactBroker::Client::VERSION
139
147
  end
140
148
 
@@ -144,6 +152,12 @@ module PactBroker
144
152
  true
145
153
  end
146
154
 
155
+ def validate_credentials
156
+ if options.broker_username && options.broker_token
157
+ raise AuthError, "You cannot provide both a username/password and a bearer token. If your Pact Broker uses a bearer token, please remove the username and password configuration."
158
+ end
159
+ end
160
+
147
161
  def validate_pact_files pact_files
148
162
  unless pact_files && pact_files.any?
149
163
  raise ::Thor::RequiredArgumentMissingError, "No value provided for required pact_files"
@@ -156,6 +170,8 @@ module PactBroker
156
170
  end
157
171
 
158
172
  def publish_pacts pact_files
173
+ require 'pact_broker/client/publish_pacts'
174
+
159
175
  PactBroker::Client::PublishPacts.call(
160
176
  options.broker_base_url,
161
177
  file_list(pact_files),
@@ -166,6 +182,8 @@ module PactBroker
166
182
  end
167
183
 
168
184
  def file_list pact_files
185
+ require 'rake/file_list'
186
+
169
187
  correctly_separated_pact_files = pact_files.collect{ |path| path.gsub(/\\+/, '/') }
170
188
  Rake::FileList[correctly_separated_pact_files].collect do | path |
171
189
  if File.directory?(path)
@@ -177,13 +195,16 @@ module PactBroker
177
195
  end
178
196
 
179
197
  def tags
198
+ require 'pact_broker/client/git'
199
+
180
200
  t = [*options.tag]
181
201
  t << PactBroker::Client::Git.branch if options.tag_with_git_branch
182
202
  t.compact.uniq
183
203
  end
184
204
 
185
205
  def pact_broker_client_options
186
- client_options = { verbose: options.verbose, token: options.broker_token }
206
+ client_options = { verbose: options.verbose }
207
+ client_options[:token] = options.broker_token if options.broker_token
187
208
  if options.broker_username
188
209
  client_options[:basic_auth] = {
189
210
  username: options.broker_username,
@@ -243,6 +264,8 @@ module PactBroker
243
264
 
244
265
  def run_webhook_commands webhook_url
245
266
  require 'pact_broker/client/webhooks/create'
267
+
268
+ validate_credentials
246
269
  result = PactBroker::Client::Webhooks::Create.call(parse_webhook_options(webhook_url), options.broker_base_url, pact_broker_client_options)
247
270
  $stdout.puts result.message
248
271
  exit(1) unless result.success
@@ -20,7 +20,7 @@ module PactBroker
20
20
  end
21
21
 
22
22
  def self.add_broker_config_from_environment_variables argv
23
- return argv if argv[0] == 'version' || argv[0] == 'help'
23
+ return argv if argv[0] == 'help'
24
24
 
25
25
  new_argv = add_option_from_environment_variable(argv, 'broker-base-url', 'b', 'PACT_BROKER_BASE_URL')
26
26
  new_argv = add_option_from_environment_variable(new_argv, 'broker-username', 'u', 'PACT_BROKER_USERNAME')
@@ -20,7 +20,11 @@ module PactBroker
20
20
  if response.success?
21
21
  yield
22
22
  elsif response.code == 401
23
- raise Error.new("Authentication failed")
23
+ message = "Authentication failed"
24
+ if response.body && response.body.size > 0
25
+ message = message + ": #{response.body}"
26
+ end
27
+ raise Error.new(message)
24
28
  elsif response.code == 404
25
29
  raise Error.new("Matrix resource not found at #{base_url}/matrix. Please upgrade your Broker to the latest version.")
26
30
  else
@@ -1,5 +1,5 @@
1
1
  module PactBroker
2
2
  module Client
3
- VERSION = '1.24.0'
3
+ VERSION = '1.25.0'
4
4
  end
5
5
  end
@@ -10,7 +10,7 @@ module PactBroker
10
10
  let(:password) { 'pact_repo_password'}
11
11
  let(:token) { '123456789' }
12
12
  let(:client_options) do
13
- {
13
+ {
14
14
  basic_auth: {
15
15
  username: username,
16
16
  password: password
@@ -18,7 +18,7 @@ module PactBroker
18
18
  token: token
19
19
  }
20
20
  end
21
-
21
+
22
22
  context 'with basic url' do
23
23
  it 'sets the base url' do
24
24
  base_client = BaseClient.new(base_url: base_url)
@@ -20,7 +20,6 @@ module PactBroker
20
20
  {
21
21
  broker_base_url: 'http://pact-broker',
22
22
  output: 'table',
23
- broker_token: 'token',
24
23
  verbose: 'verbose',
25
24
  retry_while_unknown: 1,
26
25
  retry_interval: 2,
@@ -36,7 +35,7 @@ module PactBroker
36
35
  end
37
36
 
38
37
  it "invokes the CanIDeploy service" do
39
- expect(CanIDeploy).to receive(:call).with('http://pact-broker', version_selectors, {to_tag: nil, limit: 1000}, {output: 'table', retry_while_unknown: 1, retry_interval: 2}, {token: 'token', verbose: 'verbose'})
38
+ expect(CanIDeploy).to receive(:call).with('http://pact-broker', version_selectors, {to_tag: nil, limit: 1000}, {output: 'table', retry_while_unknown: 1, retry_interval: 2}, {verbose: 'verbose'})
40
39
  invoke_can_i_deploy
41
40
  end
42
41
 
@@ -66,7 +65,18 @@ module PactBroker
66
65
  end
67
66
 
68
67
  it "invokes the CanIDeploy service with the basic auth credentials" do
69
- expect(CanIDeploy).to receive(:call).with(anything, anything, anything, anything, {basic_auth: {username: "foo", password: "bar"}, token: 'token', verbose: 'verbose'})
68
+ expect(CanIDeploy).to receive(:call).with(anything, anything, anything, anything, {basic_auth: {username: "foo", password: "bar"}, verbose: 'verbose'})
69
+ invoke_can_i_deploy
70
+ end
71
+ end
72
+
73
+ context "with a bearer token" do
74
+ before do
75
+ subject.options.broker_token = "some token"
76
+ end
77
+
78
+ it "invokes the CanIDeploy service with the basic auth credentials" do
79
+ expect(CanIDeploy).to receive(:call).with(anything, anything, anything, anything, {token: "some token", verbose: 'verbose'})
70
80
  invoke_can_i_deploy
71
81
  end
72
82
  end
@@ -1,4 +1,6 @@
1
1
  require 'pact_broker/client/cli/broker'
2
+ require 'pact_broker/client/publish_pacts'
3
+ require 'pact_broker/client/git'
2
4
 
3
5
  module PactBroker::Client::CLI
4
6
  describe Broker do
@@ -27,7 +29,7 @@ module PactBroker::Client::CLI
27
29
  ["spec/support/cli_test_pacts/foo.json"],
28
30
  "1.2.3",
29
31
  [],
30
- {token: nil, verbose: nil}
32
+ {verbose: nil}
31
33
  )
32
34
  invoke_broker
33
35
  end
@@ -138,6 +140,18 @@ module PactBroker::Client::CLI
138
140
  end
139
141
  end
140
142
 
143
+ context "with basic auth and a token specified" do
144
+ before do
145
+ subject.options = OpenStruct.new(
146
+ minimum_valid_options.merge(broker_username: 'foo', broker_password: 'bar', broker_token: 'foo')
147
+ )
148
+ end
149
+
150
+ it "raises an error" do
151
+ expect { invoke_broker }.to raise_error AuthError, /both/
152
+ end
153
+ end
154
+
141
155
  context "when no pact files are specified" do
142
156
  let(:file_list) { [] }
143
157
 
@@ -31,7 +31,6 @@ module PactBroker
31
31
  broker_base_url: "http://broker",
32
32
  broker_username: "username",
33
33
  broker_password: "password",
34
- broker_token: "token",
35
34
  contract_content_changed: true,
36
35
  verbose: true
37
36
  }
@@ -65,7 +64,7 @@ module PactBroker
65
64
  it "calls PactBroker::Client::Webhooks::Create with pact broker details" do
66
65
  expect(PactBroker::Client::Webhooks::Create).to receive(:call) do | _, broker_base_url, pact_broker_client_options |
67
66
  expect(broker_base_url).to eq "http://broker"
68
- expect(pact_broker_client_options).to eq(basic_auth: { username: "username", password: "password"}, token: "token", verbose: true)
67
+ expect(pact_broker_client_options).to eq(basic_auth: { username: "username", password: "password"}, verbose: true)
69
68
  command_result
70
69
  end
71
70
  subject
@@ -91,7 +90,25 @@ module PactBroker
91
90
 
92
91
  it "calls Webhooks::Create without basic auth" do
93
92
  expect(PactBroker::Client::Webhooks::Create).to receive(:call) do | _, _, pact_broker_client_options |
94
- expect(pact_broker_client_options).to eq(token: "token", verbose: true)
93
+ expect(pact_broker_client_options).to eq(verbose: true)
94
+ command_result
95
+ end
96
+ subject
97
+ end
98
+ end
99
+
100
+ context "with a bearer token" do
101
+ before do
102
+ options_hash.delete(:broker_username)
103
+ options_hash.delete(:broker_password)
104
+ options_hash[:broker_token] = "token"
105
+ broker.options = OpenStruct.new(options_hash)
106
+ end
107
+
108
+ it "calls Webhooks::Create without basic auth" do
109
+
110
+ expect(PactBroker::Client::Webhooks::Create).to receive(:call) do | _, _, pact_broker_client_options |
111
+ expect(pact_broker_client_options).to eq(verbose: true, token: "token")
95
112
  command_result
96
113
  end
97
114
  subject
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.24.0
4
+ version: 1.25.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-02-13 00:00:00.000000000 Z
11
+ date: 2020-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty