3scale_toolbox 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/3scale_toolbox.gemspec +1 -1
- data/README.md +4 -1
- data/lib/3scale_toolbox.rb +0 -1
- data/lib/3scale_toolbox/cli.rb +4 -0
- data/lib/3scale_toolbox/cli/custom_table_printer.rb +32 -0
- data/lib/3scale_toolbox/cli/json_printer.rb +13 -0
- data/lib/3scale_toolbox/cli/output_flag.rb +20 -0
- data/lib/3scale_toolbox/cli/yaml_printer.rb +13 -0
- data/lib/3scale_toolbox/commands.rb +5 -1
- data/lib/3scale_toolbox/commands/activedocs_command/apply_command.rb +33 -10
- data/lib/3scale_toolbox/commands/activedocs_command/create_command.rb +22 -7
- data/lib/3scale_toolbox/commands/activedocs_command/list_command.rb +10 -17
- data/lib/3scale_toolbox/commands/application_command/apply_command.rb +27 -4
- data/lib/3scale_toolbox/commands/application_command/create_command.rb +16 -1
- data/lib/3scale_toolbox/commands/application_command/list_command.rb +10 -13
- data/lib/3scale_toolbox/commands/application_command/show_command.rb +8 -14
- data/lib/3scale_toolbox/commands/backend_command.rb +22 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command.rb +65 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_mapping_rules_task.rb +52 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb +40 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_metrics_task.rb +30 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb +45 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/task.rb +89 -0
- data/lib/3scale_toolbox/commands/copy_command.rb +2 -2
- data/lib/3scale_toolbox/commands/copy_command/service_command.rb +40 -0
- data/lib/3scale_toolbox/commands/import_command/openapi.rb +3 -2
- data/lib/3scale_toolbox/commands/methods_command/apply_command.rb +26 -4
- data/lib/3scale_toolbox/commands/methods_command/create_command.rb +23 -1
- data/lib/3scale_toolbox/commands/methods_command/list_command.rb +11 -9
- data/lib/3scale_toolbox/commands/metrics_command/apply_command.rb +26 -4
- data/lib/3scale_toolbox/commands/metrics_command/create_command.rb +23 -1
- data/lib/3scale_toolbox/commands/metrics_command/list_command.rb +7 -12
- data/lib/3scale_toolbox/commands/plans_command/apply_command.rb +36 -7
- data/lib/3scale_toolbox/commands/plans_command/create_command.rb +23 -1
- data/lib/3scale_toolbox/commands/plans_command/list_command.rb +8 -13
- data/lib/3scale_toolbox/commands/plans_command/show_command.rb +6 -14
- data/lib/3scale_toolbox/commands/product_command.rb +22 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command.rb +78 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command/copy_backends_task.rb +71 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command/delete_target_backend_usages_task.rb +48 -0
- data/lib/3scale_toolbox/commands/proxy_config_command/list_command.rb +13 -29
- data/lib/3scale_toolbox/commands/proxy_config_command/show_command.rb +20 -23
- data/lib/3scale_toolbox/commands/service_command.rb +7 -5
- data/lib/3scale_toolbox/commands/service_command/apply_command.rb +69 -58
- data/lib/3scale_toolbox/commands/service_command/copy_command.rb +95 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/bump_proxy_version_task.rb +36 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_activedocs_task.rb +46 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb +35 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb +39 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb +35 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_methods_task.rb +40 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_metrics_task.rb +37 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_policies_task.rb +17 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_pricingrules_task.rb +44 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_service_proxy_task.rb +17 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb +48 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/destroy_mapping_rules_task.rb +34 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/task.rb +99 -0
- data/lib/3scale_toolbox/commands/service_command/create_command.rb +58 -44
- data/lib/3scale_toolbox/commands/service_command/delete_command.rb +31 -33
- data/lib/3scale_toolbox/commands/service_command/list_command.rb +24 -34
- data/lib/3scale_toolbox/commands/service_command/show_command.rb +39 -44
- data/lib/3scale_toolbox/commands/update_command.rb +2 -2
- data/lib/3scale_toolbox/commands/update_command/{update_service.rb → service_command.rb} +19 -16
- data/lib/3scale_toolbox/commands/update_command/service_command/copy_service_settings_task.rb +35 -0
- data/lib/3scale_toolbox/commands/update_command/service_command/delete_activedocs_task.rb +26 -0
- data/lib/3scale_toolbox/entities.rb +5 -0
- data/lib/3scale_toolbox/entities/backend.rb +152 -0
- data/lib/3scale_toolbox/entities/backend_mapping_rule.rb +76 -0
- data/lib/3scale_toolbox/entities/backend_method.rb +90 -0
- data/lib/3scale_toolbox/entities/backend_metric.rb +88 -0
- data/lib/3scale_toolbox/entities/backend_usage.rb +99 -0
- data/lib/3scale_toolbox/entities/service.rb +18 -3
- data/lib/3scale_toolbox/error.rb +3 -0
- data/lib/3scale_toolbox/helper.rb +20 -0
- data/lib/3scale_toolbox/proxy_logger.rb +1 -1
- data/lib/3scale_toolbox/version.rb +1 -1
- data/licenses.xml +3 -3
- metadata +42 -22
- data/lib/3scale_toolbox/commands/copy_command/copy_service.rb +0 -144
- data/lib/3scale_toolbox/tasks.rb +0 -15
- data/lib/3scale_toolbox/tasks/bump_proxy_version_task.rb +0 -32
- data/lib/3scale_toolbox/tasks/copy_activedocs_task.rb +0 -42
- data/lib/3scale_toolbox/tasks/copy_app_plans_task.rb +0 -31
- data/lib/3scale_toolbox/tasks/copy_limits_task.rb +0 -36
- data/lib/3scale_toolbox/tasks/copy_mapping_rules_task.rb +0 -32
- data/lib/3scale_toolbox/tasks/copy_methods_task.rb +0 -36
- data/lib/3scale_toolbox/tasks/copy_metrics_task.rb +0 -33
- data/lib/3scale_toolbox/tasks/copy_policies_task.rb +0 -13
- data/lib/3scale_toolbox/tasks/copy_pricingrules_task.rb +0 -41
- data/lib/3scale_toolbox/tasks/copy_service_proxy_task.rb +0 -13
- data/lib/3scale_toolbox/tasks/copy_service_settings_task.rb +0 -38
- data/lib/3scale_toolbox/tasks/copy_task.rb +0 -66
- data/lib/3scale_toolbox/tasks/delete_activedocs_task.rb +0 -22
- data/lib/3scale_toolbox/tasks/destroy_mapping_rules_task.rb +0 -22
- data/lib/3scale_toolbox/tasks/helper_task.rb +0 -25
|
@@ -2,6 +2,21 @@ module ThreeScaleToolbox
|
|
|
2
2
|
module Commands
|
|
3
3
|
module PlansCommand
|
|
4
4
|
module Create
|
|
5
|
+
class CustomPrinter
|
|
6
|
+
attr_reader :option_default, :option_disabled
|
|
7
|
+
|
|
8
|
+
def initialize(option_default, option_disabled)
|
|
9
|
+
@option_default = option_default
|
|
10
|
+
@option_disabled = option_disabled
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def print_record(plan)
|
|
14
|
+
puts "Created application plan id: #{plan['id']}. Default: #{option_default}; Disabled: #{option_disabled}"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def print_collection(collection) end
|
|
18
|
+
end
|
|
19
|
+
|
|
5
20
|
class CreateSubcommand < Cri::CommandRunner
|
|
6
21
|
include ThreeScaleToolbox::Command
|
|
7
22
|
|
|
@@ -20,6 +35,8 @@ module ThreeScaleToolbox
|
|
|
20
35
|
option nil, 'cost-per-month', 'Cost per month', argument: :required, transform: method(:Float)
|
|
21
36
|
option nil, 'setup-fee', 'Setup fee', argument: :required, transform: method(:Float)
|
|
22
37
|
option nil, 'trial-period-days', 'Trial period days', argument: :required, transform: method(:Integer)
|
|
38
|
+
ThreeScaleToolbox::CLI.output_flag(self)
|
|
39
|
+
|
|
23
40
|
param :remote
|
|
24
41
|
param :service_ref
|
|
25
42
|
param :plan_name
|
|
@@ -32,7 +49,7 @@ module ThreeScaleToolbox
|
|
|
32
49
|
plan = create_application_plan
|
|
33
50
|
plan.make_default if option_default
|
|
34
51
|
plan.disable if option_disabled
|
|
35
|
-
|
|
52
|
+
printer.print_record plan.attrs
|
|
36
53
|
end
|
|
37
54
|
|
|
38
55
|
private
|
|
@@ -91,6 +108,11 @@ module ThreeScaleToolbox
|
|
|
91
108
|
def service_ref
|
|
92
109
|
arguments[:service_ref]
|
|
93
110
|
end
|
|
111
|
+
|
|
112
|
+
def printer
|
|
113
|
+
# keep backwards compatibility
|
|
114
|
+
options.fetch(:output, CustomPrinter.new(option_default, option_disabled))
|
|
115
|
+
end
|
|
94
116
|
end
|
|
95
117
|
end
|
|
96
118
|
end
|
|
@@ -5,7 +5,7 @@ module ThreeScaleToolbox
|
|
|
5
5
|
class ListSubcommand < Cri::CommandRunner
|
|
6
6
|
include ThreeScaleToolbox::Command
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
FIELDS = %w[id name system_name].freeze
|
|
9
9
|
|
|
10
10
|
def self.command
|
|
11
11
|
Cri::Command.define do
|
|
@@ -14,6 +14,7 @@ module ThreeScaleToolbox
|
|
|
14
14
|
summary 'list application plans'
|
|
15
15
|
description 'List application plans'
|
|
16
16
|
|
|
17
|
+
ThreeScaleToolbox::CLI.output_flag(self)
|
|
17
18
|
param :remote
|
|
18
19
|
param :service_ref
|
|
19
20
|
|
|
@@ -22,22 +23,11 @@ module ThreeScaleToolbox
|
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
def run
|
|
25
|
-
|
|
26
|
-
print_data
|
|
26
|
+
printer.print_collection service.plans
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
private
|
|
30
30
|
|
|
31
|
-
def print_header
|
|
32
|
-
puts FIELDS_TO_SHOW.map(&:upcase).join("\t")
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def print_data
|
|
36
|
-
service.plans.each do |plan|
|
|
37
|
-
puts FIELDS_TO_SHOW.map { |field| plan.fetch(field, '(empty)') }.join("\t")
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
31
|
def service
|
|
42
32
|
@service ||= find_service
|
|
43
33
|
end
|
|
@@ -56,6 +46,11 @@ module ThreeScaleToolbox
|
|
|
56
46
|
def service_ref
|
|
57
47
|
arguments[:service_ref]
|
|
58
48
|
end
|
|
49
|
+
|
|
50
|
+
def printer
|
|
51
|
+
# keep backwards compatibility
|
|
52
|
+
options.fetch(:output, CLI::CustomTablePrinter.new(FIELDS))
|
|
53
|
+
end
|
|
59
54
|
end
|
|
60
55
|
end
|
|
61
56
|
end
|
|
@@ -15,6 +15,7 @@ module ThreeScaleToolbox
|
|
|
15
15
|
summary 'show application plan'
|
|
16
16
|
description 'show application plan'
|
|
17
17
|
|
|
18
|
+
ThreeScaleToolbox::CLI.output_flag(self)
|
|
18
19
|
param :remote
|
|
19
20
|
param :service_ref
|
|
20
21
|
param :plan_ref
|
|
@@ -24,28 +25,15 @@ module ThreeScaleToolbox
|
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
def run
|
|
27
|
-
|
|
28
|
-
print_data
|
|
28
|
+
printer.print_record plan.attrs
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
private
|
|
32
32
|
|
|
33
|
-
def print_header
|
|
34
|
-
puts FIELDS_TO_SHOW.map(&:upcase).join("\t")
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def print_data
|
|
38
|
-
puts FIELDS_TO_SHOW.map { |field| plan_attrs.fetch(field, '(empty)') }.join("\t")
|
|
39
|
-
end
|
|
40
|
-
|
|
41
33
|
def service
|
|
42
34
|
@service ||= find_service
|
|
43
35
|
end
|
|
44
36
|
|
|
45
|
-
def plan_attrs
|
|
46
|
-
@plan_attrs ||= plan.attrs
|
|
47
|
-
end
|
|
48
|
-
|
|
49
37
|
def plan
|
|
50
38
|
@plan ||= find_plan
|
|
51
39
|
end
|
|
@@ -74,6 +62,10 @@ module ThreeScaleToolbox
|
|
|
74
62
|
def plan_ref
|
|
75
63
|
arguments[:plan_ref]
|
|
76
64
|
end
|
|
65
|
+
|
|
66
|
+
def printer
|
|
67
|
+
options.fetch(:output, CLI::CustomTablePrinter.new(FIELDS_TO_SHOW))
|
|
68
|
+
end
|
|
77
69
|
end
|
|
78
70
|
end
|
|
79
71
|
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require '3scale_toolbox/commands/product_command/copy_command'
|
|
2
|
+
|
|
3
|
+
module ThreeScaleToolbox
|
|
4
|
+
module Commands
|
|
5
|
+
module ProductCommand
|
|
6
|
+
include ThreeScaleToolbox::Command
|
|
7
|
+
def self.command
|
|
8
|
+
Cri::Command.define do
|
|
9
|
+
name 'product'
|
|
10
|
+
usage 'product <sub-command> [options]'
|
|
11
|
+
summary 'product super command'
|
|
12
|
+
description 'Product commands'
|
|
13
|
+
|
|
14
|
+
run do |_opts, _args, cmd|
|
|
15
|
+
puts cmd.help
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
add_subcommand(CopySubcommand)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require '3scale_toolbox/commands/product_command/copy_command/delete_target_backend_usages_task'
|
|
2
|
+
require '3scale_toolbox/commands/product_command/copy_command/copy_backends_task'
|
|
3
|
+
|
|
4
|
+
module ThreeScaleToolbox
|
|
5
|
+
module Commands
|
|
6
|
+
module ProductCommand
|
|
7
|
+
class CopySubcommand < Cri::CommandRunner
|
|
8
|
+
include ThreeScaleToolbox::Command
|
|
9
|
+
|
|
10
|
+
def self.command
|
|
11
|
+
Cri::Command.define do
|
|
12
|
+
name 'copy'
|
|
13
|
+
usage 'copy [opts] -s <source-remote> -d <target-remote> <source-product>'
|
|
14
|
+
summary 'Copy product'
|
|
15
|
+
description <<-HEREDOC
|
|
16
|
+
This command makes a copy of the referenced product.
|
|
17
|
+
Target product will be searched by source product system name. System name can be overriden with `--target-system-name` option.
|
|
18
|
+
If a product with the selected `system_name` is not found, it will be created.
|
|
19
|
+
\n Components of the product being copied:
|
|
20
|
+
\nproduct configuration
|
|
21
|
+
\nproduct settings
|
|
22
|
+
\nproduct methods&metrics: Only missing metrics&methods will be created.
|
|
23
|
+
\nproduct mapping rules: Only missing mapping rules will be created.
|
|
24
|
+
\nproduct application plans & pricing rules & limits: Only missing application plans & pricing rules & limits will be created.
|
|
25
|
+
\nproduct application usage rules
|
|
26
|
+
\nproduct policies
|
|
27
|
+
\nproduct backends: Only missing backends will be created.
|
|
28
|
+
\nproduct activedocs: Only missing activedocs will be created.
|
|
29
|
+
HEREDOC
|
|
30
|
+
|
|
31
|
+
option :s, :source, '3scale source instance. Url or remote name', argument: :required
|
|
32
|
+
option :d, :destination, '3scale target instance. Url or remote name', argument: :required
|
|
33
|
+
option :t, 'target-system-name', 'Target system name. Default to source system name', argument: :required
|
|
34
|
+
param :source_product
|
|
35
|
+
|
|
36
|
+
runner CopySubcommand
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def run
|
|
41
|
+
tasks = []
|
|
42
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CreateOrUpdateTargetServiceTask.new(context)
|
|
43
|
+
tasks << CopyCommand::DeleteExistingTargetBackendUsagesTask.new(context)
|
|
44
|
+
tasks << CopyCommand::CopyBackendsTask.new(context)
|
|
45
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CopyServiceProxyTask.new(context)
|
|
46
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CopyMethodsTask.new(context)
|
|
47
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CopyMetricsTask.new(context)
|
|
48
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::DestroyMappingRulesTask.new(context)
|
|
49
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CopyMappingRulesTask.new(context)
|
|
50
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CopyApplicationPlansTask.new(context)
|
|
51
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CopyLimitsTask.new(context)
|
|
52
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CopyPoliciesTask.new(context)
|
|
53
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CopyPricingRulesTask.new(context)
|
|
54
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CopyActiveDocsTask.new(context)
|
|
55
|
+
tasks.each(&:call)
|
|
56
|
+
|
|
57
|
+
# This should be the last step
|
|
58
|
+
ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::BumpProxyVersionTask.new(service: context[:target]).call
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
def context
|
|
64
|
+
@context ||= create_context
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def create_context
|
|
68
|
+
{
|
|
69
|
+
source_remote: threescale_client(fetch_required_option(:source)),
|
|
70
|
+
target_remote: threescale_client(fetch_required_option(:destination)),
|
|
71
|
+
source_service_ref: arguments[:source_product],
|
|
72
|
+
option_target_system_name: options[:'target-system-name']
|
|
73
|
+
}
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
module ThreeScaleToolbox
|
|
2
|
+
module Commands
|
|
3
|
+
module ProductCommand
|
|
4
|
+
module CopyCommand
|
|
5
|
+
class CopyBackendsTask
|
|
6
|
+
attr_reader :context
|
|
7
|
+
|
|
8
|
+
def initialize(context)
|
|
9
|
+
@context = context
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# entrypoint
|
|
13
|
+
def call
|
|
14
|
+
backend_list = source.backend_usage_list
|
|
15
|
+
backend_list.each(&method(:create_backend))
|
|
16
|
+
puts "created/upated #{backend_list.size} backends"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def create_backend(backend_usage)
|
|
22
|
+
source_backend = Entities::Backend.new(id: backend_usage.backend_id, remote: source_remote)
|
|
23
|
+
backend_context = create_backend_context(source_backend.system_name)
|
|
24
|
+
|
|
25
|
+
tasks = []
|
|
26
|
+
tasks << Commands::BackendCommand::CopyCommand::CreateOrUpdateTargetBackendTask.new(backend_context)
|
|
27
|
+
# First metrics as methods need 'hits' metric in target backend
|
|
28
|
+
tasks << Commands::BackendCommand::CopyCommand::CopyMetricsTask.new(backend_context)
|
|
29
|
+
tasks << Commands::BackendCommand::CopyCommand::CopyMethodsTask.new(backend_context)
|
|
30
|
+
tasks << Commands::BackendCommand::CopyCommand::CopyMappingRulesTask.new(backend_context)
|
|
31
|
+
tasks.each(&:call)
|
|
32
|
+
|
|
33
|
+
# CreateOrUpdate task will keep reference of the target backend in
|
|
34
|
+
# backend_context[:target_backend]
|
|
35
|
+
attrs = {
|
|
36
|
+
'backend_api_id' => backend_context[:target_backend].id,
|
|
37
|
+
'path' => backend_usage.path
|
|
38
|
+
}
|
|
39
|
+
# It is assumed there is no target backend usage with this backend_source's path
|
|
40
|
+
# DeleteExistingTargetBackendUsagesTask should provide that
|
|
41
|
+
Entities::BackendUsage.create(product: target, attrs: attrs)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def source
|
|
45
|
+
context[:source]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def target
|
|
49
|
+
context[:target]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def source_remote
|
|
53
|
+
context[:source_remote]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def target_remote
|
|
57
|
+
context[:target_remote]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def create_backend_context(source_backend_system_name)
|
|
61
|
+
{
|
|
62
|
+
source_remote: source_remote,
|
|
63
|
+
target_remote: target_remote,
|
|
64
|
+
source_backend_ref: source_backend_system_name
|
|
65
|
+
}
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
data/lib/3scale_toolbox/commands/product_command/copy_command/delete_target_backend_usages_task.rb
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module ThreeScaleToolbox
|
|
2
|
+
module Commands
|
|
3
|
+
module ProductCommand
|
|
4
|
+
module CopyCommand
|
|
5
|
+
class DeleteExistingTargetBackendUsagesTask
|
|
6
|
+
attr_reader :context
|
|
7
|
+
|
|
8
|
+
def initialize(context)
|
|
9
|
+
@context = context
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# entrypoint
|
|
13
|
+
def call
|
|
14
|
+
conflicting_target_backend_usage_list.each(&:delete)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
# List of target backend usage items that match source backend usage paths
|
|
20
|
+
def conflicting_target_backend_usage_list
|
|
21
|
+
# Compute array intersection
|
|
22
|
+
target_backend_usage_list.select do |target_usage|
|
|
23
|
+
source_backend_usage_list.find do |source_usage|
|
|
24
|
+
target_usage.path == source_usage.path
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def source_backend_usage_list
|
|
30
|
+
@source_backend_usage_list ||= source.backend_usage_list
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def target_backend_usage_list
|
|
34
|
+
@target_backend_usage_list ||= target.backend_usage_list
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def target
|
|
38
|
+
context[:target]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def source
|
|
42
|
+
context[:source]
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -5,30 +5,30 @@ module ThreeScaleToolbox
|
|
|
5
5
|
class ListSubcommand < Cri::CommandRunner
|
|
6
6
|
include ThreeScaleToolbox::Command
|
|
7
7
|
|
|
8
|
+
FIELDS = %w[id version environment]
|
|
9
|
+
|
|
8
10
|
def self.command
|
|
9
11
|
Cri::Command.define do
|
|
10
12
|
name 'list'
|
|
11
13
|
usage 'list <remote> <service> <environment>'
|
|
12
14
|
summary 'List Proxy Configurations'
|
|
13
15
|
description 'List all defined Proxy Configurations'
|
|
14
|
-
runner ListSubcommand
|
|
15
16
|
|
|
17
|
+
ThreeScaleToolbox::CLI.output_flag(self)
|
|
16
18
|
param :remote
|
|
17
19
|
param :service_ref
|
|
18
20
|
param :environment
|
|
21
|
+
|
|
22
|
+
runner ListSubcommand
|
|
19
23
|
end
|
|
20
24
|
end
|
|
21
25
|
|
|
22
26
|
def run
|
|
23
|
-
|
|
27
|
+
printer.print_collection service.proxy_configs(proxy_config_environment).map(&:attrs)
|
|
24
28
|
end
|
|
25
29
|
|
|
26
30
|
private
|
|
27
31
|
|
|
28
|
-
PROXYCONFIG_FIELDS_TO_SHOW = %w[
|
|
29
|
-
id version environment
|
|
30
|
-
]
|
|
31
|
-
|
|
32
32
|
def remote
|
|
33
33
|
@remote ||= threescale_client(arguments[:remote])
|
|
34
34
|
end
|
|
@@ -41,29 +41,8 @@ module ThreeScaleToolbox
|
|
|
41
41
|
arguments[:service_ref]
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
def proxy_configs
|
|
45
|
-
@proxyconfigs ||= service.proxy_configs(proxy_config_environment)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def print_proxy_config_data(proxyconfigs, fields_to_show)
|
|
49
|
-
print_header(fields_to_show)
|
|
50
|
-
print_results(proxyconfigs, fields_to_show)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def print_header(fields_to_show)
|
|
54
|
-
puts fields_to_show.map{ |e| e.upcase}.join("\t")
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def print_results(proxyconfigs, fields_to_show)
|
|
58
|
-
proxyconfigs.each do |proxyconfig|
|
|
59
|
-
proxy_config_attrs = proxyconfig.attrs
|
|
60
|
-
puts fields_to_show.map { |field| proxy_config_attrs.fetch(field, '(empty)') }.join("\t")
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
44
|
def find_service
|
|
65
|
-
Entities::Service.find(remote: remote,
|
|
66
|
-
ref: service_ref).tap do |svc|
|
|
45
|
+
Entities::Service.find(remote: remote, ref: service_ref).tap do |svc|
|
|
67
46
|
raise ThreeScaleToolbox::Error, "Service #{service_ref} does not exist" if svc.nil?
|
|
68
47
|
end
|
|
69
48
|
end
|
|
@@ -71,8 +50,13 @@ module ThreeScaleToolbox
|
|
|
71
50
|
def service
|
|
72
51
|
@service ||= find_service
|
|
73
52
|
end
|
|
53
|
+
|
|
54
|
+
def printer
|
|
55
|
+
# keep backwards compatibility
|
|
56
|
+
options.fetch(:output, CLI::CustomTablePrinter.new(FIELDS))
|
|
57
|
+
end
|
|
74
58
|
end
|
|
75
59
|
end
|
|
76
60
|
end
|
|
77
61
|
end
|
|
78
|
-
end
|
|
62
|
+
end
|