pact_broker-client 1.37.1 → 1.38.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: 5ee5df1eb310d1b9e093c4221ac3761f24cf7038dc923311cef87bc2d51fffcf
4
- data.tar.gz: 0332f399dd793f3ab9a2e37446bee976770ba4e37ddbed83ebe2ef00074a20ad
3
+ metadata.gz: 5ff434f0cdc2c246e13875eb094bf057cada5e72e6049aace2387a344ba35aa2
4
+ data.tar.gz: 508a60bac06506938f425a64eefe63d0fb56ca4b3f32df54bf8d41c9773e6fa5
5
5
  SHA512:
6
- metadata.gz: 6c3ba1e4b3303fe74c5227fdbd24c919cf6ce63bac1a85ec98e04b75618f6f75074b7cbba5933f5140ba80da903fc5c43b381c240639a0795d4cc4e835ec6244
7
- data.tar.gz: 64104a222d139eb496ebe1c4a0850c755e96e1437ab337aafe480b549bea89da49684b67108b4314fbd0fa66bd03a6ef346f04848b0340f13a0bbe1b796f22cc
6
+ metadata.gz: 4150fdf1cc5cb1970b60d07f646b151bae9fc56f68422b22a1265d64bb9f99b559ca01d7c688e1fdd047a08fb69c1d0cb28c3cd2be3370285d739cd1a9f36b0d
7
+ data.tar.gz: 91ee03c84a4ebec001ef2f2fb3c1dcc47e41a2f55b97e2b23101f99fa58a9114ffa199beb160deabc5f395ba8dc4a01cdd2901d73db2c4263ca444ec37d4b22e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ <a name="v1.38.0"></a>
2
+ ### v1.38.0 (2021-03-22)
3
+
1
4
  <a name="v1.37.1"></a>
2
5
  ### v1.37.1 (2021-03-11)
3
6
 
@@ -39,7 +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
- exit(1) unless result.success
42
+ exit(can_i_deploy_exit_status) unless result.success
43
43
  end
44
44
 
45
45
  desc 'publish PACT_DIRS_OR_FILES ...', "Publish pacts to a Pact Broker."
@@ -197,6 +197,31 @@ module PactBroker
197
197
  exit(1) unless result.success
198
198
  end
199
199
 
200
+ ignored_and_hidden_potential_options_from_environment_variables
201
+ desc "record-undeployment", "Record undeployment of (or the end of support for) a pacticipant version from an environment"
202
+ method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was deployed."
203
+ method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number that was deployed."
204
+ method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was deployed to."
205
+ method_option :output, aliases: "-o", desc: "json or text", default: 'text'
206
+ shared_authentication_options
207
+
208
+ def record_undeployment
209
+ require 'pact_broker/client/versions/record_undeployment'
210
+ params = {
211
+ pacticipant_name: options.pacticipant,
212
+ version_number: options.version,
213
+ environment_name: options.environment,
214
+ output: options.output
215
+ }
216
+ result = PactBroker::Client::Versions::RecordUndeployment.call(
217
+ params,
218
+ options.broker_base_url,
219
+ pact_broker_client_options
220
+ )
221
+ $stdout.puts result.message
222
+ exit(1) unless result.success
223
+ end
224
+
200
225
  end
201
226
 
202
227
  ignored_and_hidden_potential_options_from_environment_variables
@@ -213,6 +238,16 @@ module PactBroker
213
238
  true
214
239
  end
215
240
 
241
+ def can_i_deploy_exit_status
242
+ exit_code_string = ENV.fetch('PACT_BROKER_CAN_I_DEPLOY_EXIT_STATUS_BETA', '')
243
+ if exit_code_string =~ /^\d+$/
244
+ $stderr.puts "Exiting can-i-deploy with configured exit code #{exit_code_string}"
245
+ exit_code_string.to_i
246
+ else
247
+ 1
248
+ end
249
+ end
250
+
216
251
  def validate_credentials
