3scale_toolbox 0.15.0 → 0.18.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/3scale_toolbox.gemspec +2 -2
- data/README.md +15 -9
- data/lib/3scale_toolbox.rb +3 -1
- data/lib/3scale_toolbox/3scale_client_factory.rb +3 -4
- 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 +7 -1
- data/lib/3scale_toolbox/commands/activedocs_command/apply_command.rb +33 -10
- data/lib/3scale_toolbox/commands/activedocs_command/create_command.rb +22 -7
- data/lib/3scale_toolbox/commands/activedocs_command/list_command.rb +10 -17
- 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 +36 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb +35 -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 +46 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/task.rb +67 -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/issuer_type_transformer.rb +16 -0
- data/lib/3scale_toolbox/commands/import_command/openapi.rb +6 -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 +28 -8
- data/lib/3scale_toolbox/commands/methods_command/create_command.rb +23 -3
- data/lib/3scale_toolbox/commands/methods_command/delete_command.rb +1 -1
- data/lib/3scale_toolbox/commands/methods_command/list_command.rb +7 -13
- 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/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 +8 -13
- data/lib/3scale_toolbox/commands/plans_command/show_command.rb +7 -15
- 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 +26 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command.rb +82 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command/copy_backends_task.rb +88 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command/delete_target_backend_usages_task.rb +48 -0
- 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/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 +49 -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 +38 -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 +37 -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 +41 -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 +49 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/destroy_mapping_rules_task.rb +38 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/task.rb +85 -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 +24 -0
- 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 +8 -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 +187 -0
- data/lib/3scale_toolbox/entities/backend_mapping_rule.rb +102 -0
- data/lib/3scale_toolbox/entities/backend_method.rb +99 -0
- data/lib/3scale_toolbox/entities/backend_metric.rb +98 -0
- data/lib/3scale_toolbox/entities/backend_usage.rb +105 -0
- 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 +166 -48
- data/lib/3scale_toolbox/error.rb +53 -0
- data/lib/3scale_toolbox/helper.rb +17 -0
- data/lib/3scale_toolbox/openapi/oas3.rb +1 -1
- data/lib/3scale_toolbox/proxy_logger.rb +5 -1
- 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 +75 -26
- data/lib/3scale_toolbox/commands/copy_command/copy_service.rb +0 -144
- 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 -13
- 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,46 @@
|
|
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
|
+
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
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_attrs
|
32
|
+
source_backend.attrs.merge('system_name' => target_backend_ref)
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_attrs
|
36
|
+
source_backend.attrs.merge('system_name' => target_backend_ref)
|
37
|
+
end
|
38
|
+
|
39
|
+
def target_backend_ref
|
40
|
+
option_target_system_name || source_backend.attrs.fetch('system_name')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,67 @@
|
|
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_remote
|
30
|
+
context[:source_remote]
|
31
|
+
end
|
32
|
+
|
33
|
+
def target_remote
|
34
|
+
context[:target_remote]
|
35
|
+
end
|
36
|
+
|
37
|
+
def source_backend_ref
|
38
|
+
context[:source_backend_ref] ||= raise ThreeScaleToolbox::Error, 'Unexpected error. ' \
|
39
|
+
'source_backend_ref not found'
|
40
|
+
end
|
41
|
+
|
42
|
+
def option_target_system_name
|
43
|
+
context[:option_target_system_name]
|
44
|
+
end
|
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
|
+
private
|
57
|
+
|
58
|
+
def find_source_backend
|
59
|
+
Entities::Backend.find(remote: source_remote, ref: source_backend_ref).tap do |backend|
|
60
|
+
raise ThreeScaleToolbox::Error, "Backend #{source_backend_ref} does not exist" if backend.nil?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
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
|
@@ -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
|
@@ -51,7 +53,7 @@ module ThreeScaleToolbox
|
|
51
53
|
# other tasks might read proxy settings (CreateActiveDocsStep does)
|
52
54
|
tasks << UpdateServiceProxyStep.new(context)
|
53
55
|
tasks << CreateMethodsStep.new(context)
|
54
|
-
tasks <<
|
56
|
+
tasks << ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::DestroyMappingRulesTask.new(context)
|
55
57
|
tasks << CreateMappingRulesStep.new(context)
|
56
58
|
tasks << CreateActiveDocsStep.new(context)
|
57
59
|
tasks << UpdateServiceOidcConfStep.new(context)
|
@@ -61,7 +63,7 @@ module ThreeScaleToolbox
|
|
61
63
|
tasks.each(&:call)
|
62
64
|
|
63
65
|
# This should be the last step
|
64
|
-
|
66
|
+
ThreeScaleToolbox::Commands::ServiceCommand::CopyCommand::BumpProxyVersionTask.new(service: context[:target]).call
|
65
67
|
end
|
66
68
|
|
67
69
|
private
|
@@ -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'],
|
@@ -88,6 +91,7 @@ module ThreeScaleToolbox
|
|
88
91
|
backend_api_secret_token: options[:'backend-api-secret-token'],
|
89
92
|
backend_api_host_header: options[:'backend-api-host-header'],
|
90
93
|
prefix_matching: options[:'prefix-matching'],
|
94
|
+
delete_mapping_rules: true,
|
91
95
|
}
|
92
96
|
end
|
93
97
|
|
@@ -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
|
|
@@ -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
|
@@ -2,6 +2,24 @@ module ThreeScaleToolbox
|
|
2
2
|
module Commands
|
3
3
|
module MethodsCommand
|
4
4
|
module Apply
|
5
|
+
class CustomPrinter
|
6
|
+
attr_reader :option_disabled, :option_enabled
|
7
|
+
|
8
|
+
def initialize(options)
|
9
|
+
@option_disabled = options[:disabled]
|
10
|
+
@option_enabled = options[:enabled]
|
11
|
+
end
|
12
|
+
|
13
|
+
def print_record(method)
|
14
|
+
output_msg_array = ["Applied method id: #{method['id']}"]
|
15
|
+
output_msg_array << 'Disabled' if option_disabled
|
16
|
+
output_msg_array << 'Enabled' if option_enabled
|
17
|
+
puts output_msg_array.join('; ')
|
18
|
+
end
|
19
|
+
|
20
|
+
def print_collection(collection) end
|
21
|
+
end
|
22
|
+
|
5
23
|
class ApplySubcommand < Cri::CommandRunner
|
6
24
|
include ThreeScaleToolbox::Command
|
7
25
|
|
@@ -16,6 +34,8 @@ module ThreeScaleToolbox
|
|
16
34
|
flag nil, :disabled, 'Disables this method in all application plans'
|
17
35
|
flag nil, :enabled, 'Enables this method in all application plans'
|
18
36
|
option nil, :description, 'Method description', argument: :required
|
37
|
+
ThreeScaleToolbox::CLI.output_flag(self)
|
38
|
+
|
19
39
|
param :remote
|
20
40
|
param :service_ref
|
21
41
|
param :method_ref
|
@@ -27,11 +47,9 @@ module ThreeScaleToolbox
|
|
27
47
|
def run
|
28
48
|
validate_option_params
|
29
49
|
hits = service.hits
|
30
|
-
method = Entities::Method.find(service: service,
|
31
|
-
ref: method_ref)
|
50
|
+
method = Entities::Method.find(service: service, ref: method_ref)
|
32
51
|
if method.nil?
|
33
|
-
method = Entities::Method.create(service: service,
|
34
|
-
attrs: create_method_attrs)
|
52
|
+
method = Entities::Method.create(service: service, attrs: create_method_attrs)
|
35
53
|
else
|
36
54
|
method.update(method_attrs) unless method_attrs.empty?
|
37
55
|
end
|
@@ -39,10 +57,7 @@ module ThreeScaleToolbox
|
|
39
57
|
method.disable if option_disabled
|
40
58
|
method.enable if option_enabled
|
41
59
|
|
42
|
-
|
43
|
-
output_msg_array << 'Disabled' if option_disabled
|
44
|
-
output_msg_array << 'Enabled' if option_enabled
|
45
|
-
puts output_msg_array.join('; ')
|
60
|
+
printer.print_record method.attrs
|
46
61
|
end
|
47
62
|
|
48
63
|
private
|
@@ -94,6 +109,11 @@ module ThreeScaleToolbox
|
|
94
109
|
def method_ref
|
95
110
|
arguments[:method_ref]
|
96
111
|
end
|
112
|
+
|
113
|
+
def printer
|
114
|
+
# keep backwards compatibility
|
115
|
+
options.fetch(:output, CustomPrinter.new(disabled: option_disabled, enabled: option_enabled))
|
116
|
+
end
|
97
117
|
end
|
98
118
|
end
|
99
119
|
end
|
@@ -2,6 +2,20 @@ module ThreeScaleToolbox
|
|
2
2
|
module Commands
|
3
3
|
module MethodsCommand
|
4
4
|
module Create
|
5
|
+
class CustomPrinter
|
6
|
+
attr_reader :option_disabled
|
7
|
+
|
8
|
+
def initialize(options)
|
9
|
+
@option_disabled = options[:disabled]
|
10
|
+
end
|
11
|
+
|
12
|
+
def print_record(method)
|
13
|
+
puts "Created method id: #{method['id']}. Disabled: #{option_disabled}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def print_collection(collection) end
|
17
|
+
end
|
18
|
+
|
5
19
|
class CreateSubcommand < Cri::CommandRunner
|
6
20
|
include ThreeScaleToolbox::Command
|
7
21
|
|
@@ -15,6 +29,8 @@ module ThreeScaleToolbox
|
|
15
29
|
option :t, 'system-name', 'Method system name', argument: :required
|
16
30
|
flag nil, :disabled, 'Disables this method in all application plans'
|
17
31
|
option nil, :description, 'Method description', argument: :required
|
32
|
+
ThreeScaleToolbox::CLI.output_flag(self)
|
33
|
+
|
18
34
|
param :remote
|
19
35
|
param :service_ref
|
20
36
|
param :method_name
|
@@ -24,14 +40,13 @@ module ThreeScaleToolbox
|
|
24
40
|
end
|
25
41
|
|
26
42
|
def run
|
27
|
-
hits = service.hits
|
28
43
|
method = ThreeScaleToolbox::Entities::Method.create(
|
29
44
|
service: service,
|
30
|
-
parent_id: hits.fetch('id'),
|
31
45
|
attrs: method_attrs
|
32
46
|
)
|
33
47
|
method.disable if option_disabled
|
34
|
-
|
48
|
+
|
49
|
+
printer.print_record method.attrs
|
35
50
|
end
|
36
51
|
|
37
52
|
private
|
@@ -66,6 +81,11 @@ module ThreeScaleToolbox
|
|
66
81
|
def service_ref
|
67
82
|
arguments[:service_ref]
|
68
83
|
end
|
84
|
+
|
85
|
+
def printer
|
86
|
+
# keep backwards compatibility
|
87
|
+
options.fetch(:output, CustomPrinter.new(disabled: option_disabled))
|
88
|
+
end
|
69
89
|
end
|
70
90
|
end
|
71
91
|
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
|