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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d8b53876bf5759606f9517c2c62a32d66587a28ee6425afd1ba011f20222359c
|
|
4
|
+
data.tar.gz: 35a2783fdf7d5ee796014cbb7d1e3f85b08987b134b168a84ee40c42308b6150
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 958cb7be80dfc2293e00ad6ca4f9021c12e6e817871f7eb0f25c4ead5aa9a10fca8b42db16b45d01e998cd39980545e30087f5a8064ba57c3e3acb07f07c4934
|
|
7
|
+
data.tar.gz: 7c6e163ad4948037a50c88365407e2b91dd4217d0e3effc9c21d79badbbcd93f823e0695997edf791ade3ffe0e7f67e0b4bf61dde91729a1a62fdc4de42ba7c8
|
data/3scale_toolbox.gemspec
CHANGED
|
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
|
|
|
36
36
|
spec.add_development_dependency 'webmock', '~> 3.4'
|
|
37
37
|
spec.required_ruby_version = '>= 2.5'
|
|
38
38
|
|
|
39
|
-
spec.add_dependency '3scale-api', '~> 1.
|
|
39
|
+
spec.add_dependency '3scale-api', '~> 1.4'
|
|
40
40
|
spec.add_dependency 'cri', '~> 2.15'
|
|
41
41
|
spec.add_dependency 'json-schema', '~> 2.8'
|
|
42
42
|
spec.add_dependency 'oas_parser', '~> 0.20'
|
data/README.md
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* [Copy service](docs/copy-service.md)
|
|
14
14
|
* [Copy backend](docs/copy-backend.md)
|
|
15
15
|
* [Copy product](docs/copy-product.md)
|
|
16
|
+
* [Export/Import product](docs/export-import-product.md)
|
|
16
17
|
* [Import from CSV](docs/import-csv.md)
|
|
17
18
|
* [Import from OpenAPI definition](docs/openapi.md)
|
|
18
19
|
* [Export/Import Application Plan](docs/export-import-app-plan.md)
|
|
@@ -21,9 +22,10 @@
|
|
|
21
22
|
* Create, Apply, List, Delete [Method](docs/method.md)
|
|
22
23
|
* Create, Apply, List, Show, Delete [Service](docs/service.md)
|
|
23
24
|
* Create, Apply, List, Delete [ActiveDocs](docs/activedocs.md)
|
|
24
|
-
* List, Show, Promote, Export [Proxy Configuration](docs/proxy-config.md)
|
|
25
|
+
* List, Show, Promote, Export, Deploy [Proxy Configuration](docs/proxy-config.md)
|
|
25
26
|
* [Copy Policy Registry](docs/copy-policy-registry.md)
|
|
26
27
|
* Create, Apply, List, Show, Delete, Suspend, Resume [Applications](docs/applications.md)
|
|
28
|
+
* [Export/Import Product Policy Chain](docs/export-import-policy-chain.md)
|
|
27
29
|
* [Remotes](docs/remotes.md)
|
|
28
30
|
* [Development](#development)
|
|
29
31
|
* [Testing](#testing)
|
|
@@ -39,6 +41,7 @@ Supported Ruby interpreters
|
|
|
39
41
|
|
|
40
42
|
* MRI 2.5
|
|
41
43
|
* MRI 2.6
|
|
44
|
+
* MRI 2.7
|
|
42
45
|
|
|
43
46
|
## Installation
|
|
44
47
|
Install the toolbox:
|
|
@@ -120,7 +123,7 @@ rake spec:integration
|
|
|
120
123
|
|
|
121
124
|
Integration tests can be run locally or against a real 3scale account.
|
|
122
125
|
When details of the account are set via environment variables,
|
|
123
|
-
integration tests are run
|
|
126
|
+
integration tests are run against the given account.
|
|
124
127
|
Otherwise, tests are run locally with mocked 3scale clients.
|
|
125
128
|
|
|
126
129
|
The easiest way to set everything up is it to have a `.env` file in the root of the project with the following environment variables (set your own values):
|
|
@@ -163,7 +166,7 @@ end
|
|
|
163
166
|
A few things worth highlighting:
|
|
164
167
|
- Your module must include the *ThreeScaleToolbox::Command* module. It allows your command to be added to the toobox command tree.
|
|
165
168
|
- You must implement the `command` module function and return an instance of `Cri::Command` from [cri](https://github.com/ddfreyne/cri)
|
|
166
|
-
- `threescale_client` helper method returns *3scale API* client instance. All the process remote parsing, fetching from remote list and client instantiation is done out of the box.
|
|
169
|
+
- `threescale_client` helper method returns *3scale API* client instance. All the process remote parsing, fetching from the remote list and client instantiation is done out of the box.
|
|
167
170
|
|
|
168
171
|
Then register the core command in `lib/3scale_toolbox/commands.rb`
|
|
169
172
|
```
|
data/lib/3scale_toolbox.rb
CHANGED
|
@@ -10,15 +10,18 @@ require 'oas_parser'
|
|
|
10
10
|
require '3scale/api'
|
|
11
11
|
require 'json-schema'
|
|
12
12
|
require 'erb'
|
|
13
|
+
require 'logger'
|
|
13
14
|
|
|
14
15
|
require '3scale_toolbox/version'
|
|
15
16
|
require '3scale_toolbox/helper'
|
|
16
17
|
require '3scale_toolbox/error'
|
|
18
|
+
require '3scale_toolbox/remote_cache'
|
|
17
19
|
require '3scale_toolbox/proxy_logger'
|
|
18
20
|
require '3scale_toolbox/resource_reader'
|
|
19
21
|
require '3scale_toolbox/configuration'
|
|
20
22
|
require '3scale_toolbox/remotes'
|
|
21
23
|
require '3scale_toolbox/3scale_client_factory'
|
|
24
|
+
require '3scale_toolbox/crds'
|
|
22
25
|
require '3scale_toolbox/entities'
|
|
23
26
|
require '3scale_toolbox/attribute_filters'
|
|
24
27
|
require '3scale_toolbox/base_command'
|
|
@@ -22,10 +22,9 @@ module ThreeScaleToolbox
|
|
|
22
22
|
remote = remotes.fetch(remote_str)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
client = remote_client(remote.merge(verify_ssl: verify_ssl))
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
client
|
|
25
|
+
client = remote_client(**remote.merge(verify_ssl: verify_ssl))
|
|
26
|
+
client = ProxyLogger.new(client) if verbose
|
|
27
|
+
RemoteCache.new(client)
|
|
29
28
|
end
|
|
30
29
|
|
|
31
30
|
private
|
|
@@ -15,6 +15,7 @@ require '3scale_toolbox/commands/policy_registry_command'
|
|
|
15
15
|
require '3scale_toolbox/commands/application_command'
|
|
16
16
|
require '3scale_toolbox/commands/backend_command'
|
|
17
17
|
require '3scale_toolbox/commands/product_command'
|
|
18
|
+
require '3scale_toolbox/commands/policies_command'
|
|
18
19
|
|
|
19
20
|
module ThreeScaleToolbox
|
|
20
21
|
module Commands
|
|
@@ -35,6 +36,7 @@ module ThreeScaleToolbox
|
|
|
35
36
|
ThreeScaleToolbox::Commands::ApplicationCommand,
|
|
36
37
|
ThreeScaleToolbox::Commands::BackendCommand,
|
|
37
38
|
ThreeScaleToolbox::Commands::ProductCommand,
|
|
39
|
+
ThreeScaleToolbox::Commands::PoliciesCommand,
|
|
38
40
|
].freeze
|
|
39
41
|
end
|
|
40
42
|
end
|
|
@@ -7,42 +7,26 @@ module ThreeScaleToolbox
|
|
|
7
7
|
|
|
8
8
|
# entrypoint
|
|
9
9
|
def run
|
|
10
|
-
missing_rules = missing_mapping_rules(source_backend.mapping_rules,
|
|
11
|
-
target_backend.mapping_rules, metrics_map)
|
|
12
10
|
missing_rules.each do |mapping_rule|
|
|
13
|
-
mapping_rule.metric_id
|
|
14
|
-
Entities::BackendMappingRule.create(backend: target_backend,
|
|
15
|
-
attrs: mapping_rule.attrs)
|
|
11
|
+
mr_attrs = mapping_rule.attrs.merge('metric_id' => metrics_map.fetch(mapping_rule.metric_id))
|
|
12
|
+
Entities::BackendMappingRule.create(backend: target_backend, attrs: mr_attrs)
|
|
16
13
|
end
|
|
17
|
-
|
|
14
|
+
logger.info "created #{missing_rules.size} mapping rules"
|
|
15
|
+
report['missing_mapping_rules_created'] = missing_rules.size
|
|
18
16
|
end
|
|
19
17
|
|
|
20
18
|
private
|
|
21
19
|
|
|
22
20
|
def metrics_map
|
|
23
|
-
@metrics_map ||=
|
|
21
|
+
@metrics_map ||= source_backend.metrics_mapping(target_backend)
|
|
24
22
|
end
|
|
25
23
|
|
|
26
|
-
def
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
end
|
|
33
|
-
next if source.nil?
|
|
34
|
-
|
|
35
|
-
[source.id, target.id]
|
|
36
|
-
end.compact.to_h
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def missing_mapping_rules(source_rules, target_rules, metrics_map)
|
|
40
|
-
ThreeScaleToolbox::Helper.array_difference(source_rules, target_rules) do |source, target|
|
|
41
|
-
# map metric_id to the target backend domain
|
|
42
|
-
source_attrs = source.attrs.merge('metric_id' => metrics_map.fetch(source.metric_id))
|
|
43
|
-
ThreeScaleToolbox::Helper.compare_hashes(source_attrs,
|
|
44
|
-
target.attrs,
|
|
45
|
-
%w[pattern http_method delta metric_id])
|
|
24
|
+
def missing_rules
|
|
25
|
+
@missing_rules ||= ThreeScaleToolbox::Helper.array_difference(source_backend.mapping_rules, target_backend.mapping_rules) do |source_rule, target_rule|
|
|
26
|
+
source_rule.pattern == target_rule.pattern &&
|
|
27
|
+
source_rule.http_method == target_rule.http_method &&
|
|
28
|
+
source_rule.delta == target_rule.delta &&
|
|
29
|
+
metrics_map.fetch(source_rule.metric_id) == target_rule.metric_id
|
|
46
30
|
end
|
|
47
31
|
end
|
|
48
32
|
end
|
|
@@ -8,28 +8,23 @@ module ThreeScaleToolbox
|
|
|
8
8
|
# entrypoint
|
|
9
9
|
def run
|
|
10
10
|
missing_methods.each(&method(:create_method))
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
logger.info "created #{missing_methods.size} missing methods"
|
|
12
|
+
report['missing_methods_created'] = missing_methods.size
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
private
|
|
16
16
|
|
|
17
17
|
def create_method(method)
|
|
18
|
-
|
|
19
|
-
return if target_hits.nil?
|
|
20
|
-
|
|
21
|
-
Entities::BackendMethod.create(backend: target_backend,
|
|
22
|
-
parent_id: target_hits.id,
|
|
23
|
-
attrs: method.attrs)
|
|
18
|
+
Entities::BackendMethod.create(backend: target_backend, attrs: method.attrs)
|
|
24
19
|
rescue ThreeScaleToolbox::ThreeScaleApiError => e
|
|
25
20
|
raise e unless ThreeScaleToolbox::Helper.system_name_already_taken_error?(e.apierrors)
|
|
26
21
|
|
|
27
|
-
warn "[WARN] backend method #{method.
|
|
22
|
+
warn "[WARN] backend method #{method.system_name} not created. " \
|
|
28
23
|
'Backend metric with the same system_name exists.'
|
|
29
24
|
end
|
|
30
25
|
|
|
31
26
|
def missing_methods
|
|
32
|
-
@missing_methods ||= ThreeScaleToolbox::Helper.array_difference(
|
|
27
|
+
@missing_methods ||= ThreeScaleToolbox::Helper.array_difference(source_backend.methods, target_backend.methods) do |source, target|
|
|
33
28
|
source.system_name == target.system_name
|
|
34
29
|
end
|
|
35
30
|
end
|
|
@@ -8,8 +8,8 @@ module ThreeScaleToolbox
|
|
|
8
8
|
# entrypoint
|
|
9
9
|
def run
|
|
10
10
|
missing_metrics.each(&method(:create_metric))
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
logger.info "created #{missing_metrics.size} missing metrics"
|
|
12
|
+
report['missing_metrics_created'] = missing_metrics.size
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
private
|
|
@@ -19,8 +19,8 @@ module ThreeScaleToolbox
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def missing_metrics
|
|
22
|
-
@missing_metrics ||= ThreeScaleToolbox::Helper.array_difference(
|
|
23
|
-
|
|
22
|
+
@missing_metrics ||= ThreeScaleToolbox::Helper.array_difference(source_backend.metrics, target_backend.metrics) do |s_m, t_m|
|
|
23
|
+
s_m.system_name == t_m.system_name
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -23,8 +23,9 @@ module ThreeScaleToolbox
|
|
|
23
23
|
# assign target backend for other tasks to have it available
|
|
24
24
|
self.target_backend = backend
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
logger.info "source backend ID: #{source_backend.id} system_name: #{source_backend.system_name}"
|
|
27
|
+
logger.info "target backend ID: #{target_backend.id} system_name: #{target_backend.system_name}"
|
|
28
|
+
report['backend_id'] = target_backend.id
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
def create_attrs
|
|
@@ -26,38 +26,6 @@ module ThreeScaleToolbox
|
|
|
26
26
|
context[:source_backend] ||= find_source_backend
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
def source_methods
|
|
30
|
-
context[:source_methods] ||= source_backend.methods(source_hits)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def source_hits
|
|
34
|
-
context[:source_hits] ||= source_backend.hits
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def source_metrics
|
|
38
|
-
context[:source_metrics] ||= source_backend.metrics
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def target_metrics
|
|
42
|
-
context[:target_metrics] ||= target_backend.metrics
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def target_hits
|
|
46
|
-
context[:target_hits] ||= target_backend.hits
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def target_methods
|
|
50
|
-
context[:target_methods] ||= target_backend.methods(target_hits)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def invalidate_target_methods
|
|
54
|
-
context[:target_methods] = nil
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def invalidate_target_metrics
|
|
58
|
-
context[:target_metrics] = nil
|
|
59
|
-
end
|
|
60
|
-
|
|
61
29
|
def source_remote
|
|
62
30
|
context[:source_remote]
|
|
63
31
|
end
|
|
@@ -75,6 +43,16 @@ module ThreeScaleToolbox
|
|
|
75
43
|
context[:option_target_system_name]
|
|
76
44
|
end
|
|
77
45
|
|
|
46
|
+
def logger
|
|
47
|
+
context[:logger] ||= Logger.new($stdout).tap do |logger|
|
|
48
|
+
logger.formatter = proc { |severity, datetime, progname, msg| "#{msg}\n" }
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def report
|
|
53
|
+
context[:report] ||= {}
|
|
54
|
+
end
|
|
55
|
+
|
|
78
56
|
private
|
|
79
57
|
|
|
80
58
|
def find_source_backend
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module ThreeScaleToolbox
|
|
2
|
+
module Commands
|
|
3
|
+
module ImportCommand
|
|
4
|
+
module OpenAPI
|
|
5
|
+
# Helper class to validate values for the oidc-issuer-type argument of the import openapi command
|
|
6
|
+
class IssuerTypeTransformer
|
|
7
|
+
def call(issuer_type)
|
|
8
|
+
raise unless %w[rest keycloak].include?(issuer_type)
|
|
9
|
+
|
|
10
|
+
issuer_type
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -9,6 +9,7 @@ require '3scale_toolbox/commands/import_command/openapi/create_activedocs_step'
|
|
|
9
9
|
require '3scale_toolbox/commands/import_command/openapi/update_service_proxy_step'
|
|
10
10
|
require '3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step'
|
|
11
11
|
require '3scale_toolbox/commands/import_command/openapi/update_policies_step'
|
|
12
|
+
require '3scale_toolbox/commands/import_command/issuer_type_transformer'
|
|
12
13
|
|
|
13
14
|
module ThreeScaleToolbox
|
|
14
15
|
module Commands
|
|
@@ -30,6 +31,7 @@ module ThreeScaleToolbox
|
|
|
30
31
|
flag nil, 'activedocs-hidden', 'Create ActiveDocs in hidden state'
|
|
31
32
|
flag nil, 'skip-openapi-validation', 'Skip OpenAPI schema validation'
|
|
32
33
|
flag nil, 'prefix-matching', 'Use prefix matching instead of strict matching on mapping rules derived from openapi operations'
|
|
34
|
+
option nil, 'oidc-issuer-type', 'OIDC Issuer Type (rest, keycloak)', argument: :required, transform: IssuerTypeTransformer.new
|
|
33
35
|
option nil, 'oidc-issuer-endpoint', 'OIDC Issuer Endpoint', argument: :required
|
|
34
36
|
option nil, 'default-credentials-userkey', 'Default credentials policy userkey', argument: :required
|
|
35
37
|
option nil, 'override-private-basepath', 'Override the basepath for the private URLs', argument: :required
|
|
@@ -77,6 +79,7 @@ module ThreeScaleToolbox
|
|
|
77
79
|
threescale_client: threescale_client(fetch_required_option(:destination)),
|
|
78
80
|
target_system_name: options[:target_system_name],
|
|
79
81
|
activedocs_published: !options[:'activedocs-hidden'],
|
|
82
|
+
oidc_issuer_type: options[:'oidc-issuer-type'],
|
|
80
83
|
oidc_issuer_endpoint: options[:'oidc-issuer-endpoint'],
|
|
81
84
|
default_credentials_userkey: options[:'default-credentials-userkey'],
|
|
82
85
|
skip_openapi_validation: options[:'skip-openapi-validation'],
|
|
@@ -7,18 +7,13 @@ module ThreeScaleToolbox
|
|
|
7
7
|
|
|
8
8
|
def call
|
|
9
9
|
missing_operations.each do |op|
|
|
10
|
-
method = Entities::Method.create(service: service,
|
|
11
|
-
attrs: op.method)
|
|
10
|
+
method = Entities::Method.create(service: service, attrs: op.method)
|
|
12
11
|
op.set(:metric_id, method.id)
|
|
13
12
|
end
|
|
14
13
|
|
|
15
14
|
existing_operations.each do |op|
|
|
16
15
|
method_attrs = methods_index.fetch(op.method['system_name'])
|
|
17
|
-
method = Entities::Method.new(
|
|
18
|
-
id: method_attrs.fetch('id'),
|
|
19
|
-
parent_id: hits_metric_id,
|
|
20
|
-
service: service
|
|
21
|
-
)
|
|
16
|
+
method = Entities::Method.new(id: method_attrs.fetch('id'), service: service)
|
|
22
17
|
method.update(op.method)
|
|
23
18
|
op.set(:metric_id, method.id)
|
|
24
19
|
end
|
|
@@ -26,12 +21,8 @@ module ThreeScaleToolbox
|
|
|
26
21
|
|
|
27
22
|
private
|
|
28
23
|
|
|
29
|
-
def hits_metric_id
|
|
30
|
-
@hits_metric_id ||= service.hits['id']
|
|
31
|
-
end
|
|
32
|
-
|
|
33
24
|
def methods_index
|
|
34
|
-
@methods_index ||= service.methods
|
|
25
|
+
@methods_index ||= service.methods.each_with_object({}) do |method, acc|
|
|
35
26
|
acc[method['system_name']] = method
|
|
36
27
|
end
|
|
37
28
|
end
|
|
@@ -52,6 +52,7 @@ module ThreeScaleToolbox
|
|
|
52
52
|
case (type = api_spec.security[:type])
|
|
53
53
|
when 'oauth2'
|
|
54
54
|
settings[:credentials_location] = 'headers'
|
|
55
|
+
settings[:oidc_issuer_type] = oidc_issuer_type unless oidc_issuer_type.nil?
|
|
55
56
|
settings[:oidc_issuer_endpoint] = oidc_issuer_endpoint unless oidc_issuer_endpoint.nil?
|
|
56
57
|
when 'apiKey'
|
|
57
58
|
settings[:credentials_location] = credentials_location
|
|
@@ -47,11 +47,9 @@ module ThreeScaleToolbox
|
|
|
47
47
|
def run
|
|
48
48
|
validate_option_params
|
|
49
49
|
hits = service.hits
|
|
50
|
-
method = Entities::Method.find(service: service,
|
|
51
|
-
ref: method_ref)
|
|
50
|
+
method = Entities::Method.find(service: service, ref: method_ref)
|
|
52
51
|
if method.nil?
|
|
53
|
-
method = Entities::Method.create(service: service,
|
|
54
|
-
attrs: create_method_attrs)
|
|
52
|
+
method = Entities::Method.create(service: service, attrs: create_method_attrs)
|
|
55
53
|
else
|
|
56
54
|
method.update(method_attrs) unless method_attrs.empty?
|
|
57
55
|
end
|
|
@@ -44,7 +44,7 @@ module ThreeScaleToolbox
|
|
|
44
44
|
|
|
45
45
|
def find_method
|
|
46
46
|
hits = service.hits
|
|
47
|
-
Entities::Method.find(service: service,
|
|
47
|
+
Entities::Method.find(service: service, ref: method_ref).tap do |p|
|
|
48
48
|
raise ThreeScaleToolbox::Error, "Method #{method_ref} does not exist" if p.nil?
|
|
49
49
|
end
|
|
50
50
|
end
|