3scale_toolbox 0.13.0 → 0.17.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/3scale_toolbox.gemspec +4 -3
  3. data/README.md +31 -10
  4. data/lib/3scale_toolbox.rb +5 -2
  5. data/lib/3scale_toolbox/attribute_filters.rb +2 -0
  6. data/lib/3scale_toolbox/attribute_filters/attribute_filter.rb +9 -0
  7. data/lib/3scale_toolbox/attribute_filters/service_id_from_ref_filter.rb +30 -0
  8. data/lib/3scale_toolbox/cli.rb +4 -0
  9. data/lib/3scale_toolbox/cli/custom_table_printer.rb +32 -0
  10. data/lib/3scale_toolbox/cli/error_handler.rb +17 -14
  11. data/lib/3scale_toolbox/cli/json_printer.rb +13 -0
  12. data/lib/3scale_toolbox/cli/output_flag.rb +20 -0
  13. data/lib/3scale_toolbox/cli/yaml_printer.rb +13 -0
  14. data/lib/3scale_toolbox/commands.rb +5 -1
  15. data/lib/3scale_toolbox/commands/activedocs_command/apply_command.rb +34 -11
  16. data/lib/3scale_toolbox/commands/activedocs_command/create_command.rb +22 -7
  17. data/lib/3scale_toolbox/commands/activedocs_command/list_command.rb +21 -11
  18. data/lib/3scale_toolbox/commands/application_command/apply_command.rb +27 -4
  19. data/lib/3scale_toolbox/commands/application_command/create_command.rb +16 -1
  20. data/lib/3scale_toolbox/commands/application_command/list_command.rb +10 -13
  21. data/lib/3scale_toolbox/commands/application_command/show_command.rb +8 -14
  22. data/lib/3scale_toolbox/commands/backend_command.rb +22 -0
  23. data/lib/3scale_toolbox/commands/backend_command/copy_command.rb +65 -0
  24. data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_mapping_rules_task.rb +52 -0
  25. data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb +40 -0
  26. data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_metrics_task.rb +30 -0
  27. data/lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb +45 -0
  28. data/lib/3scale_toolbox/commands/backend_command/copy_command/task.rb +89 -0
  29. data/lib/3scale_toolbox/commands/copy_command.rb +2 -2
  30. data/lib/3scale_toolbox/commands/copy_command/service_command.rb +40 -0
  31. data/lib/3scale_toolbox/commands/import_command/openapi.rb +29 -7
  32. data/lib/3scale_toolbox/commands/import_command/openapi/create_activedocs_step.rb +4 -17
  33. data/lib/3scale_toolbox/commands/import_command/openapi/create_service_step.rb +1 -5
  34. data/lib/3scale_toolbox/commands/import_command/openapi/mapping_rule.rb +3 -2
  35. data/lib/3scale_toolbox/commands/import_command/openapi/step.rb +43 -5
  36. data/lib/3scale_toolbox/commands/import_command/openapi/update_policies_step.rb +9 -10
  37. data/lib/3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step.rb +2 -17
  38. data/lib/3scale_toolbox/commands/import_command/openapi/update_service_proxy_step.rb +10 -10
  39. data/lib/3scale_toolbox/commands/methods_command/apply_command.rb +26 -4
  40. data/lib/3scale_toolbox/commands/methods_command/create_command.rb +23 -1
  41. data/lib/3scale_toolbox/commands/methods_command/list_command.rb +11 -9
  42. data/lib/3scale_toolbox/commands/metrics_command/apply_command.rb +26 -4
  43. data/lib/3scale_toolbox/commands/metrics_command/create_command.rb +23 -1
  44. data/lib/3scale_toolbox/commands/metrics_command/list_command.rb +7 -12
  45. data/lib/3scale_toolbox/commands/plans_command/apply_command.rb +36 -7
  46. data/lib/3scale_toolbox/commands/plans_command/create_command.rb +23 -1
  47. data/lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb +11 -12
  48. data/lib/3scale_toolbox/commands/plans_command/import/import_plan_pricing_rules_step.rb +11 -12
  49. data/lib/3scale_toolbox/commands/plans_command/list_command.rb +8 -13
  50. data/lib/3scale_toolbox/commands/plans_command/show_command.rb +6 -14
  51. data/lib/3scale_toolbox/commands/product_command.rb +22 -0
  52. data/lib/3scale_toolbox/commands/product_command/copy_command.rb +78 -0
  53. data/lib/3scale_toolbox/commands/product_command/copy_command/copy_backends_task.rb +71 -0
  54. data/lib/3scale_toolbox/commands/product_command/copy_command/delete_target_backend_usages_task.rb +48 -0
  55. data/lib/3scale_toolbox/commands/proxy_config_command.rb +3 -0
  56. data/lib/3scale_toolbox/commands/proxy_config_command/export_command.rb +74 -0
  57. data/lib/3scale_toolbox/commands/proxy_config_command/helper.rb +15 -0
  58. data/lib/3scale_toolbox/commands/proxy_config_command/list_command.rb +13 -29
  59. data/lib/3scale_toolbox/commands/proxy_config_command/show_command.rb +20 -23
  60. data/lib/3scale_toolbox/commands/service_command.rb +7 -5
  61. data/lib/3scale_toolbox/commands/service_command/apply_command.rb +69 -58
  62. data/lib/3scale_toolbox/commands/service_command/copy_command.rb +95 -0
  63. data/lib/3scale_toolbox/commands/service_command/copy_command/bump_proxy_version_task.rb +36 -0
  64. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_activedocs_task.rb +46 -0
  65. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb +35 -0
  66. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb +39 -0
  67. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb +35 -0
  68. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_methods_task.rb +40 -0
  69. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_metrics_task.rb +37 -0
  70. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_policies_task.rb +17 -0
  71. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_pricingrules_task.rb +44 -0
  72. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_service_proxy_task.rb +32 -0
  73. data/lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb +48 -0
  74. data/lib/3scale_toolbox/commands/service_command/copy_command/destroy_mapping_rules_task.rb +34 -0
  75. data/lib/3scale_toolbox/commands/service_command/copy_command/task.rb +99 -0
  76. data/lib/3scale_toolbox/commands/service_command/create_command.rb +58 -44
  77. data/lib/3scale_toolbox/commands/service_command/delete_command.rb +31 -33
  78. data/lib/3scale_toolbox/commands/service_command/list_command.rb +24 -34
  79. data/lib/3scale_toolbox/commands/service_command/show_command.rb +39 -44
  80. data/lib/3scale_toolbox/commands/update_command.rb +3 -3
  81. data/lib/3scale_toolbox/commands/update_command/{update_service.rb → service_command.rb} +22 -18
  82. data/lib/3scale_toolbox/commands/update_command/service_command/copy_service_settings_task.rb +35 -0
  83. data/lib/3scale_toolbox/commands/update_command/service_command/delete_activedocs_task.rb +26 -0
  84. data/lib/3scale_toolbox/entities.rb +5 -0
  85. data/lib/3scale_toolbox/entities/application_plan.rb +31 -4
  86. data/lib/3scale_toolbox/entities/backend.rb +152 -0
  87. data/lib/3scale_toolbox/entities/backend_mapping_rule.rb +76 -0
  88. data/lib/3scale_toolbox/entities/backend_method.rb +90 -0
  89. data/lib/3scale_toolbox/entities/backend_metric.rb +88 -0
  90. data/lib/3scale_toolbox/entities/backend_usage.rb +99 -0
  91. data/lib/3scale_toolbox/entities/service.rb +18 -3
  92. data/lib/3scale_toolbox/error.rb +53 -0
  93. data/lib/3scale_toolbox/helper.rb +20 -0
  94. data/lib/3scale_toolbox/openapi.rb +2 -0
  95. data/lib/3scale_toolbox/openapi/oas3.rb +232 -0
  96. data/lib/3scale_toolbox/openapi/swagger.rb +192 -0
  97. data/lib/3scale_toolbox/proxy_logger.rb +1 -1
  98. data/lib/3scale_toolbox/version.rb +1 -1
  99. data/licenses.xml +188 -18
  100. data/resources/oas3_meta_schema.json +1654 -0
  101. metadata +68 -28
  102. data/lib/3scale_toolbox/commands/copy_command/copy_service.rb +0 -144
  103. data/lib/3scale_toolbox/commands/import_command/openapi/threescale_api_spec.rb +0 -80
  104. data/lib/3scale_toolbox/swagger.rb +0 -1
  105. data/lib/3scale_toolbox/swagger/swagger.rb +0 -123
  106. data/lib/3scale_toolbox/tasks.rb +0 -15
  107. data/lib/3scale_toolbox/tasks/bump_proxy_version_task.rb +0 -32
  108. data/lib/3scale_toolbox/tasks/copy_activedocs_task.rb +0 -42
  109. data/lib/3scale_toolbox/tasks/copy_app_plans_task.rb +0 -31
  110. data/lib/3scale_toolbox/tasks/copy_limits_task.rb +0 -36
  111. data/lib/3scale_toolbox/tasks/copy_mapping_rules_task.rb +0 -32
  112. data/lib/3scale_toolbox/tasks/copy_methods_task.rb +0 -36
  113. data/lib/3scale_toolbox/tasks/copy_metrics_task.rb +0 -33
  114. data/lib/3scale_toolbox/tasks/copy_policies_task.rb +0 -13
  115. data/lib/3scale_toolbox/tasks/copy_pricingrules_task.rb +0 -41
  116. data/lib/3scale_toolbox/tasks/copy_service_proxy_task.rb +0 -12
  117. data/lib/3scale_toolbox/tasks/copy_service_settings_task.rb +0 -38
  118. data/lib/3scale_toolbox/tasks/copy_task.rb +0 -66
  119. data/lib/3scale_toolbox/tasks/delete_activedocs_task.rb +0 -22
  120. data/lib/3scale_toolbox/tasks/destroy_mapping_rules_task.rb +0 -22
  121. 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: f44badf850b3935e7e0fcce80095f7914860e1fa5b427647ba7a5dc25b1d57a8
