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.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/3scale_toolbox.gemspec +1 -1
  3. data/README.md +4 -1
  4. data/lib/3scale_toolbox.rb +0 -1
  5. data/lib/3scale_toolbox/cli.rb +4 -0
  6. data/lib/3scale_toolbox/cli/custom_table_printer.rb +32 -0
  7. data/lib/3scale_toolbox/cli/json_printer.rb +13 -0
  8. data/lib/3scale_toolbox/cli/output_flag.rb +20 -0
  9. data/lib/3scale_toolbox/cli/yaml_printer.rb +13 -0
  10. data/lib/3scale_toolbox/commands.rb +5 -1
  11. data/lib/3scale_toolbox/commands/activedocs_command/apply_command.rb +33 -10
  12. data/lib/3scale_toolbox/commands/activedocs_command/create_command.rb +22 -7
  13. data/lib/3scale_toolbox/commands/activedocs_command/list_command.rb +10 -17
  14. data/lib/3scale_toolbox/commands/application_command/apply_command.rb +27 -4
  15. data/lib/3scale_toolbox/commands/application_command/create_command.rb +16 -1
  16. data/lib/3scale_toolbox/commands/application_command/list_command.rb +10 -13
  17. data/lib/3scale_toolbox/commands/application_command/show_command.rb +8 -14
  18. data/lib/3scale_toolbox/commands/backend_command.rb +22 -0
  19. data/lib/3scale_toolbox/commands/backend_command/copy_command.rb +65 -0
  20. data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_mapping_rules_task.rb +52 -0
  21. data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb +40 -0
  22. data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_metrics_task.rb +30 -0
  23. data/lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb +45 -0
  24. data/lib/3scale_toolbox/commands/backend_command/copy_command/task.rb +89 -0
  25. data/lib/3scale_toolbox/commands/copy_command.rb +2 -2
  26. data/lib/3scale_toolbox/commands/copy_command/service_command.rb +40 -0
  27. data/lib/3scale_toolbox/commands/import_command/openapi.rb +3 -2
  28. data/lib/3scale_toolbox/commands/methods_command/apply_command.rb +26 -4
  29. data/lib/3scale_toolbox/commands/methods_command/create_command.rb +23 -1
  30. data/lib/3scale_toolbox/commands/methods_command/list_command.rb +11 -9
  31. data/lib/3scale_toolbox/commands/metrics_command/apply_command.rb +26 -4
  32. data/lib/3scale_toolbox/commands/metrics_command/create_command.rb +23 -1
  33. data/lib/3scale_toolbox/commands/metrics_command/list_command.rb +7 -12
  34. data/lib/3scale_toolbox/commands/plans_command/apply_command.rb +36 -7
  35. data/lib/3scale_toolbox/commands/plans_command/create_command.rb +23 -1
  36. data/lib/3scale_toolbox/commands/plans_command/list_command.rb +8 -13
  37. data/lib/3scale_toolbox/commands/plans_command/show_command.rb +6 -14
  38. data/lib/3scale_toolbox/commands/product_command.rb +22 -0
  39. data/lib/3scale_toolbox/commands/product_command/copy_command.rb +78 -0
  40. data/lib/3scale_toolbox/commands/product_command/copy_command/copy_backends_task.rb +71 -0
  41. data/lib/3scale_toolbox/commands/product_command/copy_command/delete_target_backend_usages_task.rb +48 -0
  42. data/lib/3scale_toolbox/commands/proxy_config_command/list_command.rb +13 -29
  43. data/lib/3scale_toolbox/commands/proxy_config_command/show_command.rb +20 -23
  44. data/lib/3scale_toolbox/commands/service_command.rb +7 -5
  45. data/lib/3scale_toolbox/commands/service_command/apply_command.rb +69 -58
  46. data/lib/3scale_toolbox/commands/service_command/copy_command.rb +95 -0
  47. data/lib/3scale_toolbox/commands/service_command/copy_command/bump_proxy_version_task.rb +36 -0
  48. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_activedocs_task.rb +46 -0
  49. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb +35 -0
  50. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb +39 -0
  51. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb +35 -0
  52. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_methods_task.rb +40 -0
  53. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_metrics_task.rb +37 -0
  54. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_policies_task.rb +17 -0
  55. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_pricingrules_task.rb +44 -0
  56. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_service_proxy_task.rb +17 -0
  57. data/lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb +48 -0
  58. data/lib/3scale_toolbox/commands/service_command/copy_command/destroy_mapping_rules_task.rb +34 -0
  59. data/lib/3scale_toolbox/commands/service_command/copy_command/task.rb +99 -0
  60. data/lib/3scale_toolbox/commands/service_command/create_command.rb +58 -44
  61. data/lib/3scale_toolbox/commands/service_command/delete_command.rb +31 -33
  62. data/lib/3scale_toolbox/commands/service_command/list_command.rb +24 -34
  63. data/lib/3scale_toolbox/commands/service_command/show_command.rb +39 -44
  64. data/lib/3scale_toolbox/commands/update_command.rb +2 -2
  65. data/lib/3scale_toolbox/commands/update_command/{update_service.rb → service_command.rb} +19 -16
  66. data/lib/3scale_toolbox/commands/update_command/service_command/copy_service_settings_task.rb +35 -0
  67. data/lib/3scale_toolbox/commands/update_command/service_command/delete_activedocs_task.rb +26 -0
  68. data/lib/3scale_toolbox/entities.rb +5 -0
  69. data/lib/3scale_toolbox/entities/backend.rb +152 -0
  70. data/lib/3scale_toolbox/entities/backend_mapping_rule.rb +76 -0
  71. data/lib/3scale_toolbox/entities/backend_method.rb +90 -0
  72. data/lib/3scale_toolbox/entities/backend_metric.rb +88 -0
  73. data/lib/3scale_toolbox/entities/backend_usage.rb +99 -0
  74. data/lib/3scale_toolbox/entities/service.rb +18 -3
  75. data/lib/3scale_toolbox/error.rb +3 -0
  76. data/lib/3scale_toolbox/helper.rb +20 -0
  77. data/lib/3scale_toolbox/proxy_logger.rb +1 -1
  78. data/lib/3scale_toolbox/version.rb +1 -1
  79. data/licenses.xml +3 -3
  80. metadata +42 -22
  81. data/lib/3scale_toolbox/commands/copy_command/copy_service.rb +0 -144
  82. data/lib/3scale_toolbox/tasks.rb +0 -15
  83. data/lib/3scale_toolbox/tasks/bump_proxy_version_task.rb +0 -32
  84. data/lib/3scale_toolbox/tasks/copy_activedocs_task.rb +0 -42
  85. data/lib/3scale_toolbox/tasks/copy_app_plans_task.rb +0 -31
  86. data/lib/3scale_toolbox/tasks/copy_limits_task.rb +0 -36
  87. data/lib/3scale_toolbox/tasks/copy_mapping_rules_task.rb +0 -32
  88. data/lib/3scale_toolbox/tasks/copy_methods_task.rb +0 -36
  89. data/lib/3scale_toolbox/tasks/copy_metrics_task.rb +0 -33
  90. data/lib/3scale_toolbox/tasks/copy_policies_task.rb +0 -13
  91. data/lib/3scale_toolbox/tasks/copy_pricingrules_task.rb +0 -41
  92. data/lib/3scale_toolbox/tasks/copy_service_proxy_task.rb +0 -13
  93. data/lib/3scale_toolbox/tasks/copy_service_settings_task.rb +0 -38
  94. data/lib/3scale_toolbox/tasks/copy_task.rb +0 -66
  95. data/lib/3scale_toolbox/tasks/delete_activedocs_task.rb +0 -22
  96. data/lib/3scale_toolbox/tasks/destroy_mapping_rules_task.rb +0 -22
  97. data/lib/3scale_toolbox/tasks/helper_task.rb +0 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf0d2a187e793d654f6e6cef6990cfabaada5072f3a72b9820b1fed1ac13ddfb
