3scale_toolbox 0.12.4 → 0.17.0
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 +4 -3
- data/README.md +31 -10
- data/lib/3scale_toolbox.rb +5 -2
- data/lib/3scale_toolbox/attribute_filters.rb +2 -0
- data/lib/3scale_toolbox/attribute_filters/attribute_filter.rb +9 -0
- data/lib/3scale_toolbox/attribute_filters/service_id_from_ref_filter.rb +30 -0
- data/lib/3scale_toolbox/cli.rb +4 -0
- data/lib/3scale_toolbox/cli/custom_table_printer.rb +32 -0
- data/lib/3scale_toolbox/cli/error_handler.rb +17 -14
- data/lib/3scale_toolbox/cli/json_printer.rb +13 -0
- data/lib/3scale_toolbox/cli/output_flag.rb +20 -0
- data/lib/3scale_toolbox/cli/yaml_printer.rb +13 -0
- data/lib/3scale_toolbox/commands.rb +5 -1
- data/lib/3scale_toolbox/commands/activedocs_command/apply_command.rb +34 -11
- data/lib/3scale_toolbox/commands/activedocs_command/create_command.rb +22 -7
- data/lib/3scale_toolbox/commands/activedocs_command/list_command.rb +21 -11
- data/lib/3scale_toolbox/commands/application_command/apply_command.rb +27 -4
- data/lib/3scale_toolbox/commands/application_command/create_command.rb +16 -1
- data/lib/3scale_toolbox/commands/application_command/list_command.rb +10 -13
- data/lib/3scale_toolbox/commands/application_command/show_command.rb +8 -14
- data/lib/3scale_toolbox/commands/backend_command.rb +22 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command.rb +65 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_mapping_rules_task.rb +52 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb +40 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_metrics_task.rb +30 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb +45 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/task.rb +89 -0
- data/lib/3scale_toolbox/commands/copy_command.rb +2 -2
- data/lib/3scale_toolbox/commands/copy_command/service_command.rb +40 -0
- data/lib/3scale_toolbox/commands/import_command/openapi.rb +29 -7
- data/lib/3scale_toolbox/commands/import_command/openapi/create_activedocs_step.rb +4 -17
- data/lib/3scale_toolbox/commands/import_command/openapi/create_service_step.rb +1 -5
- data/lib/3scale_toolbox/commands/import_command/openapi/mapping_rule.rb +3 -2
- data/lib/3scale_toolbox/commands/import_command/openapi/step.rb +43 -5
- data/lib/3scale_toolbox/commands/import_command/openapi/update_policies_step.rb +9 -10
- data/lib/3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step.rb +2 -17
- data/lib/3scale_toolbox/commands/import_command/openapi/update_service_proxy_step.rb +10 -10
- data/lib/3scale_toolbox/commands/methods_command/apply_command.rb +26 -4
- data/lib/3scale_toolbox/commands/methods_command/create_command.rb +23 -1
- data/lib/3scale_toolbox/commands/methods_command/list_command.rb +11 -9
- data/lib/3scale_toolbox/commands/metrics_command/apply_command.rb +26 -4
- data/lib/3scale_toolbox/commands/metrics_command/create_command.rb +23 -1
- data/lib/3scale_toolbox/commands/metrics_command/list_command.rb +7 -12
- data/lib/3scale_toolbox/commands/plans_command/apply_command.rb +36 -7
- data/lib/3scale_toolbox/commands/plans_command/create_command.rb +23 -1
- data/lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb +11 -12
- data/lib/3scale_toolbox/commands/plans_command/import/import_plan_pricing_rules_step.rb +11 -12
- data/lib/3scale_toolbox/commands/plans_command/list_command.rb +8 -13
- data/lib/3scale_toolbox/commands/plans_command/show_command.rb +6 -14
- data/lib/3scale_toolbox/commands/product_command.rb +22 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command.rb +78 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command/copy_backends_task.rb +71 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command/delete_target_backend_usages_task.rb +48 -0
- data/lib/3scale_toolbox/commands/proxy_config_command.rb +3 -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/proxy_config_command/list_command.rb +13 -29
- data/lib/3scale_toolbox/commands/proxy_config_command/show_command.rb +20 -23
- data/lib/3scale_toolbox/commands/service_command.rb +7 -5
- data/lib/3scale_toolbox/commands/service_command/apply_command.rb +69 -58
- data/lib/3scale_toolbox/commands/service_command/copy_command.rb +95 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/bump_proxy_version_task.rb +36 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_activedocs_task.rb +46 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb +35 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb +39 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb +35 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_methods_task.rb +40 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_metrics_task.rb +37 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_policies_task.rb +17 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_pricingrules_task.rb +44 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_service_proxy_task.rb +32 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb +48 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/destroy_mapping_rules_task.rb +34 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/task.rb +99 -0
- data/lib/3scale_toolbox/commands/service_command/create_command.rb +58 -44
- data/lib/3scale_toolbox/commands/service_command/delete_command.rb +31 -33
- data/lib/3scale_toolbox/commands/service_command/list_command.rb +24 -34
- data/lib/3scale_toolbox/commands/service_command/show_command.rb +39 -44
- data/lib/3scale_toolbox/commands/update_command.rb +3 -3
- data/lib/3scale_toolbox/commands/update_command/{update_service.rb → service_command.rb} +22 -18
- data/lib/3scale_toolbox/commands/update_command/service_command/copy_service_settings_task.rb +35 -0
- data/lib/3scale_toolbox/commands/update_command/service_command/delete_activedocs_task.rb +26 -0
- data/lib/3scale_toolbox/entities.rb +5 -0
- data/lib/3scale_toolbox/entities/application_plan.rb +31 -4
- data/lib/3scale_toolbox/entities/backend.rb +152 -0
- data/lib/3scale_toolbox/entities/backend_mapping_rule.rb +76 -0
- data/lib/3scale_toolbox/entities/backend_method.rb +90 -0
- data/lib/3scale_toolbox/entities/backend_metric.rb +88 -0
- data/lib/3scale_toolbox/entities/backend_usage.rb +99 -0
- data/lib/3scale_toolbox/entities/service.rb +18 -3
- data/lib/3scale_toolbox/error.rb +53 -0
- data/lib/3scale_toolbox/helper.rb +20 -0
- data/lib/3scale_toolbox/openapi.rb +2 -0
- data/lib/3scale_toolbox/openapi/oas3.rb +232 -0
- data/lib/3scale_toolbox/openapi/swagger.rb +192 -0
- data/lib/3scale_toolbox/proxy_logger.rb +1 -1
- data/lib/3scale_toolbox/version.rb +1 -1
- data/licenses.xml +190 -20
- data/resources/oas3_meta_schema.json +1654 -0
- metadata +69 -30
- data/lib/3scale_toolbox/commands/copy_command/copy_service.rb +0 -142
- data/lib/3scale_toolbox/commands/import_command/openapi/threescale_api_spec.rb +0 -80
- data/lib/3scale_toolbox/swagger.rb +0 -1
- data/lib/3scale_toolbox/swagger/swagger.rb +0 -123
- data/lib/3scale_toolbox/tasks.rb +0 -15
- data/lib/3scale_toolbox/tasks/bump_proxy_version_task.rb +0 -32
- data/lib/3scale_toolbox/tasks/copy_activedocs_task.rb +0 -42
- data/lib/3scale_toolbox/tasks/copy_app_plans_task.rb +0 -31
- data/lib/3scale_toolbox/tasks/copy_limits_task.rb +0 -36
- data/lib/3scale_toolbox/tasks/copy_mapping_rules_task.rb +0 -32
- data/lib/3scale_toolbox/tasks/copy_methods_task.rb +0 -36
- data/lib/3scale_toolbox/tasks/copy_metrics_task.rb +0 -33
- data/lib/3scale_toolbox/tasks/copy_policies_task.rb +0 -13
- data/lib/3scale_toolbox/tasks/copy_pricingrules_task.rb +0 -41
- data/lib/3scale_toolbox/tasks/copy_service_proxy_task.rb +0 -12
- data/lib/3scale_toolbox/tasks/copy_service_settings_task.rb +0 -38
- data/lib/3scale_toolbox/tasks/copy_task.rb +0 -66
- data/lib/3scale_toolbox/tasks/delete_activedocs_task.rb +0 -22
- data/lib/3scale_toolbox/tasks/destroy_mapping_rules_task.rb +0 -22
- data/lib/3scale_toolbox/tasks/helper_task.rb +0 -25
@@ -0,0 +1,40 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module Commands
|
3
|
+
module BackendCommand
|
4
|
+
module CopyCommand
|
5
|
+
class CopyMethodsTask
|
6
|
+
include Task
|
7
|
+
|
8
|
+
# entrypoint
|
9
|
+
def run
|
10
|
+
missing_methods.each(&method(:create_method))
|
11
|
+
puts "created #{missing_methods.size} missing methods"
|
12
|
+
invalidate_target_methods if missing_methods.size.positive?
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def create_method(method)
|
18
|
+
# return silently if target metric hits does not exist
|
19
|
+
return if target_hits.nil?
|
20
|
+
|
21
|
+
Entities::BackendMethod.create(backend: target_backend,
|
22
|
+
parent_id: target_hits.id,
|
23
|
+
attrs: method.attrs)
|
24
|
+
rescue ThreeScaleToolbox::ThreeScaleApiError => e
|
25
|
+
raise e unless ThreeScaleToolbox::Helper.system_name_already_taken_error?(e.apierrors)
|
26
|
+
|
27
|
+
warn "[WARN] backend method #{method.attrs.fetch('system_name')} not created. " \
|
28
|
+
'Backend metric with the same system_name exists.'
|
29
|
+
end
|
30
|
+
|
31
|
+
def missing_methods
|
32
|
+
@missing_methods ||= ThreeScaleToolbox::Helper.array_difference(source_methods, target_methods) do |source, target|
|
33
|
+
source.system_name == target.system_name
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module Commands
|
3
|
+
module BackendCommand
|
4
|
+
module CopyCommand
|
5
|
+
class CopyMetricsTask
|
6
|
+
include Task
|
7
|
+
|
8
|
+
# entrypoint
|
9
|
+
def run
|
10
|
+
missing_metrics.each(&method(:create_metric))
|
11
|
+
puts "created #{missing_metrics.size} missing metrics"
|
12
|
+
invalidate_target_metrics if missing_metrics.size.positive?
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def create_metric(metric)
|
18
|
+
Entities::BackendMetric.create(backend: target_backend, attrs: metric.attrs)
|
19
|
+
end
|
20
|
+
|
21
|
+
def missing_metrics
|
22
|
+
@missing_metrics ||= ThreeScaleToolbox::Helper.array_difference(source_metrics, target_metrics) do |source, target|
|
23
|
+
source.system_name == target.system_name
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module Commands
|
3
|
+
module BackendCommand
|
4
|
+
module CopyCommand
|
5
|
+
class CreateOrUpdateTargetBackendTask
|
6
|
+
include Task
|
7
|
+
|
8
|
+
# entrypoint
|
9
|
+
def run
|
10
|
+
backend = Entities::Backend.find(remote: target_remote, ref: target_backend_ref)
|
11
|
+
|
12
|
+
if backend.nil?
|
13
|
+
backend = Entities::Backend.create(remote: target_remote,
|
14
|
+
attrs: create_attrs)
|
15
|
+
elsif backend == source_backend
|
16
|
+
message = 'source and destination backends are the same: ' \
|
17
|
+
"ID: #{source_backend.id} system_name: #{source_backend.attrs['system_name']}"
|
18
|
+
warn "\e[1m\e[31mWarning: #{message}\e[0m"
|
19
|
+
else
|
20
|
+
backend.update update_attrs
|
21
|
+
end
|
22
|
+
|
23
|
+
# assign target backend for other tasks to have it available
|
24
|
+
self.target_backend = backend
|
25
|
+
|
26
|
+
puts "source backend ID: #{source_backend.id} system_name: #{source_backend.attrs['system_name']}"
|
27
|
+
puts "target backend ID: #{target_backend.id} system_name: #{target_backend.attrs['system_name']}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_attrs
|
31
|
+
source_backend.attrs.merge('system_name' => target_backend_ref)
|
32
|
+
end
|
33
|
+
|
34
|
+
def update_attrs
|
35
|
+
source_backend.attrs.merge('system_name' => target_backend_ref)
|
36
|
+
end
|
37
|
+
|
38
|
+
def target_backend_ref
|
39
|
+
option_target_system_name || source_backend.attrs.fetch('system_name')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module Commands
|
3
|
+
module BackendCommand
|
4
|
+
module CopyCommand
|
5
|
+
module Task
|
6
|
+
attr_reader :context
|
7
|
+
|
8
|
+
def initialize(context)
|
9
|
+
@context = context
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
run
|
14
|
+
end
|
15
|
+
|
16
|
+
def target_backend=(target)
|
17
|
+
context[:target_backend] = target
|
18
|
+
end
|
19
|
+
|
20
|
+
def target_backend
|
21
|
+
context[:target_backend] ||= raise ThreeScaleToolbox::Error, 'Unexpected error. ' \
|
22
|
+
'Target backend should have been created or updated'
|
23
|
+
end
|
24
|
+
|
25
|
+
def source_backend
|
26
|
+
context[:source_backend] ||= find_source_backend
|
27
|
+
end
|
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
|
+
def source_remote
|
62
|
+
context[:source_remote]
|
63
|
+
end
|
64
|
+
|
65
|
+
def target_remote
|
66
|
+
context[:target_remote]
|
67
|
+
end
|
68
|
+
|
69
|
+
def source_backend_ref
|
70
|
+
context[:source_backend_ref] ||= raise ThreeScaleToolbox::Error, 'Unexpected error. ' \
|
71
|
+
'source_backend_ref not found'
|
72
|
+
end
|
73
|
+
|
74
|
+
def option_target_system_name
|
75
|
+
context[:option_target_system_name]
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def find_source_backend
|
81
|
+
Entities::Backend.find(remote: source_remote, ref: source_backend_ref).tap do |backend|
|
82
|
+
raise ThreeScaleToolbox::Error, "Backend #{source_backend_ref} does not exist" if backend.nil?
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '3scale_toolbox/commands/copy_command/
|
1
|
+
require '3scale_toolbox/commands/copy_command/service_command'
|
2
2
|
|
3
3
|
module ThreeScaleToolbox
|
4
4
|
module Commands
|
@@ -16,7 +16,7 @@ module ThreeScaleToolbox
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
-
add_subcommand(
|
19
|
+
add_subcommand(ServiceSubcommand)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module Commands
|
3
|
+
module CopyCommand
|
4
|
+
class ServiceSubcommand < Cri::CommandRunner
|
5
|
+
include ThreeScaleToolbox::Command
|
6
|
+
|
7
|
+
def self.command
|
8
|
+
Cri::Command.define do
|
9
|
+
name 'service'
|
10
|
+
usage 'service [opts] -s <src> -d <dst> <source-service>'
|
11
|
+
summary 'copy service'
|
12
|
+
description <<-HEREDOC
|
13
|
+
This command makes a copy of the referenced service.
|
14
|
+
Target service will be searched by source service system name. System name can be overriden with `--target_system_name` option.
|
15
|
+
If a service with the selected `system_name` is not found, it will be created.
|
16
|
+
\n Components of the service being copied:
|
17
|
+
\nservice settings
|
18
|
+
\nproxy settings
|
19
|
+
\npricing rules
|
20
|
+
\nactivedocs
|
21
|
+
\nmetrics
|
22
|
+
\nmethods
|
23
|
+
\napplication plans
|
24
|
+
\nmapping rules
|
25
|
+
HEREDOC
|
26
|
+
|
27
|
+
option :s, :source, '3scale source instance. Url or remote name', argument: :required
|
28
|
+
option :d, :destination, '3scale target instance. Url or remote name', argument: :required
|
29
|
+
option :t, 'target_system_name', 'Target system name. Default to source system name', argument: :required
|
30
|
+
flag :f, :force, 'Overwrites the mapping rules by deleting all rules from target service first'
|
31
|
+
flag :r, 'rules-only', 'Only mapping rules are copied'
|
32
|
+
param :source_service
|
33
|
+
|
34
|
+
runner Commands::ServiceCommand::CopySubcommand
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -2,7 +2,6 @@ require '3scale_toolbox/commands/import_command/openapi/method'
|
|
2
2
|
require '3scale_toolbox/commands/import_command/openapi/mapping_rule'
|
3
3
|
require '3scale_toolbox/commands/import_command/openapi/operation'
|
4
4
|
require '3scale_toolbox/commands/import_command/openapi/step'
|
5
|
-
require '3scale_toolbox/commands/import_command/openapi/threescale_api_spec'
|
6
5
|
require '3scale_toolbox/commands/import_command/openapi/create_method_step'
|
7
6
|
require '3scale_toolbox/commands/import_command/openapi/create_mapping_rule_step'
|
8
7
|
require '3scale_toolbox/commands/import_command/openapi/create_service_step'
|
@@ -30,6 +29,7 @@ module ThreeScaleToolbox
|
|
30
29
|
option :t, 'target_system_name', 'Target system name', argument: :required
|
31
30
|
flag nil, 'activedocs-hidden', 'Create ActiveDocs in hidden state'
|
32
31
|
flag nil, 'skip-openapi-validation', 'Skip OpenAPI schema validation'
|
32
|
+
flag nil, 'prefix-matching', 'Use prefix matching instead of strict matching on mapping rules derived from openapi operations'
|
33
33
|
option nil, 'oidc-issuer-endpoint', 'OIDC Issuer Endpoint', argument: :required
|
34
34
|
option nil, 'default-credentials-userkey', 'Default credentials policy userkey', argument: :required
|
35
35
|
option nil, 'override-private-basepath', 'Override the basepath for the private URLs', argument: :required
|
@@ -37,6 +37,8 @@ module ThreeScaleToolbox
|
|
37
37
|
option nil, 'staging-public-base-url', 'Custom public staging URL', argument: :required
|
38
38
|
option nil, 'production-public-base-url', 'Custom public production URL', argument: :required
|
39
39
|
option nil, 'override-private-base-url', 'Custom private base URL', argument: :required
|
40
|
+
option nil, 'backend-api-secret-token', 'Custom secret token sent by the API gateway to the backend API',argument: :required
|
41
|
+
option nil, 'backend-api-host-header', 'Custom host header sent by the API gateway to the backend API', argument: :required
|
40
42
|
param :openapi_resource
|
41
43
|
|
42
44
|
runner OpenAPISubcommand
|
@@ -49,7 +51,7 @@ module ThreeScaleToolbox
|
|
49
51
|
# other tasks might read proxy settings (CreateActiveDocsStep does)
|
50
52
|
tasks << UpdateServiceProxyStep.new(context)
|
51
53
|
tasks << CreateMethodsStep.new(context)
|
52
|
-
tasks <<
|
54
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::DestroyMappingRulesTask.new(context)
|
53
55
|
tasks << CreateMappingRulesStep.new(context)
|
54
56
|
tasks << CreateActiveDocsStep.new(context)
|
55
57
|
tasks << UpdateServiceOidcConfStep.new(context)
|
@@ -59,7 +61,7 @@ module ThreeScaleToolbox
|
|
59
61
|
tasks.each(&:call)
|
60
62
|
|
61
63
|
# This should be the last step
|
62
|
-
|
64
|
+
ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::BumpProxyVersionTask.new(service: context[:target]).call
|
63
65
|
end
|
64
66
|
|
65
67
|
private
|
@@ -69,10 +71,9 @@ module ThreeScaleToolbox
|
|
69
71
|
end
|
70
72
|
|
71
73
|
def create_context
|
72
|
-
openapi_resource = load_resource(arguments[:openapi_resource])
|
73
74
|
{
|
74
75
|
api_spec_resource: openapi_resource,
|
75
|
-
api_spec:
|
76
|
+
api_spec: openapi_parser,
|
76
77
|
threescale_client: threescale_client(fetch_required_option(:destination)),
|
77
78
|
target_system_name: options[:target_system_name],
|
78
79
|
activedocs_published: !options[:'activedocs-hidden'],
|
@@ -80,14 +81,35 @@ module ThreeScaleToolbox
|
|
80
81
|
default_credentials_userkey: options[:'default-credentials-userkey'],
|
81
82
|
skip_openapi_validation: options[:'skip-openapi-validation'],
|
82
83
|
override_private_basepath: options[:'override-private-basepath'],
|
84
|
+
override_public_basepath: options[:'override-public-basepath'],
|
83
85
|
production_public_base_url: options[:'production-public-base-url'],
|
84
86
|
staging_public_base_url: options[:'staging-public-base-url'],
|
85
87
|
override_private_base_url: options[:'override-private-base-url'],
|
88
|
+
backend_api_secret_token: options[:'backend-api-secret-token'],
|
89
|
+
backend_api_host_header: options[:'backend-api-host-header'],
|
90
|
+
prefix_matching: options[:'prefix-matching'],
|
91
|
+
delete_mapping_rules: true,
|
86
92
|
}
|
87
93
|
end
|
88
94
|
|
89
|
-
def
|
90
|
-
|
95
|
+
def openapi_resource
|
96
|
+
@openapi_resource ||= load_resource(openapi_path)
|
97
|
+
end
|
98
|
+
|
99
|
+
def openapi_path
|
100
|
+
arguments[:openapi_resource]
|
101
|
+
end
|
102
|
+
|
103
|
+
def validate
|
104
|
+
!options[:'skip-openapi-validation']
|
105
|
+
end
|
106
|
+
|
107
|
+
def openapi_parser
|
108
|
+
if openapi_resource.key?('openapi')
|
109
|
+
ThreeScaleToolbox::OpenAPI::OAS3.build(openapi_path, openapi_resource, validate: validate)
|
110
|
+
else
|
111
|
+
ThreeScaleToolbox::OpenAPI::Swagger.build(openapi_resource, validate: validate)
|
112
|
+
end
|
91
113
|
rescue JSON::Schema::ValidationError => e
|
92
114
|
raise ThreeScaleToolbox::Error, "OpenAPI schema validation failed: #{e.message}"
|
93
115
|
end
|
@@ -53,26 +53,13 @@ module ThreeScaleToolbox
|
|
53
53
|
# Other processing steps can work with original openapi spec
|
54
54
|
Helper.hash_deep_dup(resource).tap do |activedocs|
|
55
55
|
# public production base URL
|
56
|
-
URI(service.proxy.fetch('endpoint')).tap do |uri|
|
57
|
-
activedocs['host'] = "#{uri.host}:#{uri.port}"
|
58
|
-
activedocs['schemes'] = [uri.scheme]
|
59
|
-
end
|
60
|
-
|
61
56
|
# the basePath field is updated to a new value only when overriden by optional param
|
62
|
-
|
63
|
-
|
57
|
+
api_spec.set_server_url(activedocs,
|
58
|
+
URI.join(service.proxy.fetch('endpoint'), public_base_path))
|
64
59
|
# security definitions
|
65
60
|
# just valid for oauth2 when oidc_issuer_endpoint is supplied
|
66
|
-
if !security.nil? && security
|
67
|
-
|
68
|
-
if %w[implicit accessCode].include?(security.flow)
|
69
|
-
activedocs['securityDefinitions'][security.id]['authorizationUrl'] = authorization_url
|
70
|
-
end
|
71
|
-
|
72
|
-
# tokenUrl
|
73
|
-
if %w[password application accessCode].include?(security.flow)
|
74
|
-
activedocs['securityDefinitions'][security.id]['tokenUrl'] = token_url
|
75
|
-
end
|
61
|
+
if !api_spec.security.nil? && api_spec.security[:type] == 'oauth2' && !oidc_issuer_endpoint.nil?
|
62
|
+
api_spec.set_oauth2_urls(activedocs, api_spec.security[:id], authorization_url, token_url)
|
76
63
|
end
|
77
64
|
end
|
78
65
|
end
|
@@ -33,7 +33,7 @@ module ThreeScaleToolbox
|
|
33
33
|
default_service_settings.tap do |svc|
|
34
34
|
svc['name'] = service_name
|
35
35
|
svc['description'] = service_description
|
36
|
-
svc['backend_version'] =
|
36
|
+
svc['backend_version'] = api_spec.service_backend_version
|
37
37
|
svc['system_name'] = service_system_name
|
38
38
|
svc['deployment_option'] = 'self_managed' if !production_public_base_url.nil? || !staging_public_base_url.nil?
|
39
39
|
end
|
@@ -50,10 +50,6 @@ module ThreeScaleToolbox
|
|
50
50
|
def service_description
|
51
51
|
api_spec.description
|
52
52
|
end
|
53
|
-
|
54
|
-
def backend_version
|
55
|
-
api_spec.backend_version
|
56
|
-
end
|
57
53
|
end
|
58
54
|
end
|
59
55
|
end
|
@@ -31,7 +31,21 @@ module ThreeScaleToolbox
|
|
31
31
|
# api_spec.operations are readonly
|
32
32
|
# store operations in context
|
33
33
|
# each operation can be extended with extra information to be used later
|
34
|
-
context[:operations] ||=
|
34
|
+
context[:operations] ||= build_3scale_operations
|
35
|
+
end
|
36
|
+
|
37
|
+
def build_3scale_operations
|
38
|
+
api_spec.operations.map do |op|
|
39
|
+
Operation.new(
|
40
|
+
base_path: base_path,
|
41
|
+
public_base_path: public_base_path,
|
42
|
+
path: op[:path],
|
43
|
+
verb: op[:verb],
|
44
|
+
operationId: op[:operation_id],
|
45
|
+
description: op[:description],
|
46
|
+
prefix_matching: prefix_matching,
|
47
|
+
)
|
48
|
+
end
|
35
49
|
end
|
36
50
|
|
37
51
|
def target_system_name
|
@@ -43,10 +57,6 @@ module ThreeScaleToolbox
|
|
43
57
|
context[:api_spec_resource]
|
44
58
|
end
|
45
59
|
|
46
|
-
def security
|
47
|
-
api_spec.security
|
48
|
-
end
|
49
|
-
|
50
60
|
def oidc_issuer_endpoint
|
51
61
|
context[:oidc_issuer_endpoint]
|
52
62
|
end
|
@@ -59,6 +69,10 @@ module ThreeScaleToolbox
|
|
59
69
|
context[:override_private_basepath]
|
60
70
|
end
|
61
71
|
|
72
|
+
def override_public_basepath
|
73
|
+
context[:override_public_basepath]
|
74
|
+
end
|
75
|
+
|
62
76
|
def production_public_base_url
|
63
77
|
context[:production_public_base_url]
|
64
78
|
end
|
@@ -70,6 +84,30 @@ module ThreeScaleToolbox
|
|
70
84
|
def override_private_base_url
|
71
85
|
context[:override_private_base_url]
|
72
86
|
end
|
87
|
+
|
88
|
+
def backend_api_secret_token
|
89
|
+
context[:backend_api_secret_token]
|
90
|
+
end
|
91
|
+
|
92
|
+
def backend_api_host_header
|
93
|
+
context[:backend_api_host_header]
|
94
|
+
end
|
95
|
+
|
96
|
+
def prefix_matching
|
97
|
+
context[:prefix_matching]
|
98
|
+
end
|
99
|
+
|
100
|
+
def base_path
|
101
|
+
api_spec.base_path || '/'
|
102
|
+
end
|
103
|
+
|
104
|
+
def public_base_path
|
105
|
+
override_public_basepath || base_path
|
106
|
+
end
|
107
|
+
|
108
|
+
def private_base_path
|
109
|
+
override_private_basepath || base_path
|
110
|
+
end
|
73
111
|
end
|
74
112
|
end
|
75
113
|
end
|