3scale_toolbox 0.13.0 → 0.17.1
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 +4 -3
- data/README.md +31 -10
- data/lib/3scale_toolbox.rb +5 -2
- data/lib/3scale_toolbox/attribute_filters.rb +2 -0
- data/lib/3scale_toolbox/attribute_filters/attribute_filter.rb +9 -0
- data/lib/3scale_toolbox/attribute_filters/service_id_from_ref_filter.rb +30 -0
- 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 +5 -1
- data/lib/3scale_toolbox/commands/activedocs_command/apply_command.rb +34 -11
- data/lib/3scale_toolbox/commands/activedocs_command/create_command.rb +22 -7
- data/lib/3scale_toolbox/commands/activedocs_command/list_command.rb +21 -11
- 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 +29 -7
- data/lib/3scale_toolbox/commands/import_command/openapi/create_activedocs_step.rb +4 -17
- data/lib/3scale_toolbox/commands/import_command/openapi/create_service_step.rb +1 -5
- data/lib/3scale_toolbox/commands/import_command/openapi/mapping_rule.rb +3 -2
- data/lib/3scale_toolbox/commands/import_command/openapi/step.rb +43 -5
- data/lib/3scale_toolbox/commands/import_command/openapi/update_policies_step.rb +9 -10
- data/lib/3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step.rb +2 -17
- data/lib/3scale_toolbox/commands/import_command/openapi/update_service_proxy_step.rb +10 -10
- 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/import/import_plan_limits_step.rb +11 -12
- data/lib/3scale_toolbox/commands/plans_command/import/import_plan_pricing_rules_step.rb +11 -12
- 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.rb +3 -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 +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 +32 -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 +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 +26 -0
- data/lib/3scale_toolbox/entities.rb +5 -0
- data/lib/3scale_toolbox/entities/application_plan.rb +31 -4
- 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 +53 -0
- data/lib/3scale_toolbox/helper.rb +20 -0
- data/lib/3scale_toolbox/openapi.rb +2 -0
- data/lib/3scale_toolbox/openapi/oas3.rb +232 -0
- data/lib/3scale_toolbox/openapi/swagger.rb +192 -0
- data/lib/3scale_toolbox/proxy_logger.rb +1 -1
- data/lib/3scale_toolbox/version.rb +1 -1
- data/licenses.xml +188 -18
- data/resources/oas3_meta_schema.json +1654 -0
- metadata +68 -28
- data/lib/3scale_toolbox/commands/copy_command/copy_service.rb +0 -144
- data/lib/3scale_toolbox/commands/import_command/openapi/threescale_api_spec.rb +0 -80
- data/lib/3scale_toolbox/swagger.rb +0 -1
- data/lib/3scale_toolbox/swagger/swagger.rb +0 -123
- 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 -12
- 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
data/lib/3scale_toolbox/tasks.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require '3scale_toolbox/tasks/copy_task'
|
2
|
-
require '3scale_toolbox/tasks/helper_task'
|
3
|
-
require '3scale_toolbox/tasks/copy_service_proxy_task'
|
4
|
-
require '3scale_toolbox/tasks/copy_metrics_task'
|
5
|
-
require '3scale_toolbox/tasks/copy_methods_task'
|
6
|
-
require '3scale_toolbox/tasks/copy_app_plans_task'
|
7
|
-
require '3scale_toolbox/tasks/copy_limits_task'
|
8
|
-
require '3scale_toolbox/tasks/destroy_mapping_rules_task'
|
9
|
-
require '3scale_toolbox/tasks/copy_mapping_rules_task'
|
10
|
-
require '3scale_toolbox/tasks/copy_service_settings_task'
|
11
|
-
require '3scale_toolbox/tasks/copy_policies_task'
|
12
|
-
require '3scale_toolbox/tasks/copy_pricingrules_task'
|
13
|
-
require '3scale_toolbox/tasks/delete_activedocs_task'
|
14
|
-
require '3scale_toolbox/tasks/copy_activedocs_task'
|
15
|
-
require '3scale_toolbox/tasks/bump_proxy_version_task'
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Tasks
|
3
|
-
class BumpProxyVersionTask
|
4
|
-
attr_reader :service
|
5
|
-
|
6
|
-
def initialize(service:)
|
7
|
-
@service = service
|
8
|
-
end
|
9
|
-
|
10
|
-
##
|
11
|
-
# bumps proxy config version to propagate proxy settings updates
|
12
|
-
def call
|
13
|
-
# Proxy update is the mechanism to increase version of the proxy,
|
14
|
-
# Hence propagating (mapping rules, poicies, oidc, auth) update to
|
15
|
-
# latest proxy config, making available to gateway.
|
16
|
-
|
17
|
-
# Currently it is done always because mapping rules, at least, are always created
|
18
|
-
# So they need to be propagated
|
19
|
-
proxy_settings = {
|
20
|
-
# Adding harmless attribute to avoid empty body
|
21
|
-
# update_proxy cannot be done with empty body
|
22
|
-
# and must be done to increase proxy version
|
23
|
-
# If proxy settings have not been changed since last update,
|
24
|
-
# this request will not have effect and proxy config version will not be bumped.
|
25
|
-
service_id: service.id
|
26
|
-
}
|
27
|
-
|
28
|
-
service.update_proxy proxy_settings
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Tasks
|
3
|
-
class CopyActiveDocsTask
|
4
|
-
include CopyTask
|
5
|
-
|
6
|
-
def call
|
7
|
-
puts 'copying all service ActiveDocs'
|
8
|
-
|
9
|
-
source.activedocs.each(&method(:apply_target_activedoc))
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def apply_target_activedoc(attrs)
|
15
|
-
activedocs = Entities::ActiveDocs.find_by_system_name(remote: target.remote,
|
16
|
-
system_name: attrs['system_name'])
|
17
|
-
if activedocs.nil?
|
18
|
-
Entities::ActiveDocs.create(remote: target.remote, attrs: create_attrs(attrs))
|
19
|
-
elsif activedocs.attrs.fetch('service_id') == target.id
|
20
|
-
activedocs.update(update_attrs(attrs))
|
21
|
-
else
|
22
|
-
# activedocs with same system_name exists, but now owned by target service
|
23
|
-
new_attrs = create_attrs(attrs)
|
24
|
-
new_attrs['system_name'] = "#{attrs['system_name']}#{target.id}"
|
25
|
-
Entities::ActiveDocs.create(remote: target.remote, attrs: new_attrs)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def update_attrs(old_attrs)
|
30
|
-
create_attrs(old_attrs)
|
31
|
-
end
|
32
|
-
|
33
|
-
def create_attrs(old_attrs)
|
34
|
-
# keep same system_name
|
35
|
-
new_attrs = old_attrs.reject { |key, _| %w[id created_at updated_at].include? key }
|
36
|
-
new_attrs.tap do |attrs|
|
37
|
-
attrs['service_id'] = target.id
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Tasks
|
3
|
-
class CopyApplicationPlansTask
|
4
|
-
include CopyTask
|
5
|
-
|
6
|
-
def call
|
7
|
-
source_plans = source.plans
|
8
|
-
target_plans = target.plans
|
9
|
-
missing_plans = missing_app_plans(source_plans, target_plans)
|
10
|
-
missing_plans.each do |plan|
|
11
|
-
plan.delete('links')
|
12
|
-
plan.delete('default') # TODO: handle default plan
|
13
|
-
if plan.delete('custom') # TODO: what to do with custom plans?
|
14
|
-
puts "skipping custom plan #{plan}"
|
15
|
-
else
|
16
|
-
ThreeScaleToolbox::Entities::ApplicationPlan.create(service: target, plan_attrs: plan)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
puts "target service missing #{missing_plans.size} application plans"
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def missing_app_plans(source_plans, target_plans)
|
25
|
-
ThreeScaleToolbox::Helper.array_difference(source_plans, target_plans) do |src, target|
|
26
|
-
ThreeScaleToolbox::Helper.compare_hashes(src, target, ['system_name'])
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -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,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
|