pact_broker-client 1.51.2 → 1.55.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 +29 -0
- data/README.md +45 -33
- data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +1 -0
- data/lib/pact_broker/client/base_client.rb +7 -5
- data/lib/pact_broker/client/cli/deployment_commands.rb +7 -3
- data/lib/pact_broker/client/cli/pacticipant_commands.rb +2 -1
- data/lib/pact_broker/client/deployments/record_deployment.rb +6 -5
- data/lib/pact_broker/client/deployments/record_undeployment.rb +20 -12
- data/lib/pact_broker/client/git.rb +15 -4
- data/lib/pact_broker/client/hal/http_client.rb +16 -1
- data/lib/pact_broker/client/pacticipants/create.rb +2 -1
- data/lib/pact_broker/client/publish_pacts.rb +5 -1
- data/lib/pact_broker/client/version.rb +1 -1
- data/script/publish-pact.sh +1 -0
- data/script/record-deployments-and-releases.sh +11 -1
- data/spec/lib/pact_broker/client/deployments/record_deployment_spec.rb +6 -6
- data/spec/lib/pact_broker/client/deployments/record_undeployment_spec.rb +15 -7
- data/spec/lib/pact_broker/client/git_spec.rb +46 -0
- data/spec/pacts/pact_broker_client-pact_broker.json +1 -0
- data/spec/service_providers/record_deployment_spec.rb +7 -6
- data/spec/service_providers/record_undeployment_spec.rb +4 -4
- data/tasks/pact.rake +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b5e2bdbb0df7479cecc969634bc78e79fb64b799410bab2b1b45e33c6db635e
|
4
|
+
data.tar.gz: df5775b4c3c5d0a52cf0777cdbcffeb2b51ecafed78d40d092d4961620b21001
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89df36d9fe800cd97e0500d6d89305d3596e5f17d34c3ea4e6286a88c4257db39427c938792d784b3ed8450011d53592fb5bd436785d87cc73edefeca8722067
|
7
|
+
data.tar.gz: 617675fd4f1de88ef167c9fd5ef3b82d190d5f63fd22f1fa1e19fb8af437ad268e6406c7bd75be56f1b5c65a515b530ae878f0ba44c912d66973cb5af7193405
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,32 @@
|
|
1
|
+
<a name="v1.55.0"></a>
|
2
|
+
### v1.55.0 (2021-10-03)
|
3
|
+
|
4
|
+
#### Features
|
5
|
+
|
6
|
+
* support Github Actions environment variables for --tag-with-git-branch ([2b8dac5](/../../commit/2b8dac5))
|
7
|
+
|
8
|
+
<a name="v1.54.0"></a>
|
9
|
+
### v1.54.0 (2021-10-01)
|
10
|
+
|
11
|
+
#### Features
|
12
|
+
|
13
|
+
* disable SSL verification for HAL client and HTTParty client when environment variable PACT_DISABLE_SSL_VERIFICATION=true ([470aafa](/../../commit/470aafa))
|
14
|
+
* support setting the --main-branch for a pacticipant ([1f18e70](/../../commit/1f18e70))
|
15
|
+
|
16
|
+
<a name="v1.53.0"></a>
|
17
|
+
### v1.53.0 (2021-09-29)
|
18
|
+
|
19
|
+
#### Features
|
20
|
+
|
21
|
+
* allow pacts to be published using the old API by setting the environment variable PACT_BROKER_FEATURES=publish_pacts_using_old_api ([7c34132](/../../commit/7c34132))
|
22
|
+
|
23
|
+
<a name="v1.52.0"></a>
|
24
|
+
### v1.52.0 (2021-09-29)
|
25
|
+
|
26
|
+
#### Features
|
27
|
+
|
28
|
+
* rename target to application-instance for record-deployment and record-undeployment (backwards compatible) ([53d23eb](/../../commit/53d23eb))
|
29
|
+
|
1
30
|
<a name="v1.51.2"></a>
|
2
31
|
### v1.51.2 (2021-09-27)
|
3
32
|
|
data/README.md
CHANGED
@@ -275,29 +275,33 @@ Usage:
|
|
275
275
|
pact-broker record-deployment --environment=ENVIRONMENT -a, --pacticipant=PACTICIPANT -b, --broker-base-url=BROKER_BASE_URL -e, --version=VERSION
|
276
276
|
|
277
277
|
Options:
|
278
|
-
-a, --pacticipant=PACTICIPANT
|
278
|
+
-a, --pacticipant=PACTICIPANT
|
279
279
|
# The name of the pacticipant that was deployed.
|
280
|
-
-e, --version=VERSION
|
280
|
+
-e, --version=VERSION
|
281
281
|
# The pacticipant version number that was deployed.
|
282
|
-
--environment=ENVIRONMENT
|
282
|
+
--environment=ENVIRONMENT
|
283
283
|
# The name of the environment that the pacticipant version was
|
284
284
|
deployed to.
|
285
|
-
[--
|
286
|
-
# Optional. The
|
287
|
-
|
288
|
-
instances of the same
|
289
|
-
|
285
|
+
[--application-instance=APPLICATION_INSTANCE]
|
286
|
+
# Optional. The application instance to which the deployment has
|
287
|
+
occurred - a logical identifer required to differentiate
|
288
|
+
deployments when there are multiple instances of the same
|
289
|
+
application in an environment. This field was called 'target'
|
290
|
+
in a beta release.
|
291
|
+
[--target=TARGET]
|
292
|
+
# Renamed to application_instance
|
293
|
+
-o, [--output=OUTPUT]
|
290
294
|
# json or text
|
291
295
|
# Default: text
|
292
|
-
-b, --broker-base-url=BROKER_BASE_URL
|
296
|
+
-b, --broker-base-url=BROKER_BASE_URL
|
293
297
|
# The base URL of the Pact Broker
|
294
|
-
-u, [--broker-username=BROKER_USERNAME]
|
298
|
+
-u, [--broker-username=BROKER_USERNAME]
|
295
299
|
# Pact Broker basic auth username
|
296
|
-
-p, [--broker-password=BROKER_PASSWORD]
|
300
|
+
-p, [--broker-password=BROKER_PASSWORD]
|
297
301
|
# Pact Broker basic auth password
|
298
|
-
-k, [--broker-token=BROKER_TOKEN]
|
302
|
+
-k, [--broker-token=BROKER_TOKEN]
|
299
303
|
# Pact Broker bearer token
|
300
|
-
-v, [--verbose], [--no-verbose]
|
304
|
+
-v, [--verbose], [--no-verbose]
|
301
305
|
# Verbose output. Default: false
|
302
306
|
```
|
303
307
|
|
@@ -310,28 +314,34 @@ Usage:
|
|
310
314
|
pact-broker record-undeployment --environment=ENVIRONMENT -a, --pacticipant=PACTICIPANT -b, --broker-base-url=BROKER_BASE_URL
|
311
315
|
|
312
316
|
Options:
|
313
|
-
-a, --pacticipant=PACTICIPANT
|
317
|
+
-a, --pacticipant=PACTICIPANT
|
314
318
|
# The name of the pacticipant that was undeployed.
|
315
|
-
--environment=ENVIRONMENT
|
319
|
+
--environment=ENVIRONMENT
|
316
320
|
# The name of the environment that the pacticipant version was
|
317
321
|
undeployed from.
|
318
|
-
[--
|
322
|
+
[--application-instance=APPLICATION_INSTANCE]
|
323
|
+
# Optional. The application instance from which the application
|
324
|
+
is being undeployed - a logical identifer required to
|
325
|
+
differentiate deployments when there are multiple instances of
|
326
|
+
the same application in an environment. This field was called
|
327
|
+
'target' in a beta release.
|
328
|
+
[--target=TARGET]
|
319
329
|
# Optional. The target that the application is being undeployed
|
320
330
|
from - a logical identifer required to differentiate
|
321
331
|
deployments when there are multiple instances of the same
|
322
332
|
application in an environment.
|
323
|
-
-o, [--output=OUTPUT]
|
333
|
+
-o, [--output=OUTPUT]
|
324
334
|
# json or text
|
325
335
|
# Default: text
|
326
|
-
-b, --broker-base-url=BROKER_BASE_URL
|
336
|
+
-b, --broker-base-url=BROKER_BASE_URL
|
327
337
|
# The base URL of the Pact Broker
|
328
|
-
-u, [--broker-username=BROKER_USERNAME]
|
338
|
+
-u, [--broker-username=BROKER_USERNAME]
|
329
339
|
# Pact Broker basic auth username
|
330
|
-
-p, [--broker-password=BROKER_PASSWORD]
|
340
|
+
-p, [--broker-password=BROKER_PASSWORD]
|
331
341
|
# Pact Broker basic auth password
|
332
|
-
-k, [--broker-token=BROKER_TOKEN]
|
342
|
+
-k, [--broker-token=BROKER_TOKEN]
|
333
343
|
# Pact Broker bearer token
|
334
|
-
-v, [--verbose], [--no-verbose]
|
344
|
+
-v, [--verbose], [--no-verbose]
|
335
345
|
# Verbose output. Default: false
|
336
346
|
```
|
337
347
|
|
@@ -469,8 +479,8 @@ Description:
|
|
469
479
|
support for environments, deployments and releases. For documentation on how to use can-i-deploy with tags, please see
|
470
480
|
https://docs.pact.io/pact_broker/client_cli/can_i_deploy_usage_with_tags/
|
471
481
|
|
472
|
-
Before `can-i-deploy` can be used, the relevant environment resources must first be created in the Pact Broker using the `create-environment` command. The
|
473
|
-
and "production" environments will have been seeded for you. You can check the existing environments by running `pact-broker list-environments`. See
|
482
|
+
Before `can-i-deploy` can be used, the relevant environment resources must first be created in the Pact Broker using the `create-environment` command. The
|
483
|
+
"test" and "production" environments will have been seeded for you. You can check the existing environments by running `pact-broker list-environments`. See
|
474
484
|
https://docs.pact.io/pact_broker/client_cli/readme#environments for more information.
|
475
485
|
|
476
486
|
$ pact-broker create-environment --name "uat" --display-name "UAT" --no-production
|
@@ -480,8 +490,8 @@ Description:
|
|
480
490
|
|
481
491
|
$ pact-broker record-deployment --pacticipant Foo --version 173153ae0 --environment uat
|
482
492
|
|
483
|
-
Before an application is deployed or released to an environment, the can-i-deploy command must be run to check that the application version is safe to deploy
|
484
|
-
the versions of each integrated application that are already in that environment.
|
493
|
+
Before an application is deployed or released to an environment, the can-i-deploy command must be run to check that the application version is safe to deploy
|
494
|
+
with the versions of each integrated application that are already in that environment.
|
485
495
|
|
486
496
|
$ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION --to-environment ENVIRONMENT
|
487
497
|
|
@@ -489,8 +499,8 @@ Description:
|
|
489
499
|
|
490
500
|
$ pact-broker can-i-deploy --pacticipant Foo --version 173153ae0 --to-environment test
|
491
501
|
|
492
|
-
Can-i-deploy can also be used to check if arbitrary versions have a successful verification. When asking "Can I deploy this application version with the
|
493
|
-
from the main branch of another application" it functions as a "can I merge" check.
|
502
|
+
Can-i-deploy can also be used to check if arbitrary versions have a successful verification. When asking "Can I deploy this application version with the
|
503
|
+
latest version from the main branch of another application" it functions as a "can I merge" check.
|
494
504
|
|
495
505
|
$ pact-broker can-i-deploy --pacticipant Foo 173153ae0 \ --pacticipant Bar --latest main
|
496
506
|
|
@@ -507,6 +517,8 @@ Options:
|
|
507
517
|
# Pacticipant name
|
508
518
|
[--display-name=DISPLAY_NAME]
|
509
519
|
# Display name
|
520
|
+
[--main-branch=MAIN_BRANCH]
|
521
|
+
# The main development branch of the pacticipant repository
|
510
522
|
[--repository-url=REPOSITORY_URL]
|
511
523
|
# The repository URL of the pacticipant
|
512
524
|
-o, [--output=OUTPUT]
|
@@ -628,8 +640,8 @@ Options:
|
|
628
640
|
```
|
629
641
|
|
630
642
|
Description:
|
631
|
-
Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-webhook" and add the
|
632
|
-
provider, event types and broker details. Note that the URL must be the first parameter when executing create-webhook.
|
643
|
+
Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-webhook" and add the
|
644
|
+
consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-webhook.
|
633
645
|
|
634
646
|
Note that the -u option from the curl command clashes with the -u option from the pact-broker CLI. When used in this command, the -u will be used as a curl
|
635
647
|
option. Please use the --broker-username or environment variable for the Pact Broker username.
|
@@ -686,9 +698,9 @@ Options:
|
|
686
698
|
```
|
687
699
|
|
688
700
|
Description:
|
689
|
-
Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-or-update-webhook" and
|
690
|
-
consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-or-update-webhook and a uuid
|
691
|
-
also be provided. You can generate a valid UUID by using the `generate-uuid` command.
|
701
|
+
Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-or-update-webhook" and
|
702
|
+
add the consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-or-update-webhook and a uuid
|
703
|
+
must also be provided. You can generate a valid UUID by using the `generate-uuid` command.
|
692
704
|
|
693
705
|
Note that the -u option from the curl command clashes with the -u option from the pact-broker CLI. When used in this command, the -u will be used as a curl
|
694
706
|
option. Please use the --broker-username or environment variable for the Pact Broker username.
|
@@ -54,6 +54,8 @@ module PactBroker
|
|
54
54
|
self.class.headers('Authorization' => "Bearer #{client_options[:token]}") if client_options[:token]
|
55
55
|
self.class.ssl_ca_file(ENV['SSL_CERT_FILE']) if ENV['SSL_CERT_FILE'] && ENV['SSL_CERT_FILE'] != ''
|
56
56
|
self.class.ssl_ca_path(ENV['SSL_CERT_DIR']) if ENV['SSL_CERT_DIR'] && ENV['SSL_CERT_DIR'] != ''
|
57
|
+
@default_options = {}
|
58
|
+
@default_options[:verify] = false if (ENV['PACT_DISABLE_SSL_VERIFICATION'] == 'true' || ENV['PACT_BROKER_DISABLE_SSL_VERIFICATION'] == 'true')
|
57
59
|
end
|
58
60
|
|
59
61
|
def default_request_headers
|
@@ -102,15 +104,15 @@ module PactBroker
|
|
102
104
|
end
|
103
105
|
|
104
106
|
def patch url, options
|
105
|
-
self.class.patch(url, options.merge(body: options[:body].to_json))
|
107
|
+
self.class.patch(url, @default_options.merge(options.merge(body: options[:body].to_json)))
|
106
108
|
end
|
107
109
|
|
108
|
-
def put url,
|
109
|
-
self.class.put(url,
|
110
|
+
def put url, options = {}, &block
|
111
|
+
self.class.put(url, @default_options.merge(options), &block)
|
110
112
|
end
|
111
113
|
|
112
|
-
def get url,
|
113
|
-
self.class.get(url,
|
114
|
+
def get url, options = {}, &block
|
115
|
+
self.class.get(url, @default_options.merge(options), &block)
|
114
116
|
end
|
115
117
|
|
116
118
|
def url_for_relation relation_name, params
|
@@ -14,16 +14,18 @@ module PactBroker
|
|
14
14
|
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was deployed."
|
15
15
|
method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number that was deployed."
|
16
16
|
method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was deployed to."
|
17
|
-
method_option :
|
17
|
+
method_option :application_instance, default: nil, required: false, desc: "Optional. The application instance to which the deployment has occurred - a logical identifer required to differentiate deployments when there are multiple instances of the same application in an environment. This field was called 'target' in a beta release."
|
18
|
+
method_option :target, hidden: true, default: nil, required: false, desc: "Renamed to application_instance"
|
18
19
|
output_option_json_or_text
|
19
20
|
shared_authentication_options
|
20
21
|
|
21
22
|
def record_deployment
|
23
|
+
$stderr.puts("WARN: target has been renamed to application-instance") if options.target
|
22
24
|
params = {
|
23
25
|
pacticipant_name: options.pacticipant,
|
24
26
|
version_number: options.version,
|
25
27
|
environment_name: options.environment,
|
26
|
-
|
28
|
+
application_instance: options.application_instance || options.target
|
27
29
|
}
|
28
30
|
execute_deployment_command(params, "RecordDeployment")
|
29
31
|
end
|
@@ -32,15 +34,17 @@ module PactBroker
|
|
32
34
|
long_desc "Note that use of this command is only required if you are permanently removing an application instance from an environment. It is not required if you are deploying over a previous version, as record-deployment will automatically mark the previously deployed version as undeployed for you. See #{RECORD_UNDEPLOYMENT_HELP_URL} for more information."
|
33
35
|
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was undeployed."
|
34
36
|
method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was undeployed from."
|
37
|
+
method_option :application_instance, default: nil, required: false, desc: "Optional. The application instance from which the application is being undeployed - a logical identifer required to differentiate deployments when there are multiple instances of the same application in an environment. This field was called 'target' in a beta release."
|
35
38
|
method_option :target, default: nil, required: false, desc: "Optional. The target that the application is being undeployed from - a logical identifer required to differentiate deployments when there are multiple instances of the same application in an environment."
|
36
39
|
output_option_json_or_text
|
37
40
|
shared_authentication_options
|
38
41
|
|
39
42
|
def record_undeployment
|
43
|
+
$stderr.puts("WARN: target has been renamed to application-instance") if options.target
|
40
44
|
params = {
|
41
45
|
pacticipant_name: options.pacticipant,
|
42
46
|
environment_name: options.environment,
|
43
|
-
|
47
|
+
application_instance: options.application_instance || options.target
|
44
48
|
}
|
45
49
|
execute_deployment_command(params, "RecordUndeployment")
|
46
50
|
end
|
@@ -2,13 +2,14 @@ module PactBroker
|
|
2
2
|
module Client
|
3
3
|
module CLI
|
4
4
|
module PacticipantCommands
|
5
|
-
PACTICIPANT_PARAM_NAMES = [:name, :display_name, :repository_url]
|
5
|
+
PACTICIPANT_PARAM_NAMES = [:name, :display_name, :main_branch, :repository_url]
|
6
6
|
|
7
7
|
def self.included(thor)
|
8
8
|
thor.class_eval do
|
9
9
|
desc 'create-or-update-pacticipant', 'Create or update pacticipant by name'
|
10
10
|
method_option :name, type: :string, required: true, desc: "Pacticipant name"
|
11
11
|
method_option :display_name, type: :string, desc: "Display name"
|
12
|
+
method_option :main_branch, type: :string, required: false, desc: "The main development branch of the pacticipant repository"
|
12
13
|
method_option :repository_url, type: :string, required: false, desc: "The repository URL of the pacticipant"
|
13
14
|
output_option_json_or_text
|
14
15
|
shared_authentication_options
|
@@ -6,12 +6,12 @@ module PactBroker
|
|
6
6
|
class RecordDeployment < PactBroker::Client::Deployments::RecordRelease
|
7
7
|
def initialize(params, options, pact_broker_client_options)
|
8
8
|
super
|
9
|
-
@
|
9
|
+
@application_instance = params.fetch(:application_instance)
|
10
10
|
end
|
11
11
|
|
12
12
|
private
|
13
13
|
|
14
|
-
attr_reader :
|
14
|
+
attr_reader :application_instance
|
15
15
|
|
16
16
|
def action
|
17
17
|
"deployment"
|
@@ -22,12 +22,13 @@ module PactBroker
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def record_action_request_body
|
25
|
-
|
25
|
+
# for backwards compatibility with old broker
|
26
|
+
{ applicationInstance: application_instance, target: application_instance }.compact
|
26
27
|
end
|
27
28
|
|
28
29
|
def result_text_message
|
29
|
-
if
|
30
|
-
"#{super} (
|
30
|
+
if application_instance
|
31
|
+
"#{super} (application instance #{application_instance})"
|
31
32
|
else
|
32
33
|
super
|
33
34
|
end
|
@@ -8,7 +8,7 @@ module PactBroker
|
|
8
8
|
super
|
9
9
|
@pacticipant_name = params.fetch(:pacticipant_name)
|
10
10
|
@environment_name = params.fetch(:environment_name)
|
11
|
-
@
|
11
|
+
@application_instance = params.fetch(:application_instance)
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
@@ -21,7 +21,7 @@ module PactBroker
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
attr_reader :pacticipant_name, :environment_name, :
|
24
|
+
attr_reader :pacticipant_name, :environment_name, :application_instance
|
25
25
|
|
26
26
|
def currently_deployed_versions_link
|
27
27
|
environment_resource._link("pb:currently-deployed-deployed-versions", "pb:currently-deployed-versions") or raise PactBroker::Client::Error.new(not_supported_message)
|
@@ -31,14 +31,19 @@ module PactBroker
|
|
31
31
|
@deployed_version_links ||= currently_deployed_versions_link.get!(pacticipant: pacticipant_name).embedded_entities!("deployedVersions")
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
34
|
+
def currently_deployed_version_entities_for_pacticipant_and_instance
|
35
35
|
currently_deployed_version_entities_for_pacticipant.select do | entity |
|
36
|
-
|
36
|
+
if application_instance
|
37
|
+
entity.applicationInstance == application_instance || entity.target == application_instance
|
38
|
+
else
|
39
|
+
entity.applicationInstance == nil && entity.target == nil
|
40
|
+
end
|
41
|
+
|
37
42
|
end
|
38
43
|
end
|
39
44
|
|
40
45
|
def undeployed_versions_resources
|
41
|
-
@undeployed_versions_resources ||=
|
46
|
+
@undeployed_versions_resources ||= currently_deployed_version_entities_for_pacticipant_and_instance.collect do | entity |
|
42
47
|
entity._link!("self").patch(currentlyDeployed: false)
|
43
48
|
end
|
44
49
|
end
|
@@ -75,7 +80,7 @@ module PactBroker
|
|
75
80
|
message = "Recorded #{action} of #{pacticipant_name}"
|
76
81
|
message = "#{message} version #{version.number}" if (version && version.number)
|
77
82
|
message = "#{message} from #{environment_name} environment"
|
78
|
-
message = "#{message} (
|
83
|
+
message = "#{message} (application instance #{application_instance})" if application_instance
|
79
84
|
message
|
80
85
|
end
|
81
86
|
|
@@ -92,19 +97,22 @@ module PactBroker
|
|
92
97
|
"No pacticipant with name '#{pacticipant_name}' found."
|
93
98
|
else
|
94
99
|
if currently_deployed_version_entities_for_pacticipant.any?
|
95
|
-
|
100
|
+
application_instance_does_not_match_message
|
96
101
|
else
|
97
102
|
"#{pacticipant_name} is not currently deployed to #{environment_name} environment. Cannot record undeployment."
|
98
103
|
end
|
99
104
|
end
|
100
105
|
end
|
101
106
|
|
102
|
-
def
|
103
|
-
|
104
|
-
|
105
|
-
|
107
|
+
def application_instance_does_not_match_message
|
108
|
+
potential_application_instances = currently_deployed_version_entities_for_pacticipant.collect{|e| e.applicationInstance || e.target }
|
109
|
+
|
110
|
+
if application_instance
|
111
|
+
omit_text = potential_application_instances.include?(nil) ? "omit the application instance to undeploy from the anonymous instance" : nil
|
112
|
+
specify_text = potential_application_instances.compact.any? ? "specify one of the following application instances to record the undeployment from: #{potential_application_instances.compact.join(", ")}" : nil
|
113
|
+
"#{pacticipant_name} is not currently deployed to application instance '#{application_instance}' in #{environment_name} environment. Please #{[omit_text, specify_text].compact.join(" or ")}."
|
106
114
|
else
|
107
|
-
"Please specify one of the following
|
115
|
+
"Please specify one of the following application instances to record the undeployment from: #{potential_application_instances.compact.join(", ")}"
|
108
116
|
end
|
109
117
|
end
|
110
118
|
|
@@ -25,9 +25,8 @@ module PactBroker
|
|
25
25
|
using PactBroker::Client::HashRefinements
|
26
26
|
|
27
27
|
COMMAND = 'git rev-parse --abbrev-ref HEAD'.freeze
|
28
|
-
BRANCH_ENV_VAR_NAMES = %w{BUILDKITE_BRANCH CIRCLE_BRANCH TRAVIS_BRANCH GIT_BRANCH GIT_LOCAL_BRANCH APPVEYOR_REPO_BRANCH CI_COMMIT_REF_NAME BITBUCKET_BRANCH}.freeze
|
29
|
-
COMMIT_ENV_VAR_NAMES = %w{BUILDKITE_COMMIT CIRCLE_SHA1 TRAVIS_COMMIT GIT_COMMIT APPVEYOR_REPO_COMMIT CI_COMMIT_ID BITBUCKET_COMMIT}
|
30
|
-
|
28
|
+
BRANCH_ENV_VAR_NAMES = %w{GITHUB_REF BUILDKITE_BRANCH CIRCLE_BRANCH TRAVIS_BRANCH GIT_BRANCH GIT_LOCAL_BRANCH APPVEYOR_REPO_BRANCH CI_COMMIT_REF_NAME BITBUCKET_BRANCH}.freeze
|
29
|
+
COMMIT_ENV_VAR_NAMES = %w{GITHUB_SHA BUILDKITE_COMMIT CIRCLE_SHA1 TRAVIS_COMMIT GIT_COMMIT APPVEYOR_REPO_COMMIT CI_COMMIT_ID BITBUCKET_COMMIT}
|
31
30
|
BUILD_URL_ENV_VAR_NAMES = %w{BUILDKITE_BUILD_URL CIRCLE_BUILD_URL TRAVIS_BUILD_WEB_URL BUILD_URL }
|
32
31
|
|
33
32
|
def self.commit
|
@@ -38,6 +37,10 @@ module PactBroker
|
|
38
37
|
find_branch_from_known_env_vars || find_branch_from_env_var_ending_with_branch || branch_from_git_command(options[:raise_error])
|
39
38
|
end
|
40
39
|
|
40
|
+
def self.build_url
|
41
|
+
github_build_url || BUILD_URL_ENV_VAR_NAMES.collect{ | name | value_from_env_var(name) }.compact.first
|
42
|
+
end
|
43
|
+
|
41
44
|
# private
|
42
45
|
|
43
46
|
def self.find_commit_from_env_vars
|
@@ -45,7 +48,8 @@ module PactBroker
|
|
45
48
|
end
|
46
49
|
|
47
50
|
def self.find_branch_from_known_env_vars
|
48
|
-
BRANCH_ENV_VAR_NAMES.collect { |env_var_name| value_from_env_var(env_var_name) }.compact.first
|
51
|
+
val = BRANCH_ENV_VAR_NAMES.collect { |env_var_name| value_from_env_var(env_var_name) }.compact.first
|
52
|
+
val.gsub(%r{^refs/heads/}, "") if val
|
49
53
|
end
|
50
54
|
|
51
55
|
def self.find_branch_from_env_var_ending_with_branch
|
@@ -104,6 +108,13 @@ module PactBroker
|
|
104
108
|
return []
|
105
109
|
end
|
106
110
|
end
|
111
|
+
|
112
|
+
def self.github_build_url
|
113
|
+
parts = %w{GITHUB_SERVER_URL GITHUB_REPOSITORY GITHUB_RUN_ID}.collect{ | name | value_from_env_var(name) }
|
114
|
+
if parts.all?
|
115
|
+
[parts[0], parts[1], "actions", "runs", parts[2]].join("/")
|
116
|
+
end
|
117
|
+
end
|
107
118
|
end
|
108
119
|
end
|
109
120
|
end
|
@@ -2,6 +2,7 @@ require 'pact_broker/client/retry'
|
|
2
2
|
require 'pact_broker/client/hal/authorization_header_redactor'
|
3
3
|
require 'net/http'
|
4
4
|
require 'json'
|
5
|
+
require 'openssl'
|
5
6
|
|
6
7
|
module PactBroker
|
7
8
|
module Client
|
@@ -62,13 +63,19 @@ module PactBroker
|
|
62
63
|
def perform_request request, uri
|
63
64
|
response = until_truthy_or_max_times(condition: ->(resp) { resp.code.to_i < 500 }) do
|
64
65
|
http = Net::HTTP.new(uri.host, uri.port, :ENV)
|
65
|
-
http.set_debug_output(output_stream) if verbose
|
66
|
+
http.set_debug_output(output_stream) if verbose?
|
66
67
|
http.use_ssl = (uri.scheme == 'https')
|
67
68
|
# Need to manually set the ca_file and ca_path for the pact-ruby-standalone.
|
68
69
|
# The env vars seem to be picked up automatically in later Ruby versions.
|
69
70
|
# See https://github.com/pact-foundation/pact-ruby-standalone/issues/57
|
70
71
|
http.ca_file = ENV['SSL_CERT_FILE'] if ENV['SSL_CERT_FILE'] && ENV['SSL_CERT_FILE'] != ''
|
71
72
|
http.ca_path = ENV['SSL_CERT_DIR'] if ENV['SSL_CERT_DIR'] && ENV['SSL_CERT_DIR'] != ''
|
73
|
+
if disable_ssl_verification?
|
74
|
+
if verbose?
|
75
|
+
$stdout.puts("SSL verification is disabled")
|
76
|
+
end
|
77
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
78
|
+
end
|
72
79
|
http.start do |http|
|
73
80
|
http.request request
|
74
81
|
end
|
@@ -115,6 +122,14 @@ module PactBroker
|
|
115
122
|
AuthorizationHeaderRedactor.new($stdout)
|
116
123
|
end
|
117
124
|
|
125
|
+
def verbose?
|
126
|
+
verbose || ENV["VERBOSE"] == "true"
|
127
|
+
end
|
128
|
+
|
129
|
+
def disable_ssl_verification?
|
130
|
+
ENV['PACT_DISABLE_SSL_VERIFICATION'] == 'true' || ENV['PACT_BROKER_DISABLE_SSL_VERIFICATION'] == 'true'
|
131
|
+
end
|
132
|
+
|
118
133
|
class Response < SimpleDelegator
|
119
134
|
def body
|
120
135
|
bod = raw_body
|
@@ -28,7 +28,7 @@ module PactBroker
|
|
28
28
|
|
29
29
|
def call
|
30
30
|
validate
|
31
|
-
if index_resource.can?("pb:publish-contracts")
|
31
|
+
if !force_use_old_api? && index_resource.can?("pb:publish-contracts")
|
32
32
|
publish_pacts
|
33
33
|
PactBroker::Client::CommandResult.new(success?, message)
|
34
34
|
else
|
@@ -40,6 +40,10 @@ module PactBroker
|
|
40
40
|
|
41
41
|
attr_reader :pact_broker_base_url, :pact_file_paths, :consumer_version_params, :consumer_version_number, :branch, :tags, :build_url, :options, :pact_broker_client_options, :response_entities
|
42
42
|
|
43
|
+
def force_use_old_api?
|
44
|
+
ENV.fetch("PACT_BROKER_FEATURES", "").include?("publish_pacts_using_old_api")
|
45
|
+
end
|
46
|
+
|
43
47
|
def request_body_for(consumer_name)
|
44
48
|
{
|
45
49
|
pacticipantName: consumer_name,
|
data/script/publish-pact.sh
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
export PACT_BROKER_BASE_URL="http://localhost:9292"
|
2
2
|
export PACT_BROKER_TOKEN="localhost"
|
3
|
+
#export PACT_BROKER_FEATURES=publish_pacts_using_old_api
|
3
4
|
|
4
5
|
# bundle exec bin/pact-broker create-or-update-webhook http://localhost:9393 \
|
5
6
|
# --uuid d40f38c3-aaa3-47f5-9161-95c07bc16b14 \
|
@@ -8,9 +8,19 @@ bundle exec bin/pact-broker record-deployment --pacticipant Foo --version 2 --en
|
|
8
8
|
bundle exec bin/pact-broker record-deployment --pacticipant Foo --version 2 --environment test --target customer-1
|
9
9
|
bundle exec bin/pact-broker record-deployment --pacticipant Foo --version 2 --environment test --target customer-1
|
10
10
|
|
11
|
+
bundle exec bin/pact-broker record-undeployment --pacticipant Foo --environment test --target customer-2
|
11
12
|
bundle exec bin/pact-broker record-undeployment --pacticipant Foo --environment test
|
12
13
|
bundle exec bin/pact-broker record-undeployment --pacticipant Foo --environment test
|
13
14
|
bundle exec bin/pact-broker record-undeployment --pacticipant Foo --environment test --target customer-1
|
14
15
|
|
15
16
|
bundle exec bin/pact-broker record-release --pacticipant Foo --version 2 --environment test
|
16
|
-
bundle exec bin/pact-broker record-support-ended --pacticipant Foo --version 2 --environment test
|
17
|
+
bundle exec bin/pact-broker record-support-ended --pacticipant Foo --version 2 --environment test
|
18
|
+
|
19
|
+
bundle exec bin/pact-broker record-deployment --pacticipant Foo --version 2 --environment test
|
20
|
+
bundle exec bin/pact-broker record-deployment --pacticipant Foo --version 2 --environment test --application-instance customer-1
|
21
|
+
bundle exec bin/pact-broker record-deployment --pacticipant Foo --version 2 --environment test --application-instance customer-1
|
22
|
+
|
23
|
+
bundle exec bin/pact-broker record-undeployment --pacticipant Foo --environment test --application-instance customer-2
|
24
|
+
bundle exec bin/pact-broker record-undeployment --pacticipant Foo --environment test
|
25
|
+
bundle exec bin/pact-broker record-undeployment --pacticipant Foo --environment test
|
26
|
+
bundle exec bin/pact-broker record-undeployment --pacticipant Foo --environment test --application-instance customer-1
|
@@ -61,14 +61,14 @@ module PactBroker
|
|
61
61
|
to_return(status: 200, body: record_deployment_body_hash.to_json , headers: {})
|
62
62
|
end
|
63
63
|
|
64
|
-
let(:
|
64
|
+
let(:application_instance) { "blue" }
|
65
65
|
|
66
66
|
let(:params) do
|
67
67
|
{
|
68
68
|
pacticipant_name: "Foo",
|
69
69
|
version_number: "1",
|
70
70
|
environment_name: "test",
|
71
|
-
|
71
|
+
application_instance: application_instance
|
72
72
|
}
|
73
73
|
end
|
74
74
|
|
@@ -186,13 +186,13 @@ module PactBroker
|
|
186
186
|
end
|
187
187
|
|
188
188
|
it "indicates the API was Pactflow" do
|
189
|
-
expect(subject.message).to include "Recorded deployment of Foo version 1 to test environment (
|
189
|
+
expect(subject.message).to include "Recorded deployment of Foo version 1 to test environment (application instance blue) in Pactflow"
|
190
190
|
end
|
191
191
|
|
192
|
-
context "when
|
193
|
-
let(:
|
192
|
+
context "when application_instance is nil" do
|
193
|
+
let(:application_instance) { nil }
|
194
194
|
|
195
|
-
it "does not include the
|
195
|
+
it "does not include the application_instance in the result message" do
|
196
196
|
expect(subject.message).to include "Recorded deployment of Foo version 1 to test environment in"
|
197
197
|
end
|
198
198
|
end
|
@@ -7,11 +7,11 @@ module PactBroker
|
|
7
7
|
let(:params) do
|
8
8
|
{
|
9
9
|
pacticipant_name: "Foo",
|
10
|
-
|
10
|
+
application_instance: application_instance,
|
11
11
|
environment_name: "test"
|
12
12
|
}
|
13
13
|
end
|
14
|
-
let(:
|
14
|
+
let(:application_instance) { "customer-1" }
|
15
15
|
let(:output) { "text" }
|
16
16
|
let(:options) { { output: output, verbose: true } }
|
17
17
|
let(:pact_broker_base_url) { "http://broker" }
|
@@ -131,7 +131,7 @@ module PactBroker
|
|
131
131
|
subject { RecordUndeployment.call(params, options, pact_broker_client_options) }
|
132
132
|
|
133
133
|
its(:success) { is_expected.to eq true }
|
134
|
-
its(:message) { is_expected.to include "Recorded undeployment of Foo version 2 from test environment (
|
134
|
+
its(:message) { is_expected.to include "Recorded undeployment of Foo version 2 from test environment (application instance customer-1) in the Pact Broker" }
|
135
135
|
|
136
136
|
context "when there is no pb:environments relation in the index" do
|
137
137
|
let(:index_body_hash) do
|
@@ -173,8 +173,8 @@ module PactBroker
|
|
173
173
|
end
|
174
174
|
|
175
175
|
context "when a target is provided and there is no deployed version with a matching target" do
|
176
|
-
let(:
|
177
|
-
let(:expected_message) { "Foo is not currently deployed to
|
176
|
+
let(:application_instance) { "wrong" }
|
177
|
+
let(:expected_message) { "Foo is not currently deployed to application instance 'wrong' in test environment. Please omit the application instance to undeploy from the anonymous instance or specify one of the following application instances to record the undeployment from: customer-1." }
|
178
178
|
|
179
179
|
its(:success) { is_expected.to be false }
|
180
180
|
its(:message) { is_expected.to include expected_message }
|
@@ -186,12 +186,20 @@ module PactBroker
|
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
|
+
context "when a target is provided and there is no deployed version with a matching target and all the application instances are set" do
|
190
|
+
let(:application_instance) { "wrong" }
|
191
|
+
let(:returned_target_2) { "customer-2" }
|
192
|
+
let(:expected_message) { "Foo is not currently deployed to application instance 'wrong' in test environment. Please specify one of the following application instances to record the undeployment from: customer-1, customer-2." }
|
193
|
+
|
194
|
+
its(:message) { is_expected.to include expected_message }
|
195
|
+
end
|
196
|
+
|
189
197
|
context "when a target is not provided and there is no deployed verison without a target" do
|
190
|
-
let(:
|
198
|
+
let(:application_instance) { nil }
|
191
199
|
let(:returned_target_2) { "customer-2" }
|
192
200
|
|
193
201
|
its(:success) { is_expected.to be false }
|
194
|
-
its(:message) { is_expected.to include "Please specify one of the following
|
202
|
+
its(:message) { is_expected.to include "Please specify one of the following application instances to record the undeployment from: customer-1, customer-2" }
|
195
203
|
end
|
196
204
|
|
197
205
|
context "when there are no deployed versions for the pacticipant" do
|
@@ -35,6 +35,16 @@ module PactBroker
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
context "when the branch starts with refs/heads/" do
|
39
|
+
before do
|
40
|
+
allow(ENV).to receive(:[]).with("GITHUB_REF").and_return("refs/heads/feature-x")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "trims off the refs/heads/" do
|
44
|
+
expect(subject).to eq "feature-x"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
38
48
|
context "when there is one environment variable ending with _BRANCH" do
|
39
49
|
before do
|
40
50
|
allow(ENV).to receive(:keys).and_return(%w{FOO_BRANCH BAR_BRANCH BLAH})
|
@@ -108,6 +118,42 @@ module PactBroker
|
|
108
118
|
include_examples "when raise_error is false"
|
109
119
|
end
|
110
120
|
end
|
121
|
+
|
122
|
+
describe ".build_url" do
|
123
|
+
before do
|
124
|
+
allow(ENV).to receive(:[]).and_call_original
|
125
|
+
end
|
126
|
+
|
127
|
+
subject { Git.build_url }
|
128
|
+
|
129
|
+
context "when nothing is set" do
|
130
|
+
before do
|
131
|
+
allow(ENV).to receive(:[]).and_return(nil)
|
132
|
+
end
|
133
|
+
|
134
|
+
it { is_expected.to eq nil }
|
135
|
+
end
|
136
|
+
|
137
|
+
context "when BUILDKITE_BUILD_URL is set" do
|
138
|
+
before do
|
139
|
+
allow(ENV).to receive(:[]).and_return(nil)
|
140
|
+
allow(ENV).to receive(:[]).with("BUILDKITE_BUILD_URL").and_return("http://build")
|
141
|
+
end
|
142
|
+
|
143
|
+
it { is_expected.to eq "http://build" }
|
144
|
+
end
|
145
|
+
|
146
|
+
context "when the Github Actions env vars are set" do
|
147
|
+
before do
|
148
|
+
allow(ENV).to receive(:[]).and_return(nil)
|
149
|
+
allow(ENV).to receive(:[]).with("GITHUB_SERVER_URL").and_return("https://github.com")
|
150
|
+
allow(ENV).to receive(:[]).with("GITHUB_REPOSITORY").and_return("org/repo")
|
151
|
+
allow(ENV).to receive(:[]).with("GITHUB_RUN_ID").and_return("1")
|
152
|
+
end
|
153
|
+
|
154
|
+
it { is_expected.to eq "https://github.com/org/repo/actions/runs/1" }
|
155
|
+
end
|
156
|
+
end
|
111
157
|
end
|
112
158
|
end
|
113
159
|
end
|
@@ -9,13 +9,13 @@ RSpec.describe "recording a deployment", pact: true do
|
|
9
9
|
let(:version_number) { "5556b8149bf8bac76bc30f50a8a2dd4c22c85f30" }
|
10
10
|
let(:environment_name) { "test" }
|
11
11
|
let(:output) { "text" }
|
12
|
-
let(:
|
12
|
+
let(:application_instance) { "blue" }
|
13
13
|
let(:params) do
|
14
14
|
{
|
15
15
|
pacticipant_name: pacticipant_name,
|
16
16
|
version_number: version_number,
|
17
17
|
environment_name: environment_name,
|
18
|
-
|
18
|
+
application_instance: application_instance
|
19
19
|
}
|
20
20
|
end
|
21
21
|
let(:options) do
|
@@ -139,14 +139,15 @@ RSpec.describe "recording a deployment", pact: true do
|
|
139
139
|
path: "/HAL-REL-PLACEHOLDER-PB-RECORD-DEPLOYMENT-FOO-5556B8149BF8BAC76BC30F50A8A2DD4C22C85F30-TEST",
|
140
140
|
headers: post_request_headers,
|
141
141
|
body: {
|
142
|
-
|
142
|
+
applicationInstance: application_instance,
|
143
|
+
target: application_instance
|
143
144
|
}
|
144
145
|
)
|
145
146
|
.will_respond_with(
|
146
147
|
status: 201,
|
147
148
|
headers: pact_broker_response_headers,
|
148
149
|
body: {
|
149
|
-
target:
|
150
|
+
target: application_instance
|
150
151
|
}
|
151
152
|
)
|
152
153
|
end
|
@@ -160,14 +161,14 @@ RSpec.describe "recording a deployment", pact: true do
|
|
160
161
|
|
161
162
|
it "returns a success message" do
|
162
163
|
expect(subject.success).to be true
|
163
|
-
expect(subject.message).to include "Recorded deployment of Foo version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 to test environment (
|
164
|
+
expect(subject.message).to include "Recorded deployment of Foo version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 to test environment (application instance blue) in the Pact Broker."
|
164
165
|
end
|
165
166
|
|
166
167
|
context "when the output is json" do
|
167
168
|
let(:output) { "json" }
|
168
169
|
|
169
170
|
it "returns the JSON payload" do
|
170
|
-
expect(JSON.parse(subject.message)).to eq "target" =>
|
171
|
+
expect(JSON.parse(subject.message)).to eq "target" => application_instance
|
171
172
|
end
|
172
173
|
end
|
173
174
|
end
|
@@ -8,12 +8,12 @@ RSpec.describe "recording an undeployment", pact: true do
|
|
8
8
|
let(:pacticipant_name) { "Foo" }
|
9
9
|
let(:environment_name) { "test" }
|
10
10
|
let(:output) { "text" }
|
11
|
-
let(:
|
11
|
+
let(:application_instance) { "customer-1" }
|
12
12
|
let(:params) do
|
13
13
|
{
|
14
14
|
pacticipant_name: pacticipant_name,
|
15
15
|
environment_name: environment_name,
|
16
|
-
|
16
|
+
application_instance: application_instance
|
17
17
|
}
|
18
18
|
end
|
19
19
|
let(:options) do
|
@@ -100,7 +100,7 @@ RSpec.describe "recording an undeployment", pact: true do
|
|
100
100
|
_embedded: {
|
101
101
|
deployedVersions: [
|
102
102
|
{
|
103
|
-
target:
|
103
|
+
target: application_instance,
|
104
104
|
_links: {
|
105
105
|
self: {
|
106
106
|
href: Pact.term(pact_broker.mock_service_base_url + deployed_version_placeholder_path, /^http/)
|
@@ -150,7 +150,7 @@ RSpec.describe "recording an undeployment", pact: true do
|
|
150
150
|
|
151
151
|
it "returns a success message" do
|
152
152
|
expect(subject.success).to be true
|
153
|
-
expect(subject.message).to include "Recorded undeployment of Foo version 2 from test environment (
|
153
|
+
expect(subject.message).to include "Recorded undeployment of Foo version 2 from test environment (application instance customer-1) in the Pact Broker"
|
154
154
|
end
|
155
155
|
|
156
156
|
context "when the output is json" do
|
data/tasks/pact.rake
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require
|
1
|
+
require "pact_broker/client/tasks"
|
2
|
+
require "pact_broker/client/git"
|
2
3
|
|
3
4
|
PactBroker::Client::PublicationTask.new(:localhost) do | task |
|
4
5
|
require 'pact_broker/client/version'
|
@@ -35,4 +36,5 @@ PactBroker::Client::PublicationTask.new(:pactflow) do | task |
|
|
35
36
|
task.consumer_version = version
|
36
37
|
task.pact_broker_base_url = "https://pact-oss.pactflow.io"
|
37
38
|
task.pact_broker_token = ENV['PACT_BROKER_TOKEN']
|
39
|
+
task.build_url = PactBroker::Client::Git.build_url
|
38
40
|
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.
|
4
|
+
version: 1.55.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-
|
11
|
+
date: 2021-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|