217
252
  if options.broker_username && options.broker_token
218
253
  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."
@@ -1,5 +1,6 @@
1
1
  require 'erb'
2
2
  require 'delegate'
3
+ require 'pact_broker/client/error'
3
4
  require 'pact_broker/client/hal/link'
4
5
  require 'pact_broker/client/hal/links'
5
6
 
@@ -73,6 +74,22 @@ module PactBroker
73
74
  _links(key) or raise RelationNotFoundError.new("Could not find relation '#{key}' in resource at #{@href}")
74
75
  end
75
76
 
77
+ def embedded_entity
78
+ embedded_ent = yield @data["_embedded"]
79
+ Entity.new(embedded_ent["_links"]["self"]["href"], embedded_ent, @client, response)
80
+ end
81
+
82
+ def embedded_entities(key = nil)
83
+ embedded_ents = if key
84
+ @data["_embedded"][key]
85
+ else
86
+ yield @data["_embedded"]
87
+ end
88
+ embedded_ents.collect do | embedded_ent |
89
+ Entity.new(embedded_ent["_links"]["self"]["href"], embedded_ent, @client, response)
90
+ end
91
+ end
92
+
76
93
  def success?
77
94
  true
78
95
  end
@@ -17,7 +17,7 @@ module PactBroker
17
17
  end
18
18
 
19
19
  def get href, params = {}, headers = {}
20
- query = params.collect{ |(key, value)| "#{CGI::escape(key)}=#{CGI::escape(value)}" }.join("&")
20
+ query = params.collect{ |(key, value)| "#{CGI::escape(key.to_s)}=#{CGI::escape(value)}" }.join("&")
21
21
  uri = URI(href)
22
22
  uri.query = query
23
23
  perform_request(create_request(uri, 'Get', nil, headers), uri)
@@ -1,5 +1,5 @@
1
1
  module PactBroker
2
2
  module Client
3
- VERSION = '1.37.1'
3
+ VERSION = '1.38.0'
4
4
  end
5
5
  end
