3scale_toolbox 0.16.0 → 0.18.3
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 +11 -8
- data/lib/3scale_toolbox.rb +3 -0
- data/lib/3scale_toolbox/3scale_client_factory.rb +3 -4
- data/lib/3scale_toolbox/cli/error_handler.rb +17 -14
- 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_activedocs_step.rb +3 -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 +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 +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 +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 +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/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 +9 -12
- 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 +17 -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.rb +1 -1
- data/lib/3scale_toolbox/commands/update_command/service_command.rb +3 -2
- 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 +74 -39
- 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/error.rb +50 -0
- data/lib/3scale_toolbox/helper.rb +13 -16
- data/lib/3scale_toolbox/openapi/oas3.rb +1 -1
- 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 +113 -45
- metadata +37 -8
@@ -2,6 +2,9 @@ require '3scale_toolbox/entities/service'
|
|
2
2
|
require '3scale_toolbox/entities/application_plan'
|
3
3
|
require '3scale_toolbox/entities/metric'
|
4
4
|
require '3scale_toolbox/entities/method'
|
5
|
+
require '3scale_toolbox/entities/mapping_rule'
|
6
|
+
require '3scale_toolbox/entities/limit'
|
7
|
+
require '3scale_toolbox/entities/pricing_rule'
|
5
8
|
require '3scale_toolbox/entities/activedocs'
|
6
9
|
require '3scale_toolbox/entities/account'
|
7
10
|
require '3scale_toolbox/entities/proxy_config'
|
@@ -51,6 +51,18 @@ module ThreeScaleToolbox
|
|
51
51
|
@attrs ||= activedoc_attrs
|
52
52
|
end
|
53
53
|
|
54
|
+
def system_name
|
55
|
+
attrs['system_name']
|
56
|
+
end
|
57
|
+
|
58
|
+
def body
|
59
|
+
attrs['body']
|
60
|
+
end
|
61
|
+
|
62
|
+
def name
|
63
|
+
attrs['name']
|
64
|
+
end
|
65
|
+
|
54
66
|
def delete
|
55
67
|
remote.delete_activedocs id
|
56
68
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module ThreeScaleToolbox
|
2
2
|
module Entities
|
3
3
|
class ApplicationPlan
|
4
|
+
include CRD::ApplicationPlanSerializer
|
5
|
+
|
4
6
|
class << self
|
5
7
|
def create(service:, plan_attrs:)
|
6
8
|
plan = service.remote.create_application_plan service.id, create_plan_attrs(plan_attrs)
|
@@ -14,15 +16,12 @@ module ThreeScaleToolbox
|
|
14
16
|
# ref can be system_name or service_id
|
15
17
|
def find(service:, ref:)
|
16
18
|
new(id: ref, service: service).tap(&:attrs)
|
17
|
-
rescue ThreeScale::API::HttpClient::NotFoundError
|
19
|
+
rescue ThreeScaleToolbox::InvalidIdError, ThreeScale::API::HttpClient::NotFoundError
|
18
20
|
find_by_system_name(service: service, system_name: ref)
|
19
21
|
end
|
20
22
|
|
21
23
|
def find_by_system_name(service:, system_name:)
|
22
|
-
|
23
|
-
return if plan.nil?
|
24
|
-
|
25
|
-
new(id: plan.fetch('id'), service: service, attrs: plan)
|
24
|
+
service.plans.find { |p| p.system_name == system_name }
|
26
25
|
end
|
27
26
|
|
28
27
|
def create_plan_attrs(source_attrs)
|
@@ -49,6 +48,22 @@ module ThreeScaleToolbox
|
|
49
48
|
@attrs ||= read_plan_attrs
|
50
49
|
end
|
51
50
|
|
51
|
+
def system_name
|
52
|
+
attrs['system_name']
|
53
|
+
end
|
54
|
+
|
55
|
+
def name
|
56
|
+
attrs['name']
|
57
|
+
end
|
58
|
+
|
59
|
+
def state
|
60
|
+
attrs['state']
|
61
|
+
end
|
62
|
+
|
63
|
+
def custom
|
64
|
+
attrs.fetch('custom', false)
|
65
|
+
end
|
66
|
+
|
52
67
|
def update(plan_attrs)
|
53
68
|
return attrs if update_plan_attrs(plan_attrs).empty?
|
54
69
|
|
@@ -78,9 +93,9 @@ module ThreeScaleToolbox
|
|
78
93
|
# b) metrics having limits set with eternity period, but not zero value, must be updated
|
79
94
|
# c) metrics not having limits set with eternity period, must be created
|
80
95
|
|
81
|
-
eternity_limits = limits.select { |limit| limit.
|
82
|
-
eternity_metric_ids = eternity_limits.map { |limit| limit.
|
83
|
-
service_metric_ids = service.metrics.map { |metric| metric.
|
96
|
+
eternity_limits = limits.select { |limit| limit.period == 'eternity' }
|
97
|
+
eternity_metric_ids = eternity_limits.map { |limit| limit.metric_id }
|
98
|
+
service_metric_ids = service.metrics.map { |metric| metric.id }
|
84
99
|
metric_ids_without_eternity = service_metric_ids - eternity_metric_ids
|
85
100
|
|
86
101
|
# create eternity zero limit for each metric without eternity limit set
|
@@ -89,16 +104,14 @@ module ThreeScaleToolbox
|
|
89
104
|
end
|
90
105
|
|
91
106
|
# update eternity zero limit those metrics already having eternity limit set
|
92
|
-
not_zero_eternity_limits = eternity_limits.reject { |limit| limit.
|
107
|
+
not_zero_eternity_limits = eternity_limits.reject { |limit| limit.value.zero? }
|
93
108
|
not_zero_eternity_limits.each do |limit|
|
94
|
-
|
109
|
+
limit.update(zero_eternity_limit_attrs)
|
95
110
|
end
|
96
111
|
end
|
97
112
|
|
98
113
|
def enable
|
99
|
-
eternity_zero_limits.each
|
100
|
-
delete_limit(limit.fetch('metric_id'), limit.fetch('id'))
|
101
|
-
end
|
114
|
+
eternity_zero_limits.each(&:delete)
|
102
115
|
end
|
103
116
|
|
104
117
|
def limits
|
@@ -107,7 +120,9 @@ module ThreeScaleToolbox
|
|
107
120
|
raise ThreeScaleToolbox::ThreeScaleApiError.new('Limits per application plan not read', errors)
|
108
121
|
end
|
109
122
|
|
110
|
-
plan_limits
|
123
|
+
plan_limits.map do |limit_attrs|
|
124
|
+
Limit.new(id: limit_attrs.fetch('id'), plan: self, metric_id: limit_attrs.fetch('metric_id'), attrs: limit_attrs)
|
125
|
+
end
|
111
126
|
end
|
112
127
|
|
113
128
|
def metric_limits(metric_id)
|
@@ -116,45 +131,47 @@ module ThreeScaleToolbox
|
|
116
131
|
# Already reported. https://issues.jboss.org/browse/THREESCALE-2486
|
117
132
|
# Meanwhile, the strategy will be to get all metrics from a given plan
|
118
133
|
# and filter by metric_id
|
119
|
-
limits.select { |limit| limit
|
134
|
+
limits.select { |limit| limit.metric_id == metric_id }
|
120
135
|
end
|
121
136
|
|
122
137
|
def create_limit(metric_id, limit_attrs)
|
123
|
-
|
124
|
-
if (errors = limit['errors'])
|
125
|
-
raise ThreeScaleToolbox::ThreeScaleApiError.new('Limit has not been created', errors)
|
126
|
-
end
|
127
|
-
|
128
|
-
limit
|
129
|
-
end
|
130
|
-
|
131
|
-
def update_limit(metric_id, limit_id, limit_attrs)
|
132
|
-
limit = remote.update_application_plan_limit id, metric_id, limit_id, limit_attrs
|
133
|
-
if (errors = limit['errors'])
|
134
|
-
raise ThreeScaleToolbox::ThreeScaleApiError.new('Limit not updated', errors)
|
135
|
-
end
|
136
|
-
|
137
|
-
limit
|
138
|
-
end
|
139
|
-
|
140
|
-
def delete_limit(metric_id, limit_id)
|
141
|
-
remote.delete_application_plan_limit id, metric_id, limit_id
|
138
|
+
Limit.create(plan: self, metric_id: metric_id, attrs: limit_attrs)
|
142
139
|
end
|
143
140
|
|
144
141
|
def create_pricing_rule(metric_id, pr_attrs)
|
145
|
-
|
142
|
+
PricingRule.create(plan: self, metric_id: metric_id, attrs: pr_attrs)
|
146
143
|
end
|
147
144
|
|
148
145
|
def pricing_rules
|
149
|
-
remote.list_pricingrules_per_application_plan id
|
146
|
+
pr_list = remote.list_pricingrules_per_application_plan id
|
147
|
+
|
148
|
+
if pr_list.respond_to?(:has_key?) && (errors = pr_list['errors'])
|
149
|
+
raise ThreeScaleToolbox::ThreeScaleApiError.new('pricing rules not read', errors)
|
150
|
+
end
|
151
|
+
|
152
|
+
pr_list.map do |pr_attrs|
|
153
|
+
PricingRule.new(id: pr_attrs.fetch('id'), plan: self, metric_id: pr_attrs.fetch('metric_id'), attrs: pr_attrs)
|
154
|
+
end
|
150
155
|
end
|
151
156
|
|
152
157
|
def features
|
153
|
-
remote.list_features_per_application_plan id
|
158
|
+
feature_list = remote.list_features_per_application_plan id
|
159
|
+
|
160
|
+
if feature_list.respond_to?(:has_key?) && (errors = feature_list['errors'])
|
161
|
+
raise ThreeScaleToolbox::ThreeScaleApiError.new('features not read', errors)
|
162
|
+
end
|
163
|
+
|
164
|
+
feature_list
|
154
165
|
end
|
155
166
|
|
156
167
|
def create_feature(feature_id)
|
157
|
-
remote.create_application_plan_feature id, feature_id
|
168
|
+
feature = remote.create_application_plan_feature id, feature_id
|
169
|
+
|
170
|
+
if (errors = feature['errors'])
|
171
|
+
raise ThreeScaleToolbox::ThreeScaleApiError.new('feature not created', errors)
|
172
|
+
end
|
173
|
+
|
174
|
+
feature
|
158
175
|
end
|
159
176
|
|
160
177
|
def delete
|
@@ -176,9 +193,27 @@ module ThreeScaleToolbox
|
|
176
193
|
attrs.fetch('state') == 'published'
|
177
194
|
end
|
178
195
|
|
196
|
+
def approval_required?
|
197
|
+
attrs.fetch('approval_required', true)
|
198
|
+
end
|
199
|
+
|
200
|
+
def trial_period_days
|
201
|
+
attrs.fetch('trial_period_days', 0)
|
202
|
+
end
|
203
|
+
|
204
|
+
def setup_fee
|
205
|
+
attrs.fetch('setup_fee', 0.0)
|
206
|
+
end
|
207
|
+
|
208
|
+
def cost_per_month
|
209
|
+
attrs.fetch('cost_per_month', 0.0)
|
210
|
+
end
|
211
|
+
|
179
212
|
private
|
180
213
|
|
181
214
|
def read_plan_attrs
|
215
|
+
raise ThreeScaleToolbox::InvalidIdError if id.zero?
|
216
|
+
|
182
217
|
plan_attrs = remote.show_application_plan service.id, id
|
183
218
|
if (errors = plan_attrs['errors'])
|
184
219
|
raise ThreeScaleToolbox::ThreeScaleApiError.new('Application plan not read', errors)
|
@@ -197,7 +232,7 @@ module ThreeScaleToolbox
|
|
197
232
|
end
|
198
233
|
|
199
234
|
def eternity_zero_limits
|
200
|
-
limits.select { |limit| zero_eternity_limit_attrs < limit }
|
235
|
+
limits.select { |limit| zero_eternity_limit_attrs < limit.attrs }
|
201
236
|
end
|
202
237
|
|
203
238
|
def zero_eternity_limit_attrs
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module ThreeScaleToolbox
|
2
2
|
module Entities
|
3
3
|
class Backend
|
4
|
+
include CRD::BackendSerializer
|
5
|
+
|
4
6
|
VALID_PARAMS = %w[name description system_name private_endpoint].freeze
|
5
7
|
public_constant :VALID_PARAMS
|
6
8
|
|
@@ -22,17 +24,45 @@ module ThreeScaleToolbox
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def find_by_system_name(remote:, system_name:)
|
25
|
-
|
26
|
-
|
27
|
-
if list.respond_to?(:has_key?) && (errors = list['errors'])
|
28
|
-
raise ThreeScaleToolbox::ThreeScaleApiError.new('Backend list not read', errors)
|
27
|
+
attrs = list_backends(remote: remote).find do |backend|
|
28
|
+
backend['system_name'] == system_name
|
29
29
|
end
|
30
|
-
|
31
|
-
attrs = list.find { |backend| backend['system_name'] == system_name }
|
32
30
|
return if attrs.nil?
|
33
31
|
|
34
32
|
new(id: attrs.fetch('id'), remote: remote, attrs: attrs)
|
35
33
|
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def list_backends(remote:)
|
38
|
+
backends_enum(remote: remote).reduce([], :concat)
|
39
|
+
end
|
40
|
+
|
41
|
+
def backends_enum(remote:)
|
42
|
+
Enumerator.new do |yielder|
|
43
|
+
page = 1
|
44
|
+
loop do
|
45
|
+
list = remote.list_backends(
|
46
|
+
page: page,
|
47
|
+
per_page: ThreeScale::API::MAX_BACKENDS_PER_PAGE
|
48
|
+
)
|
49
|
+
|
50
|
+
if list.respond_to?(:has_key?) && (errors = list['errors'])
|
51
|
+
raise ThreeScaleToolbox::ThreeScaleApiError.new('Backend list not read', errors)
|
52
|
+
end
|
53
|
+
|
54
|
+
break if list.nil?
|
55
|
+
|
56
|
+
yielder << list
|
57
|
+
|
58
|
+
# The API response does not tell how many pages there are available
|
59
|
+
# If one page is not fully filled, it means that it is the last page.
|
60
|
+
break if list.length < ThreeScale::API::MAX_BACKENDS_PER_PAGE
|
61
|
+
|
62
|
+
page += 1
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
36
66
|
end
|
37
67
|
|
38
68
|
attr_reader :id, :remote
|
@@ -51,14 +81,20 @@ module ThreeScaleToolbox
|
|
51
81
|
attrs['system_name']
|
52
82
|
end
|
53
83
|
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
hits_metric_obj = hits_metric(metric_and_method_list)
|
84
|
+
def description
|
85
|
+
attrs['description']
|
86
|
+
end
|
58
87
|
|
59
|
-
|
60
|
-
|
61
|
-
|
88
|
+
def name
|
89
|
+
attrs['name']
|
90
|
+
end
|
91
|
+
|
92
|
+
def private_endpoint
|
93
|
+
attrs['private_endpoint']
|
94
|
+
end
|
95
|
+
|
96
|
+
def metrics
|
97
|
+
metric_attr_list = metrics_and_methods.select { |metric_attrs| metric_attrs['parent_id'].nil? }
|
62
98
|
|
63
99
|
metric_attr_list.map do |metric_attrs|
|
64
100
|
BackendMetric.new(id: metric_attrs.fetch('id'), backend: self, attrs: metric_attrs)
|
@@ -66,25 +102,24 @@ module ThreeScaleToolbox
|
|
66
102
|
end
|
67
103
|
|
68
104
|
def hits
|
69
|
-
|
105
|
+
metric_list = metrics_and_methods.map do |metric_attrs|
|
106
|
+
BackendMetric.new(id: metric_attrs.fetch('id'), backend: self, attrs: metric_attrs)
|
107
|
+
end
|
108
|
+
metric_list.find { |metric| metric.system_name == 'hits' }.tap do |hits_metric|
|
109
|
+
raise ThreeScaleToolbox::Error, 'missing hits metric' if hits_metric.nil?
|
110
|
+
end
|
70
111
|
end
|
71
112
|
|
72
113
|
# @api public
|
73
|
-
# @param [Object] parent_metric_id BackendMetric hits object
|
74
114
|
# @return [List]
|
75
|
-
def methods
|
76
|
-
|
77
|
-
|
78
|
-
method_attr_list = remote.list_backend_methods id, parent_metric_id.id
|
115
|
+
def methods
|
116
|
+
method_attr_list = remote.list_backend_methods id, hits.id
|
79
117
|
if method_attr_list.respond_to?(:has_key?) && (errors = method_attr_list['errors'])
|
80
118
|
raise ThreeScaleToolbox::ThreeScaleApiError.new('Backend methods not read', errors)
|
81
119
|
end
|
82
120
|
|
83
121
|
method_attr_list.map do |method_attrs|
|
84
|
-
BackendMethod.new(id: method_attrs.fetch('id'),
|
85
|
-
backend: self,
|
86
|
-
parent_id: parent_metric_id.id,
|
87
|
-
attrs: method_attrs)
|
122
|
+
BackendMethod.new(id: method_attrs.fetch('id'), backend: self, attrs: method_attrs)
|
88
123
|
end
|
89
124
|
end
|
90
125
|
|
@@ -115,6 +150,13 @@ module ThreeScaleToolbox
|
|
115
150
|
remote.delete_backend id
|
116
151
|
end
|
117
152
|
|
153
|
+
# Compute matrics mapping
|
154
|
+
def metrics_mapping(other)
|
155
|
+
(metrics + methods).product(other.metrics + other.methods).select do |m_a, m_b|
|
156
|
+
m_a.system_name == m_b.system_name
|
157
|
+
end.map { |m_a, m_b| [m_a.id, m_b.id] }.to_h
|
158
|
+
end
|
159
|
+
|
118
160
|
def ==(other)
|
119
161
|
remote.http_client.endpoint == other.remote.http_client.endpoint && id == other.id
|
120
162
|
end
|
@@ -130,13 +172,6 @@ module ThreeScaleToolbox
|
|
130
172
|
m_m
|
131
173
|
end
|
132
174
|
|
133
|
-
def hits_metric(metric_attr_list)
|
134
|
-
metric_list = metric_attr_list.map do |metric_attrs|
|
135
|
-
BackendMetric.new(id: metric_attrs.fetch('id'), backend: self, attrs: metric_attrs)
|
136
|
-
end
|
137
|
-
metric_list.find { |metric| metric.system_name == 'hits' }
|
138
|
-
end
|
139
|
-
|
140
175
|
def fetch_backend_attrs
|
141
176
|
raise ThreeScaleToolbox::InvalidIdError if id.zero?
|
142
177
|
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module ThreeScaleToolbox
|
2
2
|
module Entities
|
3
3
|
class BackendMappingRule
|
4
|
+
include CRD::BackendMappingRuleSerializer
|
5
|
+
|
4
6
|
VALID_PARAMS = %w[metric_id pattern http_method delta position last].freeze
|
5
7
|
public_constant :VALID_PARAMS
|
6
8
|
|
@@ -32,12 +34,36 @@ module ThreeScaleToolbox
|
|
32
34
|
@attrs ||= mapping_rule_attrs
|
33
35
|
end
|
34
36
|
|
37
|
+
def http_method
|
38
|
+
attrs['http_method']
|
39
|
+
end
|
40
|
+
|
41
|
+
def pattern
|
42
|
+
attrs['pattern']
|
43
|
+
end
|
44
|
+
|
45
|
+
def delta
|
46
|
+
attrs['delta']
|
47
|
+
end
|
48
|
+
|
49
|
+
def last
|
50
|
+
attrs['last']
|
51
|
+
end
|
52
|
+
|
35
53
|
def metric_id
|
36
|
-
|
54
|
+
attrs['metric_id']
|
55
|
+
end
|
56
|
+
|
57
|
+
def pattern
|
58
|
+
attrs['pattern']
|
59
|
+
end
|
60
|
+
|
61
|
+
def http_method
|
62
|
+
attrs['http_method']
|
37
63
|
end
|
38
64
|
|
39
|
-
def
|
40
|
-
|
65
|
+
def delta
|
66
|
+
attrs['delta']
|
41
67
|
end
|
42
68
|
|
43
69
|
def update(mr_attrs)
|
@@ -1,39 +1,40 @@
|
|
1
1
|
module ThreeScaleToolbox
|
2
2
|
module Entities
|
3
3
|
class BackendMethod
|
4
|
+
include CRD::BackendMethodSerializer
|
5
|
+
|
4
6
|
VALID_PARAMS = %w[friendly_name system_name description].freeze
|
5
7
|
public_constant :VALID_PARAMS
|
6
8
|
|
7
9
|
class << self
|
8
|
-
def create(backend:,
|
9
|
-
method = backend.remote.create_backend_method(backend.id,
|
10
|
+
def create(backend:, attrs:)
|
11
|
+
method = backend.remote.create_backend_method(backend.id, backend.hits.id,
|
10
12
|
Helper.filter_params(VALID_PARAMS, attrs))
|
11
13
|
if (errors = method['errors'])
|
12
14
|
raise ThreeScaleToolbox::ThreeScaleApiError.new('Backend Method has not been created',
|
13
15
|
errors)
|
14
16
|
end
|
15
17
|
|
16
|
-
new(id: method.fetch('id'),
|
18
|
+
new(id: method.fetch('id'), backend: backend, attrs: method)
|
17
19
|
end
|
18
20
|
|
19
21
|
# ref can be system_name or method_id
|
20
|
-
def find(backend:,
|
21
|
-
new(id: ref,
|
22
|
+
def find(backend:, ref:)
|
23
|
+
new(id: ref, backend: backend).tap(&:attrs)
|
22
24
|
rescue ThreeScaleToolbox::InvalidIdError, ThreeScale::API::HttpClient::NotFoundError
|
23
|
-
find_by_system_name(backend: backend,
|
25
|
+
find_by_system_name(backend: backend, system_name: ref)
|
24
26
|
end
|
25
27
|
|
26
|
-
def find_by_system_name(backend:,
|
27
|
-
backend.methods
|
28
|
+
def find_by_system_name(backend:, system_name:)
|
29
|
+
backend.methods.find { |m| m.system_name == system_name }
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
|
-
attr_reader :id, :
|
33
|
+
attr_reader :id, :backend, :remote
|
32
34
|
|
33
|
-
def initialize(id:,
|
35
|
+
def initialize(id:, backend:, attrs: nil)
|
34
36
|
@id = id.to_i
|
35
37
|
@backend = backend
|
36
|
-
@parent_id = parent_id
|
37
38
|
@remote = backend.remote
|
38
39
|
@attrs = process_attrs(attrs)
|
39
40
|
end
|
@@ -43,15 +44,19 @@ module ThreeScaleToolbox
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def system_name
|
46
|
-
|
47
|
+
attrs['system_name']
|
47
48
|
end
|
48
49
|
|
49
50
|
def friendly_name
|
50
|
-
|
51
|
+
attrs['friendly_name']
|
52
|
+
end
|
53
|
+
|
54
|
+
def description
|
55
|
+
attrs['description']
|
51
56
|
end
|
52
57
|
|
53
58
|
def update(m_attrs)
|
54
|
-
new_attrs = remote.update_backend_method(backend.id,
|
59
|
+
new_attrs = remote.update_backend_method(backend.id, hits_id, id,
|
55
60
|
Helper.filter_params(VALID_PARAMS, m_attrs))
|
56
61
|
if (errors = new_attrs['errors'])
|
57
62
|
raise ThreeScaleToolbox::ThreeScaleApiError.new('Backend Method has not been updated',
|
@@ -63,11 +68,15 @@ module ThreeScaleToolbox
|
|
63
68
|
end
|
64
69
|
|
65
70
|
def delete
|
66
|
-
remote.delete_backend_method backend.id,
|
71
|
+
remote.delete_backend_method backend.id, hits_id, id
|
67
72
|
end
|
68
73
|
|
69
74
|
private
|
70
75
|
|
76
|
+
def hits_id
|
77
|
+
backend.hits.id
|
78
|
+
end
|
79
|
+
|
71
80
|
def process_attrs(metric_attrs)
|
72
81
|
return if metric_attrs.nil?
|
73
82
|
|
@@ -78,7 +87,7 @@ module ThreeScaleToolbox
|
|
78
87
|
def method_attrs
|
79
88
|
raise ThreeScaleToolbox::InvalidIdError if id.zero?
|
80
89
|
|
81
|
-
method = remote.backend_method backend.id,
|
90
|
+
method = remote.backend_method backend.id, hits_id, id
|
82
91
|
if (errors = method['errors'])
|
83
92
|
raise ThreeScaleToolbox::ThreeScaleApiError.new('Backend method not read', errors)
|
84
93
|
end
|