3scale_toolbox 0.16.0 → 0.18.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 +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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0a3084c0b2b684a252c7e07c4c9a87e3087ada1ad6a677766aa508ac98e1f313
|
|
4
|
+
data.tar.gz: 158b1b008a67836c2b27ccd8cbcd49f59995e4ac776eae93c59bf44b002cbf3a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '02789c23291a2191617a56c3456297539b09e0922bbf62b57b613065b04d8951800d91f49989d510258c0c3b1baa308d1219f4c29373879c8a65f9a93bd4653a'
|
|
7
|
+
data.tar.gz: abaca7089c51b5de57c118f5154a74466dd6671a96d7ec043b47ba0d4772761a2d9896b1195e762115ff121296c16cc2f195a5d39e9c20191393f45e6ee756bc
|
data/3scale_toolbox.gemspec
CHANGED
|
@@ -31,12 +31,12 @@ Gem::Specification.new do |spec|
|
|
|
31
31
|
|
|
32
32
|
spec.add_development_dependency 'bundler'
|
|
33
33
|
spec.add_development_dependency 'dotenv'
|
|
34
|
-
spec.add_development_dependency 'rake', '~>
|
|
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
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
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
# 3scale toolbox
|
|
2
2
|
[](https://circleci.com/gh/3scale/3scale_toolbox)
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
See the LICENSE and NOTICE files that should have been provided along with this software for details.
|
|
3
|
+
[](http://www.apache.org/licenses/LICENSE-2.0)
|
|
4
|
+
[](https://github.com/3scale/3scale_toolbox/releases/latest)
|
|
7
5
|
|
|
8
6
|
## Description
|
|
9
7
|
3scale toolbox is a set of tools to help you manage your 3scale product. Using the [3scale API Ruby Client](https://github.com/3scale/3scale-api-ruby).
|
|
@@ -15,6 +13,7 @@ See the LICENSE and NOTICE files that should have been provided along with this
|
|
|
15
13
|
* [Copy service](docs/copy-service.md)
|
|
16
14
|
* [Copy backend](docs/copy-backend.md)
|
|
17
15
|
* [Copy product](docs/copy-product.md)
|
|
16
|
+
* [Export/Import product](docs/export-import-product.md)
|
|
18
17
|
* [Import from CSV](docs/import-csv.md)
|
|
19
18
|
* [Import from OpenAPI definition](docs/openapi.md)
|
|
20
19
|
* [Export/Import Application Plan](docs/export-import-app-plan.md)
|
|
@@ -23,15 +22,17 @@ See the LICENSE and NOTICE files that should have been provided along with this
|
|
|
23
22
|
* Create, Apply, List, Delete [Method](docs/method.md)
|
|
24
23
|
* Create, Apply, List, Show, Delete [Service](docs/service.md)
|
|
25
24
|
* Create, Apply, List, Delete [ActiveDocs](docs/activedocs.md)
|
|
26
|
-
* List, Show, Promote [Proxy Configuration](docs/proxy-config.md)
|
|
25
|
+
* List, Show, Promote, Export, Deploy [Proxy Configuration](docs/proxy-config.md)
|
|
27
26
|
* [Copy Policy Registry](docs/copy-policy-registry.md)
|
|
28
27
|
* Create, Apply, List, Show, Delete, Suspend, Resume [Applications](docs/applications.md)
|
|
28
|
+
* [Export/Import Product Policy Chain](docs/export-import-policy-chain.md)
|
|
29
29
|
* [Remotes](docs/remotes.md)
|
|
30
30
|
* [Development](#development)
|
|
31
31
|
* [Testing](#testing)
|
|
32
32
|
* [Develop your own core command](#develop-core-command)
|
|
33
33
|
* [Licenses](#licenses)
|
|
34
34
|
* [Plugins](#plugins)
|
|
35
|
+
* [Error Reporting](docs/errors.md)
|
|
35
36
|
* [Troubleshooting](#troubleshooting)
|
|
36
37
|
* [Contributing](#contributing)
|
|
37
38
|
|
|
@@ -40,6 +41,7 @@ Supported Ruby interpreters
|
|
|
40
41
|
|
|
41
42
|
* MRI 2.5
|
|
42
43
|
* MRI 2.6
|
|
44
|
+
* MRI 2.7
|
|
43
45
|
|
|
44
46
|
## Installation
|
|
45
47
|
Install the toolbox:
|
|
@@ -82,10 +84,11 @@ COMMANDS
|
|
|
82
84
|
method method super command
|
|
83
85
|
metric metric super command
|
|
84
86
|
policy-registry policy-registry super command
|
|
87
|
+
product product super command
|
|
85
88
|
proxy-config proxy-config super command
|
|
86
89
|
remote remotes super command
|
|
87
90
|
service services super command
|
|
88
|
-
update [
|
|
91
|
+
update [DEPRECATED] update super command
|
|
89
92
|
|
|
90
93
|
OPTIONS
|
|
91
94
|
-c --config-file=<value> 3scale toolbox configuration file (default:
|
|
@@ -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
|
|
@@ -20,10 +20,9 @@ module ThreeScaleToolbox
|
|
|
20
20
|
|
|
21
21
|
def handle_error(error)
|
|
22
22
|
if expected_error?(error)
|
|
23
|
-
warn
|
|
24
|
-
warn "\e[1m\e[31mError: #{error.message}\e[0m"
|
|
23
|
+
warn error_serialize(error)
|
|
25
24
|
else
|
|
26
|
-
|
|
25
|
+
print_unexpected_error(error)
|
|
27
26
|
end
|
|
28
27
|
end
|
|
29
28
|
|
|
@@ -36,21 +35,12 @@ module ThreeScaleToolbox
|
|
|
36
35
|
end
|
|
37
36
|
end
|
|
38
37
|
|
|
39
|
-
def
|
|
40
|
-
write_error(error, $stderr)
|
|
41
|
-
|
|
38
|
+
def print_unexpected_error(error)
|
|
42
39
|
File.open('crash.log', 'w') do |io|
|
|
43
40
|
write_verbose_error(error, io)
|
|
44
41
|
end
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
warn
|
|
48
|
-
warn 'A detailed crash log has been written to ./crash.log.'
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def write_error(error, stream)
|
|
52
|
-
write_error_message(error, stream)
|
|
53
|
-
write_stack_trace(error, stream)
|
|
43
|
+
warn error_serialize(UnexpectedError.new(error))
|
|
54
44
|
end
|
|
55
45
|
|
|
56
46
|
def write_error_message(error, stream)
|
|
@@ -113,6 +103,19 @@ module ThreeScaleToolbox
|
|
|
113
103
|
stream.puts "===== #{title.upcase}:"
|
|
114
104
|
stream.puts
|
|
115
105
|
end
|
|
106
|
+
|
|
107
|
+
def error_serialize(error)
|
|
108
|
+
JSON.pretty_generate format_error(error)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def format_error(error)
|
|
112
|
+
{
|
|
113
|
+
code: error.code,
|
|
114
|
+
message: error.message,
|
|
115
|
+
class: error.kind,
|
|
116
|
+
stacktrace: error.stacktrace
|
|
117
|
+
}.compact
|
|
118
|
+
end
|
|
116
119
|
end
|
|
117
120
|
end
|
|
118
121
|
end
|
|
@@ -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'],
|
|
@@ -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?
|