3scale_toolbox 0.18.3 → 0.19.3
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 +3 -3
- data/README.md +1 -2
- data/lib/3scale_toolbox/commands/backend_command/copy_command/delete_mapping_rules_task.rb +18 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/task.rb +4 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command.rb +4 -1
- data/lib/3scale_toolbox/commands/import_command/import_csv.rb +8 -8
- data/lib/3scale_toolbox/commands/import_command/openapi/create_activedocs_step.rb +1 -1
- data/lib/3scale_toolbox/commands/import_command/openapi/update_policies_step.rb +23 -10
- data/lib/3scale_toolbox/commands/import_command/openapi.rb +2 -0
- data/lib/3scale_toolbox/commands/plans_command/export_command.rb +52 -29
- data/lib/3scale_toolbox/commands/plans_command/import/import_backend_metrics_step.rb +37 -0
- data/lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb +11 -2
- data/lib/3scale_toolbox/commands/plans_command/import/import_plan_metrics_step.rb +2 -2
- data/lib/3scale_toolbox/commands/plans_command/import/import_plan_pricing_rules_step.rb +12 -1
- data/lib/3scale_toolbox/commands/plans_command/import/step.rb +23 -8
- data/lib/3scale_toolbox/commands/plans_command/import/validate_plan_step.rb +126 -0
- data/lib/3scale_toolbox/commands/plans_command/import_command.rb +5 -1
- data/lib/3scale_toolbox/commands/product_command/copy_command/copy_backends_task.rb +6 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command.rb +3 -2
- data/lib/3scale_toolbox/commands/product_command/import_command.rb +1 -0
- data/lib/3scale_toolbox/crds/limit_dump.rb +1 -1
- data/lib/3scale_toolbox/crds/pricing_rule_dump.rb +1 -1
- data/lib/3scale_toolbox/entities/application_plan.rb +64 -0
- data/lib/3scale_toolbox/entities/backend.rb +4 -0
- data/lib/3scale_toolbox/entities/backend_method.rb +16 -0
- data/lib/3scale_toolbox/entities/backend_metric.rb +16 -0
- data/lib/3scale_toolbox/entities/limit.rb +52 -7
- data/lib/3scale_toolbox/entities/method.rb +11 -0
- data/lib/3scale_toolbox/entities/metric.rb +12 -0
- data/lib/3scale_toolbox/entities/pricing_rule.rb +52 -7
- data/lib/3scale_toolbox/entities/service.rb +4 -0
- data/lib/3scale_toolbox/proxy_logger.rb +2 -0
- data/lib/3scale_toolbox/remote_cache.rb +49 -2
- data/lib/3scale_toolbox/version.rb +1 -1
- data/licenses.xml +15 -25
- metadata +8 -13
- data/lib/3scale_toolbox/commands/plans_command/export/read_app_plan_step.rb +0 -16
- data/lib/3scale_toolbox/commands/plans_command/export/read_plan_features_step.rb +0 -16
- data/lib/3scale_toolbox/commands/plans_command/export/read_plan_limits_step.rb +0 -19
- data/lib/3scale_toolbox/commands/plans_command/export/read_plan_methods_step.rb +0 -47
- data/lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb +0 -47
- data/lib/3scale_toolbox/commands/plans_command/export/read_plan_pricing_rules_step.rb +0 -19
- data/lib/3scale_toolbox/commands/plans_command/export/step.rb +0 -85
- data/lib/3scale_toolbox/commands/plans_command/export/write_artifacts_file_step.rb +0 -84
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 3scale_toolbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.19.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Miguel Soriano
|
8
8
|
- Eguzki Astiz Lezaun
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-10-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -139,7 +139,7 @@ dependencies:
|
|
139
139
|
version: '0.20'
|
140
140
|
description: 3scale tools to manage your API from the terminal.
|
141
141
|
email:
|
142
|
-
-
|
142
|
+
- msoriano@redhat.com
|
143
143
|
- eastizle@redhat.com
|
144
144
|
executables:
|
145
145
|
- 3scale
|
@@ -184,6 +184,7 @@ files:
|
|
184
184
|
- lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb
|
185
185
|
- lib/3scale_toolbox/commands/backend_command/copy_command/copy_metrics_task.rb
|
186
186
|
- lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb
|
187
|
+
- lib/3scale_toolbox/commands/backend_command/copy_command/delete_mapping_rules_task.rb
|
187
188
|
- lib/3scale_toolbox/commands/backend_command/copy_command/task.rb
|
188
189
|
- lib/3scale_toolbox/commands/copy_command.rb
|
189
190
|
- lib/3scale_toolbox/commands/copy_command/service_command.rb
|
@@ -217,21 +218,15 @@ files:
|
|
217
218
|
- lib/3scale_toolbox/commands/plans_command/apply_command.rb
|
218
219
|
- lib/3scale_toolbox/commands/plans_command/create_command.rb
|
219
220
|
- lib/3scale_toolbox/commands/plans_command/delete_command.rb
|
220
|
-
- lib/3scale_toolbox/commands/plans_command/export/read_app_plan_step.rb
|
221
|
-
- lib/3scale_toolbox/commands/plans_command/export/read_plan_features_step.rb
|
222
|
-
- lib/3scale_toolbox/commands/plans_command/export/read_plan_limits_step.rb
|
223
|
-
- lib/3scale_toolbox/commands/plans_command/export/read_plan_methods_step.rb
|
224
|
-
- lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb
|
225
|
-
- lib/3scale_toolbox/commands/plans_command/export/read_plan_pricing_rules_step.rb
|
226
|
-
- lib/3scale_toolbox/commands/plans_command/export/step.rb
|
227
|
-
- lib/3scale_toolbox/commands/plans_command/export/write_artifacts_file_step.rb
|
228
221
|
- lib/3scale_toolbox/commands/plans_command/export_command.rb
|
229
222
|
- lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
|
223
|
+
- lib/3scale_toolbox/commands/plans_command/import/import_backend_metrics_step.rb
|
230
224
|
- lib/3scale_toolbox/commands/plans_command/import/import_plan_features_step.rb
|
231
225
|
- lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb
|
232
226
|
- lib/3scale_toolbox/commands/plans_command/import/import_plan_metrics_step.rb
|
233
227
|
- lib/3scale_toolbox/commands/plans_command/import/import_plan_pricing_rules_step.rb
|
234
228
|
- lib/3scale_toolbox/commands/plans_command/import/step.rb
|
229
|
+
- lib/3scale_toolbox/commands/plans_command/import/validate_plan_step.rb
|
235
230
|
- lib/3scale_toolbox/commands/plans_command/import_command.rb
|
236
231
|
- lib/3scale_toolbox/commands/plans_command/list_command.rb
|
237
232
|
- lib/3scale_toolbox/commands/plans_command/show_command.rb
|
@@ -343,7 +338,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
343
338
|
requirements:
|
344
339
|
- - ">="
|
345
340
|
- !ruby/object:Gem::Version
|
346
|
-
version: '2.
|
341
|
+
version: '2.6'
|
347
342
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
348
343
|
requirements:
|
349
344
|
- - ">="
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Commands
|
3
|
-
module PlansCommand
|
4
|
-
module Export
|
5
|
-
class ReadPlanFeaturesStep
|
6
|
-
include Step
|
7
|
-
##
|
8
|
-
# Reads Application Plan features
|
9
|
-
def call
|
10
|
-
result[:plan_features] = plan.features
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Commands
|
3
|
-
module PlansCommand
|
4
|
-
module Export
|
5
|
-
class ReadPlanLimitsStep
|
6
|
-
include Step
|
7
|
-
##
|
8
|
-
# Reads Application Plan limits
|
9
|
-
# add metric system_name out of metric_id
|
10
|
-
def call
|
11
|
-
result[:limits] = plan.limits.map do |limit|
|
12
|
-
limit.attrs.merge('metric' => metric_info(limit, 'Limit'))
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Commands
|
3
|
-
module PlansCommand
|
4
|
-
module Export
|
5
|
-
class ReadPlanMethods
|
6
|
-
include Step
|
7
|
-
##
|
8
|
-
# Compute unique list of methods from limits and pricingrules
|
9
|
-
def call
|
10
|
-
methods = [
|
11
|
-
limit_methods,
|
12
|
-
pricingrule_methods
|
13
|
-
]
|
14
|
-
result[:plan_methods] = methods.each_with_object({}) { |elem, acc| acc.merge!(elem) }
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def limit_methods
|
20
|
-
# multiple limits can reference the same method
|
21
|
-
filtered_limit_methods.each_with_object({}) do |elem, acc|
|
22
|
-
# find_method should not return nil.
|
23
|
-
# It is assumed that metric_id refers to existing element from previous steps
|
24
|
-
acc[elem['metric_id']] = find_method(elem['metric_id']).attrs
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def filtered_limit_methods
|
29
|
-
result[:limits].select { |limit| limit.dig('metric', 'type') == 'method' }
|
30
|
-
end
|
31
|
-
|
32
|
-
def pricingrule_methods
|
33
|
-
filtered_pricing_rule_methods.each_with_object({}) do |elem, acc|
|
34
|
-
# find_method should not return nil.
|
35
|
-
# It is assumed that metric_id refers to existing element from previous steps
|
36
|
-
acc[elem['metric_id']] = find_method(elem['metric_id']).attrs
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def filtered_pricing_rule_methods
|
41
|
-
result[:pricingrules].select { |limit| limit.dig('metric', 'type') == 'method' }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Commands
|
3
|
-
module PlansCommand
|
4
|
-
module Export
|
5
|
-
class ReadPlanMetrics
|
6
|
-
include Step
|
7
|
-
##
|
8
|
-
# Compute unique list of metrics limits and pricingrules
|
9
|
-
def call
|
10
|
-
all_metrics = [
|
11
|
-
limit_metrics,
|
12
|
-
pricingrule_metrics
|
13
|
-
]
|
14
|
-
result[:plan_metrics] = all_metrics.each_with_object({}) { |elem, acc| acc.merge!(elem) }
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def limit_metrics
|
20
|
-
# multiple limits can reference the same metric
|
21
|
-
filtered_limit_metrics.each_with_object({}) do |elem, acc|
|
22
|
-
# find_metric should not return nil.
|
23
|
-
# It is assumed that metric_id refers to existing element from previous steps
|
24
|
-
acc[elem['metric_id']] = find_metric(elem['metric_id']).attrs
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def filtered_limit_metrics
|
29
|
-
result[:limits].select { |limit| limit.dig('metric', 'type') == 'metric' }
|
30
|
-
end
|
31
|
-
|
32
|
-
def pricingrule_metrics
|
33
|
-
filtered_pricing_rule_metrics.each_with_object({}) do |elem, acc|
|
34
|
-
# find_metric should not return nil.
|
35
|
-
# It is assumed that metric_id refers to existing element from previous steps
|
36
|
-
acc[elem['metric_id']] = find_metric(elem['metric_id']).attrs
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def filtered_pricing_rule_metrics
|
41
|
-
result[:pricingrules].select { |limit| limit.dig('metric', 'type') == 'metric' }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Commands
|
3
|
-
module PlansCommand
|
4
|
-
module Export
|
5
|
-
class ReadPlanPricingRulesStep
|
6
|
-
include Step
|
7
|
-
##
|
8
|
-
# Reads Application Plan pricing rules
|
9
|
-
# add metric system_name out of metric_id
|
10
|
-
def call
|
11
|
-
result[:pricingrules] = plan.pricing_rules.map do |pr|
|
12
|
-
pr.attrs.merge('metric' => metric_info(pr, 'PricingRule'), 'cost_per_unit' => pr.cost_per_unit.to_f)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Commands
|
3
|
-
module PlansCommand
|
4
|
-
module Export
|
5
|
-
APP_PLANS_BLACKLIST = %w[id links default custom created_at updated_at].freeze
|
6
|
-
LIMITS_BLACKLIST = %w[id metric_id links created_at updated_at].freeze
|
7
|
-
PRICINGRULES_BLACKLIST = %w[id metric_id links created_at updated_at].freeze
|
8
|
-
PLAN_FEATURE_BLACKLIST = %w[id links created_at updated_at].freeze
|
9
|
-
METRIC_BLACKLIST = %w[id links created_at updated_at].freeze
|
10
|
-
|
11
|
-
module Step
|
12
|
-
attr_reader :context
|
13
|
-
|
14
|
-
def initialize(context)
|
15
|
-
@context = context
|
16
|
-
end
|
17
|
-
|
18
|
-
def service
|
19
|
-
context[:service] ||= find_service
|
20
|
-
end
|
21
|
-
|
22
|
-
def file
|
23
|
-
context[:file]
|
24
|
-
end
|
25
|
-
|
26
|
-
def threescale_client
|
27
|
-
context[:threescale_client]
|
28
|
-
end
|
29
|
-
|
30
|
-
# can be id or system_name
|
31
|
-
def service_system_name
|
32
|
-
context[:service_system_name]
|
33
|
-
end
|
34
|
-
|
35
|
-
# can be id or system_name
|
36
|
-
def plan_system_name
|
37
|
-
context[:plan_system_name]
|
38
|
-
end
|
39
|
-
|
40
|
-
def result
|
41
|
-
context[:result] ||= {}
|
42
|
-
end
|
43
|
-
|
44
|
-
def plan
|
45
|
-
context[:plan] ||= find_plan
|
46
|
-
end
|
47
|
-
|
48
|
-
def metric_info(elem, elem_name)
|
49
|
-
if (method = find_method(elem.metric_id))
|
50
|
-
{ 'type' => 'method', 'system_name' => method.system_name }
|
51
|
-
elsif (metric = find_metric(elem.metric_id))
|
52
|
-
{ 'type' => 'metric', 'system_name' => metric.system_name }
|
53
|
-
else
|
54
|
-
raise ThreeScaleToolbox::Error, "Unexpected error. #{elem_name} #{elem.id} " \
|
55
|
-
"referencing to metric id #{elem.metric_id} which has not been found"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
def find_service
|
62
|
-
Entities::Service.find(remote: threescale_client,
|
63
|
-
ref: service_system_name).tap do |svc|
|
64
|
-
raise ThreeScaleToolbox::Error, "Service #{service_system_name} does not exist" if svc.nil?
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def find_plan
|
69
|
-
Entities::ApplicationPlan.find(service: service, ref: plan_system_name).tap do |p|
|
70
|
-
raise ThreeScaleToolbox::Error, "Application plan #{plan_system_name} does not exist" if p.nil?
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def find_metric(id)
|
75
|
-
service.metrics.find { |metric| metric.id == id }
|
76
|
-
end
|
77
|
-
|
78
|
-
def find_method(id)
|
79
|
-
service.methods.find { |method| method.id == id }
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Commands
|
3
|
-
module PlansCommand
|
4
|
-
module Export
|
5
|
-
class WriteArtifactsStep
|
6
|
-
include Step
|
7
|
-
##
|
8
|
-
# Serialization of Application Plan objects
|
9
|
-
def call
|
10
|
-
select_output do |output|
|
11
|
-
output.write(serialized_object.to_yaml)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def select_output
|
18
|
-
ios = if file
|
19
|
-
File.open(file, 'w')
|
20
|
-
else
|
21
|
-
$stdout
|
22
|
-
end
|
23
|
-
begin
|
24
|
-
yield(ios)
|
25
|
-
ensure
|
26
|
-
ios.close
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def serialized_object
|
31
|
-
{
|
32
|
-
'plan' => serialized_plan,
|
33
|
-
'limits' => serialized_limits,
|
34
|
-
'pricingrules' => serialized_pricing_rules,
|
35
|
-
'plan_features' => serialized_plan_features,
|
36
|
-
'metrics' => serialized_metrics,
|
37
|
-
'methods' => serialized_methods,
|
38
|
-
'created_at' => Time.now.utc.iso8601,
|
39
|
-
'toolbox_version' => ThreeScaleToolbox::VERSION
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
def serialized_plan
|
44
|
-
result[:plan].reject { |key, _| APP_PLANS_BLACKLIST.include? key }
|
45
|
-
end
|
46
|
-
|
47
|
-
def serialized_limits
|
48
|
-
result[:limits].map do |limit|
|
49
|
-
metric = limit.delete('metric')
|
50
|
-
limit['metric_system_name'] = metric['system_name']
|
51
|
-
limit.reject { |key, _| LIMITS_BLACKLIST.include? key }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def serialized_pricing_rules
|
56
|
-
result[:pricingrules].map do |pr|
|
57
|
-
metric = pr.delete('metric')
|
58
|
-
pr['metric_system_name'] = metric['system_name']
|
59
|
-
pr.reject { |key, _| PRICINGRULES_BLACKLIST.include? key }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def serialized_plan_features
|
64
|
-
result[:plan_features].map do |pr|
|
65
|
-
pr.reject { |key, _| PLAN_FEATURE_BLACKLIST.include? key }
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def serialized_metrics
|
70
|
-
result[:plan_metrics].values.map do |metric|
|
71
|
-
metric.reject { |key, _| METRIC_BLACKLIST.include? key }
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def serialized_methods
|
76
|
-
result[:plan_methods].values.map do |method|
|
77
|
-
method.reject { |key, _| METRIC_BLACKLIST.include? key }
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|