3scale_toolbox 0.10.0 → 0.11.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/README.md +21 -144
- data/lib/3scale_toolbox.rb +0 -1
- data/lib/3scale_toolbox/commands.rb +12 -0
- data/lib/3scale_toolbox/commands/3scale_command.rb +1 -1
- data/lib/3scale_toolbox/commands/account_command.rb +23 -0
- data/lib/3scale_toolbox/commands/account_command/find_command.rb +41 -0
- data/lib/3scale_toolbox/commands/activedocs_command.rb +32 -0
- data/lib/3scale_toolbox/commands/activedocs_command/apply_command.rb +127 -0
- data/lib/3scale_toolbox/commands/activedocs_command/create_command.rb +65 -0
- data/lib/3scale_toolbox/commands/activedocs_command/delete_command.rb +49 -0
- data/lib/3scale_toolbox/commands/activedocs_command/list_command.rb +54 -0
- data/lib/3scale_toolbox/commands/application_command.rb +30 -0
- data/lib/3scale_toolbox/commands/application_command/apply_command.rb +179 -0
- data/lib/3scale_toolbox/commands/application_command/create_command.rb +110 -0
- data/lib/3scale_toolbox/commands/application_command/delete_command.rb +57 -0
- data/lib/3scale_toolbox/commands/application_command/list_command.rb +124 -0
- data/lib/3scale_toolbox/commands/application_command/show_command.rb +72 -0
- data/lib/3scale_toolbox/commands/copy_command/copy_service.rb +97 -28
- data/lib/3scale_toolbox/commands/import_command/import_csv.rb +16 -17
- data/lib/3scale_toolbox/commands/import_command/openapi.rb +14 -10
- data/lib/3scale_toolbox/commands/import_command/openapi/create_service_step.rb +3 -2
- data/lib/3scale_toolbox/commands/import_command/openapi/method.rb +0 -1
- data/lib/3scale_toolbox/commands/import_command/openapi/step.rb +8 -1
- data/lib/3scale_toolbox/commands/import_command/openapi/update_service_proxy_step.rb +17 -7
- data/lib/3scale_toolbox/commands/methods_command.rb +4 -4
- data/lib/3scale_toolbox/commands/methods_command/apply_command.rb +2 -2
- data/lib/3scale_toolbox/commands/methods_command/create_command.rb +1 -1
- data/lib/3scale_toolbox/commands/metrics_command.rb +4 -4
- data/lib/3scale_toolbox/commands/metrics_command/apply_command.rb +2 -2
- data/lib/3scale_toolbox/commands/metrics_command/create_command.rb +1 -1
- data/lib/3scale_toolbox/commands/plans_command/apply_command.rb +7 -7
- data/lib/3scale_toolbox/commands/plans_command/create_command.rb +5 -5
- data/lib/3scale_toolbox/commands/policy_registry_command.rb +22 -0
- data/lib/3scale_toolbox/commands/policy_registry_command/copy_command.rb +85 -0
- data/lib/3scale_toolbox/commands/proxy_config_command.rb +30 -0
- data/lib/3scale_toolbox/commands/proxy_config_command/list_command.rb +78 -0
- data/lib/3scale_toolbox/commands/proxy_config_command/promote_command.rb +68 -0
- data/lib/3scale_toolbox/commands/proxy_config_command/show_command.rb +88 -0
- data/lib/3scale_toolbox/commands/service_command.rb +34 -0
- data/lib/3scale_toolbox/commands/service_command/apply_command.rb +77 -0
- data/lib/3scale_toolbox/commands/service_command/create_command.rb +59 -0
- data/lib/3scale_toolbox/commands/service_command/delete_command.rb +49 -0
- data/lib/3scale_toolbox/commands/service_command/list_command.rb +50 -0
- data/lib/3scale_toolbox/commands/service_command/show_command.rb +63 -0
- data/lib/3scale_toolbox/commands/update_command/update_service.rb +6 -3
- data/lib/3scale_toolbox/entities.rb +4 -0
- data/lib/3scale_toolbox/entities/account.rb +63 -0
- data/lib/3scale_toolbox/entities/activedocs.rb +88 -0
- data/lib/3scale_toolbox/entities/application.rb +124 -0
- data/lib/3scale_toolbox/entities/application_plan.rb +28 -4
- data/lib/3scale_toolbox/entities/base_entity.rb +44 -0
- data/lib/3scale_toolbox/entities/proxy_config.rb +58 -0
- data/lib/3scale_toolbox/entities/service.rb +42 -8
- data/lib/3scale_toolbox/error.rb +8 -0
- data/lib/3scale_toolbox/tasks.rb +2 -1
- data/lib/3scale_toolbox/tasks/bump_proxy_version_task.rb +32 -0
- data/lib/3scale_toolbox/tasks/copy_service_settings_task.rb +38 -0
- data/lib/3scale_toolbox/version.rb +1 -1
- metadata +36 -5
- data/lib/3scale_toolbox/tasks/update_service_settings_task.rb +0 -49
@@ -0,0 +1,78 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module Commands
|
3
|
+
module ProxyConfigCommand
|
4
|
+
module List
|
5
|
+
class ListSubcommand < Cri::CommandRunner
|
6
|
+
include ThreeScaleToolbox::Command
|
7
|
+
|
8
|
+
def self.command
|
9
|
+
Cri::Command.define do
|
10
|
+
name 'list'
|
11
|
+
usage 'list <remote> <service> <environment>'
|
12
|
+
summary 'List Proxy Configurations'
|
13
|
+
description 'List all defined Proxy Configurations'
|
14
|
+
runner ListSubcommand
|
15
|
+
|
16
|
+
param :remote
|
17
|
+
param :service_ref
|
18
|
+
param :environment
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def run
|
23
|
+
print_proxy_config_data(proxy_configs, PROXYCONFIG_FIELDS_TO_SHOW)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
PROXYCONFIG_FIELDS_TO_SHOW = %w[
|
29
|
+
id version environment
|
30
|
+
]
|
31
|
+
|
32
|
+
def remote
|
33
|
+
@remote ||= threescale_client(arguments[:remote])
|
34
|
+
end
|
35
|
+
|
36
|
+
def proxy_config_environment
|
37
|
+
arguments[:environment]
|
38
|
+
end
|
39
|
+
|
40
|
+
def service_ref
|
41
|
+
arguments[:service_ref]
|
42
|
+
end
|
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
|
+
def find_service
|
65
|
+
Entities::Service.find(remote: remote,
|
66
|
+
ref: service_ref).tap do |svc|
|
67
|
+
raise ThreeScaleToolbox::Error, "Service #{service_ref} does not exist" if svc.nil?
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def service
|
72
|
+
@service ||= find_service
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module Commands
|
3
|
+
module ProxyConfigCommand
|
4
|
+
module Promote
|
5
|
+
class PromoteSubcommand < Cri::CommandRunner
|
6
|
+
include ThreeScaleToolbox::Command
|
7
|
+
|
8
|
+
def self.command
|
9
|
+
Cri::Command.define do
|
10
|
+
name 'promote'
|
11
|
+
usage 'promote <remote> <service>'
|
12
|
+
summary 'Promote latest staging Proxy Configuration to the production environment'
|
13
|
+
description 'Promote latest staging Proxy Configuration to the production environment'
|
14
|
+
runner PromoteSubcommand
|
15
|
+
|
16
|
+
param :remote
|
17
|
+
param :service_ref
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def run
|
22
|
+
latest_proxy_config.promote(to: to_env)
|
23
|
+
puts "Proxy Configuration promoted to '#{to_env}'"
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def remote
|
29
|
+
@remote ||= threescale_client(arguments[:remote])
|
30
|
+
end
|
31
|
+
|
32
|
+
def latest_proxy_config
|
33
|
+
@proxy_config ||= find_proxy_config_latest
|
34
|
+
end
|
35
|
+
|
36
|
+
def find_proxy_config_latest
|
37
|
+
Entities::ProxyConfig.find_latest(service: service, environment: from_env).tap do |pc|
|
38
|
+
raise ThreeScaleToolbox::Error, "ProxyConfig #{from_env} in service #{service.id} does not exist" if pc.nil?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def service_ref
|
43
|
+
arguments[:service_ref]
|
44
|
+
end
|
45
|
+
|
46
|
+
def find_service
|
47
|
+
Entities::Service.find(remote: remote,
|
48
|
+
ref: service_ref).tap do |svc|
|
49
|
+
raise ThreeScaleToolbox::Error, "Service #{service_ref} does not exist" if svc.nil?
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def service
|
54
|
+
@service ||= find_service
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_env
|
58
|
+
"production"
|
59
|
+
end
|
60
|
+
|
61
|
+
def from_env
|
62
|
+
"sandbox"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module Commands
|
3
|
+
module ProxyConfigCommand
|
4
|
+
module Show
|
5
|
+
class ShowSubcommand < Cri::CommandRunner
|
6
|
+
include ThreeScaleToolbox::Command
|
7
|
+
|
8
|
+
def self.command
|
9
|
+
Cri::Command.define do
|
10
|
+
name 'show'
|
11
|
+
usage 'show <remote> <service> <environment>'
|
12
|
+
summary 'Show Proxy Configuration'
|
13
|
+
description 'Show a Proxy Configuration'
|
14
|
+
runner ShowSubcommand
|
15
|
+
|
16
|
+
param :remote
|
17
|
+
param :service_ref
|
18
|
+
param :environment
|
19
|
+
|
20
|
+
option nil, :'config-version', "Specify the Proxy Configuration version. If not specified it gets the latest version", argument: :required
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def run
|
25
|
+
print_proxy_config
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def proxy_config
|
31
|
+
@proxy_config ||= find_proxy_config
|
32
|
+
end
|
33
|
+
|
34
|
+
def find_proxy_config
|
35
|
+
if proxy_config_version == "latest"
|
36
|
+
find_proxy_config_latest
|
37
|
+
else
|
38
|
+
find_proxy_config_version
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def find_proxy_config_version
|
43
|
+
Entities::ProxyConfig.find(service: service, environment: proxy_config_environment, version: proxy_config_version).tap do |pc|
|
44
|
+
raise ThreeScaleToolbox::Error, "ProxyConfig #{proxy_config_environment} in service #{service.id} does not exist" if pc.nil?
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def find_proxy_config_latest
|
49
|
+
Entities::ProxyConfig.find_latest(service: service, environment: proxy_config_environment).tap do |pc|
|
50
|
+
raise ThreeScaleToolbox::Error, "ProxyConfig #{proxy_config_environment} in service #{service.id} does not exist" if pc.nil?
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def remote
|
55
|
+
@remote ||= threescale_client(arguments[:remote])
|
56
|
+
end
|
57
|
+
|
58
|
+
def proxy_config_version
|
59
|
+
options[:'config-version'] || "latest"
|
60
|
+
end
|
61
|
+
|
62
|
+
def proxy_config_environment
|
63
|
+
arguments[:environment]
|
64
|
+
end
|
65
|
+
|
66
|
+
def print_proxy_config
|
67
|
+
puts JSON.pretty_generate(proxy_config.attrs)
|
68
|
+
end
|
69
|
+
|
70
|
+
def service_ref
|
71
|
+
arguments[:service_ref]
|
72
|
+
end
|
73
|
+
|
74
|
+
def find_service
|
75
|
+
Entities::Service.find(remote: remote,
|
76
|
+
ref: service_ref).tap do |svc|
|
77
|
+
raise ThreeScaleToolbox::Error, "Service #{service_ref} does not exist" if svc.nil?
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def service
|
82
|
+
@service ||= find_service
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'cri'
|
2
|
+
require '3scale_toolbox/base_command'
|
3
|
+
require '3scale_toolbox/commands/service_command/list_command'
|
4
|
+
require '3scale_toolbox/commands/service_command/show_command'
|
5
|
+
require '3scale_toolbox/commands/service_command/delete_command'
|
6
|
+
require '3scale_toolbox/commands/service_command/create_command'
|
7
|
+
require '3scale_toolbox/commands/service_command/apply_command'
|
8
|
+
|
9
|
+
module ThreeScaleToolbox
|
10
|
+
module Commands
|
11
|
+
module ServiceCommand
|
12
|
+
include ThreeScaleToolbox::Command
|
13
|
+
|
14
|
+
def self.command
|
15
|
+
Cri::Command.define do
|
16
|
+
name 'service'
|
17
|
+
usage 'service <sub-command> [options]'
|
18
|
+
summary 'services super command'
|
19
|
+
description 'Manage your services'
|
20
|
+
|
21
|
+
run do |_opts, _args, cmd|
|
22
|
+
puts cmd.help
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
add_subcommand(List::ListSubcommand)
|
28
|
+
add_subcommand(Show::ShowSubcommand)
|
29
|
+
add_subcommand(Delete::DeleteSubcommand)
|
30
|
+
add_subcommand(Create::CreateSubcommand)
|
31
|
+
add_subcommand(Apply::ApplySubcommand)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module Commands
|
3
|
+
module ServiceCommand
|
4
|
+
module Apply
|
5
|
+
class ApplySubcommand < Cri::CommandRunner
|
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
|
26
|
+
|
27
|
+
def run
|
28
|
+
res = service
|
29
|
+
if res.nil?
|
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
|
34
|
+
|
35
|
+
output_msg_array = ["Applied Service id: #{res.id}"]
|
36
|
+
puts output_msg_array
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def remote
|
42
|
+
@remote ||= threescale_client(arguments[:remote])
|
43
|
+
end
|
44
|
+
|
45
|
+
def ref
|
46
|
+
@ref ||= arguments[:service_id_or_system_name]
|
47
|
+
end
|
48
|
+
|
49
|
+
def service
|
50
|
+
@service ||= find_service
|
51
|
+
end
|
52
|
+
|
53
|
+
def find_service
|
54
|
+
Entities::Service::find(remote: remote, ref: ref)
|
55
|
+
end
|
56
|
+
|
57
|
+
def service_attrs
|
58
|
+
{
|
59
|
+
"deployment_option" => options[:'deployment-mode'],
|
60
|
+
"backend_version" => options[:'authentication-mode'],
|
61
|
+
"description" => options[:description],
|
62
|
+
"support_email" => options[:'support-email'],
|
63
|
+
"name" => options[:name],
|
64
|
+
}.compact
|
65
|
+
end
|
66
|
+
|
67
|
+
def create_service_attrs
|
68
|
+
service_attrs.merge(
|
69
|
+
"system_name" => ref,
|
70
|
+
"name" => ref
|
71
|
+
) { |_key, oldval, _newval| oldval } # receiver of the merge message has key priority
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module Commands
|
3
|
+
module ServiceCommand
|
4
|
+
module Create
|
5
|
+
class CreateSubcommand < Cri::CommandRunner
|
6
|
+
include ThreeScaleToolbox::Command
|
7
|
+
|
8
|
+
def self.command
|
9
|
+
Cri::Command.define do
|
10
|
+
name 'create'
|
11
|
+
usage 'create [options] <remote> <service-name>'
|
12
|
+
summary 'Create a service'
|
13
|
+
description 'Create a service'
|
14
|
+
runner CreateSubcommand
|
15
|
+
|
16
|
+
param :remote
|
17
|
+
param :service_name
|
18
|
+
|
19
|
+
option :d, :'deployment-mode', "Specify the deployment mode of the service", argument: :required
|
20
|
+
option :s, :'system-name', "Specify the system-name of the service", 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
|
26
|
+
|
27
|
+
def run
|
28
|
+
create_service_params = service_attrs
|
29
|
+
result = Entities::Service.create(remote: remote, service_params: create_service_params)
|
30
|
+
puts "Service '#{arguments[:service_name]}' has been created with ID: #{result.id}"
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def remote
|
36
|
+
@remote ||= threescale_client(arguments[:remote])
|
37
|
+
end
|
38
|
+
|
39
|
+
def parse_options
|
40
|
+
{
|
41
|
+
"deployment_option" => options[:'deployment-mode'],
|
42
|
+
"system_name" => options[:'system-name'],
|
43
|
+
"backend_version" => options[:'authentication-mode'],
|
44
|
+
"description" => options[:description],
|
45
|
+
"support_email" => options[:'support-email'],
|
46
|
+
}.compact
|
47
|
+
end
|
48
|
+
|
49
|
+
def service_attrs
|
50
|
+
service_name = arguments[:service_name]
|
51
|
+
create_service_attrs = parse_options
|
52
|
+
create_service_attrs["name"] = service_name
|
53
|
+
create_service_attrs
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module Commands
|
3
|
+
module ServiceCommand
|
4
|
+
module Delete
|
5
|
+
class DeleteSubcommand < Cri::CommandRunner
|
6
|
+
include ThreeScaleToolbox::Command
|
7
|
+
|
8
|
+
def self.command
|
9
|
+
Cri::Command.define do
|
10
|
+
name 'delete'
|
11
|
+
usage 'delete <remote> <service-id_or_system-name>'
|
12
|
+
summary 'Delete a service'
|
13
|
+
description 'Delete a service'
|
14
|
+
runner DeleteSubcommand
|
15
|
+
|
16
|
+
param :remote
|
17
|
+
param :service_id_or_system_name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def run
|
22
|
+
service.delete
|
23
|
+
puts "Service with id: #{service.id} deleted"
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def remote
|
29
|
+
@remote ||= threescale_client(arguments[:remote])
|
30
|
+
end
|
31
|
+
|
32
|
+
def ref
|
33
|
+
@ref ||= arguments[:service_id_or_system_name]
|
34
|
+
end
|
35
|
+
|
36
|
+
def service
|
37
|
+
@service ||= find_service
|
38
|
+
end
|
39
|
+
|
40
|
+
def find_service
|
41
|
+
Entities::Service::find(remote: remote, ref: ref).tap do |svc|
|
42
|
+
raise ThreeScaleToolbox::Error, "Service #{ref} does not exist" if svc.nil?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|