pact_broker-client 1.41.0 → 1.46.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 +21 -0
- data/CHANGELOG.md +57 -0
- data/README.md +69 -48
- data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +79 -102
- data/doc/pacts/markdown/Pact Broker Client - Pactflow.md +94 -0
- data/doc/pacts/markdown/README.md +1 -0
- data/lib/pact_broker/client/backports.rb +9 -0
- data/lib/pact_broker/client/base_command.rb +98 -0
- data/lib/pact_broker/client/can_i_deploy.rb +40 -5
- data/lib/pact_broker/client/cli/broker.rb +18 -160
- data/lib/pact_broker/client/cli/custom_thor.rb +12 -16
- data/lib/pact_broker/client/cli/deployment_commands.rb +94 -0
- data/lib/pact_broker/client/cli/environment_commands.rb +70 -0
- data/lib/pact_broker/client/cli/pacticipant_commands.rb +53 -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 -0
- data/lib/pact_broker/client/environments/create_environment.rb +31 -0
- data/lib/pact_broker/client/environments/delete_environment.rb +27 -0
- data/lib/pact_broker/client/environments/describe_environment.rb +26 -0
- data/lib/pact_broker/client/environments/environment_command.rb +66 -0
- data/lib/pact_broker/client/environments/list_environments.rb +30 -0
- data/lib/pact_broker/client/environments/text_formatter.rb +30 -0
- data/lib/pact_broker/client/environments/update_environment.rb +31 -0
- data/lib/pact_broker/client/generate_display_name.rb +27 -0
- data/lib/pact_broker/client/hal/entity.rb +31 -6
- data/lib/pact_broker/client/hal/http_client.rb +8 -2
- data/lib/pact_broker/client/hal/link.rb +8 -0
- data/lib/pact_broker/client/hal_client_methods.rb +1 -3
- data/lib/pact_broker/client/matrix/text_formatter.rb +21 -13
- data/lib/pact_broker/client/pacticipants.rb +6 -0
- data/lib/pact_broker/client/pacticipants/create.rb +24 -34
- data/lib/pact_broker/client/pacticipants/describe.rb +33 -0
- data/lib/pact_broker/client/pacticipants/list.rb +34 -0
- data/lib/pact_broker/client/pacticipants/text_formatter.rb +41 -0
- data/lib/pact_broker/client/string_refinements.rb +56 -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/pact-broker-client.gemspec +1 -0
- data/script/record-deployments-and-releases.sh +18 -0
- 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_environment.approved.txt +7 -0
- data/spec/fixtures/approvals/describe_pacticipant.approved.txt +2 -0
- data/spec/fixtures/approvals/list_environments.approved.txt +3 -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 +17 -4
- data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +1 -1
- data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +7 -5
- 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/lib/pact_broker/client/environments/delete_environment_spec.rb +120 -0
- data/spec/lib/pact_broker/client/environments/describe_environment_spec.rb +89 -0
- data/spec/lib/pact_broker/client/environments/update_environment_spec.rb +167 -0
- data/spec/lib/pact_broker/client/generate_display_name_spec.rb +39 -0
- data/spec/lib/pact_broker/client/hal/entity_spec.rb +2 -2
- data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +2 -2
- data/spec/pacts/pact_broker_client-pact_broker.json +88 -108
- data/spec/pacts/pact_broker_client-pactflow.json +118 -0
- data/spec/service_providers/create_environment_spec.rb +78 -0
- data/spec/service_providers/list_environments_spec.rb +77 -0
- data/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb +1 -1
- 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/pacticipants_create_spec.rb +5 -4
- data/spec/service_providers/publish_pacts_spec.rb +3 -1
- data/spec/service_providers/record_deployment_spec.rb +14 -32
- data/spec/service_providers/record_release_spec.rb +132 -0
- data/spec/service_providers/record_undeployment_spec.rb +166 -0
- data/spec/service_providers/webhooks_create_spec.rb +1 -1
- data/spec/spec_helper.rb +15 -2
- data/spec/support/approvals.rb +1 -1
- data/spec/support/shared_context.rb +2 -1
- data/tasks/pact.rake +21 -1
- metadata +82 -7
- data/lib/pact_broker/client/versions/record_deployment.rb +0 -109
- data/lib/pact_broker/client/versions/record_undeployment.rb +0 -102
- data/spec/lib/pact_broker/client/versions/record_deployment_spec.rb +0 -82
@@ -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
|
+
```
|
@@ -10,4 +10,13 @@ class Hash
|
|
10
10
|
def compact!
|
11
11
|
reject! {|_key, value| value == nil}
|
12
12
|
end unless method_defined? :compact!
|
13
|
+
|
14
|
+
def except(*keys)
|
15
|
+
if keys.size > 4 && size > 4 # index if O(m*n) is big
|
16
|
+
h = {}
|
17
|
+
keys.each { |key| h[key] = true }
|
18
|
+
keys = h
|
19
|
+
end
|
20
|
+
reject { |key, _value| keys.include? key}
|
21
|
+
end unless method_defined? :except
|
13
22
|
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'pact_broker/client/hal_client_methods'
|
2
|
+
require 'pact_broker/client/error'
|
3
|
+
require 'pact_broker/client/command_result'
|
4
|
+
require 'term/ansicolor'
|
5
|
+
require 'pact_broker/client/backports'
|
6
|
+
|
7
|
+
module PactBroker
|
8
|
+
module Client
|
9
|
+
class BaseCommand
|
10
|
+
include PactBroker::Client::HalClientMethods
|
11
|
+
|
12
|
+
def self.call(params, options, pact_broker_client_options)
|
13
|
+
new(params, options, pact_broker_client_options).call
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(params, options, pact_broker_client_options)
|
17
|
+
@params = params
|
18
|
+
@options = options
|
19
|
+
@pact_broker_base_url = pact_broker_client_options.fetch(:pact_broker_base_url)
|
20
|
+
@pact_broker_client_options = pact_broker_client_options
|
21
|
+
end
|
22
|
+
|
23
|
+
def call
|
24
|
+
check_if_command_supported
|
25
|
+
do_call
|
26
|
+
rescue PactBroker::Client::Hal::ErrorResponseReturned => e
|
27
|
+
handle_http_error(e)
|
28
|
+
rescue PactBroker::Client::Error => e
|
29
|
+
handle_ruby_error(e)
|
30
|
+
rescue StandardError => e
|
31
|
+
handle_ruby_error(e, verbose?)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
attr_reader :params, :options
|
37
|
+
attr_reader :pact_broker_base_url, :pact_broker_client_options
|
38
|
+
|
39
|
+
def handle_http_error(e)
|
40
|
+
message = if json_output?
|
41
|
+
body = e.entity.response.raw_body
|
42
|
+
(body.nil? || body == "") ? "{}" : body
|
43
|
+
else
|
44
|
+
red(e.message)
|
45
|
+
end
|
46
|
+
PactBroker::Client::CommandResult.new(false, message)
|
47
|
+
end
|
48
|
+
|
49
|
+
def handle_ruby_error(e, include_backtrace = false)
|
50
|
+
PactBroker::Client::CommandResult.new(false, error_message(e, include_backtrace))
|
51
|
+
end
|
52
|
+
|
53
|
+
def error_message(e, include_backtrace)
|
54
|
+
if json_output?
|
55
|
+
json_error_message(e, include_backtrace)
|
56
|
+
else
|
57
|
+
text_error_message(e, include_backtrace)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def json_error_message(e, include_backtrace)
|
62
|
+
error_hash = { message: e.message }
|
63
|
+
error_hash[:class] = e.class.name unless e.is_a?(PactBroker::Client::Error)
|
64
|
+
error_hash[:backtrace] = e.backtrace if include_backtrace
|
65
|
+
{ error: error_hash }.to_json
|
66
|
+
end
|
67
|
+
|
68
|
+
def error_message_as_json(message)
|
69
|
+
{ error: { message: message } }.to_json
|
70
|
+
end
|
71
|
+
|
72
|
+
def text_error_message(e, include_backtrace)
|
73
|
+
maybe_backtrace = (include_backtrace ? "\n" + e.backtrace.join("\n") : "")
|
74
|
+
exception_message = e.is_a?(PactBroker::Client::Error) ? e.message : "#{e.class} - #{e.message}"
|
75
|
+
red(exception_message) + maybe_backtrace
|
76
|
+
end
|
77
|
+
|
78
|
+
def check_if_command_supported
|
79
|
+
end
|
80
|
+
|
81
|
+
def json_output?
|
82
|
+
options[:output] == "json"
|
83
|
+
end
|
84
|
+
|
85
|
+
def verbose?
|
86
|
+
options[:verbose]
|
87
|
+
end
|
88
|
+
|
89
|
+
def green(text)
|
90
|
+
::Term::ANSIColor.green(text)
|
91
|
+
end
|
92
|
+
|
93
|
+
def red(text)
|
94
|
+
::Term::ANSIColor.red(text)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -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? },
|
@@ -1,28 +1,35 @@
|
|
1
1
|
require 'pact_broker/client/cli/custom_thor'
|
2
2
|
require 'pact_broker/client/hash_refinements'
|
3
3
|
require 'thor/error'
|
4
|
+
require 'pact_broker/client/cli/environment_commands'
|
5
|
+
require 'pact_broker/client/cli/deployment_commands'
|
6
|
+
require 'pact_broker/client/cli/pacticipant_commands'
|
7
|
+
require 'pact_broker/client/cli/webhook_commands'
|
4
8
|
|
5
9
|
module PactBroker
|
6
10
|
module Client
|
7
11
|
module CLI
|
8
12
|
# Thor::Error will have its backtrace hidden
|
9
13
|
class PactPublicationError < ::Thor::Error; end
|
10
|
-
class WebhookCreationError < ::Thor::Error; end
|
11
14
|
class AuthError < ::Thor::Error; end
|
12
15
|
class VersionCreationError < ::Thor::Error; end
|
13
16
|
|
14
17
|
class Broker < CustomThor
|
15
18
|
using PactBroker::Client::HashRefinements
|
19
|
+
if ENV.fetch("PACT_BROKER_FEATURES", "").include?("deployments")
|
20
|
+
include PactBroker::Client::CLI::EnvironmentCommands
|
21
|
+
include PactBroker::Client::CLI::DeploymentCommands
|
22
|
+
end
|
23
|
+
include PactBroker::Client::CLI::PacticipantCommands
|
24
|
+
include PactBroker::Client::CLI::WebhookCommands
|
25
|
+
|
16
26
|
|
17
27
|
desc 'can-i-deploy', ''
|
18
28
|
long_desc File.read(File.join(__dir__, 'can_i_deploy_long_desc.txt'))
|
19
29
|
|
20
30
|
method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name. Use once for each pacticipant being checked."
|
21
31
|
method_option :version, required: false, aliases: "-e", desc: "The pacticipant version. Must be entered after the --pacticipant that it relates to."
|
22
|
-
|
23
|
-
if ENV.fetch("PACT_BROKER_FEATURES", "").include?("ignore")
|
24
|
-
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."
|
25
|
-
end
|
32
|
+
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."
|
26
33
|
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."
|
27
34
|
method_option :to, required: false, banner: 'TAG', desc: "This is too hard to explain in a short sentence. Look at the examples.", default: nil
|
28
35
|
method_option :to_environment, required: false, banner: 'ENVIRONMENT', desc: "The environment into which the pacticipant(s) are to be deployed", default: nil, hide: true
|
@@ -31,6 +38,7 @@ module PactBroker
|
|
31
38
|
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"
|
32
39
|
# Allow limit to be set manually until https://github.com/pact-foundation/pact_broker-client/issues/53 is fixed
|
33
40
|
method_option :limit, hide: true
|
41
|
+
method_option :dry_run, type: :boolean, default: false, desc: "When dry-run is enabled, always exit process with a success code. Can also be enabled by setting the environment variable PACT_BROKER_CAN_I_DEPLOY_DRY_RUN=true."
|
34
42
|
shared_authentication_options
|
35
43
|
|
36
44
|
def can_i_deploy(*ignored_but_necessary)
|
@@ -45,7 +53,8 @@ module PactBroker
|
|
45
53
|
[]
|
46
54
|
end
|
47
55
|
validate_can_i_deploy_selectors(selectors)
|
48
|
-
|
56
|
+
dry_run = options.dry_run || ENV["PACT_BROKER_CAN_I_DEPLOY_DRY_RUN"] == "true"
|
57
|
+
can_i_deploy_options = { output: options.output, retry_while_unknown: options.retry_while_unknown, retry_interval: options.retry_interval, dry_run: dry_run }
|
49
58
|
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)
|
50
59
|
$stdout.puts result.message
|
51
60
|
$stdout.flush
|
@@ -60,7 +69,7 @@ module PactBroker
|
|
60
69
|
method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag consumer version with the name of the current git branch. Default: false"
|
61
70
|
method_option :build_url, desc: "The build URL that created the pact"
|
62
71
|
method_option :merge, type: :boolean, default: false, require: false, desc: "If a pact already exists for this consumer version and provider, merge the contents. Useful when running Pact tests concurrently on different build nodes."
|
63
|
-
|
72
|
+
output_option_json_or_text
|
64
73
|
shared_authentication_options
|
65
74
|
|
66
75
|
def publish(*pact_files)
|
@@ -123,31 +132,7 @@ module PactBroker
|
|
123
132
|
exit(1) unless result.success
|
124
133
|
end
|
125
134
|
|
126
|
-
shared_options_for_webhook_commands
|
127
|
-
|
128
|
-
desc 'create-webhook URL', 'Creates a webhook using the same switches as a curl request.'
|
129
|
-
long_desc File.read(File.join(File.dirname(__FILE__), 'create_webhook_long_desc.txt'))
|
130
|
-
def create_webhook webhook_url
|
131
|
-
run_webhook_commands webhook_url
|
132
|
-
end
|
133
|
-
|
134
|
-
shared_options_for_webhook_commands
|
135
|
-
method_option :uuid, type: :string, required: true, desc: "Specify the uuid for the webhook"
|
136
135
|
|
137
|
-
desc 'create-or-update-webhook URL', 'Creates or updates a webhook with a provided uuid and using the same switches as a curl request.'
|
138
|
-
long_desc File.read(File.join(File.dirname(__FILE__), 'create_or_update_webhook_long_desc.txt'))
|
139
|
-
def create_or_update_webhook webhook_url
|
140
|
-
run_webhook_commands webhook_url
|
141
|
-
end
|
142
|
-
|
143
|
-
desc 'test-webhook', 'Test the execution of a webhook'
|
144
|
-
method_option :uuid, type: :string, required: true, desc: "Specify the uuid for the webhook"
|
145
|
-
shared_authentication_options
|
146
|
-
def test_webhook
|
147
|
-
require 'pact_broker/client/webhooks/test'
|
148
|
-
result = PactBroker::Client::Webhooks::Test.call(options, pact_broker_client_options)
|
149
|
-
$stdout.puts result.message
|
150
|
-
end
|
151
136
|
|
152
137
|
ignored_and_hidden_potential_options_from_environment_variables
|
153
138
|
desc 'generate-uuid', 'Generate a UUID for use when calling create-or-update-webhook'
|
@@ -157,22 +142,9 @@ module PactBroker
|
|
157
142
|
puts SecureRandom.uuid
|
158
143
|
end
|
159
144
|
|
160
|
-
desc 'create-or-update-pacticipant', 'Create or update pacticipant by name'
|
161
|
-
method_option :name, type: :string, required: true, desc: "Pacticipant name"
|
162
|
-
method_option :repository_url, type: :string, required: false, desc: "The repository URL of the pacticipant"
|
163
|
-
shared_authentication_options
|
164
|
-
verbose_option
|
165
|
-
def create_or_update_pacticipant(*required_but_ignored)
|
166
|
-
raise ::Thor::RequiredArgumentMissingError, "Pacticipant name cannot be blank" if options.name.strip.size == 0
|
167
|
-
require 'pact_broker/client/pacticipants/create'
|
168
|
-
result = PactBroker::Client::Pacticipants2::Create.call({ name: options.name, repository_url: options.repository_url }, options.broker_base_url, pact_broker_client_options)
|
169
|
-
$stdout.puts result.message
|
170
|
-
exit(1) unless result.success
|
171
|
-
end
|
172
|
-
|
173
145
|
desc 'list-latest-pact-versions', 'List the latest pact for each integration'
|
174
146
|
shared_authentication_options
|
175
|
-
|
147
|
+
output_option_json_or_table
|
176
148
|
def list_latest_pact_versions(*required_but_ignored)
|
177
149
|
require 'pact_broker/client/pacts/list_latest_versions'
|
178
150
|
result = PactBroker::Client::Pacts::ListLatestVersions.call(options.broker_base_url, options.output, pact_broker_client_options)
|
@@ -180,62 +152,6 @@ module PactBroker
|
|
180
152
|
exit(1) unless result.success
|
181
153
|
end
|
182
154
|
|
183
|
-
if ENV.fetch("PACT_BROKER_FEATURES", "").include?("deployments")
|
184
|
-
|
185
|
-
ignored_and_hidden_potential_options_from_environment_variables
|
186
|
-
desc "record-deployment", "Record deployment of a pacticipant version to an environment. See https://docs.pact.io/go/record_deployment for more information."
|
187
|
-
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was deployed."
|
188
|
-
method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number that was deployed."
|
189
|
-
method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was deployed to."
|
190
|
-
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."
|
191
|
-
method_option :output, aliases: "-o", desc: "json or text", default: 'text'
|
192
|
-
shared_authentication_options
|
193
|
-
|
194
|
-
def record_deployment
|
195
|
-
require 'pact_broker/client/versions/record_deployment'
|
196
|
-
params = {
|
197
|
-
pacticipant_name: options.pacticipant,
|
198
|
-
version_number: options.version,
|
199
|
-
environment_name: options.environment,
|
200
|
-
target: options.target,
|
201
|
-
output: options.output
|
202
|
-
}
|
203
|
-
result = PactBroker::Client::Versions::RecordDeployment.call(
|
204
|
-
params,
|
205
|
-
options.broker_base_url,
|
206
|
-
pact_broker_client_options
|
207
|
-
)
|
208
|
-
$stdout.puts result.message
|
209
|
-
exit(1) unless result.success
|
210
|
-
end
|
211
|
-
|
212
|
-
ignored_and_hidden_potential_options_from_environment_variables
|
213
|
-
desc "record-undeployment", "Record undeployment of (or the end of support for) a pacticipant version from an environment"
|
214
|
-
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was deployed."
|
215
|
-
method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number that was deployed."
|
216
|
-
method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was deployed to."
|
217
|
-
method_option :output, aliases: "-o", desc: "json or text", default: 'text'
|
218
|
-
shared_authentication_options
|
219
|
-
|
220
|
-
def record_undeployment
|
221
|
-
require 'pact_broker/client/versions/record_undeployment'
|
222
|
-
params = {
|
223
|
-
pacticipant_name: options.pacticipant,
|
224
|
-
version_number: options.version,
|
225
|
-
environment_name: options.environment,
|
226
|
-
output: options.output
|
227
|
-
}
|
228
|
-
result = PactBroker::Client::Versions::RecordUndeployment.call(
|
229
|
-
params,
|
230
|
-
options.broker_base_url,
|
231
|
-
pact_broker_client_options
|
232
|
-
)
|
233
|
-
$stdout.puts result.message
|
234
|
-
exit(1) unless result.success
|
235
|
-
end
|
236
|
-
|
237
|
-
end
|
238
|
-
|
239
155
|
ignored_and_hidden_potential_options_from_environment_variables
|
240
156
|
desc 'version', "Show the pact_broker-client gem version"
|
241
157
|
def version
|
@@ -347,7 +263,7 @@ module PactBroker
|
|
347
263
|
end
|
348
264
|
|
349
265
|
def pact_broker_client_options
|
350
|
-
client_options = { verbose: options.verbose }
|
266
|
+
client_options = { verbose: options.verbose, pact_broker_base_url: options.broker_base_url }
|
351
267
|
client_options[:token] = options.broker_token || ENV['PACT_BROKER_TOKEN']
|
352
268
|
if options.broker_username || ENV['PACT_BROKER_USERNAME']
|
353
269
|
client_options[:basic_auth] = {
|
@@ -358,64 +274,6 @@ module PactBroker
|
|
358
274
|
|
359
275
|
client_options.compact
|
360
276
|
end
|
361
|
-
|
362
|
-
def parse_webhook_events
|
363
|
-
events = []
|
364
|
-
events << 'contract_content_changed' if options.contract_content_changed
|
365
|
-
events << 'contract_published' if options.contract_published
|
366
|
-
events << 'provider_verification_published' if options.provider_verification_published
|
367
|
-
events << 'provider_verification_succeeded' if options.provider_verification_succeeded
|
368
|
-
events << 'provider_verification_failed' if options.provider_verification_failed
|
369
|
-
events
|
370
|
-
end
|
371
|
-
|
372
|
-
def parse_webhook_options(webhook_url)
|
373
|
-
events = parse_webhook_events
|
374
|
-
|
375
|
-
if events.size == 0
|
376
|
-
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")
|
377
|
-
end
|
378
|
-
|
379
|
-
username = options.user ? options.user.split(":", 2).first : nil
|
380
|
-
password = options.user ? options.user.split(":", 2).last : nil
|
381
|
-
|
382
|
-
headers = (options.header || []).each_with_object({}) { | header, headers | headers[header.split(":", 2).first.strip] = header.split(":", 2).last.strip }
|
383
|
-
|
384
|
-
body = options.data
|
385
|
-
if body && body.start_with?("@")
|
386
|
-
filepath = body[1..-1]
|
387
|
-
begin
|
388
|
-
body = File.read(filepath)
|
389
|
-
rescue StandardError => e
|
390
|
-
raise WebhookCreationError.new("Couldn't read data from file \"#{filepath}\" due to #{e.class} #{e.message}")
|
391
|
-
end
|
392
|
-
end
|
393
|
-
|
394
|
-
{
|
395
|
-
uuid: options.uuid,
|
396
|
-
description: options.description,
|
397
|
-
http_method: options.request,
|
398
|
-
url: webhook_url,
|
399
|
-
headers: headers,
|
400
|
-
username: username,
|
401
|
-
password: password,
|
402
|
-
body: body,
|
403
|
-
consumer: options.consumer,
|
404
|
-
provider: options.provider,
|
405
|
-
events: events
|
406
|
-
}
|
407
|
-
end
|
408
|
-
|
409
|
-
def run_webhook_commands webhook_url
|
410
|
-
require 'pact_broker/client/webhooks/create'
|
411
|
-
|
412
|
-
validate_credentials
|
413
|
-
result = PactBroker::Client::Webhooks::Create.call(parse_webhook_options(webhook_url), options.broker_base_url, pact_broker_client_options)
|
414
|
-
$stdout.puts result.message
|
415
|
-
exit(1) unless result.success
|
416
|
-
rescue PactBroker::Client::Error => e
|
417
|
-
raise WebhookCreationError, "#{e.class} - #{e.message}"
|
418
|
-
end
|
419
277
|
end
|
420
278
|
end
|
421
279
|
end
|