4
- data.tar.gz: c1b56e8e76059e0143444ff9ef12da633b97ef74b0fccb6875480be8b22cf9e6
3
+ metadata.gz: 77ce2f220c416d634541773317d35da8018a75d7e3d91c009338b7a971614eee
4
+ data.tar.gz: 4d5ee60b4cc55c0ba002fc007ba578801012c9c5580b4fe540f03c3c9dbb2d26
5
5
  SHA512:
6
- metadata.gz: f2bf8c3a1f5860a3c6d24fa5fbc976b9b3361ea8ef6a57bbc0707d5f3900a31d8022e9596080bf8129d47116d13d3ab4d2ae7bfc41e246d179adf0f757c7c598
7
- data.tar.gz: 3a206838d82a662f56276e7d98291cf74f5bc69eb9f39de239bb3d15f457e62b81e336ee1d0438a508fdecc46f692b49610627ef6413d05788b4c9f1a8c3f2e5
6
+ metadata.gz: 947d84f88a8b8e673ea313ba79a3e72eda4b03b85af30f12003b8c6b867f98addf8bc0eebea2e4a3c3bdbc64f80f241346c0e70bdb2ec9e5e9b3a698ab539438
7
+ data.tar.gz: 106e99be0a64a27284d6b7a64b796ac0ef6b14e30011b3d42366d1e6494e9f623fdb6221924204830e4e9dbb59a6086b0aac8601a4e7b5a968a59f9bfaefed61
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency 'webmock', '~> 3.4'
37
37
  spec.required_ruby_version = '>= 2.5'
38
38
 
39
- spec.add_dependency '3scale-api', '~> 0.6.0'
39
+ spec.add_dependency '3scale-api', '~> 1.0'
40
40
  spec.add_dependency 'cri', '~> 2.15'
41
41
  spec.add_dependency 'json-schema', '~> 2.8'
42
42
  spec.add_dependency 'oas_parser', '~> 0.20'
data/README.md CHANGED
@@ -12,7 +12,9 @@ See the LICENSE and NOTICE files that should have been provided along with this
12
12
  * [Requirements](#requirements)
13
13
  * [Installation](#installation)
14
14
  * [Usage](#usage)
15
- * [Copy a service](docs/copy-service.md)
15
+ * [Copy service](docs/copy-service.md)
16
+ * [Copy backend](docs/copy-backend.md)
17
+ * [Copy product](docs/copy-product.md)
16
18
  * [Import from CSV](docs/import-csv.md)
17
19
  * [Import from OpenAPI definition](docs/openapi.md)
18
20
  * [Export/Import Application Plan](docs/export-import-app-plan.md)
@@ -73,6 +75,7 @@ COMMANDS
73
75
  activedocs activedocs super command
74
76
  application application super command
75
77
  application-plan application-plan super command
78
+ backend backend super command
76
79
  copy copy super command
77
80
  help show help
78
81
  import import super command
@@ -20,7 +20,6 @@ require '3scale_toolbox/configuration'
20
20
  require '3scale_toolbox/remotes'
21
21
  require '3scale_toolbox/3scale_client_factory'
22
22
  require '3scale_toolbox/entities'
23
- require '3scale_toolbox/tasks'
24
23
  require '3scale_toolbox/attribute_filters'
25
24
  require '3scale_toolbox/base_command'
26
25
  require '3scale_toolbox/openapi'
@@ -1,4 +1,8 @@
1
1
  require '3scale_toolbox/cli/error_handler'
2
+ require '3scale_toolbox/cli/json_printer'
3
+ require '3scale_toolbox/cli/yaml_printer'
4
+ require '3scale_toolbox/cli/custom_table_printer'
5
+ require '3scale_toolbox/cli/output_flag'
2
6
 
3
7
  module ThreeScaleToolbox::CLI
4
8
  def self.root_command
@@ -0,0 +1,32 @@
1
+ module ThreeScaleToolbox
2
+ module CLI
3
+ class CustomTablePrinter
4
+ attr_reader :fields
5
+
6
+ def initialize(fields)
7
+ @fields = fields
8
+ end
9
+
10
+ def print_record(record)
11
+ print_collection([record])
12
+ end
13
+
14
+ def print_collection(collection)
15
+ print_header
16
+ print_data(collection)
17
+ end
18
+
19
+ private
20
+
21
+ def print_header
22
+ puts fields.map(&:upcase).join("\t")
23
+ end
24
+
25
+ def print_data(collection)
26
+ collection.each do |obj|
27
+ puts fields.map { |field| obj.fetch(field, '(empty)').to_s }.join("\t")
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,13 @@
1
+ module ThreeScaleToolbox
2
+ module CLI
3
+ class JsonPrinter
4
+ def print_record(record)
5
+ puts JSON.pretty_generate(record)
6
+ end
7
+
8
+ def print_collection(collection)
9
+ puts JSON.pretty_generate(collection)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ module ThreeScaleToolbox
2
+ module CLI
3
+ class PrinterTransformer
4
+ def call(output_format)
5
+ raise unless %w[yaml json].include?(output_format)
6
+
7
+ case output_format
8
+ when 'yaml'
9
+ YamlPrinter.new
10
+ when 'json'
11
+ JsonPrinter.new
12
+ end
13
+ end
14
+ end
15
+
16
+ def self.output_flag(dsl)
17
+ dsl.option :o, :output, 'Output format. One of: json|yaml', argument: :required, transform: PrinterTransformer.new
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ module ThreeScaleToolbox
2
+ module CLI
3
+ class YamlPrinter
4
+ def print_record(record)
5
+ puts YAML.dump(record)
6
+ end
7
+
8
+ def print_collection(collection)
9
+ puts YAML.dump(collection)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,6 +1,5 @@
1
1
  require '3scale_toolbox/commands/3scale_command'
2
2
  require '3scale_toolbox/commands/help_command'
3
- require '3scale_toolbox/commands/copy_command'
4
3
  require '3scale_toolbox/commands/import_command'
5
4
  require '3scale_toolbox/commands/update_command'
6
5
  require '3scale_toolbox/commands/remote_command'
@@ -8,11 +7,14 @@ require '3scale_toolbox/commands/plans_command'
8
7
  require '3scale_toolbox/commands/metrics_command'
9
8
  require '3scale_toolbox/commands/methods_command'
10
9
  require '3scale_toolbox/commands/service_command'
10
+ require '3scale_toolbox/commands/copy_command'
11
11
  require '3scale_toolbox/commands/activedocs_command'
12
12
  require '3scale_toolbox/commands/account_command'
13
13
  require '3scale_toolbox/commands/proxy_config_command'
14
14
  require '3scale_toolbox/commands/policy_registry_command'
15
15
  require '3scale_toolbox/commands/application_command'
16
+ require '3scale_toolbox/commands/backend_command'
17
+ require '3scale_toolbox/commands/product_command'
16
18
 
17
19
  module ThreeScaleToolbox
18
20
  module Commands
@@ -31,6 +33,8 @@ module ThreeScaleToolbox
31
33
  ThreeScaleToolbox::Commands::ProxyConfigCommand,
32
34
  ThreeScaleToolbox::Commands::PolicyRegistryCommand,
33
35
  ThreeScaleToolbox::Commands::ApplicationCommand,
36
+ ThreeScaleToolbox::Commands::BackendCommand,
37
+ ThreeScaleToolbox::Commands::ProductCommand,
34
38
  ].freeze
35
39
  end
36
40
  end
@@ -2,6 +2,24 @@ module ThreeScaleToolbox
2
2
  module Commands
3
3
  module ActiveDocsCommand
4
4
  module Apply
5
+ class CustomPrinter
6
+ attr_reader :option_publish, :option_hide
7
+
8
+ def initialize(options)
9
+ @option_publish = options[:publish]
10
+ @option_hide = options[:hide]
11
+ end
12
+
13
+ def print_record(active_docs)
14
+ output_msg_array = ["Applied ActiveDocs id: #{active_docs['id']}"]
15
+ output_msg_array << 'Published' if option_publish
16
+ output_msg_array << 'Hidden' if option_hide
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
  include ThreeScaleToolbox::ResourceReader
@@ -12,10 +30,6 @@ module ThreeScaleToolbox
12
30
  usage 'apply <remote> <activedocs_id_or_system_name>'
13
31
  summary 'Update activedocs'
14
32
  description 'Create or update an ActiveDocs'
15
- runner ApplySubcommand
16
-
17
- param :remote
18
- param :activedocs_id_or_system_name
19
33
 
20
34
  option :i, :'service-id', "Specify the Service ID associated to the ActiveDocs", argument: :required
21
35
  option :p, :'publish', "Specify it to publish the ActiveDocs on the Developer Portal. Otherwise it will be hidden", argument: :forbidden
@@ -24,22 +38,26 @@ module ThreeScaleToolbox
24
38
  option :d, :'description', "Specify the description of the ActiveDocs", argument: :required
25
39
  option :s, :'name', "Specify the name of the ActiveDocs", argument: :required
26
40
  option nil, :'openapi-spec', "Specify the swagger spec. Can be a file, an URL or '-' to read from stdin. This option is mandatory when applying the ActiveDoc for the first time", argument: :required
41
+
42
+ param :remote
43
+ param :activedocs_id_or_system_name
44
+
45
+ ThreeScaleToolbox::CLI.output_flag(self)
46
+
47
+ runner ApplySubcommand
27
48
  end
28
49
  end
29
50
 
30
51
  def run
31
- res = activedocs
32
52
  validate_option_params
53
+ res = activedocs
33
54
  if !res
34
- res = Entities::ActiveDocs::create(remote: remote, attrs: create_activedocs_attrs)
55
+ res = Entities::ActiveDocs.create(remote: remote, attrs: create_activedocs_attrs)
35
56
  else
36
57
  res.update(activedocs_attrs) unless activedocs_attrs.empty?
37
58
  end
38
59
 
39
- output_msg_array = ["Applied ActiveDocs id: #{res.id}"]
40
- output_msg_array << "Published" if option_publish
41
- output_msg_array << "Hidden" if option_hide
42
- puts output_msg_array.join(";")
60
+ printer.print_record res.attrs
43
61
  end
44
62
 
45
63
  private
@@ -120,6 +138,11 @@ module ThreeScaleToolbox
120
138
  "body" => activedocs_json_spec,
121
139
  ) { |_key, oldval, _newval| oldval } # receiver of the merge message has key priority
122
140
  end
141
+
142
+ def printer
143
+ # keep backwards compatibility
144
+ options.fetch(:output, CustomPrinter.new(publish: option_publish, hide: option_hide))
145
+ end
123
146
  end
124
147
  end
125
148
  end
@@ -2,6 +2,14 @@ module ThreeScaleToolbox
2
2
  module Commands
3
3
  module ActiveDocsCommand
4
4
  module Create
5
+ class CustomPrinter
6
+ def print_record(activedocs)
7
+ puts "ActiveDocs '#{activedocs['name']}' has been created with ID: #{activedocs['id']}"
8
+ end
9
+
10
+ def print_collection(collection) end
11
+ end
12
+
5
13
  class CreateSubcommand < Cri::CommandRunner
6
14
  include ThreeScaleToolbox::Command
7
15
  include ThreeScaleToolbox::ResourceReader
@@ -12,23 +20,25 @@ module ThreeScaleToolbox
12
20
  usage 'create <remote> <activedocs-name> <spec>'
13
21
  summary 'Create an ActiveDocs'
14
22
  description 'Create an ActiveDocs'
15
- runner CreateSubcommand
16
-
17
- param :remote
18
- param :activedocs_name
19
- param :activedocs_spec
20
23
 
21
24
  option :i, :'service-id', "Specify the Service ID associated to the ActiveDocs", argument: :required
22
25
  option :p, :'published', "Specify it to publish the ActiveDoc on the Developer Portal. Otherwise it will be hidden", argument: :forbidden
23
26
  option nil, :'skip-swagger-validations', "Specify it to skip validation of the Swagger specification", argument: :forbidden
24
27
  option :d, :'description', "Specify the description of the ActiveDocs", argument: :required
25
28
  option :s, :'system-name', "Specify the system-name of the ActiveDocs", argument: :required
29
+ ThreeScaleToolbox::CLI.output_flag(self)
30
+
31
+ param :remote
32
+ param :activedocs_name
33
+ param :activedocs_spec
34
+
35
+ runner CreateSubcommand
26
36
  end
27
37
  end
28
38
 
29
39
  def run
30
- res = Entities::ActiveDocs::create(remote: remote, attrs: activedocs_attrs)
31
- puts "ActiveDocs '#{activedocs_name}' has been created with ID: #{res.id}"
40
+ res = Entities::ActiveDocs.create(remote: remote, attrs: activedocs_attrs)
41
+ printer.print_record res.attrs
32
42
  end
33
43
 
34
44
  private
@@ -58,6 +68,11 @@ module ThreeScaleToolbox
58
68
  "body" => activedocs_json_spec,
59
69
  }.compact
60
70
  end
71
+
72
+ def printer
73
+ # keep backwards compatibility
74
+ options.fetch(:output, CustomPrinter.new)
75
+ end
61
76
  end
62
77
  end
63
78
  end
@@ -11,16 +11,17 @@ module ThreeScaleToolbox
11
11
  usage 'list <remote>'
12
12
  summary 'List ActiveDocs'
13
13
  description 'List all defined ActiveDocs'
14
- runner ListSubcommand
15
14
 
15
+ ThreeScaleToolbox::CLI.output_flag(self)
16
16
  param :remote
17
17
  option :s, :'service-ref', "Filter the ActiveDocs by Service reference", argument: :required
18
+
19
+ runner ListSubcommand
18
20
  end
19
21
  end
20
22
 
21
23
  def run
22
- activedocs = remote.list_activedocs
23
- print_activedocs_data(activedocs, ACTIVEDOCS_FIELDS_TO_SHOW)
24
+ printer.print_collection filtered_activedocs
24
25
  end
25
26
 
26
27
  private
@@ -34,13 +35,9 @@ module ThreeScaleToolbox
34
35
  @remote ||= threescale_client(arguments[:remote])
35
36
  end
36
37
 
37
- def print_activedocs_data(activedocs, fields_to_show)
38
- print_header(fields_to_show)
39
- print_results(activedocs, fields_to_show)
40
- end
41
-
42
- def print_header(fields_to_show)
43
- puts fields_to_show.map { |e| e.upcase }.join("\t")
38
+ def printer
39
+ # keep backwards compatibility
40
+ options.fetch(:output, CLI::CustomTablePrinter.new(ACTIVEDOCS_FIELDS_TO_SHOW))
44
41
  end