4
- data.tar.gz: ba0ea206371d28c88e7ea4fc27edc074850e72bd8825d2ab98b2fdb6b32c83c0
3
+ metadata.gz: 2757cb4872a0b79aecc940e202197af6474d8d4057b2b576b1e094315a3c91c6
4
+ data.tar.gz: 84702d1a9d6430db62c85689ae4c18f2a1cab152ffd3dc2ea4ac8b8b6c22df39
5
5
  SHA512:
6
- metadata.gz: e50cf4c210e27b2ca2c0d38bb5a52ecfcf39bc440b1fc7a6974b68dc7ca06d976fe2375d41c2dae79f0c08fcd320c213936bef462673c87418cd54b2710c904e
7
- data.tar.gz: 1479ae95b5b42856aac547e5a495c1bb4a5c56c4065753e760a3c43405132900eb474e4b8c2d1f597b508f68a93abf3f013ddbf2db1ba3ac39c28426fb5fd2d7
6
+ metadata.gz: 6e19f6db5644ecdd2825aba35bc1113dbfb45a19ee66ed8caa3f1a1295febaf158a2d39b66d1755c8f4b2826e2334fe149f3711c7c75d6bdfd31544fee5f5d31
7
+ data.tar.gz: 838988ab2096976ec1bda3b94a0cea0e5bcefbca49ecf8cbe56a6fee0648a8e4ed2dba26819da3e061ceae9bdba8a1191899ead70b8fe0eb8cf73e9d29a2ef3a
@@ -31,12 +31,13 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.add_development_dependency 'bundler'
33
33
  spec.add_development_dependency 'dotenv'
