3scale_toolbox 0.15.0 → 0.18.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/3scale_toolbox.gemspec +2 -2
- data/README.md +15 -9
- data/lib/3scale_toolbox.rb +3 -1
- data/lib/3scale_toolbox/3scale_client_factory.rb +3 -4
- data/lib/3scale_toolbox/cli.rb +4 -0
- data/lib/3scale_toolbox/cli/custom_table_printer.rb +32 -0
- data/lib/3scale_toolbox/cli/error_handler.rb +17 -14
- 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 +7 -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 +36 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb +35 -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 +46 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/task.rb +67 -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/issuer_type_transformer.rb +16 -0
- data/lib/3scale_toolbox/commands/import_command/openapi.rb +6 -2
- data/lib/3scale_toolbox/commands/import_command/openapi/create_mapping_rule_step.rb +2 -1
- data/lib/3scale_toolbox/commands/import_command/openapi/create_method_step.rb +5 -14
- data/lib/3scale_toolbox/commands/import_command/openapi/step.rb +4 -0
- data/lib/3scale_toolbox/commands/import_command/openapi/update_service_proxy_step.rb +1 -0
- data/lib/3scale_toolbox/commands/methods_command/apply_command.rb +28 -8
- data/lib/3scale_toolbox/commands/methods_command/create_command.rb +23 -3
- data/lib/3scale_toolbox/commands/methods_command/delete_command.rb +1 -1
- data/lib/3scale_toolbox/commands/methods_command/list_command.rb +7 -13
- 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/export/read_plan_limits_step.rb +1 -1
- data/lib/3scale_toolbox/commands/plans_command/export/read_plan_methods_step.rb +2 -2
- data/lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb +2 -2
- data/lib/3scale_toolbox/commands/plans_command/export/read_plan_pricing_rules_step.rb +1 -2
- data/lib/3scale_toolbox/commands/plans_command/export/step.rb +8 -20
- data/lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb +12 -14
- data/lib/3scale_toolbox/commands/plans_command/import/import_plan_metrics_step.rb +6 -13
- data/lib/3scale_toolbox/commands/plans_command/import/import_plan_pricing_rules_step.rb +12 -20
- data/lib/3scale_toolbox/commands/plans_command/import/step.rb +2 -22
- data/lib/3scale_toolbox/commands/plans_command/list_command.rb +8 -13
- data/lib/3scale_toolbox/commands/plans_command/show_command.rb +7 -15
- data/lib/3scale_toolbox/commands/policies_command.rb +24 -0
- data/lib/3scale_toolbox/commands/policies_command/export_command.rb +98 -0
- data/lib/3scale_toolbox/commands/policies_command/import_command.rb +61 -0
- data/lib/3scale_toolbox/commands/product_command.rb +26 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command.rb +82 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command/copy_backends_task.rb +88 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command/delete_target_backend_usages_task.rb +48 -0
- data/lib/3scale_toolbox/commands/product_command/export_command.rb +81 -0
- data/lib/3scale_toolbox/commands/product_command/import_command.rb +125 -0
- data/lib/3scale_toolbox/commands/proxy_config_command.rb +5 -0
- data/lib/3scale_toolbox/commands/proxy_config_command/deploy_command.rb +54 -0
- data/lib/3scale_toolbox/commands/proxy_config_command/export_command.rb +74 -0
- data/lib/3scale_toolbox/commands/proxy_config_command/helper.rb +15 -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 +49 -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 +38 -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 +37 -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 +41 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_service_proxy_task.rb +32 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb +49 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/destroy_mapping_rules_task.rb +38 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/task.rb +85 -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 +3 -3
- data/lib/3scale_toolbox/commands/update_command/{update_service.rb → service_command.rb} +22 -18
- 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 +24 -0
- data/lib/3scale_toolbox/crds.rb +16 -0
- data/lib/3scale_toolbox/crds/application_plan_dump.rb +19 -0
- data/lib/3scale_toolbox/crds/backend_dump.rb +39 -0
- data/lib/3scale_toolbox/crds/backend_mapping_rule_dump.rb +26 -0
- data/lib/3scale_toolbox/crds/backend_method_dump.rb +12 -0
- data/lib/3scale_toolbox/crds/backend_metric_dump.rb +13 -0
- data/lib/3scale_toolbox/crds/backend_parser.rb +55 -0
- data/lib/3scale_toolbox/crds/backend_usage_dump.rb +11 -0
- data/lib/3scale_toolbox/crds/limit_dump.rb +37 -0
- data/lib/3scale_toolbox/crds/mapping_rule_dump.rb +26 -0
- data/lib/3scale_toolbox/crds/method_dump.rb +12 -0
- data/lib/3scale_toolbox/crds/metric_dump.rb +13 -0
- data/lib/3scale_toolbox/crds/pricing_rule_dump.rb +38 -0
- data/lib/3scale_toolbox/crds/product_deployment_parser.rb +329 -0
- data/lib/3scale_toolbox/crds/product_dump.rb +157 -0
- data/lib/3scale_toolbox/crds/product_parser.rb +114 -0
- data/lib/3scale_toolbox/crds/remote.rb +682 -0
- data/lib/3scale_toolbox/entities.rb +8 -0
- data/lib/3scale_toolbox/entities/activedocs.rb +12 -0
- data/lib/3scale_toolbox/entities/application_plan.rb +74 -39
- data/lib/3scale_toolbox/entities/backend.rb +187 -0
- data/lib/3scale_toolbox/entities/backend_mapping_rule.rb +102 -0
- data/lib/3scale_toolbox/entities/backend_method.rb +99 -0
- data/lib/3scale_toolbox/entities/backend_metric.rb +98 -0
- data/lib/3scale_toolbox/entities/backend_usage.rb +105 -0
- data/lib/3scale_toolbox/entities/limit.rb +71 -0
- data/lib/3scale_toolbox/entities/mapping_rule.rb +90 -0
- data/lib/3scale_toolbox/entities/method.rb +33 -19
- data/lib/3scale_toolbox/entities/metric.rb +29 -18
- data/lib/3scale_toolbox/entities/pricing_rule.rb +63 -0
- data/lib/3scale_toolbox/entities/proxy_config.rb +0 -1
- data/lib/3scale_toolbox/entities/service.rb +166 -48
- data/lib/3scale_toolbox/error.rb +53 -0
- data/lib/3scale_toolbox/helper.rb +17 -0
- data/lib/3scale_toolbox/openapi/oas3.rb +1 -1
- data/lib/3scale_toolbox/proxy_logger.rb +5 -1
- data/lib/3scale_toolbox/remote_cache.rb +157 -0
- data/lib/3scale_toolbox/remotes.rb +2 -2
- data/lib/3scale_toolbox/version.rb +1 -1
- data/licenses.xml +113 -45
- metadata +75 -26
- 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
@@ -1,36 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Tasks
|
3
|
-
class CopyLimitsTask
|
4
|
-
include CopyTask
|
5
|
-
include Helper
|
6
|
-
|
7
|
-
def call
|
8
|
-
plan_mapping = application_plan_mapping(source.plans, target.plans)
|
9
|
-
plan_mapping.each do |plan_id, target_plan|
|
10
|
-
source_plan = ThreeScaleToolbox::Entities::ApplicationPlan.new(id: plan_id, service: source)
|
11
|
-
target_plan = ThreeScaleToolbox::Entities::ApplicationPlan.new(id: target_plan['id'], service: target)
|
12
|
-
missing_limits = missing_limits(source_plan.limits, target_plan.limits, metrics_map)
|
13
|
-
missing_limits.each do |limit|
|
14
|
-
limit.delete('links')
|
15
|
-
target_plan.create_limit(metrics_map.fetch(limit.fetch('metric_id')), limit)
|
16
|
-
end
|
17
|
-
puts "Missing #{missing_limits.size} plan limits from target application plan " \
|
18
|
-
"#{target_plan.id}. Source plan #{plan_id}"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def metrics_map
|
25
|
-
@metrics_map ||= metrics_mapping(source_metrics_and_methods, target_metrics_and_methods)
|
26
|
-
end
|
27
|
-
|
28
|
-
def missing_limits(source_limits, target_limits, metrics_map)
|
29
|
-
ThreeScaleToolbox::Helper.array_difference(source_limits, target_limits) do |limit, target|
|
30
|
-
ThreeScaleToolbox::Helper.compare_hashes(limit, target, ['period']) &&
|
31
|
-
metrics_map.fetch(limit.fetch('metric_id')) == target.fetch('metric_id')
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Tasks
|
3
|
-
class CopyMappingRulesTask
|
4
|
-
include CopyTask
|
5
|
-
include Helper
|
6
|
-
|
7
|
-
def call
|
8
|
-
missing_rules = missing_mapping_rules(source.mapping_rules,
|
9
|
-
target.mapping_rules, metrics_map)
|
10
|
-
missing_rules.each do |mapping_rule|
|
11
|
-
mapping_rule.delete('links')
|
12
|
-
mapping_rule['metric_id'] = metrics_map.fetch(mapping_rule.delete('metric_id'))
|
13
|
-
target.create_mapping_rule mapping_rule
|
14
|
-
end
|
15
|
-
puts "created #{missing_rules.size} mapping rules"
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def metrics_map
|
21
|
-
@metrics_map ||= metrics_mapping(source_metrics_and_methods, target_metrics_and_methods)
|
22
|
-
end
|
23
|
-
|
24
|
-
def missing_mapping_rules(source_rules, target_rules, metrics_map)
|
25
|
-
ThreeScaleToolbox::Helper.array_difference(source_rules, target_rules) do |source_rule, target_rule|
|
26
|
-
ThreeScaleToolbox::Helper.compare_hashes(source_rule, target_rule, %w[pattern http_method delta]) &&
|
27
|
-
metrics_map.fetch(source_rule.fetch('metric_id')) == target_rule.fetch('metric_id')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Tasks
|
3
|
-
class CopyMethodsTask
|
4
|
-
include CopyTask
|
5
|
-
|
6
|
-
def call
|
7
|
-
puts "original service hits metric #{source_hits.fetch('id')} has #{source_methods.size} methods"
|
8
|
-
puts "target service hits metric #{target_hits.fetch('id')} has #{target_methods.size} methods"
|
9
|
-
missing_methods.each(&method(:create_method))
|
10
|
-
puts "created #{missing_methods.size} missing methods on target service"
|
11
|
-
invalidate_target_methods if missing_methods.size.positive?
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def create_method(method)
|
17
|
-
Entities::Method.create(
|
18
|
-
service: target,
|
19
|
-
parent_id: target_hits.fetch('id'),
|
20
|
-
attrs: ThreeScaleToolbox::Helper.filter_params(%w[friendly_name system_name], method)
|
21
|
-
)
|
22
|
-
rescue ThreeScaleToolbox::ThreeScaleApiError => e
|
23
|
-
raise e unless ThreeScaleToolbox::Helper.system_name_already_taken_error?(e.apierrors)
|
24
|
-
|
25
|
-
warn "[WARN] method #{method.fetch('system_name')} not created. " \
|
26
|
-
'Metric with the same system_name exists.'
|
27
|
-
end
|
28
|
-
|
29
|
-
def missing_methods
|
30
|
-
@missing_methods ||= ThreeScaleToolbox::Helper.array_difference(source_methods, target_methods) do |method, target|
|
31
|
-
ThreeScaleToolbox::Helper.compare_hashes(method, target, ['system_name'])
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Tasks
|
3
|
-
class CopyMetricsTask
|
4
|
-
include CopyTask
|
5
|
-
|
6
|
-
def call
|
7
|
-
puts "original service has #{source_metrics.size} metrics"
|
8
|
-
puts "target service has #{target_metrics.size} metrics"
|
9
|
-
missing_metrics.each(&method(:create_metric))
|
10
|
-
puts "created #{missing_metrics.size} metrics on the target service"
|
11
|
-
invalidate_target_metrics if missing_metrics.size.positive?
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def create_metric(metric)
|
17
|
-
new_metric = metric.reject { |key, _| %w[id links].include? key }
|
18
|
-
Entities::Metric.create(service: target, attrs: new_metric)
|
19
|
-
rescue ThreeScaleToolbox::ThreeScaleApiError => e
|
20
|
-
raise e unless ThreeScaleToolbox::Helper.system_name_already_taken_error?(e.apierrors)
|
21
|
-
|
22
|
-
warn "[WARN] metric #{metric.fetch('system_name')} not created. " \
|
23
|
-
'Method with the same system_name exists.'
|
24
|
-
end
|
25
|
-
|
26
|
-
def missing_metrics
|
27
|
-
@missing_metrics ||= ThreeScaleToolbox::Helper.array_difference(source_metrics, target_metrics) do |source, target|
|
28
|
-
ThreeScaleToolbox::Helper.compare_hashes(source, target, ['system_name'])
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Tasks
|
3
|
-
class CopyPricingRulesTask
|
4
|
-
include CopyTask
|
5
|
-
include Helper
|
6
|
-
|
7
|
-
def call
|
8
|
-
plan_mapping = application_plan_mapping(source.plans, target.plans)
|
9
|
-
plan_mapping.each do |plan_id, target_plan|
|
10
|
-
pricing_rules_source = source.remote.list_pricingrules_per_application_plan(plan_id)
|
11
|
-
pricing_rules_target = target.remote.list_pricingrules_per_application_plan(target_plan['id'])
|
12
|
-
missing_pricing_rules = missing_pricing_rules(pricing_rules_source, pricing_rules_target,
|
13
|
-
metrics_map)
|
14
|
-
missing_pricing_rules.each do |pricing_rule|
|
15
|
-
pricing_rule.delete('links')
|
16
|
-
target.remote.create_pricingrule(
|
17
|
-
target_plan['id'],
|
18
|
-
metrics_map.fetch(pricing_rule['metric_id']),
|
19
|
-
pricing_rule
|
20
|
-
)
|
21
|
-
end
|
22
|
-
puts "Missing #{missing_pricing_rules.size} pricing rules from target application plan " \
|
23
|
-
"#{target_plan['id']}. Source plan #{plan_id}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def metrics_map
|
30
|
-
@metrics_map ||= metrics_mapping(source_metrics_and_methods, target_metrics_and_methods)
|
31
|
-
end
|
32
|
-
|
33
|
-
def missing_pricing_rules(source_pricing_rules, target_pricing_rules, metrics_map)
|
34
|
-
ThreeScaleToolbox::Helper.array_difference(source_pricing_rules, target_pricing_rules) do |src, target|
|
35
|
-
ThreeScaleToolbox::Helper.compare_hashes(src, target, %w[cost_per_unit min max]) &&
|
36
|
-
metrics_map.fetch(src.fetch('metric_id')) == target.fetch('metric_id')
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Tasks
|
3
|
-
class CopyServiceProxyTask
|
4
|
-
include CopyTask
|
5
|
-
|
6
|
-
def call
|
7
|
-
target.update_proxy source.proxy
|
8
|
-
target.update_oidc source.oidc if source.attrs['backend_version'] == 'oidc'
|
9
|
-
puts "updated proxy of #{target.id} to match the original"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Tasks
|
3
|
-
class CopyServiceSettingsTask
|
4
|
-
include CopyTask
|
5
|
-
PARAMS_FILTER = %w[system_name id links]
|
6
|
-
|
7
|
-
def call
|
8
|
-
svc_obj = update_service source_service_settings
|
9
|
-
if (errors = svc_obj['errors'])
|
10
|
-
raise ThreeScaleToolbox::Error, "Service has not been saved. Errors: #{errors}" \
|
11
|
-
end
|
12
|
-
|
13
|
-
puts "updated service settings for service id #{source.id}..."
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def source_service_settings
|
19
|
-
source.attrs.reject { |k, _| PARAMS_FILTER.include? k }
|
20
|
-
end
|
21
|
-
|
22
|
-
def update_service(service_attrs)
|
23
|
-
svc_obj = target.update service_attrs
|
24
|
-
|
25
|
-
# Source and target remotes might not allow same set of deployment options
|
26
|
-
# Invalid deployment option check
|
27
|
-
# use default deployment_option
|
28
|
-
if (errors = svc_obj['errors']) &&
|
29
|
-
ThreeScaleToolbox::Helper.service_invalid_deployment_option?(errors)
|
30
|
-
service_attrs.delete('deployment_option')
|
31
|
-
svc_obj = target.update service_attrs
|
32
|
-
end
|
33
|
-
|
34
|
-
svc_obj
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Tasks
|
3
|
-
module CopyTask
|
4
|
-
def self.included(base)
|
5
|
-
base.extend(ClassMethods)
|
6
|
-
end
|
7
|
-
|
8
|
-
module ClassMethods
|
9
|
-
end
|
10
|
-
|
11
|
-
attr_reader :context
|
12
|
-
|
13
|
-
def initialize(context)
|
14
|
-
@context = context
|
15
|
-
end
|
16
|
-
|
17
|
-
def source
|
18
|
-
context[:source]
|
19
|
-
end
|
20
|
-
|
21
|
-
def target
|
22
|
-
context[:target]
|
23
|
-
end
|
24
|
-
|
25
|
-
def source_metrics
|
26
|
-
context[:source_metrics] ||= source.metrics
|
27
|
-
end
|
28
|
-
|
29
|
-
def source_hits
|
30
|
-
context[:source_hits] ||= source.hits
|
31
|
-
end
|
32
|
-
|
33
|
-
def source_methods
|
34
|
-
context[:source_methods] ||= source.methods(source_hits.fetch('id'))
|
35
|
-
end
|
36
|
-
|
37
|
-
def source_metrics_and_methods
|
38
|
-
source_metrics + source_methods
|
39
|
-
end
|
40
|
-
|
41
|
-
def target_metrics
|
42
|
-
context[:target_metrics] ||= target.metrics
|
43
|
-
end
|
44
|
-
|
45
|
-
def target_hits
|
46
|
-
context[:target_hits] ||= target.hits
|
47
|
-
end
|
48
|
-
|
49
|
-
def target_methods
|
50
|
-
context[:target_methods] ||= target.methods(target_hits.fetch('id'))
|
51
|
-
end
|
52
|
-
|
53
|
-
def target_metrics_and_methods
|
54
|
-
target_metrics + target_methods
|
55
|
-
end
|
56
|
-
|
57
|
-
def invalidate_target_methods
|
58
|
-
context[:target_methods] = nil
|
59
|
-
end
|
60
|
-
|
61
|
-
def invalidate_target_metrics
|
62
|
-
context[:target_metrics] = nil
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Tasks
|
3
|
-
class DeleteActiveDocsTask
|
4
|
-
attr_reader :context
|
5
|
-
|
6
|
-
def initialize(context)
|
7
|
-
@context = context
|
8
|
-
end
|
9
|
-
|
10
|
-
def call
|
11
|
-
puts 'deleting all target service ActiveDocs'
|
12
|
-
target.activedocs.each do |activedoc|
|
13
|
-
target.remote.delete_activedocs(activedoc['id'])
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def target
|
18
|
-
context[:target]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Tasks
|
3
|
-
class DestroyMappingRulesTask
|
4
|
-
attr_reader :context
|
5
|
-
|
6
|
-
def initialize(context)
|
7
|
-
@context = context
|
8
|
-
end
|
9
|
-
|
10
|
-
def call
|
11
|
-
puts 'destroying all mapping rules'
|
12
|
-
target.mapping_rules.each do |mapping_rule|
|
13
|
-
target.delete_mapping_rule mapping_rule['id']
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def target
|
18
|
-
context[:target]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Tasks
|
3
|
-
module Helper
|
4
|
-
def metrics_mapping(source_metrics, target_metrics)
|
5
|
-
target_metrics.map do |target|
|
6
|
-
source = source_metrics.find do |m|
|
7
|
-
ThreeScaleToolbox::Helper.compare_hashes(m, target, ['system_name'])
|
8
|
-
end || {}
|
9
|
-
|
10
|
-
[source['id'], target['id']]
|
11
|
-
end.to_h
|
12
|
-
end
|
13
|
-
|
14
|
-
def application_plan_mapping(source_app_plans, target_app_plans)
|
15
|
-
mapping = target_app_plans.map do |target|
|
16
|
-
source = source_app_plans.find do |app_plan|
|
17
|
-
ThreeScaleToolbox::Helper.compare_hashes(app_plan, target, ['system_name'])
|
18
|
-
end || {}
|
19
|
-
[source['id'], target]
|
20
|
-
end
|
21
|
-
mapping.reject { |key, _| key.nil? }
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|