3scale_toolbox 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/3scale_toolbox.gemspec +1 -1
- data/README.md +4 -1
- data/lib/3scale_toolbox.rb +0 -1
- data/lib/3scale_toolbox/cli.rb +4 -0
- data/lib/3scale_toolbox/cli/custom_table_printer.rb +32 -0
- 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 +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 +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 +3 -2
- 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/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/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 +17 -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 +2 -2
- data/lib/3scale_toolbox/commands/update_command/{update_service.rb → service_command.rb} +19 -16
- 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/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 +3 -0
- data/lib/3scale_toolbox/helper.rb +20 -0
- data/lib/3scale_toolbox/proxy_logger.rb +1 -1
- data/lib/3scale_toolbox/version.rb +1 -1
- data/licenses.xml +3 -3
- metadata +42 -22
- 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
|
@@ -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
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
require '3scale_toolbox/commands/service_command/copy_command/task'
|
|
2
|
+
require '3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task'
|
|
3
|
+
require '3scale_toolbox/commands/service_command/copy_command/copy_limits_task'
|
|
4
|
+
require '3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task'
|
|
5
|
+
require '3scale_toolbox/commands/service_command/copy_command/copy_activedocs_task'
|
|
6
|
+
require '3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task'
|
|
7
|
+
require '3scale_toolbox/commands/service_command/copy_command/copy_methods_task'
|
|
8
|
+
require '3scale_toolbox/commands/service_command/copy_command/copy_metrics_task'
|
|
9
|
+
require '3scale_toolbox/commands/service_command/copy_command/copy_policies_task'
|
|
10
|
+
require '3scale_toolbox/commands/service_command/copy_command/copy_pricingrules_task'
|
|
11
|
+
require '3scale_toolbox/commands/service_command/copy_command/copy_service_proxy_task'
|
|
12
|
+
require '3scale_toolbox/commands/service_command/copy_command/destroy_mapping_rules_task'
|
|
13
|
+
require '3scale_toolbox/commands/service_command/copy_command/bump_proxy_version_task'
|
|
14
|
+
|
|
15
|
+
module ThreeScaleToolbox
|
|
16
|
+
module Commands
|
|
17
|
+
module ServiceCommand
|
|
18
|
+
class CopySubcommand < Cri::CommandRunner
|
|
19
|
+
include ThreeScaleToolbox::Command
|
|
20
|
+
|
|
21
|
+
def self.command
|
|
22
|
+
Cri::Command.define do
|
|
23
|
+
name 'copy'
|
|
24
|
+
usage 'copy [opts] -s <src> -d <dst> <source-service>'
|
|
25
|
+
summary 'Copy service'
|
|
26
|
+
description <<-HEREDOC
|
|
27
|
+
This command makes a copy of the referenced service.
|
|
28
|
+
Target service will be searched by source service system name. System name can be overriden with `--target_system_name` option.
|
|
29
|
+
If a service with the selected `system_name` is not found, it will be created.
|
|
30
|
+
\n Components of the service being copied:
|
|
31
|
+
\nservice settings
|
|
32
|
+
\nproxy settings
|
|
33
|
+
\npricing rules
|
|
34
|
+
\nactivedocs
|
|
35
|
+
\nmetrics
|
|
36
|
+
\nmethods
|
|
37
|
+
\napplication plans
|
|
38
|
+
\nmapping rules
|
|
39
|
+
HEREDOC
|
|
40
|
+
|
|
41
|
+
option :s, :source, '3scale source instance. Url or remote name', argument: :required
|
|
42
|
+
option :d, :destination, '3scale target instance. Url or remote name', argument: :required
|
|
43
|
+
option :t, 'target_system_name', 'Target system name. Default to source system name', argument: :required
|
|
44
|
+
flag :f, :force, 'Overwrites the mapping rules by deleting all rules from target service first'
|
|
45
|
+
flag :r, 'rules-only', 'Only mapping rules are copied'
|
|
46
|
+
param :source_service
|
|
47
|
+
|
|
48
|
+
runner CopySubcommand
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def run
|
|
53
|
+
tasks = []
|
|
54
|
+
unless option_rules_only
|
|
55
|
+
tasks << CopyCommand::CreateOrUpdateTargetServiceTask.new(context)
|
|
56
|
+
tasks << CopyCommand::CopyServiceProxyTask.new(context)
|
|
57
|
+
tasks << CopyCommand::CopyMethodsTask.new(context)
|
|
58
|
+
tasks << CopyCommand::CopyMetricsTask.new(context)
|
|
59
|
+
tasks << CopyCommand::CopyApplicationPlansTask.new(context)
|
|
60
|
+
tasks << CopyCommand::CopyLimitsTask.new(context)
|
|
61
|
+
tasks << CopyCommand::CopyPoliciesTask.new(context)
|
|
62
|
+
tasks << CopyCommand::CopyPricingRulesTask.new(context)
|
|
63
|
+
tasks << CopyCommand::CopyActiveDocsTask.new(context)
|
|
64
|
+
end
|
|
65
|
+
tasks << CopyCommand::DestroyMappingRulesTask.new(context)
|
|
66
|
+
tasks << CopyCommand::CopyMappingRulesTask.new(context)
|
|
67
|
+
tasks.each(&:call)
|
|
68
|
+
|
|
69
|
+
# This should be the last step
|
|
70
|
+
CopyCommand::BumpProxyVersionTask.new(service: context[:target]).call
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
private
|
|
74
|
+
|
|
75
|
+
def context
|
|
76
|
+
@context ||= create_context
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def create_context
|
|
80
|
+
{
|
|
81
|
+
source_remote: threescale_client(fetch_required_option(:source)),
|
|
82
|
+
target_remote: threescale_client(fetch_required_option(:destination)),
|
|
83
|
+
source_service_ref: arguments[:source_service],
|
|
84
|
+
option_target_system_name: options[:target_system_name],
|
|
85
|
+
delete_mapping_rules: options[:force]
|
|
86
|
+
}
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def option_rules_only
|
|
90
|
+
options[:'rules-only']
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module ThreeScaleToolbox
|
|
2
|
+
module Commands
|
|
3
|
+
module ServiceCommand
|
|
4
|
+
module CopyCommand
|
|
5
|
+
class BumpProxyVersionTask
|
|
6
|
+
attr_reader :service
|
|
7
|
+
|
|
8
|
+
def initialize(service:)
|
|
9
|
+
@service = service
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
##
|
|
13
|
+
# bumps proxy config version to propagate proxy settings updates
|
|
14
|
+
def call
|
|
15
|
+
# Proxy update is the mechanism to increase version of the proxy,
|
|
16
|
+
# Hence propagating (mapping rules, poicies, oidc, auth) update to
|
|
17
|
+
# latest proxy config, making available to gateway.
|
|
18
|
+
|
|
19
|
+
# Currently it is done always because mapping rules, at least, are always created
|
|
20
|
+
# So they need to be propagated
|
|
21
|
+
proxy_settings = {
|
|
22
|
+
# Adding harmless attribute to avoid empty body
|
|
23
|
+
# update_proxy cannot be done with empty body
|
|
24
|
+
# and must be done to increase proxy version
|
|
25
|
+
# If proxy settings have not been changed since last update,
|
|
26
|
+
# this request will not have effect and proxy config version will not be bumped.
|
|
27
|
+
service_id: service.id
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
service.update_proxy proxy_settings
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module ThreeScaleToolbox
|
|
2
|
+
module Commands
|
|
3
|
+
module ServiceCommand
|
|
4
|
+
module CopyCommand
|
|
5
|
+
class CopyActiveDocsTask
|
|
6
|
+
include Task
|
|
7
|
+
|
|
8
|
+
def call
|
|
9
|
+
puts 'copying all service ActiveDocs'
|
|
10
|
+
|
|
11
|
+
source.activedocs.each(&method(:apply_target_activedoc))
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def apply_target_activedoc(attrs)
|
|
17
|
+
activedocs = Entities::ActiveDocs.find_by_system_name(remote: target.remote,
|
|
18
|
+
system_name: attrs['system_name'])
|
|
19
|
+
if activedocs.nil?
|
|
20
|
+
Entities::ActiveDocs.create(remote: target.remote, attrs: create_attrs(attrs))
|
|
21
|
+
elsif activedocs.attrs.fetch('service_id') == target.id
|
|
22
|
+
activedocs.update(update_attrs(attrs))
|
|
23
|
+
else
|
|
24
|
+
# activedocs with same system_name exists, but now owned by target service
|
|
25
|
+
new_attrs = create_attrs(attrs)
|
|
26
|
+
new_attrs['system_name'] = "#{attrs['system_name']}#{target.id}"
|
|
27
|
+
Entities::ActiveDocs.create(remote: target.remote, attrs: new_attrs)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def update_attrs(old_attrs)
|
|
32
|
+
create_attrs(old_attrs)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def create_attrs(old_attrs)
|
|
36
|
+
# keep same system_name
|
|
37
|
+
new_attrs = old_attrs.reject { |key, _| %w[id created_at updated_at].include? key }
|
|
38
|
+
new_attrs.tap do |attrs|
|
|
39
|
+
attrs['service_id'] = target.id
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module ThreeScaleToolbox
|
|
2
|
+
module Commands
|
|
3
|
+
module ServiceCommand
|
|
4
|
+
module CopyCommand
|
|
5
|
+
class CopyApplicationPlansTask
|
|
6
|
+
include Task
|
|
7
|
+
|
|
8
|
+
def call
|
|
9
|
+
source_plans = source.plans
|
|
10
|
+
target_plans = target.plans
|
|
11
|
+
missing_plans = missing_app_plans(source_plans, target_plans)
|
|
12
|
+
missing_plans.each do |plan|
|
|
13
|
+
plan.delete('links')
|
|
14
|
+
plan.delete('default') # TODO: handle default plan
|
|
15
|
+
if plan.delete('custom') # TODO: what to do with custom plans?
|
|
16
|
+
puts "skipping custom plan #{plan}"
|
|
17
|
+
else
|
|
18
|
+
ThreeScaleToolbox::Entities::ApplicationPlan.create(service: target, plan_attrs: plan)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
puts "target service missing #{missing_plans.size} application plans"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def missing_app_plans(source_plans, target_plans)
|
|
27
|
+
ThreeScaleToolbox::Helper.array_difference(source_plans, target_plans) do |src, target|
|
|
28
|
+
ThreeScaleToolbox::Helper.compare_hashes(src, target, ['system_name'])
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|