3scale_toolbox 0.17.1 → 0.18.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 +6 -3
- data/lib/3scale_toolbox.rb +3 -0
- data/lib/3scale_toolbox/3scale_client_factory.rb +3 -4
- data/lib/3scale_toolbox/commands.rb +2 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_mapping_rules_task.rb +11 -27
- data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb +5 -10
- data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_metrics_task.rb +4 -4
- data/lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb +3 -2
- data/lib/3scale_toolbox/commands/backend_command/copy_command/task.rb +10 -32
- data/lib/3scale_toolbox/commands/import_command/issuer_type_transformer.rb +16 -0
- data/lib/3scale_toolbox/commands/import_command/openapi.rb +3 -0
- 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 +3 -12
- 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 +2 -4
- data/lib/3scale_toolbox/commands/methods_command/create_command.rb +0 -2
- data/lib/3scale_toolbox/commands/methods_command/delete_command.rb +1 -1
- data/lib/3scale_toolbox/commands/methods_command/list_command.rb +1 -9
- data/lib/3scale_toolbox/commands/metrics_command/list_command.rb +1 -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 +7 -8
- 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 +8 -15
- data/lib/3scale_toolbox/commands/plans_command/import/step.rb +2 -22
- data/lib/3scale_toolbox/commands/plans_command/list_command.rb +1 -1
- data/lib/3scale_toolbox/commands/plans_command/show_command.rb +1 -1
- 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 +4 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command.rb +7 -3
- data/lib/3scale_toolbox/commands/product_command/copy_command/copy_backends_task.rb +22 -5
- 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 +2 -0
- data/lib/3scale_toolbox/commands/proxy_config_command/deploy_command.rb +54 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_activedocs_task.rb +15 -12
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb +15 -15
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb +12 -13
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb +11 -11
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_methods_task.rb +8 -9
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_metrics_task.rb +8 -8
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_policies_task.rb +1 -1
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_pricingrules_task.rb +15 -18
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_service_proxy_task.rb +2 -2
- data/lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb +2 -1
- data/lib/3scale_toolbox/commands/service_command/copy_command/destroy_mapping_rules_task.rb +9 -5
- data/lib/3scale_toolbox/commands/service_command/copy_command/task.rb +20 -34
- data/lib/3scale_toolbox/commands/update_command/service_command/delete_activedocs_task.rb +1 -3
- 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 +3 -0
- data/lib/3scale_toolbox/entities/activedocs.rb +12 -0
- data/lib/3scale_toolbox/entities/application_plan.rb +54 -46
- data/lib/3scale_toolbox/entities/backend.rb +65 -30
- data/lib/3scale_toolbox/entities/backend_mapping_rule.rb +29 -3
- data/lib/3scale_toolbox/entities/backend_method.rb +25 -16
- data/lib/3scale_toolbox/entities/backend_metric.rb +12 -2
- data/lib/3scale_toolbox/entities/backend_usage.rb +7 -1
- 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 +149 -46
- data/lib/3scale_toolbox/helper.rb +13 -16
- data/lib/3scale_toolbox/proxy_logger.rb +4 -0
- 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 +58 -50
- metadata +33 -6
|
@@ -7,29 +7,28 @@ module ThreeScaleToolbox
|
|
|
7
7
|
|
|
8
8
|
def call
|
|
9
9
|
plan_mapping = Helper.application_plan_mapping(source.plans, target.plans)
|
|
10
|
-
plan_mapping.each do |
|
|
11
|
-
|
|
12
|
-
target_plan = ThreeScaleToolbox::Entities::ApplicationPlan.new(id: target_plan['id'], service: target)
|
|
13
|
-
missing_limits = missing_limits(source_plan.limits, target_plan.limits, metrics_map)
|
|
10
|
+
plan_mapping.each do |source_plan, target_plan|
|
|
11
|
+
missing_limits = compute_missing_limits(source_plan.limits, target_plan.limits)
|
|
14
12
|
missing_limits.each do |limit|
|
|
15
|
-
limit.
|
|
16
|
-
target_plan.create_limit(metrics_map.fetch(limit.fetch('metric_id')), limit)
|
|
13
|
+
target_plan.create_limit(metrics_map.fetch(limit.metric_id), limit.attrs)
|
|
17
14
|
end
|
|
18
|
-
|
|
19
|
-
"#{target_plan.id}. Source plan #{
|
|
15
|
+
logger.info "Missing #{missing_limits.size} plan limits from target application plan " \
|
|
16
|
+
"#{target_plan.id}. Source plan #{source_plan.id}"
|
|
17
|
+
|
|
18
|
+
plans_report[target_plan.system_name] = {'application_plan_id' => target_plan.id} unless plans_report.has_key? target_plan.system_name
|
|
19
|
+
plans_report[target_plan.system_name].merge!({'missing_limits_created' => missing_limits.size})
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
private
|
|
24
24
|
|
|
25
25
|
def metrics_map
|
|
26
|
-
@metrics_map ||=
|
|
26
|
+
@metrics_map ||= source.metrics_mapping(target)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
def
|
|
30
|
-
ThreeScaleToolbox::Helper.array_difference(source_limits, target_limits) do |limit,
|
|
31
|
-
|
|
32
|
-
metrics_map.fetch(limit.fetch('metric_id')) == target.fetch('metric_id')
|
|
29
|
+
def compute_missing_limits(source_limits, target_limits)
|
|
30
|
+
ThreeScaleToolbox::Helper.array_difference(source_limits, target_limits) do |limit, target_limit|
|
|
31
|
+
limit.period == target_limit.period && metrics_map.fetch(limit.metric_id) == target_limit.metric_id
|
|
33
32
|
end
|
|
34
33
|
end
|
|
35
34
|
end
|
|
@@ -6,26 +6,26 @@ module ThreeScaleToolbox
|
|
|
6
6
|
include Task
|
|
7
7
|
|
|
8
8
|
def call
|
|
9
|
-
missing_rules = missing_mapping_rules(source.mapping_rules,
|
|
10
|
-
target.mapping_rules, metrics_map)
|
|
11
9
|
missing_rules.each do |mapping_rule|
|
|
12
|
-
mapping_rule.
|
|
13
|
-
|
|
14
|
-
target.create_mapping_rule mapping_rule
|
|
10
|
+
mr_attrs = mapping_rule.attrs.merge('metric_id' => metrics_map.fetch(mapping_rule.metric_id))
|
|
11
|
+
Entities::MappingRule.create(service: target, attrs: mr_attrs)
|
|
15
12
|
end
|
|
16
|
-
|
|
13
|
+
logger.info "created #{missing_rules.size} mapping rules"
|
|
14
|
+
report['missing_mapping_rules_created'] = missing_rules.size
|
|
17
15
|
end
|
|
18
16
|
|
|
19
17
|
private
|
|
20
18
|
|
|
21
19
|
def metrics_map
|
|
22
|
-
@metrics_map ||=
|
|
20
|
+
@metrics_map ||= source.metrics_mapping(target)
|
|
23
21
|
end
|
|
24
22
|
|
|
25
|
-
def
|
|
26
|
-
ThreeScaleToolbox::Helper.array_difference(
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
def missing_rules
|
|
24
|
+
@missing_rules ||= ThreeScaleToolbox::Helper.array_difference(source.mapping_rules, target.mapping_rules) do |source_rule, target_rule|
|
|
25
|
+
source_rule.pattern == target_rule.pattern &&
|
|
26
|
+
source_rule.http_method == target_rule.http_method &&
|
|
27
|
+
source_rule.delta == target_rule.delta &&
|
|
28
|
+
metrics_map.fetch(source_rule.metric_id) == target_rule.metric_id
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
end
|
|
@@ -6,11 +6,11 @@ module ThreeScaleToolbox
|
|
|
6
6
|
include Task
|
|
7
7
|
|
|
8
8
|
def call
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
logger.info "original service hits metric #{source.hits.id} has #{source.methods.size} methods"
|
|
10
|
+
logger.info "target service hits metric #{target.hits.id} has #{target.methods.size} methods"
|
|
11
11
|
missing_methods.each(&method(:create_method))
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
logger.info "created #{missing_methods.size} missing methods on target service"
|
|
13
|
+
report['missing_methods_created'] = missing_methods.size
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
private
|
|
@@ -18,19 +18,18 @@ module ThreeScaleToolbox
|
|
|
18
18
|
def create_method(method)
|
|
19
19
|
Entities::Method.create(
|
|
20
20
|
service: target,
|
|
21
|
-
|
|
22
|
-
attrs: ThreeScaleToolbox::Helper.filter_params(%w[friendly_name system_name], method)
|
|
21
|
+
attrs: ThreeScaleToolbox::Helper.filter_params(%w[friendly_name system_name], method.attrs)
|
|
23
22
|
)
|
|
24
23
|
rescue ThreeScaleToolbox::ThreeScaleApiError => e
|
|
25
24
|
raise e unless ThreeScaleToolbox::Helper.system_name_already_taken_error?(e.apierrors)
|
|
26
25
|
|
|
27
|
-
warn "[WARN] method #{method.
|
|
26
|
+
warn "[WARN] method #{method.system_name} not created. " \
|
|
28
27
|
'Metric with the same system_name exists.'
|
|
29
28
|
end
|
|
30
29
|
|
|
31
30
|
def missing_methods
|
|
32
|
-
@missing_methods ||= ThreeScaleToolbox::Helper.array_difference(
|
|
33
|
-
|
|
31
|
+
@missing_methods ||= ThreeScaleToolbox::Helper.array_difference(source.methods, target.methods) do |method, target|
|
|
32
|
+
method.system_name == target.system_name
|
|
34
33
|
end
|
|
35
34
|
end
|
|
36
35
|
end
|
|
@@ -6,28 +6,28 @@ module ThreeScaleToolbox
|
|
|
6
6
|
include Task
|
|
7
7
|
|
|
8
8
|
def call
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
logger.info "original service has #{source.metrics.size} metrics"
|
|
10
|
+
logger.info "target service has #{target.metrics.size} metrics"
|
|
11
11
|
missing_metrics.each(&method(:create_metric))
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
logger.info "created #{missing_metrics.size} metrics on the target service"
|
|
13
|
+
report['missing_metrics_created'] = missing_metrics.size
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
private
|
|
17
17
|
|
|
18
18
|
def create_metric(metric)
|
|
19
|
-
new_metric = metric.reject { |key, _| %w[id links].include? key }
|
|
19
|
+
new_metric = metric.attrs.reject { |key, _| %w[id links].include? key }
|
|
20
20
|
Entities::Metric.create(service: target, attrs: new_metric)
|
|
21
21
|
rescue ThreeScaleToolbox::ThreeScaleApiError => e
|
|
22
22
|
raise e unless ThreeScaleToolbox::Helper.system_name_already_taken_error?(e.apierrors)
|
|
23
23
|
|
|
24
|
-
warn "[WARN] metric #{metric.
|
|
24
|
+
warn "[WARN] metric #{metric.system_name} not created. " \
|
|
25
25
|
'Method with the same system_name exists.'
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def missing_metrics
|
|
29
|
-
@missing_metrics ||= ThreeScaleToolbox::Helper.array_difference(
|
|
30
|
-
|
|
29
|
+
@missing_metrics ||= ThreeScaleToolbox::Helper.array_difference(source.metrics, target.metrics) do |s_m, t_m|
|
|
30
|
+
s_m.system_name == t_m.system_name
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
end
|
|
@@ -7,34 +7,31 @@ module ThreeScaleToolbox
|
|
|
7
7
|
|
|
8
8
|
def call
|
|
9
9
|
plan_mapping = Helper.application_plan_mapping(source.plans, target.plans)
|
|
10
|
-
plan_mapping.each do |
|
|
11
|
-
|
|
12
|
-
pricing_rules_target = target.remote.list_pricingrules_per_application_plan(target_plan['id'])
|
|
13
|
-
missing_pricing_rules = missing_pricing_rules(pricing_rules_source, pricing_rules_target,
|
|
14
|
-
metrics_map)
|
|
10
|
+
plan_mapping.each do |source_plan, target_plan|
|
|
11
|
+
missing_pricing_rules = compute_missing_pricing_rules(source_plan.pricing_rules, target_plan.pricing_rules)
|
|
15
12
|
missing_pricing_rules.each do |pricing_rule|
|
|
16
|
-
pricing_rule.
|
|
17
|
-
target.remote.create_pricingrule(
|
|
18
|
-
target_plan['id'],
|
|
19
|
-
metrics_map.fetch(pricing_rule['metric_id']),
|
|
20
|
-
pricing_rule
|
|
21
|
-
)
|
|
13
|
+
target_plan.create_pricing_rule(metrics_map.fetch(pricing_rule.metric_id), pricing_rule.attrs)
|
|
22
14
|
end
|
|
23
|
-
|
|
24
|
-
"#{target_plan
|
|
15
|
+
logger.info "Missing #{missing_pricing_rules.size} pricing rules from target application plan " \
|
|
16
|
+
"#{target_plan.id}. Source plan #{source_plan.id}"
|
|
17
|
+
|
|
18
|
+
plans_report[target_plan.system_name] = {'application_plan_id' => target_plan.id} unless plans_report.has_key? target_plan.system_name
|
|
19
|
+
plans_report[target_plan.system_name].merge!({'missing_pricing_rules_created' => missing_pricing_rules.size})
|
|
25
20
|
end
|
|
26
21
|
end
|
|
27
22
|
|
|
28
23
|
private
|
|
29
24
|
|
|
30
25
|
def metrics_map
|
|
31
|
-
@metrics_map ||=
|
|
26
|
+
@metrics_map ||= source.metrics_mapping(target)
|
|
32
27
|
end
|
|
33
28
|
|
|
34
|
-
def
|
|
35
|
-
ThreeScaleToolbox::Helper.array_difference(source_pricing_rules, target_pricing_rules) do |src,
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
def compute_missing_pricing_rules(source_pricing_rules, target_pricing_rules)
|
|
30
|
+
ThreeScaleToolbox::Helper.array_difference(source_pricing_rules, target_pricing_rules) do |src, target_pr|
|
|
31
|
+
src.cost_per_unit == target_pr.cost_per_unit &&
|
|
32
|
+
src.min == target_pr.min &&
|
|
33
|
+
src.max == target_pr.max &&
|
|
34
|
+
metrics_map.fetch(src.metric_id) == target_pr.metric_id
|
|
38
35
|
end
|
|
39
36
|
end
|
|
40
37
|
end
|
|
@@ -8,12 +8,12 @@ module ThreeScaleToolbox
|
|
|
8
8
|
def call
|
|
9
9
|
target.update_proxy target_proxy_attrs
|
|
10
10
|
target.update_oidc source.oidc if source.attrs['backend_version'] == 'oidc'
|
|
11
|
-
|
|
11
|
+
logger.info "updated proxy of #{target.id} to match the original"
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def target_proxy_attrs
|
|
15
15
|
if source.attrs['deployment_option'] == 'hosted'
|
|
16
|
-
# For services with "hosted" deployment config,
|
|
16
|
+
# For services with "hosted" deployment config,
|
|
17
17
|
# "Public Base URL" should not be copied, mainly because public base URL is self-assigned.
|
|
18
18
|
# Two 3scale products (aka services) cannot be served using the same public base URL.
|
|
19
19
|
source_proxy.dup.delete_if { |key, _v| %w[endpoint sandbox_endpoint].include? key }
|
data/lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb
CHANGED
|
@@ -25,7 +25,8 @@ module ThreeScaleToolbox
|
|
|
25
25
|
# assign target service for other tasks to have it available
|
|
26
26
|
self.target = service
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
logger.info "new service id #{service.id}"
|
|
29
|
+
report['product_id'] = service.id
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
private
|
|
@@ -12,10 +12,8 @@ module ThreeScaleToolbox
|
|
|
12
12
|
def call
|
|
13
13
|
return unless delete_mapping_rules
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
target.mapping_rules.each
|
|
17
|
-
target.delete_mapping_rule mapping_rule['id']
|
|
18
|
-
end
|
|
15
|
+
logger.info 'destroying all mapping rules'
|
|
16
|
+
target.mapping_rules.each(&:delete)
|
|
19
17
|
end
|
|
20
18
|
|
|
21
19
|
private
|
|
@@ -25,7 +23,13 @@ module ThreeScaleToolbox
|
|
|
25
23
|
end
|
|
26
24
|
|
|
27
25
|
def target
|
|
28
|
-
context
|
|
26
|
+
context.fetch(:target)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def logger
|
|
30
|
+
context[:logger] ||= Logger.new($stdout).tap do |logger|
|
|
31
|
+
logger.formatter = proc { |severity, datetime, progname, msg| "#{msg}\n" }
|
|
32
|
+
end
|
|
29
33
|
end
|
|
30
34
|
end
|
|
31
35
|
end
|
|
@@ -36,44 +36,12 @@ module ThreeScaleToolbox
|
|
|
36
36
|
context[:delete_mapping_rules] = true
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
def source_metrics
|
|
40
|
-
context[:source_metrics] ||= source.metrics
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def source_hits
|
|
44
|
-
context[:source_hits] ||= source.hits
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def source_methods
|
|
48
|
-
context[:source_methods] ||= source.methods(source_hits.fetch('id'))
|
|
49
|
-
end
|
|
50
|
-
|
|
51
39
|
def source_metrics_and_methods
|
|
52
|
-
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def target_metrics
|
|
56
|
-
context[:target_metrics] ||= target.metrics
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def target_hits
|
|
60
|
-
context[:target_hits] ||= target.hits
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def target_methods
|
|
64
|
-
context[:target_methods] ||= target.methods(target_hits.fetch('id'))
|
|
40
|
+
source.metrics + source.methods
|
|
65
41
|
end
|
|
66
42
|
|
|
67
43
|
def target_metrics_and_methods
|
|
68
|
-
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def invalidate_target_methods
|
|
72
|
-
context[:target_methods] = nil
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def invalidate_target_metrics
|
|
76
|
-
context[:target_metrics] = nil
|
|
44
|
+
target.metrics + target.methods
|
|
77
45
|
end
|
|
78
46
|
|
|
79
47
|
def source_remote
|
|
@@ -92,6 +60,24 @@ module ThreeScaleToolbox
|
|
|
92
60
|
def option_target_system_name
|
|
93
61
|
context[:option_target_system_name]
|
|
94
62
|
end
|
|
63
|
+
|
|
64
|
+
def logger
|
|
65
|
+
context[:logger] ||= Logger.new($stdout).tap do |logger|
|
|
66
|
+
logger.formatter = proc { |severity, datetime, progname, msg| "#{msg}\n" }
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def plans_report
|
|
71
|
+
report['application_plans'] ||= {}
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def activedocs_report
|
|
75
|
+
report['activedocs'] ||= {}
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def report
|
|
79
|
+
context[:report] ||= {}
|
|
80
|
+
end
|
|
95
81
|
end
|
|
96
82
|
end
|
|
97
83
|
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require '3scale_toolbox/crds/application_plan_dump'
|
|
2
|
+
require '3scale_toolbox/crds/backend_method_dump'
|
|
3
|
+
require '3scale_toolbox/crds/backend_mapping_rule_dump'
|
|
4
|
+
require '3scale_toolbox/crds/backend_metric_dump'
|
|
5
|
+
require '3scale_toolbox/crds/backend_dump'
|
|
6
|
+
require '3scale_toolbox/crds/backend_usage_dump'
|
|
7
|
+
require '3scale_toolbox/crds/limit_dump'
|
|
8
|
+
require '3scale_toolbox/crds/mapping_rule_dump'
|
|
9
|
+
require '3scale_toolbox/crds/method_dump'
|
|
10
|
+
require '3scale_toolbox/crds/metric_dump'
|
|
11
|
+
require '3scale_toolbox/crds/pricing_rule_dump'
|
|
12
|
+
require '3scale_toolbox/crds/product_dump'
|
|
13
|
+
require '3scale_toolbox/crds/product_deployment_parser'
|
|
14
|
+
require '3scale_toolbox/crds/backend_parser'
|
|
15
|
+
require '3scale_toolbox/crds/product_parser'
|
|
16
|
+
require '3scale_toolbox/crds/remote'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module ThreeScaleToolbox
|
|
2
|
+
module CRD
|
|
3
|
+
module ApplicationPlanSerializer
|
|
4
|
+
def to_cr
|
|
5
|
+
{
|
|
6
|
+
'name' => name,
|
|
7
|
+
'appsRequireApproval' => approval_required?,
|
|
8
|
+
'trialPeriod' => trial_period_days,
|
|
9
|
+
'setupFee' => setup_fee,
|
|
10
|
+
'custom' => custom,
|
|
11
|
+
'state' => state,
|
|
12
|
+
'costMonth' => cost_per_month,
|
|
13
|
+
'pricingRules' => pricing_rules.map(&:to_cr),
|
|
14
|
+
'limits' => limits.map(&:to_cr)
|
|
15
|
+
}
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module ThreeScaleToolbox
|
|
2
|
+
module CRD
|
|
3
|
+
module BackendSerializer
|
|
4
|
+
def to_cr
|
|
5
|
+
{
|
|
6
|
+
'apiVersion' => 'capabilities.3scale.net/v1beta1',
|
|
7
|
+
'kind' => 'Backend',
|
|
8
|
+
'metadata' => {
|
|
9
|
+
'annotations' => {
|
|
10
|
+
'3scale_toolbox_created_at' => Time.now.utc.iso8601,
|
|
11
|
+
'3scale_toolbox_version' => ThreeScaleToolbox::VERSION
|
|
12
|
+
},
|
|
13
|
+
'name' => cr_name
|
|
14
|
+
},
|
|
15
|
+
'spec' => {
|
|
16
|
+
'name' => name,
|
|
17
|
+
'systemName' => system_name,
|
|
18
|
+
'privateBaseURL' => private_endpoint,
|
|
19
|
+
'description' => description,
|
|
20
|
+
'mappingRules' => mapping_rules.map(&:to_cr),
|
|
21
|
+
'metrics' => metrics.each_with_object({}) do |metric, hash|
|
|
22
|
+
hash[metric.system_name] = metric.to_cr
|
|
23
|
+
end,
|
|
24
|
+
'methods' => methods.each_with_object({}) do |method, hash|
|
|
25
|
+
hash[method.system_name] = method.to_cr
|
|
26
|
+
end
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def cr_name
|
|
32
|
+
# Should be DNS1123 subdomain name
|
|
33
|
+
# TODO run validation for DNS1123
|
|
34
|
+
# https://kubernetes.io/docs/concepts/overview/working-with-objects/names/
|
|
35
|
+
"#{system_name.gsub(/[^[a-zA-Z0-9\-\.]]/, '.')}.#{Helper.random_lowercase_name}"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module ThreeScaleToolbox
|
|
2
|
+
module CRD
|
|
3
|
+
module BackendMappingRuleSerializer
|
|
4
|
+
def to_cr
|
|
5
|
+
{
|
|
6
|
+
'httpMethod' => http_method,
|
|
7
|
+
'pattern' => pattern,
|
|
8
|
+
'metricMethodRef' => metric_method_ref,
|
|
9
|
+
'increment' => delta,
|
|
10
|
+
'last' => last,
|
|
11
|
+
}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def metric_method_ref
|
|
15
|
+
if (method = backend.methods.find { |m| m.id == metric_id })
|
|
16
|
+
method.system_name
|
|
17
|
+
elsif (metric = backend.metrics.find { |m| m.id == metric_id })
|
|
18
|
+
metric.system_name
|
|
19
|
+
else
|
|
20
|
+
raise ThreeScaleToolbox::Error, "Unexpected error. Backend #{backend.system_name} " \
|
|
21
|
+
"mapping rule #{id} referencing to metric id #{metric_id} which has not been found"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|