pact_broker-client 1.23.0 → 1.24.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +27 -0
- data/README.md +87 -14
- data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +160 -0
- data/lib/pact_broker/client/cli/broker.rb +71 -54
- data/lib/pact_broker/client/cli/can_i_deploy_long_desc.txt +23 -7
- data/lib/pact_broker/client/cli/create_or_update_webhook_long_desc.txt +1 -0
- data/lib/pact_broker/client/cli/custom_thor.rb +30 -0
- data/lib/pact_broker/client/version.rb +1 -1
- data/lib/pact_broker/client/webhooks/create.rb +20 -7
- data/spec/lib/pact_broker/client/cli/broker_create_or_update_webhook_spec.rb +23 -0
- data/spec/lib/pact_broker/client/cli/broker_create_webhook_spec.rb +2 -170
- data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +210 -0
- data/spec/lib/pact_broker/client/cli/custom_thor_spec.rb +11 -0
- data/spec/lib/pact_broker/client/webhooks/create_spec.rb +16 -6
- data/spec/pacts/pact_broker_client-pact_broker.json +168 -0
- data/spec/service_providers/pact_helper.rb +21 -0
- data/spec/service_providers/webhooks_create_spec.rb +54 -5
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b12cd2f4a46260bb9c9642e5ae8c402f36e99e876409eb5f5a5718c24ff705e7
|
4
|
+
data.tar.gz: 79a2e1cea4055116b3b11017b8ee877f496a6b911107cdde0551a2eff944fd0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7488d1136e7153157c411c671a7c82309f1f1c1bd33afe1fbb1dc315bed1ddda5759b9b78363d2a8c1c6dcdc1b126d50a729fab23cf6744a122fb2264b864c0
|
7
|
+
data.tar.gz: ab8cd8cb2f6ce39b9138440a1a065eb81b10c90cf926d557b5852f6aa1e677348b42491d02e1f601a08027b49990e4710dd3da979568ae0a6cd5978397f5c2ce
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,30 @@
|
|
1
|
+
<a name="v1.24.0"></a>
|
2
|
+
### v1.24.0 (2020-02-13)
|
3
|
+
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
* **create-webhook**
|
8
|
+
* support creating webhooks for contract_published, provider_verification_succeeded and provider_verification_failed events, and allow description to be set ([b76f9c4](/../../commit/b76f9c4))
|
9
|
+
|
10
|
+
* **create-or-update-webhook**
|
11
|
+
* show helpful error message when attempting to create a webhook with a UUID on a version of the Pact Broker that doesn't support it ([6e3d30f](/../../commit/6e3d30f))
|
12
|
+
|
13
|
+
* **cli**
|
14
|
+
* add generate-uuid command for use when using create-or-update-webhook ([52824fb](/../../commit/52824fb))
|
15
|
+
* allow all versions for a particular tag to be specified when determining if it safe to deploy (mobile provider use case) ([da54dc1](/../../commit/da54dc1))
|
16
|
+
|
17
|
+
* suppport equals sign in can-i-deploy pacticipant selector parameters ([b5d89bc](/../../commit/b5d89bc))
|
18
|
+
* use different git command to get git branch name ([9373827](/../../commit/9373827))
|
19
|
+
* attempt to get git branch name from environment variable first before running git ([d512ef0](/../../commit/d512ef0))
|
20
|
+
|
21
|
+
|
22
|
+
#### Bug Fixes
|
23
|
+
|
24
|
+
* **can-i-deploy**
|
25
|
+
* if only one selector is specified and no --to TAG is specified, set latest=true for automatically calculated dependencies ([045fa91](/../../commit/045fa91))
|
26
|
+
|
27
|
+
|
1
28
|
<a name="v1.23.0"></a>
|
2
29
|
### v1.23.0 (2020-01-21)
|
3
30
|
|
data/README.md
CHANGED
@@ -111,7 +111,7 @@ Using a specific version is the easiest way to ensure you get an accurate respon
|
|
111
111
|
|
112
112
|
#### Recommended usage - allowing the Pact Broker to automatically determine the dependencies
|
113
113
|
|
114
|
-
If you would like the Pact Broker to calculate the dependencies for you when you want to deploy an application into a given environment, you will need to let the Broker know
|
114
|
+
If you would like the Pact Broker to calculate the dependencies for you when you want to deploy an application into a given environment, you will need to let the Broker know which version of each application is in that environment. To do this, the relevant application version resource in the Broker will need to be "tagged" with the name of the environment during the deployment process:
|
115
115
|
|
116
116
|
$ pact-broker create-version-tag --pacticipant Foo --version 173153ae0 --tag test
|
117
117
|
|
@@ -195,21 +195,43 @@ Mobile provider use case - can I deploy version b80e7b1b of Bar, all versions of
|
|
195
195
|
|
196
196
|
```
|
197
197
|
Usage:
|
198
|
-
pact-broker create-webhook URL
|
198
|
+
pact-broker create-webhook URL -X, --request=METHOD -b, --broker-base-url=BROKER_BASE_URL
|
199
199
|
|
200
200
|
Options:
|
201
|
-
-X, --request=
|
202
|
-
|
203
|
-
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
[--provider
|
212
|
-
|
201
|
+
-X, --request=METHOD
|
202
|
+
# HTTP method
|
203
|
+
-H, [--header=one two three]
|
204
|
+
# Header
|
205
|
+
-d, [--data=DATA]
|
206
|
+
# Data
|
207
|
+
-u, [--user=USER]
|
208
|
+
# Basic auth username and password eg. username:password
|
209
|
+
[--consumer=CONSUMER]
|
210
|
+
# Consumer name
|
211
|
+
[--provider=PROVIDER]
|
212
|
+
# Provider name
|
213
|
+
-b, --broker-base-url=BROKER_BASE_URL
|
214
|
+
# The base URL of the Pact Broker
|
215
|
+
[--broker-username=BROKER_USERNAME]
|
216
|
+
# Pact Broker basic auth username
|
217
|
+
-p, [--broker-password=BROKER_PASSWORD]
|
218
|
+
# Pact Broker basic auth password
|
219
|
+
-k, [--broker-token=BROKER_TOKEN]
|
220
|
+
# Pact Broker bearer token
|
221
|
+
[--description=DESCRIPTION]
|
222
|
+
# The description of the webhook
|
223
|
+
[--contract-content-changed], [--no-contract-content-changed]
|
224
|
+
# Trigger this webhook when the pact content changes
|
225
|
+
[--contract-published], [--no-contract-published]
|
226
|
+
# Trigger this webhook when a pact is published
|
227
|
+
[--provider-verification-published], [--no-provider-verification-published]
|
228
|
+
# Trigger this webhook when a provider verification result is published
|
229
|
+
[--provider-verification-failed], [--no-provider-verification-failed]
|
230
|
+
# Trigger this webhook when a failed provider verification result is published
|
231
|
+
[--provider-verification-succeeded], [--no-provider-verification-succeeded]
|
232
|
+
# Trigger this webhook when a successful provider verification result is published
|
233
|
+
-v, [--verbose], [--no-verbose]
|
234
|
+
# Verbose output. Default: false
|
213
235
|
|
214
236
|
Description:
|
215
237
|
Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker
|
@@ -217,6 +239,57 @@ Description:
|
|
217
239
|
when executing create-webhook.
|
218
240
|
```
|
219
241
|
|
242
|
+
### create-or-update-webhook
|
243
|
+
|
244
|
+
```
|
245
|
+
Usage:
|
246
|
+
pact-broker create-or-update-webhook URL --uuid=UUID -X, --request=METHOD -b, --broker-base-url=BROKER_BASE_URL
|
247
|
+
|
248
|
+
Options:
|
249
|
+
-X, --request=METHOD
|
250
|
+
# HTTP method
|
251
|
+
-H, [--header=one two three]
|
252
|
+
# Header
|
253
|
+
-d, [--data=DATA]
|
254
|
+
# Data
|
255
|
+
-u, [--user=USER]
|
256
|
+
# Basic auth username and password eg. username:password
|
257
|
+
[--consumer=CONSUMER]
|
258
|
+
# Consumer name
|
259
|
+
[--provider=PROVIDER]
|
260
|
+
# Provider name
|
261
|
+
-b, --broker-base-url=BROKER_BASE_URL
|
262
|
+
# The base URL of the Pact Broker
|
263
|
+
[--broker-username=BROKER_USERNAME]
|
264
|
+
# Pact Broker basic auth username
|
265
|
+
-p, [--broker-password=BROKER_PASSWORD]
|
266
|
+
# Pact Broker basic auth password
|
267
|
+
-k, [--broker-token=BROKER_TOKEN]
|
268
|
+
# Pact Broker bearer token
|
269
|
+
[--description=DESCRIPTION]
|
270
|
+
# The description of the webhook
|
271
|
+
[--contract-content-changed], [--no-contract-content-changed]
|
272
|
+
# Trigger this webhook when the pact content changes
|
273
|
+
[--contract-published], [--no-contract-published]
|
274
|
+
# Trigger this webhook when a pact is published
|
275
|
+
[--provider-verification-published], [--no-provider-verification-published]
|
276
|
+
# Trigger this webhook when a provider verification result is published
|
277
|
+
[--provider-verification-failed], [--no-provider-verification-failed]
|
278
|
+
# Trigger this webhook when a failed provider verification result is published
|
279
|
+
[--provider-verification-succeeded], [--no-provider-verification-succeeded]
|
280
|
+
# Trigger this webhook when a successful provider verification result is published
|
281
|
+
-v, [--verbose], [--no-verbose]
|
282
|
+
# Verbose output. Default: false
|
283
|
+
--uuid=UUID
|
284
|
+
# Specify the uuid for the webhook
|
285
|
+
|
286
|
+
Description:
|
287
|
+
Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker
|
288
|
+
create-or-update-webhook" and add the consumer, provider, event types and broker details. Note that the URL must be the first
|
289
|
+
parameter when executing create-or-update-webhook and a uuid must also be provided. You can generate a valid UUID by using
|
290
|
+
the `generate-uuid` command.
|
291
|
+
```
|
292
|
+
|
220
293
|
### describe-version
|
221
294
|
|
222
295
|
```
|
@@ -26,6 +26,8 @@
|
|
26
26
|
|
27
27
|
* [A request for the index resource](#a_request_for_the_index_resource_given_the_pb:latest-version_relation_exists_in_the_index_resource) given the pb:latest-version relation exists in the index resource
|
28
28
|
|
29
|
+
* [A request for the index resource with the webhook relation](#a_request_for_the_index_resource_with_the_webhook_relation)
|
30
|
+
|
29
31
|
* [A request for the list of the latest pacts from all consumers for the Pricing Service'](#a_request_for_the_list_of_the_latest_pacts_from_all_consumers_for_the_Pricing_Service'_given_a_latest_pact_between_Condor_and_the_Pricing_Service_exists) given a latest pact between Condor and the Pricing Service exists
|
30
32
|
|
31
33
|
* [A request for the list of the latest prod pacts from all consumers for the Pricing Service'](#a_request_for_the_list_of_the_latest_prod_pacts_from_all_consumers_for_the_Pricing_Service'_given_tagged_as_prod_pact_between_Condor_and_the_Pricing_Service_exists) given tagged as prod pact between Condor and the Pricing Service exists
|
@@ -38,6 +40,8 @@
|
|
38
40
|
|
39
41
|
* [A request to create a webhook for a consumer and provider](#a_request_to_create_a_webhook_for_a_consumer_and_provider_given_'Condor'_does_not_exist_in_the_pact-broker) given 'Condor' does not exist in the pact-broker
|
40
42
|
|
43
|
+
* [A request to create a webhook with a JSON body and a uuid](#a_request_to_create_a_webhook_with_a_JSON_body_and_a_uuid_given_the_'Pricing_Service'_and_'Condor'_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker
|
44
|
+
|
41
45
|
* [A request to create a webhook with a JSON body for a consumer](#a_request_to_create_a_webhook_with_a_JSON_body_for_a_consumer_given_the_'Pricing_Service'_and_'Condor'_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker
|
42
46
|
|
43
47
|
* [A request to create a webhook with a JSON body for a consumer and provider](#a_request_to_create_a_webhook_with_a_JSON_body_for_a_consumer_and_provider_given_the_'Pricing_Service'_and_'Condor'_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker
|
@@ -48,6 +52,8 @@
|
|
48
52
|
|
49
53
|
* [A request to create a webhook with a non-JSON body for a consumer and provider](#a_request_to_create_a_webhook_with_a_non-JSON_body_for_a_consumer_and_provider_given_the_'Pricing_Service'_and_'Condor'_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker
|
50
54
|
|
55
|
+
* [A request to create a webhook with every possible event type](#a_request_to_create_a_webhook_with_every_possible_event_type_given_the_'Pricing_Service'_and_'Condor'_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker
|
56
|
+
|
51
57
|
* [A request to get the Pricing Service](#a_request_to_get_the_Pricing_Service_given_the_'Pricing_Service'_already_exists_in_the_pact-broker) given the 'Pricing Service' already exists in the pact-broker
|
52
58
|
|
53
59
|
* [A request to get the Pricing Service](#a_request_to_get_the_Pricing_Service_given_the_'Pricing_Service'_does_not_exist_in_the_pact-broker) given the 'Pricing Service' does not exist in the pact-broker
|
@@ -557,6 +563,34 @@ Pact Broker will respond with:
|
|
557
563
|
}
|
558
564
|
}
|
559
565
|
```
|
566
|
+
<a name="a_request_for_the_index_resource_with_the_webhook_relation"></a>
|
567
|
+
Upon receiving **a request for the index resource with the webhook relation** from Pact Broker Client, with
|
568
|
+
```json
|
569
|
+
{
|
570
|
+
"method": "get",
|
571
|
+
"path": "/",
|
572
|
+
"headers": {
|
573
|
+
"Accept": "application/hal+json"
|
574
|
+
}
|
575
|
+
}
|
576
|
+
```
|
577
|
+
Pact Broker will respond with:
|
578
|
+
```json
|
579
|
+
{
|
580
|
+
"status": 200,
|
581
|
+
"headers": {
|
582
|
+
"Content-Type": "application/hal+json;charset=utf-8"
|
583
|
+
},
|
584
|
+
"body": {
|
585
|
+
"_links": {
|
586
|
+
"pb:webhook": {
|
587
|
+
"href": "http://localhost:1234/webhooks/{uuid}",
|
588
|
+
"templated": true
|
589
|
+
}
|
590
|
+
}
|
591
|
+
}
|
592
|
+
}
|
593
|
+
```
|
560
594
|
<a name="a_request_for_the_list_of_the_latest_pacts_from_all_consumers_for_the_Pricing_Service'_given_a_latest_pact_between_Condor_and_the_Pricing_Service_exists"></a>
|
561
595
|
Given **a latest pact between Condor and the Pricing Service exists**, upon receiving **a request for the list of the latest pacts from all consumers for the Pricing Service'** from Pact Broker Client, with
|
562
596
|
```json
|
@@ -702,6 +736,7 @@ Upon receiving **a request to create a global webhook with a JSON body** from Pa
|
|
702
736
|
"Accept": "application/hal+json"
|
703
737
|
},
|
704
738
|
"body": {
|
739
|
+
"description": "a webhook",
|
705
740
|
"events": [
|
706
741
|
{
|
707
742
|
"name": "contract_content_changed"
|
@@ -751,6 +786,7 @@ Given **'Condor' does not exist in the pact-broker**, upon receiving **a request
|
|
751
786
|
"Accept": "application/hal+json"
|
752
787
|
},
|
753
788
|
"body": {
|
789
|
+
"description": "a webhook",
|
754
790
|
"events": [
|
755
791
|
{
|
756
792
|
"name": "contract_content_changed"
|
@@ -781,6 +817,62 @@ Pact Broker will respond with:
|
|
781
817
|
}
|
782
818
|
}
|
783
819
|
```
|
820
|
+
<a name="a_request_to_create_a_webhook_with_a_JSON_body_and_a_uuid_given_the_'Pricing_Service'_and_'Condor'_already_exist_in_the_pact-broker"></a>
|
821
|
+
Given **the 'Pricing Service' and 'Condor' already exist in the pact-broker**, upon receiving **a request to create a webhook with a JSON body and a uuid** from Pact Broker Client, with
|
822
|
+
```json
|
823
|
+
{
|
824
|
+
"method": "put",
|
825
|
+
"path": "/webhooks/696c5f93-1b7f-44bc-8d03-59440fcaa9a0",
|
826
|
+
"headers": {
|
827
|
+
"Content-Type": "application/json",
|
828
|
+
"Accept": "application/hal+json"
|
829
|
+
},
|
830
|
+
"body": {
|
831
|
+
"description": "a webhook",
|
832
|
+
"events": [
|
833
|
+
{
|
834
|
+
"name": "contract_content_changed"
|
835
|
+
}
|
836
|
+
],
|
837
|
+
"request": {
|
838
|
+
"url": "https://webhook",
|
839
|
+
"method": "POST",
|
840
|
+
"headers": {
|
841
|
+
"Foo": "bar",
|
842
|
+
"Bar": "foo"
|
843
|
+
},
|
844
|
+
"body": {
|
845
|
+
"some": "body"
|
846
|
+
},
|
847
|
+
"username": "username",
|
848
|
+
"password": "password"
|
849
|
+
},
|
850
|
+
"provider": {
|
851
|
+
"name": "Pricing Service"
|
852
|
+
},
|
853
|
+
"consumer": {
|
854
|
+
"name": "Condor"
|
855
|
+
}
|
856
|
+
}
|
857
|
+
}
|
858
|
+
```
|
859
|
+
Pact Broker will respond with:
|
860
|
+
```json
|
861
|
+
{
|
862
|
+
"status": 201,
|
863
|
+
"headers": {
|
864
|
+
"Content-Type": "application/hal+json;charset=utf-8"
|
865
|
+
},
|
866
|
+
"body": {
|
867
|
+
"_links": {
|
868
|
+
"self": {
|
869
|
+
"href": "http://localhost:1234/some-url",
|
870
|
+
"title": "A title"
|
871
|
+
}
|
872
|
+
}
|
873
|
+
}
|
874
|
+
}
|
875
|
+
```
|
784
876
|
<a name="a_request_to_create_a_webhook_with_a_JSON_body_for_a_consumer_given_the_'Pricing_Service'_and_'Condor'_already_exist_in_the_pact-broker"></a>
|
785
877
|
Given **the 'Pricing Service' and 'Condor' already exist in the pact-broker**, upon receiving **a request to create a webhook with a JSON body for a consumer** from Pact Broker Client, with
|
786
878
|
```json
|
@@ -792,6 +884,7 @@ Given **the 'Pricing Service' and 'Condor' already exist in the pact-broker**, u
|
|
792
884
|
"Accept": "application/hal+json"
|
793
885
|
},
|
794
886
|
"body": {
|
887
|
+
"description": "a webhook",
|
795
888
|
"events": [
|
796
889
|
{
|
797
890
|
"name": "contract_content_changed"
|
@@ -844,6 +937,7 @@ Given **the 'Pricing Service' and 'Condor' already exist in the pact-broker**, u
|
|
844
937
|
"Accept": "application/hal+json"
|
845
938
|
},
|
846
939
|
"body": {
|
940
|
+
"description": "a webhook",
|
847
941
|
"events": [
|
848
942
|
{
|
849
943
|
"name": "contract_content_changed"
|
@@ -893,6 +987,7 @@ Upon receiving **a request to create a webhook with a JSON body for a consumer t
|
|
893
987
|
"Accept": "application/hal+json"
|
894
988
|
},
|
895
989
|
"body": {
|
990
|
+
"description": "a webhook",
|
896
991
|
"events": [
|
897
992
|
{
|
898
993
|
"name": "contract_content_changed"
|
@@ -944,6 +1039,7 @@ Given **the 'Pricing Service' and 'Condor' already exist in the pact-broker**, u
|
|
944
1039
|
"Accept": "application/hal+json"
|
945
1040
|
},
|
946
1041
|
"body": {
|
1042
|
+
"description": "a webhook",
|
947
1043
|
"events": [
|
948
1044
|
{
|
949
1045
|
"name": "contract_content_changed"
|
@@ -996,6 +1092,7 @@ Given **the 'Pricing Service' and 'Condor' already exist in the pact-broker**, u
|
|
996
1092
|
"Accept": "application/hal+json"
|
997
1093
|
},
|
998
1094
|
"body": {
|
1095
|
+
"description": "a webhook",
|
999
1096
|
"events": [
|
1000
1097
|
{
|
1001
1098
|
"name": "contract_content_changed"
|
@@ -1032,6 +1129,68 @@ Pact Broker will respond with:
|
|
1032
1129
|
}
|
1033
1130
|
}
|
1034
1131
|
```
|
1132
|
+
<a name="a_request_to_create_a_webhook_with_every_possible_event_type_given_the_'Pricing_Service'_and_'Condor'_already_exist_in_the_pact-broker"></a>
|
1133
|
+
Given **the 'Pricing Service' and 'Condor' already exist in the pact-broker**, upon receiving **a request to create a webhook with every possible event type** from Pact Broker Client, with
|
1134
|
+
```json
|
1135
|
+
{
|
1136
|
+
"method": "post",
|
1137
|
+
"path": "/webhooks/provider/Pricing%20Service/consumer/Condor",
|
1138
|
+
"headers": {
|
1139
|
+
"Content-Type": "application/json",
|
1140
|
+
"Accept": "application/hal+json"
|
1141
|
+
},
|
1142
|
+
"body": {
|
1143
|
+
"description": "a webhook",
|
1144
|
+
"events": [
|
1145
|
+
{
|
1146
|
+
"name": "contract_content_changed"
|
1147
|
+
},
|
1148
|
+
{
|
1149
|
+
"name": "contract_published"
|
1150
|
+
},
|
1151
|
+
{
|
1152
|
+
"name": "provider_verification_published"
|
1153
|
+
},
|
1154
|
+
{
|
1155
|
+
"name": "provider_verification_succeeded"
|
1156
|
+
},
|
1157
|
+
{
|
1158
|
+
"name": "provider_verification_failed"
|
1159
|
+
}
|
1160
|
+
],
|
1161
|
+
"request": {
|
1162
|
+
"url": "https://webhook",
|
1163
|
+
"method": "POST",
|
1164
|
+
"headers": {
|
1165
|
+
"Foo": "bar",
|
1166
|
+
"Bar": "foo"
|
1167
|
+
},
|
1168
|
+
"body": {
|
1169
|
+
"some": "body"
|
1170
|
+
},
|
1171
|
+
"username": "username",
|
1172
|
+
"password": "password"
|
1173
|
+
}
|
1174
|
+
}
|
1175
|
+
}
|
1176
|
+
```
|
1177
|
+
Pact Broker will respond with:
|
1178
|
+
```json
|
1179
|
+
{
|
1180
|
+
"status": 201,
|
1181
|
+
"headers": {
|
1182
|
+
"Content-Type": "application/hal+json;charset=utf-8"
|
1183
|
+
},
|
1184
|
+
"body": {
|
1185
|
+
"_links": {
|
1186
|
+
"self": {
|
1187
|
+
"href": "http://localhost:1234/some-url",
|
1188
|
+
"title": "A title"
|
1189
|
+
}
|
1190
|
+
}
|
1191
|
+
}
|
1192
|
+
}
|
1193
|
+
```
|
1035
1194
|
<a name="a_request_to_get_the_Pricing_Service_given_the_'Pricing_Service'_already_exists_in_the_pact-broker"></a>
|
1036
1195
|
Given **the 'Pricing Service' already exists in the pact-broker**, upon receiving **a request to get the Pricing Service** from Pact Broker Client, with
|
1037
1196
|
```json
|
@@ -1652,6 +1811,7 @@ Given **the 'Pricing Service' and 'Condor' already exist in the pact-broker**, u
|
|
1652
1811
|
"Accept": "application/hal+json"
|
1653
1812
|
},
|
1654
1813
|
"body": {
|
1814
|
+
"description": "a webhook",
|
1655
1815
|
"events": [
|
1656
1816
|
{
|
1657
1817
|
"name": "contract_content_changed"
|
@@ -109,67 +109,28 @@ module PactBroker
|
|
109
109
|
exit(1) unless result.success
|
110
110
|
end
|
111
111
|
|
112
|
-
|
113
|
-
method_option :header, aliases: "-H", type: :array, desc: "Header"
|
114
|
-
method_option :data, aliases: "-d", desc: "Data"
|
115
|
-
method_option :user, aliases: "-u", desc: "Basic auth username and password eg. username:password"
|
116
|
-
method_option :consumer, desc: "Consumer name"
|
117
|
-
method_option :provider, desc: "Provider name"
|
118
|
-
method_option :broker_base_url, required: true, aliases: "-b", desc: "The base URL of the Pact Broker"
|
119
|
-
method_option :broker_username, desc: "Pact Broker basic auth username"
|
120
|
-
method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
|
121
|
-
method_option :broker_token, aliases: "-k", desc: "Pact Broker bearer token"
|
122
|
-
method_option :contract_content_changed, type: :boolean, desc: "Trigger this webhook when the pact content changes"
|
123
|
-
method_option :provider_verification_published, type: :boolean, desc: "Trigger this webhook when a provider verification result is published"
|
124
|
-
method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
|
112
|
+
shared_options_for_webhook_commands
|
125
113
|
|
126
114
|
desc 'create-webhook URL', 'Creates a webhook using the same switches as a curl request.'
|
127
115
|
long_desc File.read(File.join(File.dirname(__FILE__), 'create_webhook_long_desc.txt'))
|
128
116
|
def create_webhook webhook_url
|
129
|
-
|
130
|
-
|
131
|
-
if !(options.contract_content_changed || options.provider_verification_published)
|
132
|
-
raise PactBroker::Client::Error.new("You must select at least one of --contract-content-changed or --provider-verification-published")
|
133
|
-
end
|
134
|
-
|
135
|
-
username = options.user ? options.user.split(":", 2).first : nil
|
136
|
-
password = options.user ? options.user.split(":", 2).last : nil
|
137
|
-
|
138
|
-
headers = (options.header || []).each_with_object({}) { | header, headers | headers[header.split(":", 2).first.strip] = header.split(":", 2).last.strip }
|
139
|
-
|
140
|
-
body = options.data
|
141
|
-
if body && body.start_with?("@")
|
142
|
-
filepath = body[1..-1]
|
143
|
-
begin
|
144
|
-
body = File.read(filepath)
|
145
|
-
rescue StandardError => e
|
146
|
-
raise PactBroker::Client::Error.new("Couldn't read data from file \"#{filepath}\" due to #{e.class} #{e.message}")
|
147
|
-
end
|
148
|
-
end
|
117
|
+
run_webhook_commands webhook_url
|
118
|
+
end
|
149
119
|
|
150
|
-
|
151
|
-
|
152
|
-
events << 'provider_verification_published' if options.provider_verification_published
|
120
|
+
shared_options_for_webhook_commands
|
121
|
+
method_option :uuid, type: :string, required: true, desc: "Specify the uuid for the webhook"
|
153
122
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
password: password,
|
160
|
-
body: body,
|
161
|
-
consumer: options.consumer,
|
162
|
-
provider: options.provider,
|
163
|
-
events: events
|
164
|
-
}
|
123
|
+
desc 'create-or-update-webhook URL', 'Creates or updates a webhook with a provided uuid and using the same switches as a curl request.'
|
124
|
+
long_desc File.read(File.join(File.dirname(__FILE__), 'create_or_update_webhook_long_desc.txt'))
|
125
|
+
def create_or_update_webhook webhook_url
|
126
|
+
run_webhook_commands webhook_url
|
127
|
+
end
|
165
128
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
raise WebhookCreationError, "#{e.class} - #{e.message}"
|
172
|
-
end
|
129
|
+
ignored_and_hidden_potential_options_from_environment_variables
|
130
|
+
desc 'generate-uuid', 'Generate a UUID for use when calling create-or-update-webhook'
|
131
|
+
def generate_uuid
|
132
|
+
require 'securerandom'
|
133
|
+
puts SecureRandom.uuid
|
173
134
|
end
|
174
135
|
|
175
136
|
desc 'version', "Show the pact_broker-client gem version"
|
@@ -232,6 +193,62 @@ module PactBroker
|
|
232
193
|
|
233
194
|
client_options
|
234
195
|
end
|
196
|
+
|
197
|
+
def parse_webhook_events
|
198
|
+
events = []
|
199
|
+
events << 'contract_content_changed' if options.contract_content_changed
|
200
|
+
events << 'contract_published' if options.contract_published
|
201
|
+
events << 'provider_verification_published' if options.provider_verification_published
|
202
|
+
events << 'provider_verification_succeeded' if options.provider_verification_succeeded
|
203
|
+
events << 'provider_verification_failed' if options.provider_verification_failed
|
204
|
+
events
|
205
|
+
end
|
206
|
+
|
207
|
+
def parse_webhook_options(webhook_url)
|
208
|
+
events = parse_webhook_events
|
209
|
+
|
210
|
+
if events.size == 0
|
211
|
+
raise WebhookCreationError.new("You must specify at least one of --contract-content-changed, --contract-published, --provider-verification-published, --provider-verification-succeeded or --provider-verification-failed")
|
212
|
+
end
|
213
|
+
|
214
|
+
username = options.user ? options.user.split(":", 2).first : nil
|
215
|
+
password = options.user ? options.user.split(":", 2).last : nil
|
216
|
+
|
217
|
+
headers = (options.header || []).each_with_object({}) { | header, headers | headers[header.split(":", 2).first.strip] = header.split(":", 2).last.strip }
|
218
|
+
|
219
|
+
body = options.data
|
220
|
+
if body && body.start_with?("@")
|
221
|
+
filepath = body[1..-1]
|
222
|
+
begin
|
223
|
+
body = File.read(filepath)
|
224
|
+
rescue StandardError => e
|
225
|
+
raise WebhookCreationError.new("Couldn't read data from file \"#{filepath}\" due to #{e.class} #{e.message}")
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
{
|
230
|
+
uuid: options.uuid,
|
231
|
+
http_method: options.request,
|
232
|
+
url: webhook_url,
|
233
|
+
headers: headers,
|
234
|
+
username: username,
|
235
|
+
password: password,
|
236
|
+
body: body,
|
237
|
+
consumer: options.consumer,
|
238
|
+
provider: options.provider,
|
239
|
+
events: events
|
240
|
+
}
|
241
|
+
|
242
|
+
end
|
243
|
+
|
244
|
+
def run_webhook_commands webhook_url
|
245
|
+
require 'pact_broker/client/webhooks/create'
|
246
|
+
result = PactBroker::Client::Webhooks::Create.call(parse_webhook_options(webhook_url), options.broker_base_url, pact_broker_client_options)
|
247
|
+
$stdout.puts result.message
|
248
|
+
exit(1) unless result.success
|
249
|
+
rescue PactBroker::Client::Error => e
|
250
|
+
raise WebhookCreationError, "#{e.class} - #{e.message}"
|
251
|
+
end
|
235
252
|
end
|
236
253
|
end
|
237
254
|
end
|