pact_broker-client 1.39.0 → 1.44.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/.gitignore +1 -0
- data/CHANGELOG.md +52 -0
- data/Gemfile +4 -0
- data/README.md +39 -18
- data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +79 -280
- data/lib/pact_broker/client/backports.rb +9 -0
- data/lib/pact_broker/client/base_command.rb +95 -0
- data/lib/pact_broker/client/can_i_deploy.rb +20 -3
- data/lib/pact_broker/client/cli/broker.rb +20 -75
- data/lib/pact_broker/client/cli/custom_thor.rb +12 -0
- data/lib/pact_broker/client/cli/deployment_commands.rb +74 -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/record_deployment_long_desc.txt +0 -55
- data/lib/pact_broker/client/cli/version_selector_options_parser.rb +4 -0
- data/lib/pact_broker/client/colorize_notices.rb +31 -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_undeployment.rb +120 -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 +14 -4
- 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.rb +4 -0
- data/lib/pact_broker/client/matrix/abbreviate_version_number.rb +15 -0
- data/lib/pact_broker/client/matrix/resource.rb +26 -1
- data/lib/pact_broker/client/matrix/text_formatter.rb +28 -17
- 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/publish_pacts.rb +7 -3
- 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/pact-broker-client.gemspec +2 -0
- data/script/approve-all.sh +6 -0
- data/script/publish-pact.sh +24 -6
- data/script/record-deployments-and-releases.sh +10 -0
- data/spec/fixtures/approvals/can_i_deploy_ignore.approved.txt +13 -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 +47 -5
- data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +5 -5
- 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 +3 -3
- data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +21 -0
- data/spec/lib/pact_broker/client/deployments/record_deployment_spec.rb +204 -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 -287
- 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 +98 -0
- data/spec/service_providers/pacticipants_create_spec.rb +5 -4
- data/spec/service_providers/publish_pacts_spec.rb +5 -2
- data/spec/service_providers/record_deployment_spec.rb +17 -36
- data/spec/service_providers/record_release_spec.rb +135 -0
- data/spec/spec_helper.rb +15 -2
- data/spec/support/approvals.rb +26 -0
- data/spec/support/shared_context.rb +6 -2
- data/tasks/pact.rake +19 -1
- metadata +93 -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
@@ -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,95 @@
|
|
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
|
+
|
69
|
+
def text_error_message(e, include_backtrace)
|
70
|
+
maybe_backtrace = (include_backtrace ? "\n" + e.backtrace.join("\n") : "")
|
71
|
+
exception_message = e.is_a?(PactBroker::Client::Error) ? e.message : "#{e.class} - #{e.message}"
|
72
|
+
red(exception_message) + maybe_backtrace
|
73
|
+
end
|
74
|
+
|
75
|
+
def check_if_command_supported
|
76
|
+
end
|
77
|
+
|
78
|
+
def json_output?
|
79
|
+
options[:output] == "json"
|
80
|
+
end
|
81
|
+
|
82
|
+
def verbose?
|
83
|
+
options[:verbose]
|
84
|
+
end
|
85
|
+
|
86
|
+
def green(text)
|
87
|
+
::Term::ANSIColor.green(text)
|
88
|
+
end
|
89
|
+
|
90
|
+
def red(text)
|
91
|
+
::Term::ANSIColor.red(text)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -3,6 +3,7 @@ require 'pact_broker/client/pact_broker_client'
|
|
3
3
|
require 'pact_broker/client/retry'
|
4
4
|
require 'pact_broker/client/matrix/formatter'
|
5
5
|
require 'term/ansicolor'
|
6
|
+
require 'pact_broker/client/colorize_notices'
|
6
7
|
|
7
8
|
module PactBroker
|
8
9
|
module Client
|
@@ -32,7 +33,7 @@ module PactBroker
|
|
32
33
|
def call
|
33
34
|
create_result(fetch_matrix_with_retries)
|
34
35
|
rescue PactBroker::Client::Error => e
|
35
|
-
Result.new(false, e.message)
|
36
|
+
Result.new(false, Term::ANSIColor.red(e.message))
|
36
37
|
rescue StandardError => e
|
37
38
|
Result.new(false, "Error retrieving matrix. #{e.class} - #{e.message}\n#{e.backtrace.join("\n")}")
|
38
39
|
end
|
@@ -52,7 +53,7 @@ module PactBroker
|
|
52
53
|
def success_message(matrix)
|
53
54
|
message = format_matrix(matrix)
|
54
55
|
if format != 'json'
|
55
|
-
message = 'Computer says yes \o/ ' + message + "\n\n" +
|
56
|
+
message = warning(matrix) + Term::ANSIColor.green('Computer says yes \o/ ') + message + "\n\n" + notice_or_reason(matrix, :green)
|
56
57
|
end
|
57
58
|
message
|
58
59
|
end
|
@@ -60,11 +61,19 @@ module PactBroker
|
|
60
61
|
def failure_message(matrix)
|
61
62
|
message = format_matrix(matrix)
|
62
63
|
if format != 'json'
|
63
|
-
message = 'Computer says no ¯\_(ツ)_/¯ ' + message + "\n\n" +
|
64
|
+
message = warning(matrix) + Term::ANSIColor.red('Computer says no ¯\_(ツ)_/¯ ') + message + "\n\n" + notice_or_reason(matrix, :red)
|
64
65
|
end
|
65
66
|
message
|
66
67
|
end
|
67
68
|
|
69
|
+
def notice_or_reason(matrix, reason_color)
|
70
|
+
if matrix.notices
|
71
|
+
PactBroker::Client::ColorizeNotices.call(matrix.notices).join("\n")
|
72
|
+
else
|
73
|
+
Term::ANSIColor.send(reason_color, matrix.reason)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
68
77
|
def format_matrix(matrix)
|
69
78
|
formatted_matrix = Matrix::Formatter.call(matrix, format)
|
70
79
|
if format != 'json' && formatted_matrix.size > 0
|
@@ -131,6 +140,14 @@ module PactBroker
|
|
131
140
|
raise PactBroker::Client::Error.new("This version of the Pact Broker does not provide a count of the unknown verification results. Please upgrade your Broker to >= v2.23.4")
|
132
141
|
end
|
133
142
|
end
|
143
|
+
|
144
|
+
def warning(matrix)
|
145
|
+
if matrix_options[:ignore_selectors] && matrix_options[:ignore_selectors].any? && !matrix.supports_ignore?
|
146
|
+
Term::ANSIColor.yellow("WARN: This version of the Pact Broker does not support ignoring pacticipants. Please upgrade your Broker to >= 2.80.0") + "\n\n"
|
147
|
+
else
|
148
|
+
""
|
149
|
+
end
|
150
|
+
end
|
134
151
|
end
|
135
152
|
end
|
136
153
|
end
|
@@ -1,6 +1,9 @@
|
|
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'
|
4
7
|
|
5
8
|
module PactBroker
|
6
9
|
module Client
|
@@ -13,12 +16,19 @@ module PactBroker
|
|
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
|
+
|
16
25
|
|
17
26
|
desc 'can-i-deploy', ''
|
18
27
|
long_desc File.read(File.join(__dir__, 'can_i_deploy_long_desc.txt'))
|
19
28
|
|
20
29
|
method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name. Use once for each pacticipant being checked."
|
21
30
|
method_option :version, required: false, aliases: "-e", desc: "The pacticipant version. Must be entered after the --pacticipant that it relates to."
|
31
|
+
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."
|
22
32
|
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."
|
23
33
|
method_option :to, required: false, banner: 'TAG', desc: "This is too hard to explain in a short sentence. Look at the examples.", default: nil
|
24
34
|
method_option :to_environment, required: false, banner: 'ENVIRONMENT', desc: "The environment into which the pacticipant(s) are to be deployed", default: nil, hide: true
|
@@ -34,10 +44,15 @@ module PactBroker
|
|
34
44
|
require 'pact_broker/client/can_i_deploy'
|
35
45
|
|
36
46
|
validate_credentials
|
37
|
-
selectors = VersionSelectorOptionsParser.call(ARGV)
|
47
|
+
selectors = VersionSelectorOptionsParser.call(ARGV).select { |s| !s[:ignore] }
|
48
|
+
ignore_selectors = if ENV.fetch("PACT_BROKER_FEATURES", "").include?("ignore")
|
49
|
+
VersionSelectorOptionsParser.call(ARGV).select { |s| s[:ignore] }
|
50
|
+
else
|
51
|
+
[]
|
52
|
+
end
|
38
53
|
validate_can_i_deploy_selectors(selectors)
|
39
54
|
can_i_deploy_options = { output: options.output, retry_while_unknown: options.retry_while_unknown, retry_interval: options.retry_interval }
|
40
|
-
result = CanIDeploy.call(options.broker_base_url, selectors, { to_tag: options.to, to_environment: options.to_environment, limit: options.limit }, can_i_deploy_options, pact_broker_client_options)
|
55
|
+
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)
|
41
56
|
$stdout.puts result.message
|
42
57
|
$stdout.flush
|
43
58
|
exit(can_i_deploy_exit_status) unless result.success
|
@@ -51,7 +66,7 @@ module PactBroker
|
|
51
66
|
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"
|
52
67
|
method_option :build_url, desc: "The build URL that created the pact"
|
53
68
|
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."
|
54
|
-
|
69
|
+
output_option_json_or_text
|
55
70
|
shared_authentication_options
|
56
71
|
|
57
72
|
def publish(*pact_files)
|
@@ -148,22 +163,9 @@ module PactBroker
|
|
148
163
|
puts SecureRandom.uuid
|
149
164
|
end
|
150
165
|
|
151
|
-
desc 'create-or-update-pacticipant', 'Create or update pacticipant by name'
|
152
|
-
method_option :name, type: :string, required: true, desc: "Pacticipant name"
|
153
|
-
method_option :repository_url, type: :string, required: false, desc: "The repository URL of the pacticipant"
|
154
|
-
shared_authentication_options
|
155
|
-
verbose_option
|
156
|
-
def create_or_update_pacticipant(*required_but_ignored)
|
157
|
-
raise ::Thor::RequiredArgumentMissingError, "Pacticipant name cannot be blank" if options.name.strip.size == 0
|
158
|
-
require 'pact_broker/client/pacticipants/create'
|
159
|
-
result = PactBroker::Client::Pacticipants2::Create.call({ name: options.name, repository_url: options.repository_url }, options.broker_base_url, pact_broker_client_options)
|
160
|
-
$stdout.puts result.message
|
161
|
-
exit(1) unless result.success
|
162
|
-
end
|
163
|
-
|
164
166
|
desc 'list-latest-pact-versions', 'List the latest pact for each integration'
|
165
167
|
shared_authentication_options
|
166
|
-
|
168
|
+
output_option_json_or_table
|
167
169
|
def list_latest_pact_versions(*required_but_ignored)
|
168
170
|
require 'pact_broker/client/pacts/list_latest_versions'
|
169
171
|
result = PactBroker::Client::Pacts::ListLatestVersions.call(options.broker_base_url, options.output, pact_broker_client_options)
|
@@ -171,63 +173,6 @@ module PactBroker
|
|
171
173
|
exit(1) unless result.success
|
172
174
|
end
|
173
175
|
|
174
|
-
if ENV.fetch("PACT_BROKER_FEATURES", "").include?("deployments")
|
175
|
-
|
176
|
-
ignored_and_hidden_potential_options_from_environment_variables
|
177
|
-
desc "record-deployment", "Record deployment of a pacticipant version to an environment"
|
178
|
-
long_desc File.read(File.join(__dir__, 'record_deployment_long_desc.txt'))
|
179
|
-
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was deployed."
|
180
|
-
method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number that was deployed."
|
181
|
-
method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was deployed to."
|
182
|
-
method_option :target, default: nil, required: false, desc: "The target of the deployment - a logical identifer that represents where the application version was deployed to. See the usage docs for information on when to use this."
|
183
|
-
method_option :output, aliases: "-o", desc: "json or text", default: 'text'
|
184
|
-
shared_authentication_options
|
185
|
-
|
186
|
-
def record_deployment
|
187
|
-
require 'pact_broker/client/versions/record_deployment'
|
188
|
-
params = {
|
189
|
-
pacticipant_name: options.pacticipant,
|
190
|
-
version_number: options.version,
|
191
|
-
environment_name: options.environment,
|
192
|
-
target: options.target,
|
193
|
-
output: options.output
|
194
|
-
}
|
195
|
-
result = PactBroker::Client::Versions::RecordDeployment.call(
|
196
|
-
params,
|
197
|
-
options.broker_base_url,
|
198
|
-
pact_broker_client_options
|
199
|
-
)
|
200
|
-
$stdout.puts result.message
|
201
|
-
exit(1) unless result.success
|
202
|
-
end
|
203
|
-
|
204
|
-
ignored_and_hidden_potential_options_from_environment_variables
|
205
|
-
desc "record-undeployment", "Record undeployment of (or the end of support for) a pacticipant version from an environment"
|
206
|
-
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was deployed."
|
207
|
-
method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number that was deployed."
|
208
|
-
method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was deployed to."
|
209
|
-
method_option :output, aliases: "-o", desc: "json or text", default: 'text'
|
210
|
-
shared_authentication_options
|
211
|
-
|
212
|
-
def record_undeployment
|
213
|
-
require 'pact_broker/client/versions/record_undeployment'
|
214
|
-
params = {
|
215
|
-
pacticipant_name: options.pacticipant,
|
216
|
-
version_number: options.version,
|
217
|
-
environment_name: options.environment,
|
218
|
-
output: options.output
|
219
|
-
}
|
220
|
-
result = PactBroker::Client::Versions::RecordUndeployment.call(
|
221
|
-
params,
|
222
|
-
options.broker_base_url,
|
223
|
-
pact_broker_client_options
|
224
|
-
)
|
225
|
-
$stdout.puts result.message
|
226
|
-
exit(1) unless result.success
|
227
|
-
end
|
228
|
-
|
229
|
-
end
|
230
|
-
|
231
176
|
ignored_and_hidden_potential_options_from_environment_variables
|
232
177
|
desc 'version', "Show the pact_broker-client gem version"
|
233
178
|
def version
|
@@ -339,7 +284,7 @@ module PactBroker
|
|
339
284
|
end
|
340
285
|
|
341
286
|
def pact_broker_client_options
|
342
|
-
client_options = { verbose: options.verbose }
|
287
|
+
client_options = { verbose: options.verbose, pact_broker_base_url: options.broker_base_url }
|
343
288
|
client_options[:token] = options.broker_token || ENV['PACT_BROKER_TOKEN']
|
344
289
|
if options.broker_username || ENV['PACT_BROKER_USERNAME']
|
345
290
|
client_options[:basic_auth] = {
|
@@ -110,6 +110,18 @@ module PactBroker
|
|
110
110
|
def self.verbose_option
|
111
111
|
method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
|
112
112
|
end
|
113
|
+
|
114
|
+
def self.output_option_json_or_text
|
115
|
+
method_option :output, aliases: "-o", desc: "json or text", default: 'text'
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.output_option_json_or_table
|
119
|
+
method_option :output, aliases: "-o", desc: "json or table", default: 'table'
|
120
|
+
end
|
121
|
+
|
122
|
+
def params_from_options(keys)
|
123
|
+
keys.each_with_object({}) { | key, p | p[key] = options[key] }
|
124
|
+
end
|
113
125
|
end
|
114
126
|
end
|
115
127
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module PactBroker
|
2
|
+
module Client
|
3
|
+
module CLI
|
4
|
+
module DeploymentCommands
|
5
|
+
HELP_URL = "https://docs.pact.io/pact_broker/recording_deployments_and_releases/"
|
6
|
+
|
7
|
+
def self.included(thor)
|
8
|
+
thor.class_eval do
|
9
|
+
desc "record-deployment", "Record deployment of a pacticipant version to an environment. See #{HELP_URL} for more information."
|
10
|
+
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was deployed."
|
11
|
+
method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number that was deployed."
|
12
|
+
method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was deployed to."
|
13
|
+
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."
|
14
|
+
output_option_json_or_text
|
15
|
+
shared_authentication_options
|
16
|
+
|
17
|
+
def record_deployment
|
18
|
+
params = {
|
19
|
+
pacticipant_name: options.pacticipant,
|
20
|
+
version_number: options.version,
|
21
|
+
environment_name: options.environment,
|
22
|
+
target: options.target
|
23
|
+
}
|
24
|
+
execute_deployment_command(params, "RecordDeployment")
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "record-undeployment", "Record undeployment of a pacticipant version from an environment."
|
28
|
+
long_desc "Note that use of this command is not required if you are deploying over a previous version, as record-deployment will handle that scenario for you. This command is only required if you are permanently removing an application instance from an environment."
|
29
|
+
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was undeployed."
|
30
|
+
method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was undeployed from."
|
31
|
+
method_option :target, default: nil, required: false, desc: "Optional. The target that the application is being undeployed from - a logical identifer required to differentiate deployments when there are multiple instances of the same application in an environment."
|
32
|
+
output_option_json_or_text
|
33
|
+
shared_authentication_options
|
34
|
+
|
35
|
+
def record_undeployment
|
36
|
+
params = {
|
37
|
+
pacticipant_name: options.pacticipant,
|
38
|
+
environment_name: options.environment,
|
39
|
+
target: options.target
|
40
|
+
}
|
41
|
+
execute_deployment_command(params, "RecordUndeployment")
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "record-release", "Record release of a pacticipant version to an environment. See See #{HELP_URL} for more information."
|
45
|
+
method_option :pacticipant, required: true, aliases: "-a", desc: "The name of the pacticipant that was released."
|
46
|
+
method_option :version, required: true, aliases: "-e", desc: "The pacticipant version number that was released."
|
47
|
+
method_option :environment, required: true, desc: "The name of the environment that the pacticipant version was released to."
|
48
|
+
output_option_json_or_text
|
49
|
+
shared_authentication_options
|
50
|
+
|
51
|
+
def record_release
|
52
|
+
params = {
|
53
|
+
pacticipant_name: options.pacticipant,
|
54
|
+
version_number: options.version,
|
55
|
+
environment_name: options.environment
|
56
|
+
}
|
57
|
+
execute_deployment_command(params, "RecordRelease")
|
58
|
+
end
|
59
|
+
|
60
|
+
no_commands do
|
61
|
+
def execute_deployment_command(params, command_class_name)
|
62
|
+
require 'pact_broker/client/deployments'
|
63
|
+
command_options = { verbose: options.verbose, output: options.output }
|
64
|
+
result = PactBroker::Client::Deployments.const_get(command_class_name).call(params, command_options, pact_broker_client_options)
|
65
|
+
$stdout.puts result.message
|
66
|
+
exit(1) unless result.success
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module PactBroker
|
2
|
+
module Client
|
3
|
+
module CLI
|
4
|
+
module EnvironmentCommands
|
5
|
+
ENVIRONMENT_PARAM_NAMES = [:name, :display_name, :production, :contact_name, :contact_email_address]
|
6
|
+
|
7
|
+
def self.included(thor)
|
8
|
+
thor.class_eval do
|
9
|
+
def self.shared_environment_options(name_required: false)
|
10
|
+
method_option :name, required: name_required, desc: "The uniquely identifying name of the environment as used in deployment code"
|
11
|
+
method_option :display_name, desc: "The display name of the environment"
|
12
|
+
method_option :production, type: :boolean, default: false, desc: "Whether or not this environment is a production environment. Default: false"
|
13
|
+
method_option :contact_name, required: false, desc: "The name of the team/person responsible for this environment"
|
14
|
+
method_option :contact_email_address, required: false, desc: "The email address of the team/person responsible for this environment"
|
15
|
+
output_option_json_or_text
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "create-environment", "Create an environment resource in the Pact Broker to represent a real world deployment or release environment."
|
19
|
+
shared_environment_options(name_required: true)
|
20
|
+
shared_authentication_options
|
21
|
+
def create_environment
|
22
|
+
execute_environment_command(params_from_options(ENVIRONMENT_PARAM_NAMES), "CreateEnvironment")
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "update-environment", "Update an environment resource in the Pact Broker."
|
26
|
+
method_option :uuid, required: true, desc: "The UUID of the environment to update"
|
27
|
+
shared_environment_options(name_required: false)
|
28
|
+
shared_authentication_options
|
29
|
+
def update_environment
|
30
|
+
execute_environment_command(params_from_options(ENVIRONMENT_PARAM_NAMES + [:uuid]), "UpdateEnvironment")
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "describe-environment", "Describe an environment"
|
34
|
+
method_option :uuid, required: true, desc: "The UUID of the environment to describe"
|
35
|
+
method_option :output, aliases: "-o", desc: "json or text", default: 'text'
|
36
|
+
shared_authentication_options
|
37
|
+
def describe_environment
|
38
|
+
execute_environment_command(params_from_options([:uuid]), "DescribeEnvironment")
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "list-environments", "List environment"
|
42
|
+
method_option :output, aliases: "-o", desc: "json or text", default: 'text'
|
43
|
+
shared_authentication_options
|
44
|
+
def list_environments
|
45
|
+
execute_environment_command({}, "ListEnvironments")
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "delete-environment", "Delete an environment"
|
49
|
+
method_option :uuid, required: true, desc: "The UUID of the environment to delete"
|
50
|
+
method_option :output, aliases: "-o", desc: "json or text", default: 'text'
|
51
|
+
shared_authentication_options
|
52
|
+
def delete_environment
|
53
|
+
execute_environment_command(params_from_options([:uuid]), "DeleteEnvironment")
|
54
|
+
end
|
55
|
+
|
56
|
+
no_commands do
|
57
|
+
def execute_environment_command(params, command_class_name)
|
58
|
+
require 'pact_broker/client/environments'
|
59
|
+
command_options = { verbose: options.verbose, output: options.output }
|
60
|
+
result = PactBroker::Client::Environments.const_get(command_class_name).call(params, command_options, pact_broker_client_options)
|
61
|
+
$stdout.puts result.message
|
62
|
+
exit(1) unless result.success
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|