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,4 +1,4 @@
|
|
1
|
-
require '3scale_toolbox/commands/update_command/
|
1
|
+
require '3scale_toolbox/commands/update_command/service_command'
|
2
2
|
|
3
3
|
module ThreeScaleToolbox
|
4
4
|
module Commands
|
@@ -8,7 +8,7 @@ module ThreeScaleToolbox
|
|
8
8
|
Cri::Command.define do
|
9
9
|
name 'update'
|
10
10
|
usage 'update <sub-command> [options]'
|
11
|
-
summary '[
|
11
|
+
summary '[DEPRECATED] update super command'
|
12
12
|
description 'Update 3scale entities between tenants'
|
13
13
|
|
14
14
|
run do |_opts, _args, cmd|
|
@@ -16,7 +16,7 @@ module ThreeScaleToolbox
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
-
add_subcommand(
|
19
|
+
add_subcommand(ServiceSubcommand)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -1,16 +1,19 @@
|
|
1
|
+
require '3scale_toolbox/commands/update_command/service_command/delete_activedocs_task'
|
2
|
+
require '3scale_toolbox/commands/update_command/service_command/copy_service_settings_task'
|
3
|
+
|
1
4
|
module ThreeScaleToolbox
|
2
5
|
module Commands
|
3
6
|
module UpdateCommand
|
4
|
-
class
|
7
|
+
class ServiceSubcommand < Cri::CommandRunner
|
5
8
|
include ThreeScaleToolbox::Command
|
6
9
|
|
7
10
|
def self.command
|
8
11
|
Cri::Command.define do
|
9
12
|
name 'service'
|
10
13
|
usage 'service [opts] -s <src> -d <dst> <src_service_id> <dst_service_id>'
|
11
|
-
summary '[
|
14
|
+
summary '[DEPRECATED] update service'
|
12
15
|
description <<-HEREDOC
|
13
|
-
This command has been deprecated. Use '3scale copy
|
16
|
+
This command has been deprecated. Use '3scale service copy' instead.
|
14
17
|
\n Update existing service, update proxy settings, metrics, methods, application plans and mapping rules.'
|
15
18
|
HEREDOC
|
16
19
|
|
@@ -22,11 +25,12 @@ module ThreeScaleToolbox
|
|
22
25
|
param :src_service_id
|
23
26
|
param :dst_service_id
|
24
27
|
|
25
|
-
runner
|
28
|
+
runner ServiceSubcommand
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
29
32
|
def run
|
33
|
+
warn "\e[1m\e[31mThis command has been deprecated. Use '3scale service copy' instead\e[0m"
|
30
34
|
source_service = Entities::Service.new(
|
31
35
|
id: arguments[:src_service_id],
|
32
36
|
remote: threescale_client(fetch_required_option(:source))
|
@@ -35,28 +39,27 @@ module ThreeScaleToolbox
|
|
35
39
|
id: arguments[:dst_service_id],
|
36
40
|
remote: threescale_client(fetch_required_option(:destination))
|
37
41
|
)
|
38
|
-
system_name = options[:target_system_name]
|
39
42
|
context = create_context(source_service, update_service)
|
40
43
|
|
41
44
|
tasks = []
|
42
45
|
unless options[:'rules-only']
|
43
|
-
tasks <<
|
44
|
-
tasks <<
|
45
|
-
tasks <<
|
46
|
-
tasks <<
|
47
|
-
tasks <<
|
48
|
-
tasks <<
|
49
|
-
tasks <<
|
50
|
-
tasks <<
|
51
|
-
tasks <<
|
46
|
+
tasks << ServiceCommand::CopyServiceSettingsTask.new(context)
|
47
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CopyMethodsTask.new(context)
|
48
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CopyMetricsTask.new(context)
|
49
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CopyApplicationPlansTask.new(context)
|
50
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CopyLimitsTask.new(context)
|
51
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CopyPoliciesTask.new(context)
|
52
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CopyPricingRulesTask.new(context)
|
53
|
+
tasks << ServiceCommand::DeleteActiveDocsTask.new(context)
|
54
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CopyActiveDocsTask.new(context)
|
52
55
|
# Copy proxy must be the last task
|
53
56
|
# Proxy update is the mechanism to increase version of the proxy,
|
54
57
|
# Hence propagating (mapping rules, poicies, oidc, auth) update to
|
55
58
|
# latest proxy config, making available to gateway.
|
56
|
-
tasks <<
|
59
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CopyServiceProxyTask.new(context)
|
57
60
|
end
|
58
|
-
tasks <<
|
59
|
-
tasks <<
|
61
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::DestroyMappingRulesTask.new(context)
|
62
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::CopyMappingRulesTask.new(context)
|
60
63
|
|
61
64
|
# run tasks
|
62
65
|
tasks.each(&:call)
|
@@ -67,7 +70,8 @@ module ThreeScaleToolbox
|
|
67
70
|
def create_context(source, target)
|
68
71
|
{
|
69
72
|
source: source,
|
70
|
-
target: target
|
73
|
+
target: target,
|
74
|
+
delete_mapping_rules: options[:force]
|
71
75
|
}
|
72
76
|
end
|
73
77
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module Commands
|
3
|
+
module UpdateCommand
|
4
|
+
module ServiceCommand
|
5
|
+
class CopyServiceSettingsTask
|
6
|
+
attr_reader :context
|
7
|
+
|
8
|
+
def initialize(context)
|
9
|
+
@context = context
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
target.update source_attrs
|
14
|
+
|
15
|
+
puts "updated service settings for service id #{source.id}..."
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def source
|
21
|
+
context[:source]
|
22
|
+
end
|
23
|
+
|
24
|
+
def target
|
25
|
+
context[:target]
|
26
|
+
end
|
27
|
+
|
28
|
+
def source_attrs
|
29
|
+
source.attrs.reject { |k, _| %w[system_name id links].include? k }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module Commands
|
3
|
+
module UpdateCommand
|
4
|
+
module ServiceCommand
|
5
|
+
class DeleteActiveDocsTask
|
6
|
+
attr_reader :context
|
7
|
+
|
8
|
+
def initialize(context)
|
9
|
+
@context = context
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
puts 'deleting all target service ActiveDocs'
|
14
|
+
target.activedocs.each(&:delete)
|
15
|
+
end
|
16
|
+
|
17
|
+
def target
|
18
|
+
context[:target]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
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
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module CRD
|
3
|
+
class BackendParser
|
4
|
+
Metric = Struct.new(:system_name, :friendly_name, :description, :unit)
|
5
|
+
Method = Struct.new(:system_name, :friendly_name, :description)
|
6
|
+
MappingRule = Struct.new(:metric_ref, :http_method, :pattern, :delta, :last)
|
7
|
+
|
8
|
+
attr_reader :cr
|
9
|
+
|
10
|
+
def initialize(cr)
|
11
|
+
@cr = cr
|
12
|
+
end
|
13
|
+
|
14
|
+
def system_name
|
15
|
+
cr.dig('spec', 'systemName')
|
16
|
+
end
|
17
|
+
|
18
|
+
def name
|
19
|
+
cr.dig('spec', 'name')
|
20
|
+
end
|
21
|
+
|
22
|
+
def description
|
23
|
+
cr.dig('spec', 'description')
|
24
|
+
end
|
25
|
+
|
26
|
+
def private_endpoint
|
27
|
+
cr.dig('spec', 'privateBaseURL')
|
28
|
+
end
|
29
|
+
|
30
|
+
def metrics
|
31
|
+
@metrics ||= (cr.dig('spec', 'metrics') || {}).map do |system_name, metric|
|
32
|
+
Metric.new(system_name, metric['friendlyName'], metric['description'], metric['unit'])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def methods
|
37
|
+
@methods ||= (cr.dig('spec', 'methods') || {}).map do |system_name, method|
|
38
|
+
Method.new(system_name, method['friendlyName'], method['description'])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def mapping_rules
|
43
|
+
@mapping_rules ||= (cr.dig('spec', 'mappingRules') || []).map do |mapping_rule|
|
44
|
+
MappingRule.new(mapping_rule['metricMethodRef'], mapping_rule['httpMethod'],
|
45
|
+
mapping_rule['pattern'], mapping_rule['increment'], mapping_rule['last'])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Metrics and methods index by system_name
|
50
|
+
def metrics_index
|
51
|
+
@metrics_index ||= (methods + metrics).each_with_object({}) { |metric, h| h[metric.system_name] = metric }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module CRD
|
3
|
+
module Limit
|
4
|
+
def to_cr
|
5
|
+
{
|
6
|
+
'period' => period,
|
7
|
+
'value' => value,
|
8
|
+
'metricMethodRef' => metric_system_name,
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def metric_system_name
|
13
|
+
# Find in service methods
|
14
|
+
# Find in service metrics
|
15
|
+
# Find in backend methods
|
16
|
+
# Find in backend metrics
|
17
|
+
if (method = plan.service.methods.find { |m| m.id == metric_id })
|
18
|
+
{ 'systemName' => method.system_name }
|
19
|
+
elsif (metric = plan.service.metrics.find { |m| m.id == metric_id })
|
20
|
+
{ 'systemName' => metric.system_name }
|
21
|
+
elsif (backend = backend_from_metric)
|
22
|
+
if (backend_metric = backend.metrics.find { |m| m.id == metric_id })
|
23
|
+
{ 'systemName' => backend_metric.system_name, 'backend' => backend.system_name }
|
24
|
+
elsif (backend_method = backend.methods.find { |m| m.id == metric_id })
|
25
|
+
{ 'systemName' => backend_method.system_name, 'backend' => backend.system_name }
|
26
|
+
else
|
27
|
+
raise ThreeScaleToolbox::Error, "Unexpected error. Limit #{id} " \
|
28
|
+
"referencing to metric id #{metric_id} which has not been found"
|
29
|
+
end
|
30
|
+
else
|
31
|
+
raise ThreeScaleToolbox::Error, "Unexpected error. Limit #{id} " \
|
32
|
+
"referencing to metric id #{metric_id} which has not been found"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module CRD
|
3
|
+
module MappingRuleSerializer
|
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 = service.methods.find { |m| m.id == metric_id })
|
16
|
+
method.system_name
|
17
|
+
elsif (metric = service.metrics.find { |m| m.id == metric_id })
|
18
|
+
metric.system_name
|
19
|
+
else
|
20
|
+
raise ThreeScaleToolbox::Error, "Unexpected error. Service #{service.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
|