@@ -0,0 +1,125 @@
1
+ require 'pact_broker/client/hal_client_methods'
2
+ require 'pact_broker/client/error'
3
+ require 'pact_broker/client/command_result'
4
+
5
+ module PactBroker
6
+ module Client
7
+ class Versions
8
+ class RecordUndeployment
9
+ include PactBroker::Client::HalClientMethods
10
+
11
+ NOT_SUPPORTED_MESSAGE = "This version of the Pact Broker does not support recording undeployments. Please upgrade to version 2.80.0 or later."
12
+
13
+ def self.call(params, pact_broker_base_url, pact_broker_client_options)
14
+ new(params, pact_broker_base_url, pact_broker_client_options).call
15
+ end
16
+
17
+ def initialize(params, pact_broker_base_url, pact_broker_client_options)
18
+ @pact_broker_base_url = pact_broker_base_url
19
+ @pacticipant_name = params.fetch(:pacticipant_name)
20
+ @version_number = params.fetch(:version_number)
21
+ @environment_name = params.fetch(:environment_name)
22
+ @output = params.fetch(:output)
23
+ @pact_broker_client_options = pact_broker_client_options
24
+ end
25
+
26
+ def call
27
+ check_environment_exists
28
+ # record_undeployment
29
+
30
+ PactBroker::Client::CommandResult.new(true, result_message)
31
+ rescue PactBroker::Client::Error => e
32
+ PactBroker::Client::CommandResult.new(false, e.message)
33
+ end
34
+
35
+ private
36
+
37
+ attr_reader :pact_broker_base_url, :pact_broker_client_options
38
+ attr_reader :pacticipant_name, :version_number, :environment_name, :replaced_previous_deployed_version, :output
39
+ attr_reader :deployed_version_resource
40
+
41
+ def check_environment_exists
42
+ deployed_versions = currently_deployed_versions_for_pacticipant
43
+ .get(version: version_number)
44
+ .embedded_entities("deployedVersions")
45
+ deployed_versions
46
+ end
47
+
48
+ def currently_deployed_versions_for_pacticipant
49
+ @currently_deployed_versions_for_pacticipant ||= index_resource
50
+ ._link!("pb:environments")
51
+ .get!(name: environment_name)
52
+ .embedded_entities("environments")
53
+ .tap { |it| raise "Environment not found '#{environment_name}'" if it.empty? }
54
+ .first
55
+ ._link!("pb:currently-deployed-versions-for-pacticipant")
56
+ .expand(pacticipant: pacticipant_name)
57
+ end
58
+
59
+ def currently_deployed_versions_for_pacticipant_version
60
+ @currently_deployed_versions ||= currently_deployed_versions_for_pacticipant
61
+ .get(version: version_number)
62
+ .embedded_entities("deployedVersions")
63
+ end
64
+
65
+ # def record_deployment
66
+ # @deployed_version_resource =
67
+ # get_record_deployment_relation
68
+ # .post(record_deployment_request_body)
69
+ # .assert_success!
70
+ # end
71
+
72
+ # def get_record_deployment_relation
73
+ # record_deployment_links = get_pacticipant_version._links!("pb:record-deployment")
74
+ # link_for_environment = record_deployment_links.find(environment_name)
75
+ # if link_for_environment
76
+ # link_for_environment
77
+ # else
78
+ # check_environment_exists
79
+ # # Force the exception to be raised
80
+ # record_deployment_links.find!(environment_name, "Environment '#{environment_name}' is not an available option for recording a deployment of #{pacticipant_name}.")
81
+ # end
82
+ # end
83
+
84
+ # def get_pacticipant_version
85
+ # index_resource
86
+ # ._link!("pb:pacticipant-version")
87
+ # .expand(pacticipant: pacticipant_name, version: version_number)
88
+ # .get
89
+ # .assert_success!(404 => "#{pacticipant_name} version #{version_number} not found")
90
+ # end
91
+
92
+ # def record_deployment_request_body
93
+ # { replacedPreviousDeployedVersion: replaced_previous_deployed_version }
94
+ # end
95
+
96
+ def result_message
97
+ ""
98
+ # if output == "text"
99
+ # message = "Recorded deployment of #{pacticipant_name} version #{version_number} to #{environment_name} in #{pact_broker_name}."
100
+ # suffix = replaced_previous_deployed_version ? " Marked previous deployed version as undeployed." : ""
101
+ # message + suffix
102
+ # elsif output == "json"
103
+ # deployed_version_resource.response.raw_body
104
+ # else
105
+ # ""
106
+ # end
107
+ end
108
+
109
+ def pact_broker_name
110
+ is_pactflow? ? "Pactflow" : "the Pact Broker"
111
+ end
112
+
113
+ def is_pactflow?
114
+ deployed_version_resource.response.headers.keys.any?{ | header_name | header_name.downcase.include?("pactflow") }
115
+ end
116
+
117
+ def check_if_command_supported
118
+ unless index_resource.can?("pb:environments")
119
+ raise PactBroker::Client::Error.new(NOT_SUPPORTED_MESSAGE)
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -32,5 +32,5 @@ Gem::Specification.new do |gem|
32
32
  gem.add_development_dependency 'webmock', '~> 3.0'
33
33
  gem.add_development_dependency 'conventional-changelog', '~>1.3'
34
34
  gem.add_development_dependency 'pact', '~> 1.16'
35
- gem.add_development_dependency 'pact-support', '1.15.0'
35
+ gem.add_development_dependency 'pact-support', '~> 1.16'
36
36
  end
@@ -0,0 +1,4 @@
1
+ PACT_BROKER_FEATURES=deployments bundle exec bin/pact-broker record-deployment \
2
+ --pacticipant Foo --version 1.0.0 --environment prod --broker-base-url http://localhost:9292
3
+
4
+
@@ -113,13 +113,45 @@ module PactBroker
113
113
  end