34
- spec.add_development_dependency 'rake', '~> 10.0'
34
+ spec.add_development_dependency 'rake', '~> 13.0'
35
35
  spec.add_development_dependency 'rspec', '~> 3.8'
36
36
  spec.add_development_dependency 'webmock', '~> 3.4'
37
- spec.required_ruby_version = '>= 2.4'
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.1'
40
40
  spec.add_dependency 'cri', '~> 2.15'
41
41
  spec.add_dependency 'json-schema', '~> 2.8'
42
+ spec.add_dependency 'oas_parser', '~> 0.20'
42
43
  end
data/README.md CHANGED
@@ -1,17 +1,18 @@
1
1
  # 3scale toolbox
2
- [![Build Status](https://travis-ci.org/3scale/3scale_toolbox.svg?branch=master)](https://travis-ci.org/3scale/3scale_toolbox)
3
-
4
- This software is licensed under the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0).
5
-
6
- See the LICENSE and NOTICE files that should have been provided along with this software for details.
2
+ [![CircleCI](https://circleci.com/gh/3scale/3scale_toolbox.svg?style=svg)](https://circleci.com/gh/3scale/3scale_toolbox)
3
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)
4
+ [![GitHub release](https://img.shields.io/github/v/release/3scale/3scale_toolbox.svg)](https://github.com/3scale/3scale_toolbox/releases/latest)
7
5
 
8
6
  ## Description
9
7
  3scale toolbox is a set of tools to help you manage your 3scale product. Using the [3scale API Ruby Client](https://github.com/3scale/3scale-api-ruby).
10
8
 
11
9
  ## Table of contents
10
+ * [Requirements](#requirements)
12
11
  * [Installation](#installation)
13
12
  * [Usage](#usage)
14
- * [Copy a service](docs/copy-service.md)
13
+ * [Copy service](docs/copy-service.md)
14
+ * [Copy backend](docs/copy-backend.md)
15
+ * [Copy product](docs/copy-product.md)
15
16
  * [Import from CSV](docs/import-csv.md)
16
17
  * [Import from OpenAPI definition](docs/openapi.md)
17
18
  * [Export/Import Application Plan](docs/export-import-app-plan.md)
@@ -20,7 +21,7 @@ See the LICENSE and NOTICE files that should have been provided along with this
20
21
  * Create, Apply, List, Delete [Method](docs/method.md)
21
22
  * Create, Apply, List, Show, Delete [Service](docs/service.md)
22
23
  * Create, Apply, List, Delete [ActiveDocs](docs/activedocs.md)
23
- * List, Show, Promote [Proxy Configuration](docs/proxy-config.md)
24
+ * List, Show, Promote, Export [Proxy Configuration](docs/proxy-config.md)
24
25
  * [Copy Policy Registry](docs/copy-policy-registry.md)
25
26
  * Create, Apply, List, Show, Delete, Suspend, Resume [Applications](docs/applications.md)
26
27
  * [Remotes](docs/remotes.md)
@@ -29,13 +30,31 @@ See the LICENSE and NOTICE files that should have been provided along with this
29
30
  * [Develop your own core command](#develop-core-command)
30
31
  * [Licenses](#licenses)
31
32
  * [Plugins](#plugins)
33
+ * [Error Reporting](docs/errors.md)
32
34
  * [Troubleshooting](#troubleshooting)
33
35
  * [Contributing](#contributing)
34
36
 
37
+ ## Requirements
38
+ Supported Ruby interpreters
39
+
40
+ * MRI 2.5
41
+ * MRI 2.6
42
+
35
43
  ## Installation
36
44
  Install the toolbox:
37
45
 
38
- $ gem install 3scale_toolbox
46
+ ```
47
+ $ gem install 3scale_toolbox
48
+ ```
49
+
50
+ The [3scale toolbox packaging repo](https://github.com/3scale/3scale_toolbox_packaging)
51
+ provides packages and installation/deployment steps for the following platforms:
52
+ * CentOS/Fedora
53
+ * Ubuntu/Debian
54
+ * Mac OS X
55
+ * Windows
56
+ * Docker
57
+ * Kubernetes / Openshift
39
58
 
40
59
  ## Usage
41
60
 
@@ -55,16 +74,18 @@ COMMANDS
55
74
  activedocs activedocs super command
56
75
  application application super command
57
76
  application-plan application-plan super command
77
+ backend backend super command
58
78
  copy copy super command
59
79
  help show help
60
80
  import import super command
61
81
  method method super command
62
82
  metric metric super command
63
83
  policy-registry policy-registry super command
84
+ product product super command
64
85
  proxy-config proxy-config super command
65
86
  remote remotes super command
66
87
  service services super command
67
- update [DEPRECTATED] update super command
88
+ update [DEPRECATED] update super command
68
89
 
69
90
  OPTIONS
70
91
  -c --config-file=<value> 3scale toolbox configuration file (default:
@@ -178,7 +199,7 @@ $ 3scale service_list my-3scale-instance
178
199
 
179
200
  It is a requirement that we include a file describing all the licenses used in the product, so that users can examine it.
180
201
 
181
- Run `rake license_finder:check` to check licenses when dependencies change.
202
+ Run `rake license_finder:check` to check licenses when dependencies change.
182
203
 
183
204
  Run `rake license_finder:report > licenses.xml` to update licenses file.
184
205
 
@@ -6,20 +6,23 @@ require 'time'
6
6
  require 'csv'
7
7
  require 'net/http'
8
8
  require 'pathname'
9
+ require 'oas_parser'
9
10
  require '3scale/api'
11
+ require 'json-schema'
12
+ require 'erb'
10
13
 
11
14
  require '3scale_toolbox/version'
12
15
  require '3scale_toolbox/helper'
13
16
  require '3scale_toolbox/error'
14
17
  require '3scale_toolbox/proxy_logger'
15
18
  require '3scale_toolbox/resource_reader'
16
- require '3scale_toolbox/swagger'
17
19
  require '3scale_toolbox/configuration'
18
20
  require '3scale_toolbox/remotes'
19
21
  require '3scale_toolbox/3scale_client_factory'
20
22
  require '3scale_toolbox/entities'
21
- require '3scale_toolbox/tasks'
23
+ require '3scale_toolbox/attribute_filters'
22
24
  require '3scale_toolbox/base_command'
25
+ require '3scale_toolbox/openapi'
23
26
  require '3scale_toolbox/commands'
24
27
  require '3scale_toolbox/cli'
25
28
 
@@ -0,0 +1,2 @@
1
+ require '3scale_toolbox/attribute_filters/attribute_filter'
2
+ require '3scale_toolbox/attribute_filters/service_id_from_ref_filter'
@@ -0,0 +1,9 @@
1
+ module ThreeScaleToolbox
2
+ module AttributeFilters
3
+ module AttributeFilter
4
+ def filter(enumerable)
5
+ raise "Not implemented"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,30 @@
1
+ module ThreeScaleToolbox
2
+ module AttributeFilters
3
+ class ServiceIDFilterFromServiceRef
4
+ include AttributeFilter
5
+
6
+ attr_reader :remote, :service_ref, :service_id_key
7
+
8
+ def initialize(remote, service_ref, service_id_key)
9
+ @remote = remote
10
+ @service_ref = service_ref
11
+ @service_id_key = service_id_key
12
+ end
13
+
14
+ def filter(enumerable)
15
+ svc_id = find_service
16
+ enumerable.select { |e| e.key?(service_id_key) && e[service_id_key].to_s == svc_id.to_s }
17
+ end
18
+
19
+ private
20
+
21
+ def find_service
22
+ svc_id = -1
23
+ Entities::Service.find(remote: remote, ref: service_ref).tap do |svc|
24
+ svc_id = svc.id if !svc.nil?
25
+ end
26
+ svc_id
27
+ end
28
+ end
29
+ end
30
+ end
@@ -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
@@ -20,10 +20,9 @@ module ThreeScaleToolbox
20
20
 
21
21
  def handle_error(error)
22
22
  if expected_error?(error)
23
- warn
24
- warn "\e[1m\e[31mError: #{error.message}\e[0m"
23
+ warn error_serialize(error)
25
24
  else
26
- print_error(error)
25
+ print_unexpected_error(error)
27
26
  end
28
27
  end
29
28
 
@@ -36,21 +35,12 @@ module ThreeScaleToolbox
36
35
  end
37
36
  end
38
37
 
39
- def print_error(error)
40
- write_error(error, $stderr)
41
-
38
+ def print_unexpected_error(error)
42
39
  File.open('crash.log', 'w') do |io|
43
40
  write_verbose_error(error, io)
44
41
  end
45
42
 
46
- write_section_header($stderr, 'Detailed information')
47
- warn
48
- warn 'A detailed crash log has been written to ./crash.log.'
49
- end
50
-
51
- def write_error(error, stream)
52
- write_error_message(error, stream)
53
- write_stack_trace(error, stream)
43
+ warn error_serialize(UnexpectedError.new(error))
54
44
  end
55
45
 
56
46
  def write_error_message(error, stream)
@@ -113,6 +103,19 @@ module ThreeScaleToolbox
113
103
  stream.puts "===== #{title.upcase}:"
114
104
  stream.puts
115
105
  end
106
+
107
+ def error_serialize(error)
108
+ JSON.pretty_generate format_error(error)
109
+ end
110
+
111
+ def format_error(error)
112
+ {
113
+ code: error.code,
114
+ message: error.message,
115
+ class: error.kind,
116
+ stacktrace: error.stacktrace
117
+ }.compact
118
+ end
116
119
  end
117
120
  end
118
121
  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,34 +30,34 @@ 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
22
36
  option nil, :'hide', "Specify it to hide the ActiveDocs on the Developer Portal", argument: :forbidden
23
- option nil, :'skip-swagger-validations', "Specify it to skip validation of the Swagger specification", argument: :forbidden
37
+ option nil, :'skip-swagger-validations', "Skip validation of the Swagger specification. true or false", argument: :required, transform: ThreeScaleToolbox::Helper::BooleanTransformer.new
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