3scale_toolbox 0.9.0 → 0.10.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 +5 -23
- data/lib/3scale_toolbox/base_command.rb +0 -1
- data/lib/3scale_toolbox/commands.rb +4 -0
- data/lib/3scale_toolbox/commands/copy_command/copy_service.rb +1 -1
- data/lib/3scale_toolbox/commands/import_command/openapi/create_activedocs_step.rb +2 -2
- data/lib/3scale_toolbox/commands/import_command/openapi/create_method_step.rb +21 -15
- data/lib/3scale_toolbox/commands/import_command/openapi/create_service_step.rb +10 -13
- data/lib/3scale_toolbox/commands/methods_command.rb +28 -0
- data/lib/3scale_toolbox/commands/methods_command/apply_command.rb +101 -0
- data/lib/3scale_toolbox/commands/methods_command/create_command.rb +73 -0
- data/lib/3scale_toolbox/commands/methods_command/delete_command.rb +67 -0
- data/lib/3scale_toolbox/commands/methods_command/list_command.rb +64 -0
- data/lib/3scale_toolbox/commands/metrics_command.rb +28 -0
- data/lib/3scale_toolbox/commands/metrics_command/apply_command.rb +102 -0
- data/lib/3scale_toolbox/commands/metrics_command/create_command.rb +77 -0
- data/lib/3scale_toolbox/commands/metrics_command/delete_command.rb +66 -0
- data/lib/3scale_toolbox/commands/metrics_command/list_command.rb +70 -0
- data/lib/3scale_toolbox/commands/plans_command/create_command.rb +1 -1
- data/lib/3scale_toolbox/commands/plans_command/export/read_app_plan_step.rb +1 -1
- data/lib/3scale_toolbox/commands/plans_command/export/step.rb +5 -1
- data/lib/3scale_toolbox/commands/plans_command/import/import_plan_metrics_step.rb +7 -13
- data/lib/3scale_toolbox/commands/plans_command/import/step.rb +2 -8
- data/lib/3scale_toolbox/commands/plans_command/show_command.rb +1 -1
- data/lib/3scale_toolbox/commands/remote_command/remote_add.rb +1 -1
- data/lib/3scale_toolbox/entities.rb +2 -0
- data/lib/3scale_toolbox/entities/application_plan.rb +47 -14
- data/lib/3scale_toolbox/entities/method.rb +80 -0
- data/lib/3scale_toolbox/entities/metric.rb +113 -0
- data/lib/3scale_toolbox/entities/service.rb +112 -38
- data/lib/3scale_toolbox/error.rb +13 -0
- data/lib/3scale_toolbox/tasks/copy_activedocs_task.rb +1 -1
- data/lib/3scale_toolbox/tasks/copy_methods_task.rb +11 -8
- data/lib/3scale_toolbox/tasks/copy_metrics_task.rb +1 -1
- data/lib/3scale_toolbox/tasks/copy_service_proxy_task.rb +1 -1
- data/lib/3scale_toolbox/tasks/delete_activedocs_task.rb +1 -1
- data/lib/3scale_toolbox/tasks/update_service_settings_task.rb +3 -3
- data/lib/3scale_toolbox/version.rb +1 -1
- metadata +16 -4
@@ -0,0 +1,64 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module Commands
|
3
|
+
module MethodsCommand
|
4
|
+
module List
|
5
|
+
class ListSubcommand < Cri::CommandRunner
|
6
|
+
include ThreeScaleToolbox::Command
|
7
|
+
|
8
|
+
FIELDS_TO_SHOW = %w[id friendly_name system_name description].freeze
|
9
|
+
|
10
|
+
def self.command
|
11
|
+
Cri::Command.define do
|
12
|
+
name 'list'
|
13
|
+
usage 'list [opts] <remote> <service>'
|
14
|
+
summary 'list methods'
|
15
|
+
description 'List methods'
|
16
|
+
|
17
|
+
param :remote
|
18
|
+
param :service_ref
|
19
|
+
|
20
|
+
runner ListSubcommand
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def run
|
25
|
+
print_header
|
26
|
+
print_data
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def print_header
|
32
|
+
puts FIELDS_TO_SHOW.map(&:upcase).join("\t")
|
33
|
+
end
|
34
|
+
|
35
|
+
def print_data
|
36
|
+
hits = service.hits
|
37
|
+
service.methods(hits.fetch('id')).each do |method|
|
38
|
+
puts FIELDS_TO_SHOW.map { |field| method.fetch(field, '(empty)') }.join("\t")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def service
|
43
|
+
@service ||= find_service
|
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 remote
|
54
|
+
@remote ||= threescale_client(arguments[:remote])
|
55
|
+
end
|
56
|
+
|
57
|
+
def service_ref
|
58
|
+
arguments[:service_ref]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require '3scale_toolbox/commands/metrics_command/create_command'
|
2
|
+
require '3scale_toolbox/commands/metrics_command/list_command'
|
3
|
+
require '3scale_toolbox/commands/metrics_command/apply_command'
|
4
|
+
require '3scale_toolbox/commands/metrics_command/delete_command'
|
5
|
+
|
6
|
+
module ThreeScaleToolbox
|
7
|
+
module Commands
|
8
|
+
module MetricsCommand
|
9
|
+
include ThreeScaleToolbox::Command
|
10
|
+
def self.command
|
11
|
+
Cri::Command.define do
|
12
|
+
name 'metrics'
|
13
|
+
usage 'metrics <sub-command> [options]'
|
14
|
+
summary 'metrics super command'
|
15
|
+
description 'Metrics commands'
|
16
|
+
|
17
|
+
run do |_opts, _args, cmd|
|
18
|
+
puts cmd.help
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
add_subcommand(Create::CreateSubcommand)
|
23
|
+
add_subcommand(List::ListSubcommand)
|
24
|
+
add_subcommand(Apply::ApplySubcommand)
|
25
|
+
add_subcommand(Delete::DeleteSubcommand)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module Commands
|
3
|
+
module MetricsCommand
|
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 [opts] <remote> <service> <metric>'
|
12
|
+
summary 'Update metric'
|
13
|
+
description 'Update (create if it does not exist) metric'
|
14
|
+
|
15
|
+
option :n, :name, 'Metric name', argument: :required
|
16
|
+
flag nil, :disabled, 'Disables this metric in all application plans'
|
17
|
+
flag nil, :enabled, 'Enables this metric in all application plans'
|
18
|
+
option nil, :unit, 'Metric unit. Default hit', argument: :required
|
19
|
+
option nil, :description, 'Metric description', argument: :required
|
20
|
+
param :remote
|
21
|
+
param :service_ref
|
22
|
+
param :metric_ref
|
23
|
+
|
24
|
+
runner ApplySubcommand
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def run
|
29
|
+
validate_option_params
|
30
|
+
metric = Entities::Metric.find(service: service, ref: metric_ref)
|
31
|
+
if metric.nil?
|
32
|
+
metric = Entities::Metric.create(service: service,
|
33
|
+
attrs: create_metric_attrs)
|
34
|
+
else
|
35
|
+
metric.update(metric_attrs) unless metric_attrs.empty?
|
36
|
+
end
|
37
|
+
|
38
|
+
metric.disable if option_disabled
|
39
|
+
metric.enable if option_enabled
|
40
|
+
|
41
|
+
output_msg_array = ["Applied metric id: #{metric.id}"]
|
42
|
+
output_msg_array << 'Disabled' if option_disabled
|
43
|
+
output_msg_array << 'Enabled' if option_enabled
|
44
|
+
puts output_msg_array.join('; ')
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def validate_option_params
|
50
|
+
raise ThreeScaleToolbox::Error, '--disabled and --enabled are mutually exclusive' \
|
51
|
+
if option_enabled && option_disabled
|
52
|
+
end
|
53
|
+
|
54
|
+
def create_metric_attrs
|
55
|
+
metric_attrs.merge('system_name' => metric_ref,
|
56
|
+
'unit' => 'hit',
|
57
|
+
'friendly_name' => metric_ref) { |_key, oldval, _newval| oldval }
|
58
|
+
end
|
59
|
+
|
60
|
+
def metric_attrs
|
61
|
+
{
|
62
|
+
'friendly_name' => options[:name],
|
63
|
+
'unit' => options[:unit],
|
64
|
+
'description' => options[:description]
|
65
|
+
}.compact
|
66
|
+
end
|
67
|
+
|
68
|
+
def option_enabled
|
69
|
+
!options[:enabled].nil?
|
70
|
+
end
|
71
|
+
|
72
|
+
def option_disabled
|
73
|
+
!options[:disabled].nil?
|
74
|
+
end
|
75
|
+
|
76
|
+
def service
|
77
|
+
@service ||= find_service
|
78
|
+
end
|
79
|
+
|
80
|
+
def find_service
|
81
|
+
Entities::Service.find(remote: remote,
|
82
|
+
ref: service_ref).tap do |svc|
|
83
|
+
raise ThreeScaleToolbox::Error, "Service #{service_ref} does not exist" if svc.nil?
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def remote
|
88
|
+
@remote ||= threescale_client(arguments[:remote])
|
89
|
+
end
|
90
|
+
|
91
|
+
def service_ref
|
92
|
+
arguments[:service_ref]
|
93
|
+
end
|
94
|
+
|
95
|
+
def metric_ref
|
96
|
+
arguments[:metric_ref]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module Commands
|
3
|
+
module MetricsCommand
|
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 [opts] <remote> <service> <metric-name>'
|
12
|
+
summary 'create metric'
|
13
|
+
description 'Create metric'
|
14
|
+
|
15
|
+
option :t, 'system-name', 'Metric system name', argument: :required
|
16
|
+
flag nil, :disabled, 'Disables this metric in all application plans'
|
17
|
+
option nil, :unit, 'Metric unit. Default hit', argument: :required
|
18
|
+
option nil, :description, 'Metric description', argument: :required
|
19
|
+
param :remote
|
20
|
+
param :service_ref
|
21
|
+
param :metric_name
|
22
|
+
|
23
|
+
runner CreateSubcommand
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def run
|
28
|
+
metric = ThreeScaleToolbox::Entities::Metric.create(
|
29
|
+
service: service,
|
30
|
+
attrs: metric_attrs
|
31
|
+
)
|
32
|
+
metric.disable if option_disabled
|
33
|
+
puts "Created metric id: #{metric.id}. Disabled: #{option_disabled}"
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def metric_attrs
|
39
|
+
{
|
40
|
+
'system_name' => options[:'system-name'],
|
41
|
+
'unit' => unit,
|
42
|
+
'friendly_name' => arguments[:metric_name],
|
43
|
+
'description' => options[:description]
|
44
|
+
}.compact
|
45
|
+
end
|
46
|
+
|
47
|
+
def unit
|
48
|
+
options[:unit] || 'hit'
|
49
|
+
end
|
50
|
+
|
51
|
+
def option_disabled
|
52
|
+
!options[:disabled].nil?
|
53
|
+
end
|
54
|
+
|
55
|
+
def service
|
56
|
+
@service ||= find_service
|
57
|
+
end
|
58
|
+
|
59
|
+
def find_service
|
60
|
+
Entities::Service.find(remote: remote,
|
61
|
+
ref: service_ref).tap do |svc|
|
62
|
+
raise ThreeScaleToolbox::Error, "Service #{service_ref} does not exist" if svc.nil?
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def remote
|
67
|
+
@remote ||= threescale_client(arguments[:remote])
|
68
|
+
end
|
69
|
+
|
70
|
+
def service_ref
|
71
|
+
arguments[:service_ref]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module Commands
|
3
|
+
module MetricsCommand
|
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 [opts] <remote> <service> <metric>'
|
12
|
+
summary 'delete metric'
|
13
|
+
description 'Delete metric'
|
14
|
+
|
15
|
+
param :remote
|
16
|
+
param :service_ref
|
17
|
+
param :metric_ref
|
18
|
+
|
19
|
+
runner DeleteSubcommand
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def run
|
24
|
+
metric.delete
|
25
|
+
puts "Metric id: #{metric.id} deleted"
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def service
|
31
|
+
@service ||= find_service
|
32
|
+
end
|
33
|
+
|
34
|
+
def metric
|
35
|
+
@metric ||= find_metric
|
36
|
+
end
|
37
|
+
|
38
|
+
def find_service
|
39
|
+
Entities::Service.find(remote: remote,
|
40
|
+
ref: service_ref).tap do |svc|
|
41
|
+
raise ThreeScaleToolbox::Error, "Service #{service_ref} does not exist" if svc.nil?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def find_metric
|
46
|
+
Entities::Metric.find(service: service, ref: metric_ref).tap do |p|
|
47
|
+
raise ThreeScaleToolbox::Error, "Metric #{metric_ref} does not exist" if p.nil?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def remote
|
52
|
+
@remote ||= threescale_client(arguments[:remote])
|
53
|
+
end
|
54
|
+
|
55
|
+
def service_ref
|
56
|
+
arguments[:service_ref]
|
57
|
+
end
|
58
|
+
|
59
|
+
def metric_ref
|
60
|
+
arguments[:metric_ref]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module ThreeScaleToolbox
|
2
|
+
module Commands
|
3
|
+
module MetricsCommand
|
4
|
+
module List
|
5
|
+
class ListSubcommand < Cri::CommandRunner
|
6
|
+
include ThreeScaleToolbox::Command
|
7
|
+
|
8
|
+
FIELDS_TO_SHOW = %w[id friendly_name system_name unit description].freeze
|
9
|
+
|
10
|
+
def self.command
|
11
|
+
Cri::Command.define do
|
12
|
+
name 'list'
|
13
|
+
usage 'list [opts] <remote> <service>'
|
14
|
+
summary 'list metrics'
|
15
|
+
description 'List metrics'
|
16
|
+
|
17
|
+
param :remote
|
18
|
+
param :service_ref
|
19
|
+
|
20
|
+
runner ListSubcommand
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def run
|
25
|
+
print_header
|
26
|
+
print_data
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def print_header
|
32
|
+
puts FIELDS_TO_SHOW.map(&:upcase).join("\t")
|
33
|
+
end
|
34
|
+
|
35
|
+
def print_data
|
36
|
+
metrics.each do |metric|
|
37
|
+
puts FIELDS_TO_SHOW.map { |field| metric.fetch(field, '(empty)') }.join("\t")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def metrics
|
42
|
+
hits_id = service.hits['id']
|
43
|
+
ThreeScaleToolbox::Helper.array_difference(service.metrics, service.methods(hits_id)) do |metric, method|
|
44
|
+
ThreeScaleToolbox::Helper.compare_hashes(metric, method, %w[id])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def service
|
49
|
+
@service ||= find_service
|
50
|
+
end
|
51
|
+
|
52
|
+
def find_service
|
53
|
+
Entities::Service.find(remote: remote,
|
54
|
+
ref: service_ref).tap do |svc|
|
55
|
+
raise ThreeScaleToolbox::Error, "Service #{service_ref} does not exist" if svc.nil?
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def remote
|
60
|
+
@remote ||= threescale_client(arguments[:remote])
|
61
|
+
end
|
62
|
+
|
63
|
+
def service_ref
|
64
|
+
arguments[:service_ref]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -8,7 +8,7 @@ module ThreeScaleToolbox
|
|
8
8
|
def self.command
|
9
9
|
Cri::Command.define do
|
10
10
|
name 'create'
|
11
|
-
usage 'create [opts] <remote> <service> <
|
11
|
+
usage 'create [opts] <remote> <service> <plan-name>'
|
12
12
|
summary 'create application plan'
|
13
13
|
description 'Create application plan'
|
14
14
|
|
@@ -50,7 +50,7 @@ module ThreeScaleToolbox
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def service_methods
|
53
|
-
context[:service_methods] ||= service.methods
|
53
|
+
context[:service_methods] ||= service.methods(service_hits['id'])
|
54
54
|
end
|
55
55
|
|
56
56
|
def metric_info(elem, elem_name)
|
@@ -88,6 +88,10 @@ module ThreeScaleToolbox
|
|
88
88
|
def find_method(id)
|
89
89
|
service_methods.find { |method| method['id'] == id }
|
90
90
|
end
|
91
|
+
|
92
|
+
def service_hits
|
93
|
+
context[:service_hits] ||= service.hits
|
94
|
+
end
|
91
95
|
end
|
92
96
|
end
|
93
97
|
end
|