pact_broker-client 1.70.0 → 1.71.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +4 -1
- data/CHANGELOG.md +7 -0
- data/README.md +64 -16
- data/doc/pacts/markdown/Pact Broker Client - Pactflow.md +98 -4
- data/doc/pacts/markdown/README.md +1 -1
- data/lib/pact_broker/client/cli/matrix_commands.rb +1 -2
- data/lib/pact_broker/client/version.rb +1 -1
- data/lib/pactflow/client/cli/provider_contract_commands.rb +2 -1
- data/lib/pactflow/client/provider_contracts/publish.rb +48 -56
- data/lib/pactflow/client/provider_contracts/publish_the_old_way.rb +104 -0
- data/script/foo-bar.json +81 -0
- data/script/publish-pact.sh +8 -10
- data/script/publish-provider-contract.sh +1 -1
- data/script/update-cli-usage-in-readme.rb +1 -1
- data/spec/fixtures/approvals/publish_provider_contract.approved.txt +2 -0
- data/spec/integration/publish_provider_contract_spec.rb +57 -0
- data/spec/lib/pactflow/client/provider_contracts/publish_spec.rb +179 -0
- data/spec/pacts/pact_broker_client-pactflow.json +105 -3
- data/spec/service_providers/pact_helper.rb +16 -2
- data/spec/service_providers/pactflow_publish_provider_contract_spec.rb +64 -52
- data/spec/service_providers/pactflow_publish_provider_contract_the_old_way_spec.rb +129 -0
- data/spec/spec_helper.rb +4 -0
- data/tasks/pact.rake +29 -8
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cab4d53c9ef3be0be8a1bdd732c4e7eefddad4e2bd27591ca06500e5c63a81d
|
4
|
+
data.tar.gz: 67e2015656535cf37325f9a45d7fca195c1a2fb64e157e6a1485447d76173551
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d70c00647a761e2cf37028514027b4a36ae0159a65145949144cdc2e3026dfdcaef93d3ac8a827bf1ad43e55e0cf8e7dc40a5ad1117e4424fe70054b153334e9
|
7
|
+
data.tar.gz: 88264d74be62413f138453b54a842eab64b975d3a5f433ffd370993f86afe4ebd2bb79f969f92c3b54b6ac51a641b729515224996d3c154d721e036cdc8d7448
|
data/.github/workflows/test.yml
CHANGED
@@ -30,12 +30,15 @@ jobs:
|
|
30
30
|
with:
|
31
31
|
ruby-version: "3.2"
|
32
32
|
- run: "bundle install"
|
33
|
+
# Publish to old and new account until we can disable the old account
|
33
34
|
- run: |
|
34
35
|
rm -rf spec/pacts/*
|
35
36
|
bundle exec rspec spec/service_providers/
|
36
|
-
VERBOSE=true bundle exec rake pact:publish:
|
37
|
+
VERBOSE=true bundle exec rake pact:publish:pactflow_oss
|
38
|
+
VERBOSE=true bundle exec rake pact:publish:pactflow_pact_foundation
|
37
39
|
env:
|
38
40
|
PACT_BROKER_TOKEN: ${{ secrets.PACTFLOW_PACT_OSS_TOKEN }}
|
41
|
+
PACT_BROKER_TOKEN_PACT_FOUNDATION: ${{ secrets.PACT_BROKER_TOKEN_PACT_FOUNDATION }}
|
39
42
|
PACT_BROKER_FEATURES: ${{ matrix.feature }}
|
40
43
|
TEST_FEATURE: ${{ matrix.feature }}
|
41
44
|
can-i-deploy:
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -434,7 +434,7 @@ Options:
|
|
434
434
|
-e, [--version=VERSION]
|
435
435
|
# The pacticipant version. Must be entered after the
|
436
436
|
--pacticipant that it relates to.
|
437
|
-
[--ignore=
|
437
|
+
[--ignore=PACTICIPANT]
|
438
438
|
# The pacticipant name to ignore. Use once for each pacticipant
|
439
439
|
being ignored. A specific version can be ignored by also
|
440
440
|
specifying a --version after the pacticipant name option. The
|
@@ -458,10 +458,6 @@ Options:
|
|
458
458
|
# The tag that represents the branch or environment of the
|
459
459
|
integrated applications for which you want to check the
|
460
460
|
verification result status.
|
461
|
-
[--ignore=IGNORE]
|
462
|
-
# The pacticipant name to ignore. Use once for each pacticipant
|
463
|
-
being ignored. A specific version can be ignored by also
|
464
|
-
specifying a --version after the pacticipant name option.
|
465
461
|
-o, [--output=OUTPUT]
|
466
462
|
# json or table
|
467
463
|
# Default: table
|
@@ -505,8 +501,8 @@ Description:
|
|
505
501
|
support for environments, deployments and releases. For documentation on how to use can-i-deploy with tags, please see
|
506
502
|
https://docs.pact.io/pact_broker/client_cli/can_i_deploy_usage_with_tags/
|
507
503
|
|
508
|
-
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
|
509
|
-
and "production" environments will have been seeded for you. You can check the existing environments by running `pact-broker list-environments`. See
|
504
|
+
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
|
505
|
+
"test" and "production" environments will have been seeded for you. You can check the existing environments by running `pact-broker list-environments`. See
|
510
506
|
https://docs.pact.io/pact_broker/client_cli/readme#environments for more information.
|
511
507
|
|
512
508
|
$ pact-broker create-environment --name "uat" --display-name "UAT" --no-production
|
@@ -516,8 +512,8 @@ Description:
|
|
516
512
|
|
517
513
|
$ pact-broker record-deployment --pacticipant Foo --version 173153ae0 --environment uat
|
518
514
|
|
519
|
-
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
|
520
|
-
the versions of each integrated application that are already in that environment.
|
515
|
+
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
|
516
|
+
with the versions of each integrated application that are already in that environment.
|
521
517
|
|
522
518
|
$ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION --to-environment ENVIRONMENT
|
523
519
|
|
@@ -525,8 +521,8 @@ Description:
|
|
525
521
|
|
526
522
|
$ pact-broker can-i-deploy --pacticipant Foo --version 173153ae0 --to-environment test
|
527
523
|
|
528
|
-
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
|
529
|
-
from the main branch of another application" it functions as a "can I merge" check.
|
524
|
+
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
|
525
|
+
latest version from the main branch of another application" it functions as a "can I merge" check.
|
530
526
|
|
531
527
|
$ pact-broker can-i-deploy --pacticipant Foo 173153ae0 \ --pacticipant Bar --latest main
|
532
528
|
|
@@ -536,6 +532,56 @@ If the verification process takes a long time and there are results missing when
|
|
536
532
|
command to poll and wait for the missing results to arrive. The arguments to specify are `--retry-while-unknown TIMES` and `--retry-interval SECONDS`, set to
|
537
533
|
appropriate values for your pipeline.
|
538
534
|
|
535
|
+
#### can-i-merge
|
536
|
+
|
537
|
+
```
|
538
|
+
Usage:
|
539
|
+
pact-broker can-i-merge -a, --pacticipant=PACTICIPANT -b, --broker-base-url=BROKER_BASE_URL
|
540
|
+
|
541
|
+
Options:
|
542
|
+
-a, --pacticipant=PACTICIPANT
|
543
|
+
# The pacticipant name. Use once for each pacticipant being
|
544
|
+
checked.
|
545
|
+
-e, [--version=VERSION]
|
546
|
+
# The pacticipant version. Must be entered after the
|
547
|
+
--pacticipant that it relates to.
|
548
|
+
-o, [--output=OUTPUT]
|
549
|
+
# json or table
|
550
|
+
# Default: table
|
551
|
+
[--retry-while-unknown=TIMES]
|
552
|
+
# The number of times to retry while there is an unknown
|
553
|
+
verification result (ie. the provider verification is likely
|
554
|
+
still running)
|
555
|
+
# Default: 0
|
556
|
+
[--retry-interval=SECONDS]
|
557
|
+
# The time between retries in seconds. Use in conjuction with
|
558
|
+
--retry-while-unknown
|
559
|
+
# Default: 10
|
560
|
+
[--dry-run], [--no-dry-run]
|
561
|
+
# When dry-run is enabled, always exit process with a success
|
562
|
+
code. Can also be enabled by setting the environment variable
|
563
|
+
PACT_BROKER_CAN_I_MERGE_DRY_RUN=true. This mode is useful when
|
564
|
+
setting up your CI/CD pipeline for the first time, or in a
|
565
|
+
'break glass' situation where you need to knowingly deploy what
|
566
|
+
Pact considers a breaking change. For the second scenario, it
|
567
|
+
is recommended to use the environment variable and just set it
|
568
|
+
for the build required to deploy that particular version, so
|
569
|
+
you don't accidentally leave the dry run mode enabled.
|
570
|
+
-b, --broker-base-url=BROKER_BASE_URL
|
571
|
+
# The base URL of the Pact Broker
|
572
|
+
-u, [--broker-username=BROKER_USERNAME]
|
573
|
+
# Pact Broker basic auth username
|
574
|
+
-p, [--broker-password=BROKER_PASSWORD]
|
575
|
+
# Pact Broker basic auth password
|
576
|
+
-k, [--broker-token=BROKER_TOKEN]
|
577
|
+
# Pact Broker bearer token
|
578
|
+
-v, [--verbose], [--no-verbose]
|
579
|
+
# Verbose output. Default: false
|
580
|
+
```
|
581
|
+
|
582
|
+
Description:
|
583
|
+
Checks if the specified pacticipant version is compatible with the configured main branch of each of the pacticipants with which it is integrated.
|
584
|
+
|
539
585
|
### Pacticipants
|
540
586
|
|
541
587
|
#### create-or-update-pacticipant
|
@@ -679,8 +725,8 @@ Options:
|
|
679
725
|
```
|
680
726
|
|
681
727
|
Description:
|
682
|
-
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
|
683
|
-
provider, event types and broker details. Note that the URL must be the first parameter when executing create-webhook.
|
728
|
+
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
|
729
|
+
consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-webhook.
|
684
730
|
|
685
731
|
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
|
686
732
|
option. Please use the --broker-username or environment variable for the Pact Broker username.
|
@@ -744,9 +790,9 @@ Options:
|
|
744
790
|
```
|
745
791
|
|
746
792
|
Description:
|
747
|
-
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
|
748
|
-
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
|
749
|
-
also be provided. You can generate a valid UUID by using the `generate-uuid` command.
|
793
|
+
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
|
794
|
+
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
|
795
|
+
must also be provided. You can generate a valid UUID by using the `generate-uuid` command.
|
750
796
|
|
751
797
|
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
|
752
798
|
option. Please use the --broker-username or environment variable for the Pact Broker username.
|
@@ -930,6 +976,8 @@ Options:
|
|
930
976
|
# The tool used to verify the provider contract
|
931
977
|
[--verifier-version=VERIFIER_VERSION]
|
932
978
|
# The version of the tool used to verify the provider contract
|
979
|
+
[--build-url=BUILD_URL]
|
980
|
+
# The build URL that created the provider contract
|
933
981
|
-o, [--output=OUTPUT]
|
934
982
|
# json or text
|
935
983
|
# Default: text
|
@@ -4,12 +4,16 @@
|
|
4
4
|
|
5
5
|
* [A request for the index resource](#a_request_for_the_index_resource)
|
6
6
|
|
7
|
+
* [A request for the index resource](#a_request_for_the_index_resource_given_the_pb:publish-provider-contract_relation_exists_in_the_index_resource) given the pb:publish-provider-contract relation exists in the index resource
|
8
|
+
|
7
9
|
* [A request to create a provider contract](#a_request_to_create_a_provider_contract)
|
8
10
|
|
9
11
|
* [A request to create a provider contract](#a_request_to_create_a_provider_contract_given_there_is_a_pf:ui_href_in_the_response) given there is a pf:ui href in the response
|
10
12
|
|
11
13
|
* [A request to create a webhook for a team](#a_request_to_create_a_webhook_for_a_team_given_a_team_with_UUID_2abbc12a-427d-432a-a521-c870af1739d9_exists) given a team with UUID 2abbc12a-427d-432a-a521-c870af1739d9 exists
|
12
14
|
|
15
|
+
* [A request to publish a provider contract](#a_request_to_publish_a_provider_contract)
|
16
|
+
|
13
17
|
#### Interactions
|
14
18
|
|
15
19
|
<a name="a_request_for_the_index_resource"></a>
|
@@ -45,6 +49,33 @@ PactFlow will respond with:
|
|
45
49
|
}
|
46
50
|
}
|
47
51
|
```
|
52
|
+
<a name="a_request_for_the_index_resource_given_the_pb:publish-provider-contract_relation_exists_in_the_index_resource"></a>
|
53
|
+
Given **the pb:publish-provider-contract relation exists in the index resource**, upon receiving **a request for the index resource** from Pact Broker Client, with
|
54
|
+
```json
|
55
|
+
{
|
56
|
+
"method": "GET",
|
57
|
+
"path": "/",
|
58
|
+
"headers": {
|
59
|
+
"Accept": "application/hal+json"
|
60
|
+
}
|
61
|
+
}
|
62
|
+
```
|
63
|
+
PactFlow will respond with:
|
64
|
+
```json
|
65
|
+
{
|
66
|
+
"status": 200,
|
67
|
+
"headers": {
|
68
|
+
"Content-Type": "application/hal+json;charset=utf-8"
|
69
|
+
},
|
70
|
+
"body": {
|
71
|
+
"_links": {
|
72
|
+
"pf:publish-provider-contract": {
|
73
|
+
"href": "http://localhost:1235/HAL-REL-PLACEHOLDER-PF-PUBLISH-PROVIDER-CONTRACT-{provider}"
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
```
|
48
79
|
<a name="a_request_to_create_a_provider_contract"></a>
|
49
80
|
Upon receiving **a request to create a provider contract** from Pact Broker Client, with
|
50
81
|
```json
|
@@ -56,7 +87,7 @@ Upon receiving **a request to create a provider contract** from Pact Broker Clie
|
|
56
87
|
"Accept": "application/hal+json"
|
57
88
|
},
|
58
89
|
"body": {
|
59
|
-
"content": "
|
90
|
+
"content": "LS0tCnNvbWU6IGNvbnRyYWN0Cg==",
|
60
91
|
"contractType": "oas",
|
61
92
|
"contentType": "application/yaml",
|
62
93
|
"verificationResults": {
|
@@ -90,7 +121,7 @@ Given **there is a pf:ui href in the response**, upon receiving **a request to c
|
|
90
121
|
"Accept": "application/hal+json"
|
91
122
|
},
|
92
123
|
"body": {
|
93
|
-
"content": "
|
124
|
+
"content": "LS0tCnNvbWU6IGNvbnRyYWN0Cg==",
|
94
125
|
"contractType": "oas",
|
95
126
|
"contentType": "application/yaml",
|
96
127
|
"verificationResults": {
|
@@ -104,7 +135,7 @@ Given **there is a pf:ui href in the response**, upon receiving **a request to c
|
|
104
135
|
}
|
105
136
|
}
|
106
137
|
```
|
107
|
-
|
138
|
+
PactFlow will respond with:
|
108
139
|
```json
|
109
140
|
{
|
110
141
|
"status": 201,
|
@@ -114,7 +145,7 @@ Pactflow will respond with:
|
|
114
145
|
"body": {
|
115
146
|
"_links": {
|
116
147
|
"pf:ui": {
|
117
|
-
"href": "
|
148
|
+
"href": "some-url"
|
118
149
|
}
|
119
150
|
}
|
120
151
|
}
|
@@ -171,3 +202,66 @@ PactFlow will respond with:
|
|
171
202
|
}
|
172
203
|
}
|
173
204
|
```
|
205
|
+
<a name="a_request_to_publish_a_provider_contract"></a>
|
206
|
+
Upon receiving **a request to publish a provider contract** from Pact Broker Client, with
|
207
|
+
```json
|
208
|
+
{
|
209
|
+
"method": "post",
|
210
|
+
"path": "/HAL-REL-PLACEHOLDER-PF-PUBLISH-PROVIDER-CONTRACT-Bar",
|
211
|
+
"headers": {
|
212
|
+
"Content-Type": "application/json",
|
213
|
+
"Accept": "application/hal+json"
|
214
|
+
},
|
215
|
+
"body": {
|
216
|
+
"pacticipantVersionNumber": "1",
|
217
|
+
"tags": [
|
218
|
+
"dev"
|
219
|
+
],
|
220
|
+
"branch": "main",
|
221
|
+
"buildUrl": "http://build",
|
222
|
+
"contract": {
|
223
|
+
"content": "LS0tCnNvbWU6IGNvbnRyYWN0Cg==",
|
224
|
+
"contentType": "application/yaml",
|
225
|
+
"specification": "oas",
|
226
|
+
"selfVerificationResults": {
|
227
|
+
"success": true,
|
228
|
+
"content": "c29tZSByZXN1bHRz",
|
229
|
+
"contentType": "text/plain",
|
230
|
+
"format": "text",
|
231
|
+
"verifier": "my custom tool",
|
232
|
+
"verifierVersion": "1.0"
|
233
|
+
}
|
234
|
+
}
|
235
|
+
}
|
236
|
+
}
|
237
|
+
```
|
238
|
+
PactFlow will respond with:
|
239
|
+
```json
|
240
|
+
{
|
241
|
+
"status": 200,
|
242
|
+
"headers": {
|
243
|
+
"Content-Type": "application/hal+json;charset=utf-8"
|
244
|
+
},
|
245
|
+
"body": {
|
246
|
+
"notices": [
|
247
|
+
{
|
248
|
+
"text": "some notice",
|
249
|
+
"type": "info"
|
250
|
+
}
|
251
|
+
],
|
252
|
+
"_embedded": {
|
253
|
+
"version": {
|
254
|
+
"number": "1"
|
255
|
+
}
|
256
|
+
},
|
257
|
+
"_links": {
|
258
|
+
"pb:pacticipant-version-tags": [
|
259
|
+
{
|
260
|
+
}
|
261
|
+
],
|
262
|
+
"pb:branch-version": {
|
263
|
+
}
|
264
|
+
}
|
265
|
+
}
|
266
|
+
}
|
267
|
+
```
|
@@ -13,13 +13,12 @@ module PactBroker
|
|
13
13
|
|
14
14
|
method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name. Use once for each pacticipant being checked."
|
15
15
|
method_option :version, required: false, aliases: "-e", desc: "The pacticipant version. Must be entered after the --pacticipant that it relates to."
|
16
|
-
method_option :ignore, required: false, desc: "The pacticipant name to ignore. Use once for each pacticipant being ignored. A specific version can be ignored by also specifying a --version after the pacticipant name option. The environment variable PACT_BROKER_CAN_I_DEPLOY_IGNORE may also be used to specify a pacticipant name to ignore, with commas to separate multiple pacticipant names if necessary."
|
16
|
+
method_option :ignore, required: false, banner: "PACTICIPANT", desc: "The pacticipant name to ignore. Use once for each pacticipant being ignored. A specific version can be ignored by also specifying a --version after the pacticipant name option. The environment variable PACT_BROKER_CAN_I_DEPLOY_IGNORE may also be used to specify a pacticipant name to ignore, with commas to separate multiple pacticipant names if necessary."
|
17
17
|
method_option :latest, required: false, aliases: "-l", banner: "[TAG]", desc: "Use the latest pacticipant version. Optionally specify a TAG to use the latest version with the specified tag."
|
18
18
|
method_option :branch, required: false, desc: "The branch of the version for which you want to check the verification results.", default: nil
|
19
19
|
method_option :main_branch, required: false, type: :boolean, desc: "Use the latest version of the configured main branch of the pacticipant as the version for which you want to check the verification results", default: false
|
20
20
|
method_option :to_environment, required: false, banner: "ENVIRONMENT", desc: "The environment into which the pacticipant(s) are to be deployed", default: nil
|
21
21
|
method_option :to, required: false, banner: "TAG", desc: "The tag that represents the branch or environment of the integrated applications for which you want to check the verification result status.", default: nil
|
22
|
-
method_option :ignore, required: false, desc: "The pacticipant name to ignore. Use once for each pacticipant being ignored. A specific version can be ignored by also specifying a --version after the pacticipant name option."
|
23
22
|
method_option :output, aliases: "-o", desc: "json or table", default: "table"
|
24
23
|
method_option :retry_while_unknown, banner: "TIMES", type: :numeric, default: 0, required: false, desc: "The number of times to retry while there is an unknown verification result (ie. the provider verification is likely still running)"
|
25
24
|
method_option :retry_interval, banner: "SECONDS", type: :numeric, default: 10, required: false, desc: "The time between retries in seconds. Use in conjuction with --retry-while-unknown"
|
@@ -26,7 +26,7 @@ module Pactflow
|
|
26
26
|
method_option :verification_results_format, desc: "The format of the verification output eg. junit, text"
|
27
27
|
method_option :verifier, desc: "The tool used to verify the provider contract"
|
28
28
|
method_option :verifier_version, desc: "The version of the tool used to verify the provider contract"
|
29
|
-
|
29
|
+
method_option :build_url, desc: "The build URL that created the provider contract"
|
30
30
|
|
31
31
|
output_option_json_or_text
|
32
32
|
shared_authentication_options
|
@@ -70,6 +70,7 @@ module Pactflow
|
|
70
70
|
provider_version_number: options.provider_app_version.strip,
|
71
71
|
branch_name: options.branch && options.branch.strip,
|
72
72
|
tags: (options.tag && options.tag.collect(&:strip)) || [],
|
73
|
+
build_url: options.build_url,
|
73
74
|
contract: {
|
74
75
|
content: File.read(provider_contract_path),
|
75
76
|
content_type: options.content_type,
|
@@ -1,13 +1,14 @@
|
|
1
|
-
require "pact_broker/client/base_command"
|
2
|
-
require "pact_broker/client/versions/create"
|
3
|
-
require 'pact_broker/client/colorize_notices'
|
4
1
|
require "base64"
|
2
|
+
require "pact_broker/client/base_command"
|
3
|
+
require "pact_broker/client/colorize_notices"
|
4
|
+
require "pactflow/client/provider_contracts/publish_the_old_way"
|
5
5
|
|
6
6
|
module Pactflow
|
7
7
|
module Client
|
8
8
|
module ProviderContracts
|
9
9
|
class Publish < PactBroker::Client::BaseCommand
|
10
|
-
|
10
|
+
PUBLISH_RELATION = "pf:publish-provider-contract"
|
11
|
+
|
11
12
|
|
12
13
|
def initialize(params, options, pact_broker_client_options)
|
13
14
|
super
|
@@ -15,62 +16,30 @@ module Pactflow
|
|
15
16
|
@provider_version_number = params[:provider_version_number]
|
16
17
|
@branch_name = params[:branch_name]
|
17
18
|
@tags = params[:tags] || []
|
19
|
+
@build_url = params[:build_url]
|
18
20
|
@contract = params[:contract]
|
19
21
|
@verification_results = params[:verification_results]
|
20
22
|
end
|
21
23
|
|
22
24
|
private
|
23
25
|
|
24
|
-
|
25
|
-
create_branch_version_and_tags
|
26
|
-
render_response(create_contract)
|
27
|
-
end
|
26
|
+
attr_reader :provider_name, :provider_version_number, :branch_name, :tags, :build_url, :contract, :verification_results
|
28
27
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
def do_call
|
29
|
+
if enabled? && index_resource.assert_success!.can?(PUBLISH_RELATION)
|
30
|
+
publish_provider_contracts
|
31
|
+
PactBroker::Client::CommandResult.new(success?, message)
|
32
|
+
else
|
33
|
+
PublishTheOldWay.call(params, options, pact_broker_client_options)
|
35
34
|
end
|
36
|
-
notices.concat(next_steps)
|
37
|
-
PactBroker::Client::CommandResult.new(true, PactBroker::Client::ColorizeNotices.call(notices.collect do |n|
|
38
|
-
OpenStruct.new(n)
|
39
|
-
end).join("\n"))
|
40
|
-
end
|
41
|
-
|
42
|
-
def next_steps
|
43
|
-
[
|
44
|
-
{ type: 'prompt', text: 'Next steps:' },
|
45
|
-
{ type: 'prompt',
|
46
|
-
text: ' * Check your application is safe to deploy - https://docs.pact.io/can_i_deploy' },
|
47
|
-
{ text: " pact-broker can-i-deploy --pacticipant #{provider_name} --version #{provider_version_number} --to-environment <your environment name>" },
|
48
|
-
{ type: 'prompt',
|
49
|
-
text: ' * Record deployment or release to specified environment (choose one) - https://docs.pact.io/go/record-deployment' },
|
50
|
-
{ text: " pact-broker record-deployment --pacticipant #{provider_name} --version #{provider_version_number} --environment <your environment name>" },
|
51
|
-
{ text: " pact-broker record-release --pacticipant #{provider_name} --version #{provider_version_number} --environment <your environment name>" }
|
52
|
-
]
|
53
35
|
end
|
54
36
|
|
55
|
-
def
|
56
|
-
|
57
|
-
pacticipant_version_params = {
|
58
|
-
pacticipant_name: provider_name,
|
59
|
-
version_number: provider_version_number,
|
60
|
-
branch_name: branch_name,
|
61
|
-
tags: tags
|
62
|
-
}
|
63
|
-
result = PactBroker::Client::Versions::Create.call(pacticipant_version_params, options, pact_broker_client_options)
|
64
|
-
if !result.success
|
65
|
-
raise PactBroker::Client::Error.new(result.message)
|
66
|
-
end
|
67
|
-
end
|
37
|
+
def enabled?
|
38
|
+
ENV.fetch("PACT_BROKER_FEATURES", "").include?("publish_provider_contracts_all_in_one")
|
68
39
|
end
|
69
40
|
|
70
|
-
def
|
71
|
-
|
72
|
-
entrypoint = create_entry_point(contract_path, pact_broker_client_options)
|
73
|
-
entrypoint.expand(provider: provider_name, version: provider_version_number).put!(contract_params).response
|
41
|
+
def publish_provider_contracts
|
42
|
+
@response_entity = index_resource._link(PUBLISH_RELATION).expand(provider: provider_name).post!(contract_params, headers: { "Accept" => "application/hal+json,application/problem+json" })
|
74
43
|
end
|
75
44
|
|
76
45
|
def contract_params
|
@@ -82,22 +51,45 @@ module Pactflow
|
|
82
51
|
verifier: verification_results[:verifier],
|
83
52
|
verifierVersion: verification_results[:verifier_version]
|
84
53
|
}.compact
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
54
|
+
|
55
|
+
contract_params = {
|
56
|
+
content: encode_content(contract[:content]),
|
57
|
+
specification: contract[:specification],
|
58
|
+
contentType: contract[:content_type]
|
59
|
+
}.compact
|
91
60
|
|
92
61
|
if verification_results_params.any?
|
93
|
-
|
62
|
+
contract_params[:selfVerificationResults] = verification_results_params
|
94
63
|
end
|
95
|
-
|
64
|
+
|
65
|
+
{
|
66
|
+
pacticipantVersionNumber: provider_version_number,
|
67
|
+
tags: tags,
|
68
|
+
branch: branch_name,
|
69
|
+
buildUrl: build_url,
|
70
|
+
contract: contract_params
|
71
|
+
}
|
96
72
|
end
|
97
73
|
|
98
74
|
def encode_content oas
|
99
75
|
Base64.strict_encode64(oas)
|
100
76
|
end
|
77
|
+
|
78
|
+
def message
|
79
|
+
if options[:output] == "json"
|
80
|
+
@response_entity.response.raw_body
|
81
|
+
else
|
82
|
+
text_message
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def success?
|
87
|
+
@response_entity.success?
|
88
|
+
end
|
89
|
+
|
90
|
+
def text_message
|
91
|
+
PactBroker::Client::ColorizeNotices.call(@response_entity.notices.collect{ |n| OpenStruct.new(n) } )
|
92
|
+
end
|
101
93
|
end
|
102
94
|
end
|
103
95
|
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require "pact_broker/client/base_command"
|
2
|
+
require "pact_broker/client/versions/create"
|
3
|
+
require 'pact_broker/client/colorize_notices'
|
4
|
+
require "base64"
|
5
|
+
|
6
|
+
module Pactflow
|
7
|
+
module Client
|
8
|
+
module ProviderContracts
|
9
|
+
class PublishTheOldWay < PactBroker::Client::BaseCommand
|
10
|
+
attr_reader :branch_name, :tags, :provider_name, :provider_version_number, :contract, :verification_results
|
11
|
+
|
12
|
+
def initialize(params, options, pact_broker_client_options)
|
13
|
+
super
|
14
|
+
@provider_name = params[:provider_name]
|
15
|
+
@provider_version_number = params[:provider_version_number]
|
16
|
+
@branch_name = params[:branch_name]
|
17
|
+
@tags = params[:tags] || []
|
18
|
+
@contract = params[:contract]
|
19
|
+
@verification_results = params[:verification_results]
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def do_call
|
25
|
+
create_branch_version_and_tags
|
26
|
+
render_response(create_contract)
|
27
|
+
end
|
28
|
+
|
29
|
+
def render_response(res)
|
30
|
+
notices = [
|
31
|
+
{ type: 'success', text: "Successfully published provider contract for #{provider_name} version #{provider_version_number} to PactFlow"},
|
32
|
+
]
|
33
|
+
if res.body && res.body['_links'] && res.body['_links']['pf:ui']['href']
|
34
|
+
notices.concat([{ text: "View the uploaded contract at #{res.body['_links']['pf:ui']['href']}" }])
|
35
|
+
end
|
36
|
+
notices.concat(next_steps)
|
37
|
+
PactBroker::Client::CommandResult.new(true, PactBroker::Client::ColorizeNotices.call(notices.collect do |n|
|
38
|
+
OpenStruct.new(n)
|
39
|
+
end).join("\n"))
|
40
|
+
end
|
41
|
+
|
42
|
+
def next_steps
|
43
|
+
[
|
44
|
+
{ type: 'prompt', text: 'Next steps:' },
|
45
|
+
{ type: 'prompt',
|
46
|
+
text: ' * Check your application is safe to deploy - https://docs.pact.io/can_i_deploy' },
|
47
|
+
{ text: " pact-broker can-i-deploy --pacticipant #{provider_name} --version #{provider_version_number} --to-environment <your environment name>" },
|
48
|
+
{ type: 'prompt',
|
49
|
+
text: ' * Record deployment or release to specified environment (choose one) - https://docs.pact.io/go/record-deployment' },
|
50
|
+
{ text: " pact-broker record-deployment --pacticipant #{provider_name} --version #{provider_version_number} --environment <your environment name>" },
|
51
|
+
{ text: " pact-broker record-release --pacticipant #{provider_name} --version #{provider_version_number} --environment <your environment name>" }
|
52
|
+
]
|
53
|
+
end
|
54
|
+
|
55
|
+
def create_branch_version_and_tags
|
56
|
+
if branch_name || tags.any?
|
57
|
+
pacticipant_version_params = {
|
58
|
+
pacticipant_name: provider_name,
|
59
|
+
version_number: provider_version_number,
|
60
|
+
branch_name: branch_name,
|
61
|
+
tags: tags
|
62
|
+
}
|
63
|
+
result = PactBroker::Client::Versions::Create.call(pacticipant_version_params, options, pact_broker_client_options)
|
64
|
+
if !result.success
|
65
|
+
raise PactBroker::Client::Error.new(result.message)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_contract
|
71
|
+
contract_path = "#{pact_broker_base_url}/contracts/provider/{provider}/version/{version}"
|
72
|
+
entrypoint = create_entry_point(contract_path, pact_broker_client_options)
|
73
|
+
entrypoint.expand(provider: provider_name, version: provider_version_number).put!(contract_params).response
|
74
|
+
end
|
75
|
+
|
76
|
+
def contract_params
|
77
|
+
verification_results_params = {
|
78
|
+
success: verification_results[:success],
|
79
|
+
content: verification_results[:content] ? encode_content(verification_results[:content]) : nil,
|
80
|
+
contentType: verification_results[:content_type],
|
81
|
+
format: verification_results[:format],
|
82
|
+
verifier: verification_results[:verifier],
|
83
|
+
verifierVersion: verification_results[:verifier_version]
|
84
|
+
}.compact
|
85
|
+
|
86
|
+
body_params = {
|
87
|
+
content: encode_content(contract[:content]),
|
88
|
+
contractType: contract[:specification],
|
89
|
+
contentType: contract[:content_type],
|
90
|
+
}.compact
|
91
|
+
|
92
|
+
if verification_results_params.any?
|
93
|
+
body_params[:verificationResults] = verification_results_params
|
94
|
+
end
|
95
|
+
body_params
|
96
|
+
end
|
97
|
+
|
98
|
+
def encode_content oas
|
99
|
+
Base64.strict_encode64(oas)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|