pact_broker-client 1.43.0 → 1.47.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 +35 -0
- data/CHANGELOG.md +41 -0
- data/README.md +54 -54
- data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +127 -94
- data/doc/pacts/markdown/Pact Broker Client - Pactflow.md +94 -0
- data/doc/pacts/markdown/README.md +1 -0
- data/lib/pact_broker/client/base_command.rb +3 -0
- data/lib/pact_broker/client/can_i_deploy.rb +40 -5
- data/lib/pact_broker/client/cli/broker.rb +8 -190
- data/lib/pact_broker/client/cli/custom_thor.rb +0 -16
- data/lib/pact_broker/client/cli/deployment_commands.rb +94 -0
- data/lib/pact_broker/client/cli/matrix_commands.rb +93 -0
- data/lib/pact_broker/client/cli/pacticipant_commands.rb +9 -0
- data/lib/pact_broker/client/cli/webhook_commands.rb +122 -0
- data/lib/pact_broker/client/deployments.rb +4 -0
- data/lib/pact_broker/client/deployments/record_deployment.rb +38 -0
- data/lib/pact_broker/client/deployments/record_release.rb +99 -0
- data/lib/pact_broker/client/deployments/record_support_ended.rb +103 -0
- data/lib/pact_broker/client/deployments/record_undeployment.rb +127 -0
- data/lib/pact_broker/client/describe_text_formatter.rb +23 -0
- data/lib/pact_broker/client/environments.rb +6 -3
- data/lib/pact_broker/client/environments/describe_environment.rb +3 -13
- data/lib/pact_broker/client/hal/entity.rb +22 -4
- data/lib/pact_broker/client/hal/http_client.rb +3 -2
- data/lib/pact_broker/client/pacticipants.rb +3 -3
- data/lib/pact_broker/client/pacticipants/create.rb +2 -2
- data/lib/pact_broker/client/pacticipants/describe.rb +33 -0
- data/lib/pact_broker/client/verification_required.rb +32 -0
- data/lib/pact_broker/client/version.rb +1 -1
- data/lib/pact_broker/client/versions.rb +4 -1
- data/lib/pact_broker/client/versions/describe.rb +3 -1
- data/lib/pact_broker/client/versions/formatter.rb +3 -1
- data/lib/pact_broker/client/versions/json_formatter.rb +5 -3
- data/lib/pact_broker/client/versions/text_formatter.rb +3 -1
- data/lib/pact_broker/client/webhooks/create.rb +14 -8
- data/script/record-deployment.sh +1 -1
- data/script/record-deployments-and-releases.sh +16 -0
- data/script/record-undeployment.sh +1 -1
- data/script/webhook-commands.sh +12 -0
- data/spec/fixtures/approvals/can_i_deploy_failure_dry_run.approved.txt +7 -0
- data/spec/fixtures/approvals/can_i_deploy_success_dry_run.approved.txt +7 -0
- data/spec/fixtures/approvals/describe_pacticipant.approved.txt +2 -0
- data/spec/integration/describe_environment_spec.rb +31 -0
- data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +62 -2
- data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +15 -2
- data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +4 -2
- data/spec/lib/pact_broker/client/deployments/record_deployment_spec.rb +204 -0
- data/spec/lib/pact_broker/client/deployments/record_support_ended_spec.rb +208 -0
- data/spec/lib/pact_broker/client/deployments/record_undeployment_spec.rb +219 -0
- data/spec/pacts/pact_broker_client-pact_broker.json +140 -112
- data/spec/pacts/pact_broker_client-pactflow.json +118 -0
- data/spec/service_providers/pact_broker_client_register_repository_spec.rb +2 -2
- data/spec/service_providers/pact_helper.rb +15 -10
- data/spec/service_providers/pactflow_webhooks_create_spec.rb +86 -0
- data/spec/service_providers/publish_pacts_spec.rb +3 -1
- data/spec/service_providers/record_deployment_spec.rb +4 -28
- data/spec/service_providers/record_release_spec.rb +130 -0
- data/spec/service_providers/record_undeployment_spec.rb +164 -0
- data/spec/service_providers/webhooks_create_spec.rb +1 -1
- data/spec/spec_helper.rb +14 -2
- data/spec/support/shared_context.rb +2 -1
- data/tasks/pact.rake +21 -1
- metadata +39 -7
- data/lib/pact_broker/client/versions/record_deployment.rb +0 -85
- data/lib/pact_broker/client/versions/record_undeployment.rb +0 -102
- data/spec/lib/pact_broker/client/versions/record_deployment_spec.rb +0 -75
@@ -0,0 +1,94 @@
|
|
1
|
+
### A pact between Pact Broker Client and Pactflow
|
2
|
+
|
3
|
+
#### Requests from Pact Broker Client to Pactflow
|
4
|
+
|
5
|
+
* [A request for the index resource](#a_request_for_the_index_resource)
|
6
|
+
|
7
|
+
* [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
|
8
|
+
|
9
|
+
#### Interactions
|
10
|
+
|
11
|
+
<a name="a_request_for_the_index_resource"></a>
|
12
|
+
Upon receiving **a request for the index resource** from Pact Broker Client, with
|
13
|
+
```json
|
14
|
+
{
|
15
|
+
"method": "get",
|
16
|
+
"path": "/",
|
17
|
+
"headers": {
|
18
|
+
"Accept": "application/hal+json"
|
19
|
+
}
|
20
|
+
}
|
21
|
+
```
|
22
|
+
Pactflow will respond with:
|
23
|
+
```json
|
24
|
+
{
|
25
|
+
"status": 200,
|
26
|
+
"headers": {
|
27
|
+
"Content-Type": "application/hal+json;charset=utf-8"
|
28
|
+
},
|
29
|
+
"body": {
|
30
|
+
"_links": {
|
31
|
+
"pb:webhooks": {
|
32
|
+
"href": "http://localhost:1235/HAL-REL-PLACEHOLDER-PB-WEBHOOKS"
|
33
|
+
},
|
34
|
+
"pb:pacticipants": {
|
35
|
+
"href": "http://localhost:1235/HAL-REL-PLACEHOLDER-PB-PACTICIPANTS"
|
36
|
+
},
|
37
|
+
"pb:pacticipant": {
|
38
|
+
"href": "http://localhost:1235/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-{pacticipant}"
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
```
|
44
|
+
<a name="a_request_to_create_a_webhook_for_a_team_given_a_team_with_UUID_2abbc12a-427d-432a-a521-c870af1739d9_exists"></a>
|
45
|
+
Given **a team with UUID 2abbc12a-427d-432a-a521-c870af1739d9 exists**, upon receiving **a request to create a webhook for a team** from Pact Broker Client, with
|
46
|
+
```json
|
47
|
+
{
|
48
|
+
"method": "post",
|
49
|
+
"path": "/HAL-REL-PLACEHOLDER-PB-WEBHOOKS",
|
50
|
+
"headers": {
|
51
|
+
"Content-Type": "application/json",
|
52
|
+
"Accept": "application/hal+json"
|
53
|
+
},
|
54
|
+
"body": {
|
55
|
+
"description": "a webhook",
|
56
|
+
"events": [
|
57
|
+
{
|
58
|
+
"name": "contract_content_changed"
|
59
|
+
}
|
60
|
+
],
|
61
|
+
"request": {
|
62
|
+
"url": "https://webhook",
|
63
|
+
"method": "POST",
|
64
|
+
"headers": {
|
65
|
+
"Foo": "bar",
|
66
|
+
"Bar": "foo"
|
67
|
+
},
|
68
|
+
"body": {
|
69
|
+
"some": "body"
|
70
|
+
}
|
71
|
+
},
|
72
|
+
"teamUuid": "2abbc12a-427d-432a-a521-c870af1739d9"
|
73
|
+
}
|
74
|
+
}
|
75
|
+
```
|
76
|
+
Pactflow will respond with:
|
77
|
+
```json
|
78
|
+
{
|
79
|
+
"status": 201,
|
80
|
+
"headers": {
|
81
|
+
"Content-Type": "application/hal+json;charset=utf-8"
|
82
|
+
},
|
83
|
+
"body": {
|
84
|
+
"description": "a webhook",
|
85
|
+
"teamUuid": "2abbc12a-427d-432a-a521-c870af1739d9",
|
86
|
+
"_links": {
|
87
|
+
"self": {
|
88
|
+
"href": "http://localhost:1234/some-url",
|
89
|
+
"title": "A title"
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
}
|
94
|
+
```
|
@@ -65,6 +65,9 @@ module PactBroker
|
|
65
65
|
{ error: error_hash }.to_json
|
66
66
|
end
|
67
67
|
|
68
|
+
def error_message_as_json(message)
|
69
|
+
{ error: { message: message } }.to_json
|
70
|
+
end
|
68
71
|
|
69
72
|
def text_error_message(e, include_backtrace)
|
70
73
|
maybe_backtrace = (include_backtrace ? "\n" + e.backtrace.join("\n") : "")
|
@@ -33,9 +33,9 @@ module PactBroker
|
|
33
33
|
def call
|
34
34
|
create_result(fetch_matrix_with_retries)
|
35
35
|
rescue PactBroker::Client::Error => e
|
36
|
-
Result.new(
|
36
|
+
Result.new(dry_run_or_false, for_dry_run(Term::ANSIColor.red(e.message)))
|
37
37
|
rescue StandardError => e
|
38
|
-
Result.new(
|
38
|
+
Result.new(dry_run_or_false, for_dry_run(Term::ANSIColor.red("Error retrieving matrix. #{e.class} - #{e.message}") + "\n#{e.backtrace.join("\n")}"))
|
39
39
|
end
|
40
40
|
|
41
41
|
private
|
@@ -46,14 +46,15 @@ module PactBroker
|
|
46
46
|
if matrix.deployable?
|
47
47
|
Result.new(true, success_message(matrix))
|
48
48
|
else
|
49
|
-
Result.new(
|
49
|
+
Result.new(dry_run_or_false, failure_message(matrix))
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
def success_message(matrix)
|
54
54
|
message = format_matrix(matrix)
|
55
55
|
if format != 'json'
|
56
|
-
message = warning(matrix) +
|
56
|
+
message = warning(matrix) + computer_says(true) + message + "\n\n" + notice_or_reason(matrix, :green)
|
57
|
+
message = for_dry_run(message)
|
57
58
|
end
|
58
59
|
message
|
59
60
|
end
|
@@ -61,11 +62,28 @@ module PactBroker
|
|
61
62
|
def failure_message(matrix)
|
62
63
|
message = format_matrix(matrix)
|
63
64
|
if format != 'json'
|
64
|
-
message = warning(matrix) +
|
65
|
+
message = warning(matrix) + computer_says(false) + message + "\n\n" + notice_or_reason(matrix, :red)
|
66
|
+
message = for_dry_run(message)
|
65
67
|
end
|
66
68
|
message
|
67
69
|
end
|
68
70
|
|
71
|
+
def computer_says(success)
|
72
|
+
if success
|
73
|
+
if dry_run?
|
74
|
+
"Computer says yes \\o/ (and maybe you don't need to enable dry run)"
|
75
|
+
else
|
76
|
+
Term::ANSIColor.green('Computer says yes \o/ ')
|
77
|
+
end
|
78
|
+
else
|
79
|
+
if dry_run?
|
80
|
+
"Computer says no ¯\\_(ツ)_/¯ (but you're ignoring this by enabling dry run)"
|
81
|
+
else
|
82
|
+
Term::ANSIColor.red("Computer says no ¯\_(ツ)_/¯")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
69
87
|
def notice_or_reason(matrix, reason_color)
|
70
88
|
if matrix.notices
|
71
89
|
PactBroker::Client::ColorizeNotices.call(matrix.notices).join("\n")
|
@@ -114,6 +132,23 @@ module PactBroker
|
|
114
132
|
options[:retry_while_unknown] > 0
|
115
133
|
end
|
116
134
|
|
135
|
+
def dry_run?
|
136
|
+
options[:dry_run]
|
137
|
+
end
|
138
|
+
|
139
|
+
def dry_run_or_false
|
140
|
+
dry_run? || false
|
141
|
+
end
|
142
|
+
|
143
|
+
def for_dry_run(lines)
|
144
|
+
if dry_run?
|
145
|
+
prefix = Term::ANSIColor.yellow("[dry-run] ")
|
146
|
+
lines.split("\n").collect { |line| prefix + Term::ANSIColor.uncolor(line) }.join("\n") + "\n" + prefix + "\n" + prefix + Term::ANSIColor.green("Dry run enabled - ignoring any failures")
|
147
|
+
else
|
148
|
+
lines
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
117
152
|
def retry_options
|
118
153
|
{
|
119
154
|
condition: lambda { |matrix| !matrix.any_unknown? },
|
@@ -2,58 +2,27 @@ require 'pact_broker/client/cli/custom_thor'
|
|
2
2
|
require 'pact_broker/client/hash_refinements'
|
3
3
|
require 'thor/error'
|
4
4
|
require 'pact_broker/client/cli/environment_commands'
|
5
|
+
require 'pact_broker/client/cli/deployment_commands'
|
5
6
|
require 'pact_broker/client/cli/pacticipant_commands'
|
7
|
+
require 'pact_broker/client/cli/webhook_commands'
|
8
|
+
require "pact_broker/client/cli/matrix_commands"
|
6
9
|
|
7
10
|
module PactBroker
|
8
11
|
module Client
|
9
12
|
module CLI
|
10
13
|
# Thor::Error will have its backtrace hidden
|
11
14
|
class PactPublicationError < ::Thor::Error; end
|
12
|
-
class WebhookCreationError < ::Thor::Error; end
|
13
15
|
class AuthError < ::Thor::Error; end
|
14
16
|
class VersionCreationError < ::Thor::Error; end
|
15
17
|
|
16
18
|
class Broker < CustomThor
|
17
19
|
using PactBroker::Client::HashRefinements
|
18
|
-
if ENV.fetch("PACT_BROKER_FEATURES", "").include?("deployments")
|
19
|
-
include PactBroker::Client::CLI::EnvironmentCommands
|
20
|
-
end
|
21
|
-
include PactBroker::Client::CLI::PacticipantCommands
|
22
|
-
|
23
|
-
desc 'can-i-deploy', ''
|
24
|
-
long_desc File.read(File.join(__dir__, 'can_i_deploy_long_desc.txt'))
|
25
|
-
|
26
|
-
method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name. Use once for each pacticipant being checked."
|
27
|
-
method_option :version, required: false, aliases: "-e", desc: "The pacticipant version. Must be entered after the --pacticipant that it relates to."
|
28
|
-
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."
|
29
|
-
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."
|
30
|
-
method_option :to, required: false, banner: 'TAG', desc: "This is too hard to explain in a short sentence. Look at the examples.", default: nil
|
31
|
-
method_option :to_environment, required: false, banner: 'ENVIRONMENT', desc: "The environment into which the pacticipant(s) are to be deployed", default: nil, hide: true
|
32
|
-
method_option :output, aliases: "-o", desc: "json or table", default: 'table'
|
33
|
-
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)"
|
34
|
-
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"
|
35
|
-
# Allow limit to be set manually until https://github.com/pact-foundation/pact_broker-client/issues/53 is fixed
|
36
|
-
method_option :limit, hide: true
|
37
|
-
shared_authentication_options
|
38
|
-
|
39
|
-
def can_i_deploy(*ignored_but_necessary)
|
40
|
-
require 'pact_broker/client/cli/version_selector_options_parser'
|
41
|
-
require 'pact_broker/client/can_i_deploy'
|
42
20
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
[]
|
49
|
-
end
|
50
|
-
validate_can_i_deploy_selectors(selectors)
|
51
|
-
can_i_deploy_options = { output: options.output, retry_while_unknown: options.retry_while_unknown, retry_interval: options.retry_interval }
|
52
|
-
result = CanIDeploy.call(options.broker_base_url, selectors, { to_tag: options.to, to_environment: options.to_environment, limit: options.limit, ignore_selectors: ignore_selectors }, can_i_deploy_options, pact_broker_client_options)
|
53
|
-
$stdout.puts result.message
|
54
|
-
$stdout.flush
|
55
|
-
exit(can_i_deploy_exit_status) unless result.success
|
56
|
-
end
|
21
|
+
include PactBroker::Client::CLI::EnvironmentCommands
|
22
|
+
include PactBroker::Client::CLI::DeploymentCommands
|
23
|
+
include PactBroker::Client::CLI::MatrixCommands
|
24
|
+
include PactBroker::Client::CLI::PacticipantCommands
|
25
|
+
include PactBroker::Client::CLI::WebhookCommands
|
57
26
|
|
58
27
|
desc 'publish PACT_DIRS_OR_FILES ...', "Publish pacts to a Pact Broker."
|
59
28
|
method_option :consumer_app_version, required: true, aliases: "-a", desc: "The consumer application version"
|
@@ -126,31 +95,7 @@ module PactBroker
|
|
126
95
|
exit(1) unless result.success
|
127
96
|
end
|
128
97
|
|
129
|
-
shared_options_for_webhook_commands
|
130
|
-
|
131
|
-
desc 'create-webhook URL', 'Creates a webhook using the same switches as a curl request.'
|
132
|
-
long_desc File.read(File.join(File.dirname(__FILE__), 'create_webhook_long_desc.txt'))
|
133
|
-
def create_webhook webhook_url
|
134
|
-
run_webhook_commands webhook_url
|
135
|
-
end
|
136
|
-
|
137
|
-
shared_options_for_webhook_commands
|
138
|
-
method_option :uuid, type: :string, required: true, desc: "Specify the uuid for the webhook"
|
139
|
-
|
140
|
-
desc 'create-or-update-webhook URL', 'Creates or updates a webhook with a provided uuid and using the same switches as a curl request.'
|
141
|
-
long_desc File.read(File.join(File.dirname(__FILE__), 'create_or_update_webhook_long_desc.txt'))
|
142
|
-
def create_or_update_webhook webhook_url
|
143
|
-
run_webhook_commands webhook_url
|
144
|
-
end
|
145
98
|
|
146
|
-
desc 'test-webhook', 'Test the execution of a webhook'
|
147
|
-
method_option :uuid, type: :string, required: true, desc: "Specify the uuid for the webhook"
|
148
|
-
shared_authentication_options
|
149
|
-
def test_webhook
|
150
|
-
require 'pact_broker/client/webhooks/test'
|
151
|
-
result = PactBroker::Client::Webhooks::Test.call(options, pact_broker_client_options)
|
152
|
-
$stdout.puts result.message
|
153
|
-
end
|
154
99
|
|
155
100
|
ignored_and_hidden_potential_options_from_environment_variables
|
156
101
|
desc 'generate-uuid', 'Generate a UUID for use when calling create-or-update-webhook'
|
@@ -170,61 +115,6 @@ module PactBroker
|
|
170
115
|
exit(1) unless result.success
|
171
116
|
end
|
172
117
|
|
173
|
-
if ENV.fetch("PACT_BROKER_FEATURES", "").include?("deployments")
|
174
|
-
ignored_and_hidden_potential_options_from_environment_variables
|
175
|
-
desc "record-deployment", "Record deployment of a pacticipant version to an environment. See https://docs.pact.io/go/record_deployment for more information."
|
176
|
-
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was deployed."
|
177
|
-
method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number that was deployed."
|
178
|
-
method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was deployed to."
|
179
|
-
method_option :target, default: nil, required: false, desc: "Optional. The target of the deployment - a logical identifer required to differentiate deployments when there are multiple instances of the same application in an environment."
|
180
|
-
output_option_json_or_text
|
181
|
-
shared_authentication_options
|
182
|
-
|
183
|
-
def record_deployment
|
184
|
-
require 'pact_broker/client/versions/record_deployment'
|
185
|
-
params = {
|
186
|
-
pacticipant_name: options.pacticipant,
|
187
|
-
version_number: options.version,
|
188
|
-
environment_name: options.environment,
|
189
|
-
target: options.target,
|
190
|
-
output: options.output
|
191
|
-
}
|
192
|
-
result = PactBroker::Client::Versions::RecordDeployment.call(
|
193
|
-
params,
|
194
|
-
options.broker_base_url,
|
195
|
-
pact_broker_client_options
|
196
|
-
)
|
197
|
-
$stdout.puts result.message
|
198
|
-
exit(1) unless result.success
|
199
|
-
end
|
200
|
-
|
201
|
-
ignored_and_hidden_potential_options_from_environment_variables
|
202
|
-
desc "record-undeployment", "Record undeployment of (or the end of support for) a pacticipant version from an environment"
|
203
|
-
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was deployed."
|
204
|
-
method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number that was deployed."
|
205
|
-
method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was deployed to."
|
206
|
-
output_option_json_or_text
|
207
|
-
shared_authentication_options
|
208
|
-
|
209
|
-
def record_undeployment
|
210
|
-
require 'pact_broker/client/versions/record_undeployment'
|
211
|
-
params = {
|
212
|
-
pacticipant_name: options.pacticipant,
|
213
|
-
version_number: options.version,
|
214
|
-
environment_name: options.environment,
|
215
|
-
output: options.output
|
216
|
-
}
|
217
|
-
result = PactBroker::Client::Versions::RecordUndeployment.call(
|
218
|
-
params,
|
219
|
-
options.broker_base_url,
|
220
|
-
pact_broker_client_options
|
221
|
-
)
|
222
|
-
$stdout.puts result.message
|
223
|
-
exit(1) unless result.success
|
224
|
-
end
|
225
|
-
|
226
|
-
end
|
227
|
-
|
228
118
|
ignored_and_hidden_potential_options_from_environment_variables
|
229
119
|
desc 'version', "Show the pact_broker-client gem version"
|
230
120
|
def version
|
@@ -239,16 +129,6 @@ module PactBroker
|
|
239
129
|
true
|
240
130
|
end
|
241
131
|
|
242
|
-
def can_i_deploy_exit_status
|
243
|
-
exit_code_string = ENV.fetch('PACT_BROKER_CAN_I_DEPLOY_EXIT_CODE_BETA', '')
|
244
|
-
if exit_code_string =~ /^\d+$/
|
245
|
-
$stderr.puts "Exiting can-i-deploy with configured exit code #{exit_code_string}"
|
246
|
-
exit_code_string.to_i
|
247
|
-
else
|
248
|
-
1
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
132
|
def validate_credentials
|
253
133
|
if options.broker_username && options.broker_token
|
254
134
|
raise AuthError, "You cannot provide both a username/password and a bearer token. If your Pact Broker uses a bearer token, please remove the username and password configuration."
|
@@ -261,10 +141,6 @@ module PactBroker
|
|
261
141
|
end
|
262
142
|
end
|
263
143
|
|
264
|
-
def validate_can_i_deploy_selectors selectors
|
265
|
-
pacticipants_without_versions = selectors.select{ |s| s[:version].nil? && s[:latest].nil? && s[:tag].nil? }.collect{ |s| s[:pacticipant] }
|
266
|
-
raise ::Thor::RequiredArgumentMissingError, "The version must be specified using `--version VERSION`, `--latest`, `--latest TAG`, or `--all TAG` for pacticipant #{pacticipants_without_versions.join(", ")}" if pacticipants_without_versions.any?
|
267
|
-
end
|
268
144
|
|
269
145
|
def publish_pacts pact_files
|
270
146
|
require 'pact_broker/client/publish_pacts'
|
@@ -347,64 +223,6 @@ module PactBroker
|
|
347
223
|
|
348
224
|
client_options.compact
|
349
225
|
end
|
350
|
-
|
351
|
-
def parse_webhook_events
|
352
|
-
events = []
|
353
|
-
events << 'contract_content_changed' if options.contract_content_changed
|
354
|
-
events << 'contract_published' if options.contract_published
|
355
|
-
events << 'provider_verification_published' if options.provider_verification_published
|
356
|
-
events << 'provider_verification_succeeded' if options.provider_verification_succeeded
|
357
|
-
events << 'provider_verification_failed' if options.provider_verification_failed
|
358
|
-
events
|
359
|
-
end
|
360
|
-
|
361
|
-
def parse_webhook_options(webhook_url)
|
362
|
-
events = parse_webhook_events
|
363
|
-
|
364
|
-
if events.size == 0
|
365
|
-
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")
|
366
|
-
end
|
367
|
-
|
368
|
-
username = options.user ? options.user.split(":", 2).first : nil
|
369
|
-
password = options.user ? options.user.split(":", 2).last : nil
|
370
|
-
|
371
|
-
headers = (options.header || []).each_with_object({}) { | header, headers | headers[header.split(":", 2).first.strip] = header.split(":", 2).last.strip }
|
372
|
-
|
373
|
-
body = options.data
|
374
|
-
if body && body.start_with?("@")
|
375
|
-
filepath = body[1..-1]
|
376
|
-
begin
|
377
|
-
body = File.read(filepath)
|
378
|
-
rescue StandardError => e
|
379
|
-
raise WebhookCreationError.new("Couldn't read data from file \"#{filepath}\" due to #{e.class} #{e.message}")
|
380
|
-
end
|
381
|
-
end
|
382
|
-
|
383
|
-
{
|
384
|
-
uuid: options.uuid,
|
385
|
-
description: options.description,
|
386
|
-
http_method: options.request,
|
387
|
-
url: webhook_url,
|
388
|
-
headers: headers,
|
389
|
-
username: username,
|
390
|
-
password: password,
|
391
|
-
body: body,
|
392
|
-
consumer: options.consumer,
|
393
|
-
provider: options.provider,
|
394
|
-
events: events
|
395
|
-
}
|
396
|
-
end
|
397
|
-
|
398
|
-
def run_webhook_commands webhook_url
|
399
|
-
require 'pact_broker/client/webhooks/create'
|
400
|
-
|
401
|
-
validate_credentials
|
402
|
-
result = PactBroker::Client::Webhooks::Create.call(parse_webhook_options(webhook_url), options.broker_base_url, pact_broker_client_options)
|
403
|
-
$stdout.puts result.message
|
404
|
-
exit(1) unless result.success
|
405
|
-
rescue PactBroker::Client::Error => e
|
406
|
-
raise WebhookCreationError, "#{e.class} - #{e.message}"
|
407
|
-
end
|
408
226
|
end
|
409
227
|
end
|
410
228
|
end
|
@@ -91,22 +91,6 @@ module PactBroker
|
|
91
91
|
method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
|
92
92
|
end
|
93
93
|
|
94
|
-
def self.shared_options_for_webhook_commands
|
95
|
-
method_option :request, banner: "METHOD", aliases: "-X", desc: "Webhook HTTP method", required: true
|
96
|
-
method_option :header, aliases: "-H", type: :array, desc: "Webhook Header"
|
97
|
-
method_option :data, aliases: "-d", desc: "Webhook payload (file or string)"
|
98
|
-
method_option :user, aliases: "-u", desc: "Webhook basic auth username and password eg. username:password"
|
99
|
-
method_option :consumer, desc: "Consumer name"
|
100
|
-
method_option :provider, desc: "Provider name"
|
101
|
-
method_option :description, desc: "Wwebhook description"
|
102
|
-
method_option :contract_content_changed, type: :boolean, desc: "Trigger this webhook when the pact content changes"
|
103
|
-
method_option :contract_published, type: :boolean, desc: "Trigger this webhook when a pact is published"
|
104
|
-
method_option :provider_verification_published, type: :boolean, desc: "Trigger this webhook when a provider verification result is published"
|
105
|
-
method_option :provider_verification_failed, type: :boolean, desc: "Trigger this webhook when a failed provider verification result is published"
|
106
|
-
method_option :provider_verification_succeeded, type: :boolean, desc: "Trigger this webhook when a successful provider verification result is published"
|
107
|
-
shared_authentication_options
|
108
|
-
end
|
109
|
-
|
110
94
|
def self.verbose_option
|
111
95
|
method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
|
112
96
|
end
|