pact_broker-client 1.52.0 → 1.56.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c645adf22b85e738f227eec38baf09fe06241aeaeb4c75abc4c4558c66c2716f
4
- data.tar.gz: e32efad31615c7335df1c36dea365fcc5e001574143a3df3d98e23c1c5c84c71
3
+ metadata.gz: 449848d07d065628a69bd18154f106f438cadcb51cccd11a3e5214000a17dce2
4
+ data.tar.gz: 187e875cee98166e6fe85f2bd76314ac642a131a8a4cd48f861694eac5daf002
5
5
  SHA512:
6
- metadata.gz: 02c18bab0a1d08d568524ccd0a48d526e2aebf3d17db29dc83884f82db4c4ebf9864fd2e6d3de01ab6b11febc658d94efe28a817f351266059771fff8a95a446
7
- data.tar.gz: d647f077b021640b520babbc4e7ba5ed8bd4d460ebe826e98900f356bbd79dda96ee7c425d0ee6eeff7aa2648f996ded578f22a24708b8efdf5725cfd8fd97b9
6
+ metadata.gz: 354fb2790242a8b7c64f568306013055f07223fd5f016d441f0fb6addb479ac1ed59467733a5d44264d5800d13500b9b652964cc7fc34341778b5472c5c7e3c0
7
+ data.tar.gz: 0fc195c4957214522ecce949daaa9b08f84f5024c82ceea0bc16cf197493b6fd042fb1886c1da31dec25767a2ef3fd439eaf6894cb422282b8654901e796f4f1
@@ -37,7 +37,7 @@ jobs:
37
37
  - run: |