45
42
 
46
43
  def service_ref_filter
@@ -55,13 +52,9 @@ module ThreeScaleToolbox
55
52
  res
56
53
  end
57
54
 
58
- def filtered_activedocs(activedocs)
59
- filters.reduce(activedocs) { |current_list, filter| filter.filter(current_list) }
60
- end
61
-
62
- def print_results(activedocs, fields_to_show)
63
- filtered_activedocs(activedocs).each do |activedoc|
64
- puts fields_to_show.map { |field| activedoc.fetch(field, '(empty)') }.join("\t")
55
+ def filtered_activedocs
56
+ filters.reduce(remote.list_activedocs) do |current_list, filter|
57
+ filter.filter(current_list)
65
58
  end
66
59
  end
67
60
  end
@@ -2,6 +2,24 @@ module ThreeScaleToolbox
2
2
  module Commands
3
3
  module ApplicationCommand
4
4
  module Apply
5
+ class CustomPrinter
6
+ attr_reader :option_resume, :option_suspend
7
+
8
+ def initialize(options)
9
+ @option_resume = options[:resume]
10
+ @option_suspend = options[:suspend]
11
+ end
12
+
13
+ def print_record(application)
14
+ output_msg_array = ["Applied application id: #{application['id']}"]
15
+ output_msg_array << 'Resumed' if option_resume
16
+ output_msg_array << 'Suspended' if option_suspend
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
 
@@ -28,6 +46,8 @@ module ThreeScaleToolbox
28
46
  option nil, :'redirect-url', 'OpenID Connect redirect url', argument: :required
29
47
  flag nil, :resume, 'Resume a suspended application'
30
48
  flag nil, :suspend, 'Suspends an application (changes the state to suspended)'
49
+ ThreeScaleToolbox::CLI.output_flag(self)
50
+
31
51
  param :remote
32
52
  param :application
33
53
 
@@ -52,10 +72,8 @@ module ThreeScaleToolbox
52
72
 
53
73
  application.resume if option_resume
54
74
  application.suspend if option_suspend
55
- output_msg_array = ["Applied application id: #{application.id}"]
56
- output_msg_array << 'Resumed' if option_resume
57
- output_msg_array << 'Suspended' if option_suspend
58
- puts output_msg_array.join('; ')
75
+
76
+ printer.print_record application.attrs
59
77
  end
60
78
 
61
79
  private
@@ -186,6 +204,11 @@ module ThreeScaleToolbox
186
204
  def option_redirect_url
187
205
  options[:'redirect-url']
188
206
  end
207
+
208
+ def printer
209
+ # keep backwards compatibility
210
+ options.fetch(:output, CustomPrinter.new(resume: option_resume, suspend: option_suspend))
211
+ end
189
212
  end