114
114
 
115
115
  it "exits with code 1" do
116
- exited_with_error = false
116
+ exited_explicitly = false
117
+ exited_explicitlyerror = nil
117
118
  begin
118
119
  invoke_can_i_deploy
119
- rescue SystemExit
120
- exited_with_error = true
120
+ rescue SystemExit => e
121
+ exited_explicitly = true
122
+ error = e
123
+ end
124
+ expect(exited_explicitly).to be true
125
+ expect(error.status).to be 1
126
+ end
127
+
128
+ context "when an exit status is specified" do
129
+ before do
130
+ allow(ENV).to receive(:fetch).and_call_original
131
+ allow(ENV).to receive(:fetch).with('PACT_BROKER_CAN_I_DEPLOY_EXIT_STATUS_BETA', '').and_return("0")
132
+ end
133
+
134
+ it "exits with the specified code" do
135
+ exited_explicitly = false
136
+ error = nil
137
+ begin
138
+ invoke_can_i_deploy
139
+ rescue SystemExit => e
140
+ exited_explicitly = true
141
+ error = e
142
+ end
143
+ expect(exited_explicitly).to be true
144
+ expect(error.status).to be 0
145
+ end
146
+
147
+ it "prints the configured exit code" do
148
+ expect($stderr).to receive(:puts).with("Exiting can-i-deploy with configured exit code 0")
149
+ expect($stdout).to receive(:puts).with(message)
150
+ begin
151
+ invoke_can_i_deploy
152
+ rescue SystemExit
153
+ end
121
154
  end
122
- expect(exited_with_error).to be true
123
155
  end
124
156
  end
125
157
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'webmock/rspec'
2
2
 
3
+ ENV['PACT_BROKER_FEATURES'] = 'deployments'
4
+
3
5
  WebMock.disable_net_connect!(allow_localhost: true)
4
6
 
5
7
  require "./spec/support/shared_context.rb"
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.37.1
4
+ version: 1.38.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: 2021-03-10 00:00:00.000000000 Z
11
+ date: 2021-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -160,16 +160,16 @@ dependencies:
160
160
  name: pact-support
161
161
  requirement: !ruby/object:Gem::Requirement
162
162
  requirements:
163
- - - '='
163
+ - - "~>"
164
164
  - !ruby/object:Gem::Version
165
- version: 1.15.0
165
+ version: '1.16'
166
166
  type: :development
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  requirements:
170
- - - '='
170
+ - - "~>"
171
171
  - !ruby/object:Gem::Version
172
- version: 1.15.0
172
+ version: '1.16'
173
173
  description: Client for the Pact Broker. Publish, retrieve and query pacts and verification
174
174
  results.
175
175
  email:
@@ -249,6 +249,7 @@ files:
249
249
  - lib/pact_broker/client/versions/formatter.rb
250
250
  - lib/pact_broker/client/versions/json_formatter.rb
251
251
  - lib/pact_broker/client/versions/record_deployment.rb
252
+ - lib/pact_broker/client/versions/record_undeployment.rb
252
253
  - lib/pact_broker/client/versions/text_formatter.rb
253
254
  - lib/pact_broker/client/webhooks/create.rb
254
255
  - lib/pact_broker/client/webhooks/test.rb
@@ -257,6 +258,7 @@ files:
257
258
  - script/create-pacticipant.sh
258
259
  - script/generate-cli-usage.sh
259
260
  - script/publish-pact.sh
261
+ - script/record-deployment.sh
260
262
  - script/release.sh
261
263
  - script/trigger-release.sh
262
264
  - spec/integration/can_i_deploy_spec.rb
@@ -337,7 +339,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
337
339
  - !ruby/object:Gem::Version
338
340
  version: '0'
339
341
  requirements: []
340
- rubygems_version: 3.2.14
342
+ rubygems_version: 3.2.15
341
343
  signing_key:
342
344
  specification_version: 4
343
345
  summary: See description