38
38
  rm -rf spec/pacts/*
39
39
  bundle exec rspec spec/service_providers/
40
- bundle exec rake pact:publish:pactflow
40
+ VERBOSE=true bundle exec rake pact:publish:pactflow
41
41
  env:
42
42
  PACT_BROKER_TOKEN: ${{ secrets.PACTFLOW_PACT_OSS_TOKEN }}
43
43
  PACT_BROKER_FEATURES: ${{ matrix.feature }}
data/CHANGELOG.md CHANGED
@@ -1,3 +1,32 @@
1
+ <a name="v1.56.0"></a>
2
+ ### v1.56.0 (2021-10-06)
3
+
4
+ #### Features
5
+
6
+ * add pacticipant label options to webhook create/update commands (#96) ([710293f](/../../commit/710293f))
7
+
8
+ <a name="v1.55.0"></a>
9
+ ### v1.55.0 (2021-10-03)
10
+
11
+ #### Features
12
+
13
+ * support Github Actions environment variables for --tag-with-git-branch ([2b8dac5](/../../commit/2b8dac5))
14
+
15
+ <a name="v1.54.0"></a>
16
+ ### v1.54.0 (2021-10-01)
17
+
18
+ #### Features
19
+
20
+ * disable SSL verification for HAL client and HTTParty client when environment variable PACT_DISABLE_SSL_VERIFICATION=true ([470aafa](/../../commit/470aafa))
21
+ * support setting the --main-branch for a pacticipant ([1f18e70](/../../commit/1f18e70))
22
+
23
+ <a name="v1.53.0"></a>
24
+ ### v1.53.0 (2021-09-29)
25
+
26
+ #### Features
27
+
28
+ * 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))
29
+
1
30
  <a name="v1.52.0"></a>
2
31
  ### v1.52.0 (2021-09-29)
3
32
 
data/README.md CHANGED
@@ -517,6 +517,8 @@ Options:
517
517
  # Pacticipant name
518
518
  [--display-name=DISPLAY_NAME]
519
519
  # Display name
520
+ [--main-branch=MAIN_BRANCH]
521
+ # The main development branch of the pacticipant repository
520
522
  [--repository-url=REPOSITORY_URL]
521
523
  # The repository URL of the pacticipant
522
524
  -o, [--output=OUTPUT]
@@ -605,8 +607,12 @@ Options:
605
607
  # Webhook basic auth username and password eg. username:password
606
608
  [--consumer=CONSUMER]
607
609
  # Consumer name
610
+ [--consumer-label=CONSUMER_LABEL]
611
+ # Consumer label
608
612
  [--provider=PROVIDER]
609
613
  # Provider name
614
+ [--provider-label=PROVIDER_LABEL]
615
+ # Provider label
610
616
  [--description=DESCRIPTION]
611
617
  # Webhook description
612
618
  [--contract-content-changed], [--no-contract-content-changed]
@@ -661,8 +667,12 @@ Options:
661
667
  # Webhook basic auth username and password eg. username:password
662
668
  [--consumer=CONSUMER]
663
669
  # Consumer name
670
+ [--consumer-label=CONSUMER_LABEL]
671
+ # Consumer label
664
672
  [--provider=PROVIDER]
665
673
  # Provider name
674
+ [--provider-label=PROVIDER_LABEL]
675
+ # Provider label
666
676
  [--description=DESCRIPTION]
667
677
  # Webhook description
668
678
  [--contract-content-changed], [--no-contract-content-changed]
@@ -64,10 +64,14 @@
64
64
 
65
65
  * [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_&#39;Pricing_Service&#39;_and_&#39;Condor&#39;_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker
66
66
 
67
+ * [A request to create a webhook with a JSON body for a consumer specified by a label](#a_request_to_create_a_webhook_with_a_JSON_body_for_a_consumer_specified_by_a_label)
68
+
67
69
  * [A request to create a webhook with a JSON body for a consumer that does not exist](#a_request_to_create_a_webhook_with_a_JSON_body_for_a_consumer_that_does_not_exist)
68
70
 
69
71
  * [A request to create a webhook with a JSON body for a provider](#a_request_to_create_a_webhook_with_a_JSON_body_for_a_provider_given_the_&#39;Pricing_Service&#39;_and_&#39;Condor&#39;_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker
70
72
 
73
+ * [A request to create a webhook with a JSON body for a provider specified by a label](#a_request_to_create_a_webhook_with_a_JSON_body_for_a_provider_specified_by_a_label)
74
+
71
75
  * [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_&#39;Pricing_Service&#39;_and_&#39;Condor&#39;_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker
72
76
 
73
77
  * [A request to create a webhook with every possible event type](#a_request_to_create_a_webhook_with_every_possible_event_type_given_the_&#39;Pricing_Service&#39;_and_&#39;Condor&#39;_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker
@@ -1089,6 +1093,16 @@ Pact Broker will respond with:
1089
1093
  },
1090
1094
  "body": {
1091
1095
  "description": "a webhook",
1096
+ "request": {
1097
+ "body": {
1098
+ "some": "body"
1099
+ }
1100
+ },
1101
+ "events": [
1102
+ {
1103
+ "name": "contract_content_changed"
1104
+ }
1105
+ ],
1092
1106
  "_links": {
1093
1107
  "self": {
1094
1108
  "href": "http://localhost:1234/some-url",
@@ -1222,6 +1236,16 @@ Pact Broker will respond with:
1222
1236
  },
1223
1237
  "body": {
1224
1238
  "description": "a webhook",
1239
+ "request": {
1240
+ "body": {
1241
+ "some": "body"
1242
+ }
1243
+ },
1244
+ "events": [
1245
+ {
1246
+ "name": "contract_content_changed"
1247
+ }
1248
+ ],
1225
1249
  "_links": {
1226
1250
  "self": {
1227
1251
  "href": "http://localhost:1234/some-url",
@@ -1276,6 +1300,16 @@ Pact Broker will respond with:
1276
1300
  },
1277
1301
  "body": {
1278
1302
  "description": "a webhook",
1303
+ "request": {
1304
+ "body": {
1305
+ "some": "body"
1306
+ }
1307
+ },
1308
+ "events": [
1309
+ {
1310
+ "name": "contract_content_changed"
1311
+ }
1312
+ ],
1279
1313
  "_links": {
1280
1314
  "self": {
1281
1315
  "href": "http://localhost:1234/some-url",
@@ -1327,6 +1361,80 @@ Pact Broker will respond with:
1327
1361
  },
1328
1362
  "body": {
1329
1363
  "description": "a webhook",
1364
+ "request": {
1365
+ "body": {
1366
+ "some": "body"
1367
+ }
1368
+ },
1369
+ "events": [
1370
+ {
1371
+ "name": "contract_content_changed"
1372
+ }
1373
+ ],
1374
+ "_links": {
1375
+ "self": {
1376
+ "href": "http://localhost:1234/some-url",
1377
+ "title": "A title"
1378
+ }
1379
+ }
1380
+ }
1381
+ }
1382
+ ```
1383
+ <a name="a_request_to_create_a_webhook_with_a_JSON_body_for_a_consumer_specified_by_a_label"></a>
1384
+ Upon receiving **a request to create a webhook with a JSON body for a consumer specified by a label** from Pact Broker Client, with
1385
+ ```json
1386
+ {
1387
+ "method": "post",
1388
+ "path": "/HAL-REL-PLACEHOLDER-PB-WEBHOOKS",
1389
+ "headers": {
1390
+ "Content-Type": "application/json",
1391
+ "Accept": "application/hal+json"
1392
+ },
1393
+ "body": {
1394
+ "description": "a webhook",
1395
+ "events": [
1396
+ {
1397
+ "name": "contract_content_changed"
1398
+ }
1399
+ ],
1400
+ "request": {
1401
+ "url": "https://webhook",
1402
+ "method": "POST",
1403
+ "headers": {
1404
+ "Foo": "bar",
1405
+ "Bar": "foo"
1406
+ },
1407
+ "body": {
1408
+ "some": "body"
1409
+ },
1410
+ "username": "username",
1411
+ "password": "password"
1412
+ },
1413
+ "consumer": {
1414
+ "label": "consumer_label"
1415
+ }
1416
+ }
1417
+ }
1418
+ ```
1419
+ Pact Broker will respond with:
1420
+ ```json
1421
+ {
1422
+ "status": 201,
1423
+ "headers": {
1424
+ "Content-Type": "application/hal+json;charset=utf-8"
1425
+ },
1426
+ "body": {
1427
+ "description": "a webhook",
1428
+ "request": {
1429
+ "body": {
1430
+ "some": "body"
1431
+ }
1432
+ },
1433
+ "events": [
1434
+ {
1435
+ "name": "contract_content_changed"
1436
+ }
1437
+ ],
1330
1438
  "_links": {
1331
1439
  "self": {
1332
1440
  "href": "http://localhost:1234/some-url",
@@ -1433,6 +1541,80 @@ Pact Broker will respond with:
1433
1541
  },
1434
1542
  "body": {
1435
1543
  "description": "a webhook",
1544
+ "request": {
1545
+ "body": {
1546
+ "some": "body"
1547
+ }
1548
+ },
1549
+ "events": [
1550
+ {
1551
+ "name": "contract_content_changed"
1552
+ }
1553
+ ],
1554
+ "_links": {
1555
+ "self": {
1556
+ "href": "http://localhost:1234/some-url",
1557
+ "title": "A title"
1558
+ }
1559
+ }
1560
+ }
1561
+ }
1562
+ ```
1563
+ <a name="a_request_to_create_a_webhook_with_a_JSON_body_for_a_provider_specified_by_a_label"></a>
1564
+ Upon receiving **a request to create a webhook with a JSON body for a provider specified by a label** from Pact Broker Client, with
1565
+ ```json
1566
+ {
1567
+ "method": "post",
1568
+ "path": "/HAL-REL-PLACEHOLDER-PB-WEBHOOKS",
1569
+ "headers": {
1570
+ "Content-Type": "application/json",
1571
+ "Accept": "application/hal+json"
1572
+ },
1573
+ "body": {
1574
+ "description": "a webhook",
1575
+ "events": [
1576
+ {
1577
+ "name": "contract_content_changed"
1578
+ }
1579
+ ],
1580
+ "request": {
1581
+ "url": "https://webhook",
1582
+ "method": "POST",
1583
+ "headers": {
1584
+ "Foo": "bar",
1585
+ "Bar": "foo"
1586
+ },
1587
+ "body": {
1588
+ "some": "body"
1589
+ },
1590
+ "username": "username",
1591
+ "password": "password"
1592
+ },
1593
+ "provider": {
1594
+ "label": "provider_label"
1595
+ }
1596
+ }
1597
+ }
1598
+ ```
1599
+ Pact Broker will respond with:
1600
+ ```json
1601
+ {
1602
+ "status": 201,
1603
+ "headers": {
1604
+ "Content-Type": "application/hal+json;charset=utf-8"
1605
+ },
1606
+ "body": {
1607
+ "description": "a webhook",
1608
+ "request": {
1609
+ "body": {
1610
+ "some": "body"
1611
+ }
1612
+ },
1613
+ "events": [
1614
+ {
1615
+ "name": "contract_content_changed"
1616
+ }
1617
+ ],
1436
1618
  "_links": {
1437
1619
  "self": {
1438
1620
  "href": "http://localhost:1234/some-url",
@@ -1482,6 +1664,14 @@ Pact Broker will respond with:
1482
1664
  },
1483
1665
  "body": {
1484
1666
  "description": "a webhook",
1667
+ "request": {
1668
+ "body": "<xml></xml>"
1669
+ },
1670
+ "events": [
1671
+ {
1672
+ "name": "contract_content_changed"
1673
+ }
1674
+ ],
1485
1675
  "_links": {
1486
1676
  "self": {
1487
1677
  "href": "http://localhost:1234/some-url",
@@ -1545,6 +1735,28 @@ Pact Broker will respond with:
1545
1735
  },
1546
1736
  "body": {
1547
1737
  "description": "a webhook",
1738
+ "request": {
1739
+ "body": {
1740
+ "some": "body"
1741
+ }
1742
+ },
1743
+ "events": [
1744
+ {
1745
+ "name": "contract_content_changed"
1746
+ },
1747
+ {
1748
+ "name": "contract_published"
1749
+ },
1750
+ {
1751
+ "name": "provider_verification_published"
1752
+ },
1753
+ {
1754
+ "name": "provider_verification_succeeded"
1755
+ },
1756
+ {
1757
+ "name": "provider_verification_failed"
1758
+ }
1759
+ ],
1548
1760
  "_links": {
1549
1761
  "self": {
1550
1762
  "href": "http://localhost:1234/some-url",
@@ -2550,6 +2762,16 @@ Pact Broker will respond with:
2550
2762
  },
2551
2763
  "body": {
2552
2764
  "description": "a webhook",
2765
+ "request": {
2766
+ "body": {
2767
+ "some": "body"
2768
+ }
2769
+ },
2770
+ "events": [
2771
+ {
2772
+ "name": "contract_content_changed"
2773
+ }
2774
+ ],
2553
2775
  "_links": {
2554
2776
  "self": {
2555
2777
  "href": "http://localhost:1234/some-url",
@@ -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, *args
109
- self.class.put(url, *args)
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, *args
113
- self.class.get(url, *args)
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
@@ -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
@@ -15,7 +15,9 @@ module PactBroker
15
15
  method_option :data, aliases: "-d", desc: "Webhook payload (file or string)"
16
16
  method_option :user, aliases: "-u", desc: "Webhook basic auth username and password eg. username:password"
17
17
  method_option :consumer, desc: "Consumer name"
18
+ method_option :consumer_label, desc: "Consumer label, mutually exclusive with consumer name"
18
19
  method_option :provider, desc: "Provider name"
20
+ method_option :provider_label, desc: "Provider label, mutually exclusive with provider name"
19
21
  method_option :description, desc: "Webhook description"
20
22
  method_option :contract_content_changed, type: :boolean, desc: "Trigger this webhook when the pact content changes"
21
23
  method_option :contract_published, type: :boolean, desc: "Trigger this webhook when a pact is published"
@@ -70,6 +72,7 @@ module PactBroker
70
72
  end
71
73
 
72
74
  def parse_webhook_options(webhook_url)
75
+ validate_mutual_exclusiveness_of_participant_name_and_label_options
73
76
  events = parse_webhook_events
74
77
 
75
78
  # TODO update for contract_requiring_verification_published when released
@@ -102,7 +105,9 @@ module PactBroker
102
105
  password: password,
103
106
  body: body,
104
107
  consumer: options.consumer,
108
+ consumer_label: options.consumer_label,
105
109
  provider: options.provider,
110
+ provider_label: options.provider_label,
106
111
  events: events,
107
112
  team_uuid: options.team_uuid
108
113
  }
@@ -118,10 +123,20 @@ module PactBroker
118
123
  rescue PactBroker::Client::Error => e
119
124
  raise WebhookCreationError, "#{e.class} - #{e.message}"
120
125
  end
126
+
127
+ def validate_mutual_exclusiveness_of_participant_name_and_label_options
128
+ if options.consumer && options.consumer_label
129
+ raise WebhookCreationError.new("Consumer name (--consumer) and label (--consumer_label) options are mutually exclusive")
130
+ end
131
+
132
+ if options.provider && options.provider_label
133
+ raise WebhookCreationError.new("Provider name (--provider) and label (--provider_label) options are mutually exclusive")
134
+ end
135
+ end
121
136
  end
122
137
  end
123
138
  end
124
139
  end
125
140
  end
126
141
  end
127
- end
142
+ end
@@ -39,7 +39,7 @@ module PactBroker
39
39
  @existing_environment_params ||= existing_environment_resource!
40
40
  .response
41
41
  .body
42
- .except("uuid", "_links", "createdAt", "updatedAt")
42
+ .except("uuid", "_links", "_embedded", "createdAt", "updatedAt")
43
43
  end
44
44
 
45
45
  def contacts
@@ -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
@@ -38,7 +38,8 @@ module PactBroker
38
38
  {
39
39
  name: params[:name],
40
40
  repositoryUrl: params[:repository_url],
41
- displayName: params[:display_name]
41
+ displayName: params[:display_name],
42
+ mainBranch: params[:main_branch]
42
43
  }.compact
43
44
  end
44
45
  end
@@ -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,
@@ -1,5 +1,5 @@
1
1
  module PactBroker
2
2
  module Client
3
- VERSION = '1.52.0'
3
+ VERSION = '1.56.0'
4
4
  end
5
5
  end
@@ -81,10 +81,14 @@ module PactBroker
81
81
 
82
82
  if params.consumer
83
83
  body[:consumer] = { name: params.consumer }
84
+ elsif params.consumer_label
85
+ body[:consumer] = { label: params.consumer_label }
84
86
  end
85
87
 
86
88
  if params.provider
87
89
  body[:provider] = { name: params.provider }
90
+ elsif params.provider_label
91
+ body[:provider] = { label: params.provider_label }
88
92
  end
89
93
 
90
94
  if params.team_uuid
@@ -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 \
@@ -16,7 +16,6 @@ bundle exec bin/pact-broker record-undeployment --pacticipant Foo --environment
16
16
  bundle exec bin/pact-broker record-release --pacticipant Foo --version 2 --environment test
17
17
  bundle exec bin/pact-broker record-support-ended --pacticipant Foo --version 2 --environment test
18
18
 
19
-
20
19
  bundle exec bin/pact-broker record-deployment --pacticipant Foo --version 2 --environment test
21
20
  bundle exec bin/pact-broker record-deployment --pacticipant Foo --version 2 --environment test --application-instance customer-1
22
21
  bundle exec bin/pact-broker record-deployment --pacticipant Foo --version 2 --environment test --application-instance customer-1
@@ -49,7 +49,9 @@ module PactBroker
49
49
  password: "password",
50
50
  body: "data",
51
51
  consumer: "consumer",
52
+ consumer_label: nil,
52
53
  provider: "provider",
54
+ provider_label: nil,
53
55
  events: ["contract_content_changed"],
54
56
  team_uuid: "1234"
55
57
  }.tap { |it| Pact::Fixture.add_fixture(:create_webhook_params, it) }
@@ -223,6 +225,59 @@ module PactBroker
223
225
  expect { subject }.to raise_error(WebhookCreationError, /foo/)
224
226
  end
225
227
  end
228
+
229
+ end
230
+
231
+ context "when both consumer name and label options are specified" do
232
+ before do
233
+ options_hash[:consumer_label] = "consumer_label"
234
+ broker.options = OpenStruct.new(options_hash)
235
+ end
236
+
237
+ it "raises a WebhookCreationError" do
238
+ expect { subject }.to raise_error(
239
+ WebhookCreationError,
240
+ "Consumer name (--consumer) and label (--consumer_label) options are mutually exclusive"
241
+ )
242
+ end
243
+ end
244
+
245
+ context "when both provider name and label options are specified" do
246
+ before do
247
+ options_hash[:provider_label] = "provider_label"
248
+ broker.options = OpenStruct.new(options_hash)
249
+ end
250
+
251
+ it "raises a WebhookCreationError" do
252
+ expect { subject }.to raise_error(
253
+ WebhookCreationError,
254
+ "Provider name (--provider) and label (--provider_label) options are mutually exclusive"
255
+ )
256
+ end
257
+ end
258
+
259
+ context "when participant labels are specified" do
260
+ before do
261
+ options_hash.delete(:consumer)
262
+ options_hash.delete(:provider)
263
+ options_hash.merge!(consumer_label: 'consumer_label', provider_label: 'provider_label')
264
+ expected_params.merge!(
265
+ consumer: nil,
266
+ consumer_label: 'consumer_label',
267
+ provider: nil,
268
+ provider_label: 'provider_label'
269
+ )
270
+
271
+ broker.options = OpenStruct.new(options_hash)
272
+ end
273
+
274
+ it "calls PactBroker::Client::Webhooks::Create with participant labels in params" do
275
+ expect(PactBroker::Client::Webhooks::Create).to receive(:call) do | params, _, _ |
276
+ expect(params).to eq expected_params
277
+ command_result
278
+ end
279
+ subject
280
+ end
226
281
  end
227
282
  end
228
283
  end
@@ -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
@@ -1995,6 +1995,16 @@
1995
1995
  },
1996
1996
  "body": {
1997
1997
  "description": "a webhook",
1998
+ "request": {
1999
+ "body": {
2000
+ "some": "body"
2001
+ }
2002
+ },
2003
+ "events": [
2004
+ {
2005
+ "name": "contract_content_changed"
2006
+ }
2007
+ ],
1998
2008
  "_links": {
1999
2009
  "self": {
2000
2010
  "href": "http://localhost:1234/some-url",
@@ -2067,6 +2077,28 @@
2067
2077
  },
2068
2078
  "body": {
2069
2079
  "description": "a webhook",
2080
+ "request": {
2081
+ "body": {
2082
+ "some": "body"
2083
+ }
2084
+ },
2085
+ "events": [
2086
+ {
2087
+ "name": "contract_content_changed"
2088
+ },
2089
+ {
2090
+ "name": "contract_published"
2091
+ },
2092
+ {
2093
+ "name": "provider_verification_published"
2094
+ },
2095
+ {
2096
+ "name": "provider_verification_succeeded"
2097
+ },
2098
+ {
2099
+ "name": "provider_verification_failed"
2100
+ }
2101
+ ],
2070
2102
  "_links": {
2071
2103
  "self": {
2072
2104
  "href": "http://localhost:1234/some-url",
@@ -2125,6 +2157,14 @@
2125
2157
  },
2126
2158
  "body": {
2127
2159
  "description": "a webhook",
2160
+ "request": {
2161
+ "body": "<xml></xml>"
2162
+ },
2163
+ "events": [
2164
+ {
2165
+ "name": "contract_content_changed"
2166
+ }
2167
+ ],
2128
2168
  "_links": {
2129
2169
  "self": {
2130
2170
  "href": "http://localhost:1234/some-url",
@@ -2323,6 +2363,88 @@
2323
2363
  },
2324
2364
  "body": {
2325
2365
  "description": "a webhook",
2366
+ "request": {
2367
+ "body": {
2368
+ "some": "body"
2369
+ }
2370
+ },
2371
+ "events": [
2372
+ {
2373
+ "name": "contract_content_changed"
2374
+ }
2375
+ ],
2376
+ "_links": {
2377
+ "self": {
2378
+ "href": "http://localhost:1234/some-url",
2379
+ "title": "A title"
2380
+ }
2381
+ }
2382
+ },
2383
+ "matchingRules": {
2384
+ "$.body.description": {
2385
+ "match": "type"
2386
+ },
2387
+ "$.body._links.self.href": {
2388
+ "match": "regex",
2389
+ "regex": "http:\\/\\/.*"
2390
+ },
2391
+ "$.body._links.self.title": {
2392
+ "match": "type"
2393
+ }
2394
+ }
2395
+ }
2396
+ },
2397
+ {
2398
+ "description": "a request to create a webhook with a JSON body for a consumer specified by a label",
2399
+ "request": {
2400
+ "method": "post",
2401
+ "path": "/HAL-REL-PLACEHOLDER-PB-WEBHOOKS",
2402
+ "headers": {
2403
+ "Content-Type": "application/json",
2404
+ "Accept": "application/hal+json"
2405
+ },
2406
+ "body": {
2407
+ "description": "a webhook",
2408
+ "events": [
2409
+ {
2410
+ "name": "contract_content_changed"
2411
+ }
2412
+ ],
2413
+ "request": {
2414
+ "url": "https://webhook",
2415
+ "method": "POST",
2416
+ "headers": {
2417
+ "Foo": "bar",
2418
+ "Bar": "foo"
2419
+ },
2420
+ "body": {
2421
+ "some": "body"
2422
+ },
2423
+ "username": "username",
2424
+ "password": "password"
2425
+ },
2426
+ "consumer": {
2427
+ "label": "consumer_label"
2428
+ }
2429
+ }
2430
+ },
2431
+ "response": {
2432
+ "status": 201,
2433
+ "headers": {
2434
+ "Content-Type": "application/hal+json;charset=utf-8"
2435
+ },
2436
+ "body": {
2437
+ "description": "a webhook",
2438
+ "request": {
2439
+ "body": {
2440
+ "some": "body"
2441
+ }
2442
+ },
2443
+ "events": [
2444
+ {
2445
+ "name": "contract_content_changed"
2446
+ }
2447
+ ],
2326
2448
  "_links": {
2327
2449
  "self": {
2328
2450
  "href": "http://localhost:1234/some-url",
@@ -2442,6 +2564,88 @@
2442
2564
  },
2443
2565
  "body": {
2444
2566
  "description": "a webhook",
2567
+ "request": {
2568
+ "body": {
2569
+ "some": "body"
2570
+ }
2571
+ },
2572
+ "events": [
2573
+ {
2574
+ "name": "contract_content_changed"
2575
+ }
2576
+ ],
2577
+ "_links": {
2578
+ "self": {
2579
+ "href": "http://localhost:1234/some-url",
2580
+ "title": "A title"
2581
+ }
2582
+ }
2583
+ },
2584
+ "matchingRules": {
2585
+ "$.body.description": {
2586
+ "match": "type"
2587
+ },
2588
+ "$.body._links.self.href": {
2589
+ "match": "regex",
2590
+ "regex": "http:\\/\\/.*"
2591
+ },
2592
+ "$.body._links.self.title": {
2593
+ "match": "type"
2594
+ }
2595
+ }
2596
+ }
2597
+ },
2598
+ {
2599
+ "description": "a request to create a webhook with a JSON body for a provider specified by a label",
2600
+ "request": {
2601
+ "method": "post",
2602
+ "path": "/HAL-REL-PLACEHOLDER-PB-WEBHOOKS",
2603
+ "headers": {
2604
+ "Content-Type": "application/json",
2605
+ "Accept": "application/hal+json"
2606
+ },
2607
+ "body": {
2608
+ "description": "a webhook",
2609
+ "events": [
2610
+ {
2611
+ "name": "contract_content_changed"
2612
+ }
2613
+ ],
2614
+ "request": {
2615
+ "url": "https://webhook",
2616
+ "method": "POST",
2617
+ "headers": {
2618
+ "Foo": "bar",
2619
+ "Bar": "foo"
2620
+ },
2621
+ "body": {
2622
+ "some": "body"
2623
+ },
2624
+ "username": "username",
2625
+ "password": "password"
2626
+ },
2627
+ "provider": {
2628
+ "label": "provider_label"
2629
+ }
2630
+ }
2631
+ },
2632
+ "response": {
2633
+ "status": 201,
2634
+ "headers": {
2635
+ "Content-Type": "application/hal+json;charset=utf-8"
2636
+ },
2637
+ "body": {
2638
+ "description": "a webhook",
2639
+ "request": {
2640
+ "body": {
2641
+ "some": "body"
2642
+ }
2643
+ },
2644
+ "events": [
2645
+ {
2646
+ "name": "contract_content_changed"
2647
+ }
2648
+ ],
2445
2649
  "_links": {
2446
2650
  "self": {
2447
2651
  "href": "http://localhost:1234/some-url",
@@ -2501,6 +2705,16 @@
2501
2705
  },
2502
2706
  "body": {
2503
2707
  "description": "a webhook",
2708
+ "request": {
2709
+ "body": {
2710
+ "some": "body"
2711
+ }
2712
+ },
2713
+ "events": [
2714
+ {
2715
+ "name": "contract_content_changed"
2716
+ }
2717
+ ],
2504
2718
  "_links": {
2505
2719
  "self": {
2506
2720
  "href": "http://localhost:1234/some-url",
@@ -2597,6 +2811,16 @@
2597
2811
  },
2598
2812
  "body": {
2599
2813
  "description": "a webhook",
2814
+ "request": {
2815
+ "body": {
2816
+ "some": "body"
2817
+ }
2818
+ },
2819
+ "events": [
2820
+ {
2821
+ "name": "contract_content_changed"
2822
+ }
2823
+ ],
2600
2824
  "_links": {
2601
2825
  "self": {
2602
2826
  "href": "http://localhost:1234/some-url",
@@ -2663,6 +2887,16 @@
2663
2887
  },
2664
2888
  "body": {
2665
2889
  "description": "a webhook",
2890
+ "request": {
2891
+ "body": {
2892
+ "some": "body"
2893
+ }
2894
+ },
2895
+ "events": [
2896
+ {
2897
+ "name": "contract_content_changed"
2898
+ }
2899
+ ],
2666
2900
  "_links": {
2667
2901
  "self": {
2668
2902
  "href": "http://localhost:1234/some-url",
@@ -54,6 +54,14 @@ RSpec.describe "creating a webhook", pact: true do
54
54
  headers: pact_broker_response_headers,
55
55
  body: {
56
56
  description: Pact.like("a webhook"),
57
+ request: {
58
+ body: {
59
+ some: "body"
60
+ }
61
+ },
62
+ events: [
63
+ name: "contract_content_changed"
64
+ ],
57
65
  _links: {
58
66
  self: {
59
67
  href: Pact.term('http://localhost:1234/some-url', %r{http://.*}),
@@ -92,6 +100,7 @@ RSpec.describe "creating a webhook", pact: true do
92
100
  before do
93
101
  params.merge!(events: event_names)
94
102
  request_body.merge!("events" => event_names.map{ |event_name| { "name" => event_name } })
103
+ success_response[:body].merge!(events: event_names.map{ |event_name| { "name" => event_name } })
95
104
 
96
105
  pact_broker
97
106
  .given("the 'Pricing Service' and 'Condor' already exist in the pact-broker")
@@ -112,6 +121,7 @@ RSpec.describe "creating a webhook", pact: true do
112
121
  context "when a valid webhook with an XML body is submitted" do
113
122
  before do
114
123
  request_body["request"]["body"] = body
124
+ success_response[:body][:request][:body] = body
115
125
 
116
126
  pact_broker
117
127
  .given("the 'Pricing Service' and 'Condor' already exist in the pact-broker")
@@ -207,6 +217,30 @@ RSpec.describe "creating a webhook", pact: true do
207
217
  end
208
218
  end
209
219
 
220
+ context "when consumer is specified using a label" do
221
+ before do
222
+ params.delete(:consumer)
223
+ params.delete(:provider)
224
+ params.merge!(consumer_label: "consumer_label")
225
+ request_body["consumer"] = { "label" => "consumer_label" }
226
+ mock_pact_broker_index(self)
227
+
228
+ pact_broker
229
+ .upon_receiving("a request to create a webhook with a JSON body for a consumer specified by a label")
230
+ .with(
231
+ method: :post,
232
+ path: placeholder_path('pb:webhooks'),
233
+ headers: post_request_headers,
234
+ body: request_body)
235
+ .will_respond_with(success_response)
236
+ end
237
+
238
+ it "returns a CommandResult with success = true" do
239
+ expect(subject.success).to be true
240
+ expect(subject.message).to eq "Webhook \"a webhook\" created"
241
+ end
242
+ end
243
+
210
244
  context "when only a consumer is specified and it does not exist" do
211
245
  before do
212
246
  params.delete(:provider)
@@ -257,6 +291,30 @@ RSpec.describe "creating a webhook", pact: true do
257
291
  end
258
292
  end
259
293
 
294
+ context "when provider is specified using a label" do
295
+ before do
296
+ params.delete(:consumer)
297
+ params.delete(:provider)
298
+ params.merge!(provider_label: "provider_label")
299
+ request_body["provider"] = { "label" => "provider_label" }
300
+ mock_pact_broker_index(self)
301
+
302
+ pact_broker
303
+ .upon_receiving("a request to create a webhook with a JSON body for a provider specified by a label")
304
+ .with(
305
+ method: :post,
306
+ path: placeholder_path('pb:webhooks'),
307
+ headers: post_request_headers,
308
+ body: request_body)
309
+ .will_respond_with(success_response)
310
+ end
311
+
312
+ it "returns a CommandResult with success = true" do
313
+ expect(subject.success).to be true
314
+ expect(subject.message).to eq "Webhook \"a webhook\" created"
315
+ end
316
+ end
317
+
260
318
  context "when neither consumer nor provider are specified" do
261
319
  before do
262
320
  params.delete(:consumer)
data/tasks/pact.rake CHANGED
@@ -1,4 +1,5 @@
1
- require 'pact_broker/client/tasks'
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.52.0
4
+ version: 1.56.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-09-29 00:00:00.000000000 Z
11
+ date: 2021-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty