3scale_toolbox 0.15.0 → 0.18.2
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 +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,54 @@
|
|
|
1
|
+
module ThreeScaleToolbox
|
|
2
|
+
module Commands
|
|
3
|
+
module ProxyConfigCommand
|
|
4
|
+
class DeploySubcommand < Cri::CommandRunner
|
|
5
|
+
include ThreeScaleToolbox::Command
|
|
6
|
+
|
|
7
|
+
def self.command
|
|
8
|
+
Cri::Command.define do
|
|
9
|
+
name 'deploy'
|
|
10
|
+
usage 'deploy <remote> <service>'
|
|
11
|
+
summary 'Promotes the APIcast configuration to the Staging Environment'
|
|
12
|
+
description 'Promotes the APIcast configuration to the Staging Environment (Production Environment in case of Service Mesh).'
|
|
13
|
+
|
|
14
|
+
param :remote
|
|
15
|
+
param :service_ref
|
|
16
|
+
|
|
17
|
+
ThreeScaleToolbox::CLI.output_flag(self)
|
|
18
|
+
|
|
19
|
+
runner DeploySubcommand
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def run
|
|
24
|
+
printer.print_record service.proxy_deploy
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def remote
|
|
30
|
+
@remote ||= threescale_client(arguments[:remote])
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def service_ref
|
|
34
|
+
arguments[:service_ref]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def find_service
|
|
38
|
+
Entities::Service.find(remote: remote,
|
|
39
|
+
ref: service_ref).tap do |svc|
|
|
40
|
+
raise ThreeScaleToolbox::Error, "Service #{service_ref} does not exist" if svc.nil?
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def service
|
|
45
|
+
@service ||= find_service
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def printer
|
|
49
|
+
options.fetch(:output, CLI::JsonPrinter.new)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module ThreeScaleToolbox
|
|
2
|
+
module Commands
|
|
3
|
+
module ProxyConfigCommand
|
|
4
|
+
module Export
|
|
5
|
+
class ExportSubcommand < Cri::CommandRunner
|
|
6
|
+
include ThreeScaleToolbox::Command
|
|
7
|
+
|
|
8
|
+
def self.command
|
|
9
|
+
Cri::Command.define do
|
|
10
|
+
name 'export'
|
|
11
|
+
usage 'export <remote>'
|
|
12
|
+
summary 'Export proxy configuration for the entire provider account'
|
|
13
|
+
description <<-HEREDOC
|
|
14
|
+
Export proxy configuration for the entire provider account
|
|
15
|
+
\n Can be used as 3scale apicast configuration file
|
|
16
|
+
\n https://github.com/3scale/apicast/blob/master/doc/parameters.md#threescale_config_file
|
|
17
|
+
HEREDOC
|
|
18
|
+
|
|
19
|
+
param :remote
|
|
20
|
+
|
|
21
|
+
ThreeScaleToolbox::CLI.output_flag(self)
|
|
22
|
+
option nil, :environment, "Gateway environment. Must be 'sandbox' or 'production'", default: 'sandbox', argument: :required, transform: ProxyConfigCommand::EnvironmentTransformer.new
|
|
23
|
+
|
|
24
|
+
runner ExportSubcommand
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def run
|
|
29
|
+
printer.print_record proxy_config_list_obj
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def proxy_config_list_obj
|
|
35
|
+
{
|
|
36
|
+
'services' => proxy_config_list
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def proxy_config_list
|
|
41
|
+
service_list.map do |service|
|
|
42
|
+
pc = Entities::ProxyConfig.find_latest(service: service, environment: environment)
|
|
43
|
+
pc.attrs['content'] unless pc.nil?
|
|
44
|
+
end.compact
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def service_list
|
|
48
|
+
tmp_list = remote.list_services
|
|
49
|
+
|
|
50
|
+
if tmp_list.respond_to?(:has_key?) && (errors = tmp_list['errors'])
|
|
51
|
+
raise ThreeScaleToolbox::ThreeScaleApiError.new('Service list not read', errors)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
tmp_list.map do |svc_attrs|
|
|
55
|
+
Entities::Service.new(id: svc_attrs.fetch('id'), remote: remote, attrs: svc_attrs)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def remote
|
|
60
|
+
@remote ||= threescale_client(arguments[:remote])
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def environment
|
|
64
|
+
options[:environment]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def printer
|
|
68
|
+
options.fetch(:output, CLI::JsonPrinter.new)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module ThreeScaleToolbox
|
|
2
|
+
module Commands
|
|
3
|
+
module ProxyConfigCommand
|
|
4
|
+
class EnvironmentTransformer
|
|
5
|
+
def call(param_str)
|
|
6
|
+
raise ArgumentError unless param_str.is_a?(String)
|
|
7
|
+
|
|
8
|
+
raise ArgumentError unless %w[production sandbox].include? param_str
|
|
9
|
+
|
|
10
|
+
param_str
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -5,30 +5,30 @@ module ThreeScaleToolbox
|
|
|
5
5
|
class ListSubcommand < Cri::CommandRunner
|
|
6
6
|
include ThreeScaleToolbox::Command
|
|
7
7
|
|
|
8
|
+
FIELDS = %w[id version environment]
|
|
9
|
+
|
|
8
10
|
def self.command
|
|
9
11
|
Cri::Command.define do
|
|
10
12
|
name 'list'
|
|
11
13
|
usage 'list <remote> <service> <environment>'
|
|
12
14
|
summary 'List Proxy Configurations'
|
|
13
15
|
description 'List all defined Proxy Configurations'
|
|
14
|
-
runner ListSubcommand
|
|
15
16
|
|
|
17
|
+
ThreeScaleToolbox::CLI.output_flag(self)
|
|
16
18
|
param :remote
|
|
17
19
|
param :service_ref
|
|
18
20
|
param :environment
|
|
21
|
+
|
|
22
|
+
runner ListSubcommand
|
|
19
23
|
end
|
|
20
24
|
end
|
|
21
25
|
|
|
22
26
|
def run
|
|
23
|
-
|
|
27
|
+
printer.print_collection service.proxy_configs(proxy_config_environment).map(&:attrs)
|
|
24
28
|
end
|
|
25
29
|
|
|
26
30
|
private
|
|
27
31
|
|
|
28
|
-
PROXYCONFIG_FIELDS_TO_SHOW = %w[
|
|
29
|
-
id version environment
|
|
30
|
-
]
|
|
31
|
-
|
|
32
32
|
def remote
|
|
33
33
|
@remote ||= threescale_client(arguments[:remote])
|
|
34
34
|
end
|
|
@@ -41,29 +41,8 @@ module ThreeScaleToolbox
|
|
|
41
41
|
arguments[:service_ref]
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
def proxy_configs
|
|
45
|
-
@proxyconfigs ||= service.proxy_configs(proxy_config_environment)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def print_proxy_config_data(proxyconfigs, fields_to_show)
|
|
49
|
-
print_header(fields_to_show)
|
|
50
|
-
print_results(proxyconfigs, fields_to_show)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def print_header(fields_to_show)
|
|
54
|
-
puts fields_to_show.map{ |e| e.upcase}.join("\t")
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def print_results(proxyconfigs, fields_to_show)
|
|
58
|
-
proxyconfigs.each do |proxyconfig|
|
|
59
|
-
proxy_config_attrs = proxyconfig.attrs
|
|
60
|
-
puts fields_to_show.map { |field| proxy_config_attrs.fetch(field, '(empty)') }.join("\t")
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
44
|
def find_service
|
|
65
|
-
Entities::Service.find(remote: remote,
|
|
66
|
-
ref: service_ref).tap do |svc|
|
|
45
|
+
Entities::Service.find(remote: remote, ref: service_ref).tap do |svc|
|
|
67
46
|
raise ThreeScaleToolbox::Error, "Service #{service_ref} does not exist" if svc.nil?
|
|
68
47
|
end
|
|
69
48
|
end
|
|
@@ -71,8 +50,13 @@ module ThreeScaleToolbox
|
|
|
71
50
|
def service
|
|
72
51
|
@service ||= find_service
|
|
73
52
|
end
|
|
53
|
+
|
|
54
|
+
def printer
|
|
55
|
+
# keep backwards compatibility
|
|
56
|
+
options.fetch(:output, CLI::CustomTablePrinter.new(FIELDS))
|
|
57
|
+
end
|
|
74
58
|
end
|
|
75
59
|
end
|
|
76
60
|
end
|
|
77
61
|
end
|
|
78
|
-
end
|
|
62
|
+
end
|
|
@@ -11,41 +11,39 @@ module ThreeScaleToolbox
|
|
|
11
11
|
usage 'show <remote> <service> <environment>'
|
|
12
12
|
summary 'Show Proxy Configuration'
|
|
13
13
|
description 'Show a Proxy Configuration'
|
|
14
|
-
runner ShowSubcommand
|
|
15
14
|
|
|
16
15
|
param :remote
|
|
17
16
|
param :service_ref
|
|
18
17
|
param :environment
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
ThreeScaleToolbox::CLI.output_flag(self)
|
|
20
|
+
option nil, :'config-version', "Specify the Proxy Configuration version. If not specified it gets the latest version", default: 'latest', argument: :required
|
|
21
|
+
|
|
22
|
+
runner ShowSubcommand
|
|
21
23
|
end
|
|
22
24
|
end
|
|
23
25
|
|
|
24
|
-
def run
|
|
25
|
-
|
|
26
|
+
def run
|
|
27
|
+
printer.print_record proxy_config.attrs
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
private
|
|
29
31
|
|
|
30
32
|
def proxy_config
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def find_proxy_config
|
|
35
|
-
if proxy_config_version == "latest"
|
|
36
|
-
find_proxy_config_latest
|
|
33
|
+
if proxy_config_version_option == 'latest'
|
|
34
|
+
proxy_config_latest
|
|
37
35
|
else
|
|
38
|
-
|
|
36
|
+
proxy_config_version
|
|
39
37
|
end
|
|
40
38
|
end
|
|
41
39
|
|
|
42
|
-
def
|
|
43
|
-
Entities::ProxyConfig.find(service: service, environment: proxy_config_environment, version:
|
|
40
|
+
def proxy_config_version
|
|
41
|
+
Entities::ProxyConfig.find(service: service, environment: proxy_config_environment, version: proxy_config_version_option).tap do |pc|
|
|
44
42
|
raise ThreeScaleToolbox::Error, "ProxyConfig #{proxy_config_environment} in service #{service.id} does not exist" if pc.nil?
|
|
45
43
|
end
|
|
46
44
|
end
|
|
47
45
|
|
|
48
|
-
def
|
|
46
|
+
def proxy_config_latest
|
|
49
47
|
Entities::ProxyConfig.find_latest(service: service, environment: proxy_config_environment).tap do |pc|
|
|
50
48
|
raise ThreeScaleToolbox::Error, "ProxyConfig #{proxy_config_environment} in service #{service.id} does not exist" if pc.nil?
|
|
51
49
|
end
|
|
@@ -55,25 +53,20 @@ module ThreeScaleToolbox
|
|
|
55
53
|
@remote ||= threescale_client(arguments[:remote])
|
|
56
54
|
end
|
|
57
55
|
|
|
58
|
-
def
|
|
59
|
-
options[:'config-version']
|
|
56
|
+
def proxy_config_version_option
|
|
57
|
+
options[:'config-version']
|
|
60
58
|
end
|
|
61
59
|
|
|
62
60
|
def proxy_config_environment
|
|
63
61
|
arguments[:environment]
|
|
64
62
|
end
|
|
65
63
|
|
|
66
|
-
def print_proxy_config
|
|
67
|
-
puts JSON.pretty_generate(proxy_config.attrs)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
64
|
def service_ref
|
|
71
65
|
arguments[:service_ref]
|
|
72
66
|
end
|
|
73
67
|
|
|
74
68
|
def find_service
|
|
75
|
-
Entities::Service.find(remote: remote,
|
|
76
|
-
ref: service_ref).tap do |svc|
|
|
69
|
+
Entities::Service.find(remote: remote, ref: service_ref).tap do |svc|
|
|
77
70
|
raise ThreeScaleToolbox::Error, "Service #{service_ref} does not exist" if svc.nil?
|
|
78
71
|
end
|
|
79
72
|
end
|
|
@@ -81,8 +74,12 @@ module ThreeScaleToolbox
|
|
|
81
74
|
def service
|
|
82
75
|
@service ||= find_service
|
|
83
76
|
end
|
|
77
|
+
|
|
78
|
+
def printer
|
|
79
|
+
options.fetch(:output, CLI::JsonPrinter.new)
|
|
80
|
+
end
|
|
84
81
|
end
|
|
85
82
|
end
|
|
86
83
|
end
|
|
87
84
|
end
|
|
88
|
-
end
|
|
85
|
+
end
|
|
@@ -5,6 +5,7 @@ require '3scale_toolbox/commands/service_command/show_command'
|
|
|
5
5
|
require '3scale_toolbox/commands/service_command/delete_command'
|
|
6
6
|
require '3scale_toolbox/commands/service_command/create_command'
|
|
7
7
|
require '3scale_toolbox/commands/service_command/apply_command'
|
|
8
|
+
require '3scale_toolbox/commands/service_command/copy_command'
|
|
8
9
|
|
|
9
10
|
module ThreeScaleToolbox
|
|
10
11
|
module Commands
|
|
@@ -24,11 +25,12 @@ module ThreeScaleToolbox
|
|
|
24
25
|
end
|
|
25
26
|
end
|
|
26
27
|
|
|
27
|
-
add_subcommand(
|
|
28
|
-
add_subcommand(
|
|
29
|
-
add_subcommand(
|
|
30
|
-
add_subcommand(
|
|
31
|
-
add_subcommand(
|
|
28
|
+
add_subcommand(ListSubcommand)
|
|
29
|
+
add_subcommand(ShowSubcommand)
|
|
30
|
+
add_subcommand(DeleteSubcommand)
|
|
31
|
+
add_subcommand(CreateSubcommand)
|
|
32
|
+
add_subcommand(ApplySubcommand)
|
|
33
|
+
add_subcommand(CopySubcommand)
|
|
32
34
|
end
|
|
33
35
|
end
|
|
34
36
|
end
|
|
@@ -1,75 +1,86 @@
|
|
|
1
1
|
module ThreeScaleToolbox
|
|
2
2
|
module Commands
|
|
3
3
|
module ServiceCommand
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
include ThreeScaleToolbox::Command
|
|
7
|
-
|
|
8
|
-
def self.command
|
|
9
|
-
Cri::Command.define do
|
|
10
|
-
name 'apply'
|
|
11
|
-
usage 'apply <remote> <service-id_or_system-name>'
|
|
12
|
-
summary 'Update service'
|
|
13
|
-
description "Update (create if it does not exist) service"
|
|
14
|
-
runner ApplySubcommand
|
|
15
|
-
|
|
16
|
-
param :remote
|
|
17
|
-
param :service_id_or_system_name
|
|
18
|
-
|
|
19
|
-
option :d, :'deployment-mode', "Specify the deployment mode of the service", argument: :required
|
|
20
|
-
option :n, :name, "Specify the name of the metric", argument: :required
|
|
21
|
-
option :a, :'authentication-mode', "Specify authentication mode of the service ('1' for API key, '2' for App Id / App Key, 'oauth' for OAuth mode, 'oidc' for OpenID Connect)", argument: :required
|
|
22
|
-
option nil, :description, "Specify the description of the service", argument: :required
|
|
23
|
-
option nil, :'support-email', "Specify the support email of the service", argument: :required
|
|
24
|
-
end
|
|
25
|
-
end
|
|
4
|
+
class CustomPrinter
|
|
5
|
+
attr_reader :option_default, :option_disabled
|
|
26
6
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
res = Entities::Service.create(remote: remote, service_params: create_service_attrs)
|
|
31
|
-
else
|
|
32
|
-
res.update(service_attrs) unless service_attrs.empty?
|
|
33
|
-
end
|
|
7
|
+
def print_record(service)
|
|
8
|
+
puts "Applied Service id: #{service['id']}"
|
|
9
|
+
end
|
|
34
10
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
end
|
|
11
|
+
def print_collection(collection) end
|
|
12
|
+
end
|
|
38
13
|
|
|
39
|
-
|
|
14
|
+
class ApplySubcommand < Cri::CommandRunner
|
|
15
|
+
include ThreeScaleToolbox::Command
|
|
40
16
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
17
|
+
def self.command
|
|
18
|
+
Cri::Command.define do
|
|
19
|
+
name 'apply'
|
|
20
|
+
usage 'apply <remote> <service-id_or_system-name>'
|
|
21
|
+
summary 'Update service'
|
|
22
|
+
description "Update (create if it does not exist) service"
|
|
44
23
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
end
|
|
24
|
+
param :remote
|
|
25
|
+
param :service_id_or_system_name
|
|
48
26
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
27
|
+
ThreeScaleToolbox::CLI.output_flag(self)
|
|
28
|
+
option :d, :'deployment-mode', "Specify the deployment mode of the service", argument: :required
|
|
29
|
+
option :n, :name, "Specify the name of the metric", argument: :required
|
|
30
|
+
option :a, :'authentication-mode', "Specify authentication mode of the service ('1' for API key, '2' for App Id / App Key, 'oauth' for OAuth mode, 'oidc' for OpenID Connect)", argument: :required
|
|
31
|
+
option nil, :description, "Specify the description of the service", argument: :required
|
|
32
|
+
option nil, :'support-email', "Specify the support email of the service", argument: :required
|
|
52
33
|
|
|
53
|
-
|
|
54
|
-
Entities::Service::find(remote: remote, ref: ref)
|
|
34
|
+
runner ApplySubcommand
|
|
55
35
|
end
|
|
36
|
+
end
|
|
56
37
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}.compact
|
|
38
|
+
def run
|
|
39
|
+
service = Entities::Service.find(remote: remote, ref: ref)
|
|
40
|
+
if service.nil?
|
|
41
|
+
service = Entities::Service.create(remote: remote,
|
|
42
|
+
service_params: create_attrs)
|
|
43
|
+
else
|
|
44
|
+
service.update(update_attrs) unless update_attrs.empty?
|
|
65
45
|
end
|
|
66
46
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
47
|
+
printer.print_record service.attrs
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def remote
|
|
53
|
+
@remote ||= threescale_client(arguments[:remote])
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def ref
|
|
57
|
+
@ref ||= arguments[:service_id_or_system_name]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def base_service_attrs
|
|
61
|
+
{
|
|
62
|
+
"deployment_option" => options[:'deployment-mode'],
|
|
63
|
+
"backend_version" => options[:'authentication-mode'],
|
|
64
|
+
"description" => options[:description],
|
|
65
|
+
"support_email" => options[:'support-email'],
|
|
66
|
+
"name" => options[:name],
|
|
67
|
+
}.compact
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def update_attrs
|
|
71
|
+
base_service_attrs
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def create_attrs
|
|
75
|
+
base_service_attrs.merge(
|
|
76
|
+
"system_name" => ref,
|
|
77
|
+
"name" => ref
|
|
78
|
+
) { |_key, oldval, _newval| oldval } # receiver of the merge message has key priority
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def printer
|
|
82
|
+
# keep backwards compatibility
|
|
83
|
+
options.fetch(:output, CustomPrinter.new)
|
|
73
84
|
end
|
|
74
85
|
end
|
|
75
86
|
end
|