190
213
  end
191
214
  end
@@ -2,6 +2,14 @@ module ThreeScaleToolbox
2
2
  module Commands
3
3
  module ApplicationCommand
4
4
  module Create
5
+ class CustomPrinter
6
+ def print_record(application)
7
+ puts "Created application id: #{application['id']}"
8
+ end
9
+
10
+ def print_collection(collection) end
11
+ end
12
+
5
13
  class CreateSubcommand < Cri::CommandRunner
6
14
  include ThreeScaleToolbox::Command
7
15
 
@@ -17,6 +25,8 @@ module ThreeScaleToolbox
17
25
  option nil, 'application-key', 'App Key(s) or Client Secret (for OAuth and OpenID Connect authentication modes) of the application to be created.' , argument: :required
18
26
  option nil, :description, 'Application description', argument: :required
19
27
  option nil, :'redirect-url', 'OpenID Connect redirect url', argument: :required
28
+ ThreeScaleToolbox::CLI.output_flag(self)
29
+
20
30
  param :remote
21
31
  param :account
22
32
  param :service
@@ -35,7 +45,7 @@ module ThreeScaleToolbox
35
45
  app_attrs: app_attrs
36
46
  )
37
47
 
38
- puts "Created application id: #{application.id}"
48
+ printer.print_record application.attrs
39
49
  end
40
50
 
41
51
  private
@@ -105,6 +115,11 @@ module ThreeScaleToolbox
105
115
  def remote
106
116
  @remote ||= threescale_client(arguments[:remote])
107
117
  end
118
+
119
+ def printer
120
+ # keep backwards compatibility
121
+ options.fetch(:output, CustomPrinter.new)
122
+ end
108
123
  end
109
124
  end
110
125
  end