3scale_toolbox 0.17.1 → 0.19.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 +4 -4
- data/README.md +7 -5
- 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.rb +3 -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/delete_mapping_rules_task.rb +18 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/task.rb +14 -32
- data/lib/3scale_toolbox/commands/import_command/issuer_type_transformer.rb +16 -0
- data/lib/3scale_toolbox/commands/import_command/openapi.rb +5 -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 +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 +8 -3
- data/lib/3scale_toolbox/commands/product_command/copy_command/copy_backends_task.rb +28 -5
- data/lib/3scale_toolbox/commands/product_command/export_command.rb +81 -0
- data/lib/3scale_toolbox/commands/product_command/import_command.rb +126 -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 +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 +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/account.rb +1 -1
- 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 +164 -0
- data/lib/3scale_toolbox/remotes.rb +2 -2
- data/lib/3scale_toolbox/version.rb +1 -1
- data/licenses.xml +98 -50
- metadata +37 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aaf0f178f318385464342bd932cc8e0e78f3e8a291e2226204692d62c1d2dca7
|
|
4
|
+
data.tar.gz: a5aeca4f1da609adb33fc11a5cecd1ec435fcdef8c08c8755796da768c47e9ea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8521f2b23f6724ea4d9b62064710d22cd884cb2d518df211792b764cc7faaf753644801da6576d9fd61ce872b1503314346e842267632f8ff4b7b7a266658bc3
|
|
7
|
+
data.tar.gz: '099dcc4097d3d16803c30b8834e9db9985a3fc46b393f2bbfa31cb9eb5f646c5d9b729ece1fd63a7771b180d1a6d03246716163d2a42935a2b9cf2cec00a5817'
|
data/3scale_toolbox.gemspec
CHANGED
|
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
|
8
8
|
spec.name = '3scale_toolbox'
|
|
9
9
|
spec.version = ThreeScaleToolbox::VERSION
|
|
10
10
|
spec.licenses = ['MIT']
|
|
11
|
-
spec.authors = ['
|
|
12
|
-
spec.email = ['
|
|
11
|
+
spec.authors = ['Miguel Soriano', 'Eguzki Astiz Lezaun']
|
|
12
|
+
spec.email = ['msoriano@redhat.com', 'eastizle@redhat.com']
|
|
13
13
|
|
|
14
14
|
spec.summary = %q{3scale Toolbox.}
|
|
15
15
|
spec.description = %q{3scale tools to manage your API from the terminal.}
|
|
@@ -34,9 +34,9 @@ Gem::Specification.new do |spec|
|
|
|
34
34
|
spec.add_development_dependency 'rake', '~> 13.0'
|
|
35
35
|
spec.add_development_dependency 'rspec', '~> 3.8'
|
|
36
36
|
spec.add_development_dependency 'webmock', '~> 3.4'
|
|
37
|
-
spec.required_ruby_version = '>= 2.
|
|
37
|
+
spec.required_ruby_version = '>= 2.6'
|
|
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)
|
|
@@ -37,8 +39,8 @@
|
|
|
37
39
|
## Requirements
|
|
38
40
|
Supported Ruby interpreters
|
|
39
41
|
|
|
40
|
-
* MRI 2.5
|
|
41
42
|
* MRI 2.6
|
|
43
|
+
* MRI 2.7
|
|
42
44
|
|
|
43
45
|
## Installation
|
|
44
46
|
Install the toolbox:
|
|
@@ -120,7 +122,7 @@ rake spec:integration
|
|
|
120
122
|
|
|
121
123
|
Integration tests can be run locally or against a real 3scale account.
|
|
122
124
|
When details of the account are set via environment variables,
|
|
123
|
-
integration tests are run
|
|
125
|
+
integration tests are run against the given account.
|
|
124
126
|
Otherwise, tests are run locally with mocked 3scale clients.
|
|
125
127
|
|
|
126
128
|
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 +165,7 @@ end
|
|
|
163
165
|
A few things worth highlighting:
|
|
164
166
|
- Your module must include the *ThreeScaleToolbox::Command* module. It allows your command to be added to the toobox command tree.
|
|
165
167
|
- 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.
|
|
168
|
+
- `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
169
|
|
|
168
170
|
Then register the core command in `lib/3scale_toolbox/commands.rb`
|
|
169
171
|
```
|
|
@@ -216,5 +218,5 @@ Install, uninstall and update plugins using tools like [RubyGems](https://guides
|
|
|
216
218
|
|
|
217
219
|
## Contributing
|
|
218
220
|
|
|
219
|
-
|
|
221
|
+
If you are interested in contributing to 3scale Toolbox, please refer to instructions available [here](docs/contributing.md)
|
|
220
222
|
|
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
|
|
@@ -2,6 +2,7 @@ require '3scale_toolbox/commands/backend_command/copy_command/task'
|
|
|
2
2
|
require '3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task'
|
|
3
3
|
require '3scale_toolbox/commands/backend_command/copy_command/copy_metrics_task'
|
|
4
4
|
require '3scale_toolbox/commands/backend_command/copy_command/copy_methods_task'
|
|
5
|
+
require '3scale_toolbox/commands/backend_command/copy_command/delete_mapping_rules_task'
|
|
5
6
|
require '3scale_toolbox/commands/backend_command/copy_command/copy_mapping_rules_task'
|
|
6
7
|
|
|
7
8
|
module ThreeScaleToolbox
|
|
@@ -41,6 +42,7 @@ module ThreeScaleToolbox
|
|
|
41
42
|
# First metrics as methods need 'hits' metric in target backend
|
|
42
43
|
tasks << CopyCommand::CopyMetricsTask.new(context)
|
|
43
44
|
tasks << CopyCommand::CopyMethodsTask.new(context)
|
|
45
|
+
tasks << CopyCommand::DeleteMappingRulesTask.new(context)
|
|
44
46
|
tasks << CopyCommand::CopyMappingRulesTask.new(context)
|
|
45
47
|
tasks.each(&:call)
|
|
46
48
|
end
|
|
@@ -56,6 +58,7 @@ module ThreeScaleToolbox
|
|
|
56
58
|
source_remote: threescale_client(fetch_required_option(:source)),
|
|
57
59
|
target_remote: threescale_client(fetch_required_option(:destination)),
|
|
58
60
|
source_backend_ref: arguments[:source_backend],
|
|
61
|
+
delete_mapping_rules: true,
|
|
59
62
|
option_target_system_name: options[:'target-system-name']
|
|
60
63
|
}
|
|
61
64
|
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
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module ThreeScaleToolbox
|
|
2
|
+
module Commands
|
|
3
|
+
module BackendCommand
|
|
4
|
+
module CopyCommand
|
|
5
|
+
class DeleteMappingRulesTask
|
|
6
|
+
include Task
|
|
7
|
+
|
|
8
|
+
# entrypoint
|
|
9
|
+
def run
|
|
10
|
+
return unless delete_mapping_rules
|
|
11
|
+
|
|
12
|
+
target_backend.mapping_rules.each(&:delete)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -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,20 @@ 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
|
+
|
|
56
|
+
def delete_mapping_rules
|
|
57
|
+
context.fetch(:delete_mapping_rules, false)
|
|
58
|
+
end
|
|
59
|
+
|
|
78
60
|
private
|
|
79
61
|
|
|
80
62
|
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'],
|
|
@@ -105,6 +108,8 @@ module ThreeScaleToolbox
|
|
|
105
108
|
end
|
|
106
109
|
|
|
107
110
|
def openapi_parser
|
|
111
|
+
raise ThreeScaleToolbox::Error, 'only JSON/YAML format is supported' unless openapi_resource.is_a?(Hash)
|
|
112
|
+
|
|
108
113
|
if openapi_resource.key?('openapi')
|
|
109
114
|
ThreeScaleToolbox::OpenAPI::OAS3.build(openapi_path, openapi_resource, validate: validate)
|
|
110
115
|
else
|
|
@@ -54,8 +54,9 @@ module ThreeScaleToolbox
|
|
|
54
54
|
Helper.hash_deep_dup(resource).tap do |activedocs|
|
|
55
55
|
# public production base URL
|
|
56
56
|
# the basePath field is updated to a new value only when overriden by optional param
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
unless service.proxy['endpoint'].nil?
|
|
58
|
+
api_spec.set_server_url(activedocs, URI.join(service.proxy.fetch('endpoint'), public_base_path))
|
|
59
|
+
end
|
|
59
60
|
# security definitions
|
|
60
61
|
# just valid for oauth2 when oidc_issuer_endpoint is supplied
|
|
61
62
|
if !api_spec.security.nil? && api_spec.security[:type] == 'oauth2' && !oidc_issuer_endpoint.nil?
|
|
@@ -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
|
-
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
|
-
)
|
|
15
|
+
method_attrs = methods_index.fetch(op.method['system_name']).attrs
|
|
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,13 +21,9 @@ 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
|
|
35
|
-
acc[method
|
|
25
|
+
@methods_index ||= service.methods.each_with_object({}) do |method, acc|
|
|
26
|
+
acc[method.system_name] = method
|
|
36
27
|
end
|
|
37
28
|
end
|
|
38
29
|
|