3scale_toolbox 0.15.0 → 0.18.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/3scale_toolbox.gemspec +2 -2
  3. data/README.md +15 -9
  4. data/lib/3scale_toolbox.rb +3 -1
  5. data/lib/3scale_toolbox/3scale_client_factory.rb +3 -4
  6. data/lib/3scale_toolbox/cli.rb +4 -0
  7. data/lib/3scale_toolbox/cli/custom_table_printer.rb +32 -0
  8. data/lib/3scale_toolbox/cli/error_handler.rb +17 -14
  9. data/lib/3scale_toolbox/cli/json_printer.rb +13 -0
  10. data/lib/3scale_toolbox/cli/output_flag.rb +20 -0
  11. data/lib/3scale_toolbox/cli/yaml_printer.rb +13 -0
  12. data/lib/3scale_toolbox/commands.rb +7 -1
  13. data/lib/3scale_toolbox/commands/activedocs_command/apply_command.rb +33 -10
  14. data/lib/3scale_toolbox/commands/activedocs_command/create_command.rb +22 -7
  15. data/lib/3scale_toolbox/commands/activedocs_command/list_command.rb +10 -17
  16. data/lib/3scale_toolbox/commands/application_command/apply_command.rb +27 -4
  17. data/lib/3scale_toolbox/commands/application_command/create_command.rb +16 -1
  18. data/lib/3scale_toolbox/commands/application_command/list_command.rb +10 -13
  19. data/lib/3scale_toolbox/commands/application_command/show_command.rb +8 -14
  20. data/lib/3scale_toolbox/commands/backend_command.rb +22 -0
  21. data/lib/3scale_toolbox/commands/backend_command/copy_command.rb +65 -0
  22. data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_mapping_rules_task.rb +36 -0
  23. data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb +35 -0
  24. data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_metrics_task.rb +30 -0
  25. data/lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb +46 -0
  26. data/lib/3scale_toolbox/commands/backend_command/copy_command/task.rb +67 -0
  27. data/lib/3scale_toolbox/commands/copy_command.rb +2 -2
  28. data/lib/3scale_toolbox/commands/copy_command/service_command.rb +40 -0
  29. data/lib/3scale_toolbox/commands/import_command/issuer_type_transformer.rb +16 -0
  30. data/lib/3scale_toolbox/commands/import_command/openapi.rb +6 -2
  31. data/lib/3scale_toolbox/commands/import_command/openapi/create_mapping_rule_step.rb +2 -1
  32. data/lib/3scale_toolbox/commands/import_command/openapi/create_method_step.rb +5 -14
  33. data/lib/3scale_toolbox/commands/import_command/openapi/step.rb +4 -0
  34. data/lib/3scale_toolbox/commands/import_command/openapi/update_service_proxy_step.rb +1 -0
  35. data/lib/3scale_toolbox/commands/methods_command/apply_command.rb +28 -8
  36. data/lib/3scale_toolbox/commands/methods_command/create_command.rb +23 -3
  37. data/lib/3scale_toolbox/commands/methods_command/delete_command.rb +1 -1
  38. data/lib/3scale_toolbox/commands/methods_command/list_command.rb +7 -13
  39. data/lib/3scale_toolbox/commands/metrics_command/apply_command.rb +26 -4
  40. data/lib/3scale_toolbox/commands/metrics_command/create_command.rb +23 -1
  41. data/lib/3scale_toolbox/commands/metrics_command/list_command.rb +7 -12
  42. data/lib/3scale_toolbox/commands/plans_command/apply_command.rb +36 -7
  43. data/lib/3scale_toolbox/commands/plans_command/create_command.rb +23 -1
  44. data/lib/3scale_toolbox/commands/plans_command/export/read_plan_limits_step.rb +1 -1
  45. data/lib/3scale_toolbox/commands/plans_command/export/read_plan_methods_step.rb +2 -2
  46. data/lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb +2 -2
  47. data/lib/3scale_toolbox/commands/plans_command/export/read_plan_pricing_rules_step.rb +1 -2
  48. data/lib/3scale_toolbox/commands/plans_command/export/step.rb +8 -20
  49. data/lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb +12 -14
  50. data/lib/3scale_toolbox/commands/plans_command/import/import_plan_metrics_step.rb +6 -13
  51. data/lib/3scale_toolbox/commands/plans_command/import/import_plan_pricing_rules_step.rb +12 -20
  52. data/lib/3scale_toolbox/commands/plans_command/import/step.rb +2 -22
  53. data/lib/3scale_toolbox/commands/plans_command/list_command.rb +8 -13
  54. data/lib/3scale_toolbox/commands/plans_command/show_command.rb +7 -15
  55. data/lib/3scale_toolbox/commands/policies_command.rb +24 -0
  56. data/lib/3scale_toolbox/commands/policies_command/export_command.rb +98 -0
  57. data/lib/3scale_toolbox/commands/policies_command/import_command.rb +61 -0
  58. data/lib/3scale_toolbox/commands/product_command.rb +26 -0
  59. data/lib/3scale_toolbox/commands/product_command/copy_command.rb +82 -0
  60. data/lib/3scale_toolbox/commands/product_command/copy_command/copy_backends_task.rb +88 -0
  61. data/lib/3scale_toolbox/commands/product_command/copy_command/delete_target_backend_usages_task.rb +48 -0
  62. data/lib/3scale_toolbox/commands/product_command/export_command.rb +81 -0
  63. data/lib/3scale_toolbox/commands/product_command/import_command.rb +125 -0
  64. data/lib/3scale_toolbox/commands/proxy_config_command.rb +5 -0
  65. data/lib/3scale_toolbox/commands/proxy_config_command/deploy_command.rb +54 -0
  66. data/lib/3scale_toolbox/commands/proxy_config_command/export_command.rb +74 -0
  67. data/lib/3scale_toolbox/commands/proxy_config_command/helper.rb +15 -0
  68. data/lib/3scale_toolbox/commands/proxy_config_command/list_command.rb +13 -29
  69. data/lib/3scale_toolbox/commands/proxy_config_command/show_command.rb +20 -23
  70. data/lib/3scale_toolbox/commands/service_command.rb +7 -5
  71. data/lib/3scale_toolbox/commands/service_command/apply_command.rb +69 -58
  72. data/lib/3scale_toolbox/commands/service_command/copy_command.rb +95 -0
  73. data/lib/3scale_toolbox/commands/service_command/copy_command/bump_proxy_version_task.rb +36 -0
  74. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_activedocs_task.rb +49 -0
  75. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb +35 -0
  76. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb +38 -0
  77. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb +35 -0
  78. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_methods_task.rb +37 -0
  79. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_metrics_task.rb +37 -0
  80. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_policies_task.rb +17 -0
  81. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_pricingrules_task.rb +41 -0
  82. data/lib/3scale_toolbox/commands/service_command/copy_command/copy_service_proxy_task.rb +32 -0
  83. data/lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb +49 -0
  84. data/lib/3scale_toolbox/commands/service_command/copy_command/destroy_mapping_rules_task.rb +38 -0
  85. data/lib/3scale_toolbox/commands/service_command/copy_command/task.rb +85 -0
  86. data/lib/3scale_toolbox/commands/service_command/create_command.rb +58 -44
  87. data/lib/3scale_toolbox/commands/service_command/delete_command.rb +31 -33
  88. data/lib/3scale_toolbox/commands/service_command/list_command.rb +24 -34
  89. data/lib/3scale_toolbox/commands/service_command/show_command.rb +39 -44
  90. data/lib/3scale_toolbox/commands/update_command.rb +3 -3
  91. data/lib/3scale_toolbox/commands/update_command/{update_service.rb → service_command.rb} +22 -18
  92. data/lib/3scale_toolbox/commands/update_command/service_command/copy_service_settings_task.rb +35 -0
  93. data/lib/3scale_toolbox/commands/update_command/service_command/delete_activedocs_task.rb +24 -0
  94. data/lib/3scale_toolbox/crds.rb +16 -0
  95. data/lib/3scale_toolbox/crds/application_plan_dump.rb +19 -0
  96. data/lib/3scale_toolbox/crds/backend_dump.rb +39 -0
  97. data/lib/3scale_toolbox/crds/backend_mapping_rule_dump.rb +26 -0
  98. data/lib/3scale_toolbox/crds/backend_method_dump.rb +12 -0
  99. data/lib/3scale_toolbox/crds/backend_metric_dump.rb +13 -0
  100. data/lib/3scale_toolbox/crds/backend_parser.rb +55 -0
  101. data/lib/3scale_toolbox/crds/backend_usage_dump.rb +11 -0
  102. data/lib/3scale_toolbox/crds/limit_dump.rb +37 -0
  103. data/lib/3scale_toolbox/crds/mapping_rule_dump.rb +26 -0
  104. data/lib/3scale_toolbox/crds/method_dump.rb +12 -0
  105. data/lib/3scale_toolbox/crds/metric_dump.rb +13 -0
  106. data/lib/3scale_toolbox/crds/pricing_rule_dump.rb +38 -0
  107. data/lib/3scale_toolbox/crds/product_deployment_parser.rb +329 -0
  108. data/lib/3scale_toolbox/crds/product_dump.rb +157 -0
  109. data/lib/3scale_toolbox/crds/product_parser.rb +114 -0
  110. data/lib/3scale_toolbox/crds/remote.rb +682 -0
  111. data/lib/3scale_toolbox/entities.rb +8 -0
  112. data/lib/3scale_toolbox/entities/activedocs.rb +12 -0
  113. data/lib/3scale_toolbox/entities/application_plan.rb +74 -39
  114. data/lib/3scale_toolbox/entities/backend.rb +187 -0
  115. data/lib/3scale_toolbox/entities/backend_mapping_rule.rb +102 -0
  116. data/lib/3scale_toolbox/entities/backend_method.rb +99 -0
  117. data/lib/3scale_toolbox/entities/backend_metric.rb +98 -0
  118. data/lib/3scale_toolbox/entities/backend_usage.rb +105 -0
  119. data/lib/3scale_toolbox/entities/limit.rb +71 -0
  120. data/lib/3scale_toolbox/entities/mapping_rule.rb +90 -0
  121. data/lib/3scale_toolbox/entities/method.rb +33 -19
  122. data/lib/3scale_toolbox/entities/metric.rb +29 -18
  123. data/lib/3scale_toolbox/entities/pricing_rule.rb +63 -0
  124. data/lib/3scale_toolbox/entities/proxy_config.rb +0 -1
  125. data/lib/3scale_toolbox/entities/service.rb +166 -48
  126. data/lib/3scale_toolbox/error.rb +53 -0
  127. data/lib/3scale_toolbox/helper.rb +17 -0
  128. data/lib/3scale_toolbox/openapi/oas3.rb +1 -1
  129. data/lib/3scale_toolbox/proxy_logger.rb +5 -1
  130. data/lib/3scale_toolbox/remote_cache.rb +157 -0
  131. data/lib/3scale_toolbox/remotes.rb +2 -2
  132. data/lib/3scale_toolbox/version.rb +1 -1
  133. data/licenses.xml +113 -45
  134. metadata +75 -26
  135. data/lib/3scale_toolbox/commands/copy_command/copy_service.rb +0 -144
  136. data/lib/3scale_toolbox/tasks.rb +0 -15
  137. data/lib/3scale_toolbox/tasks/bump_proxy_version_task.rb +0 -32
  138. data/lib/3scale_toolbox/tasks/copy_activedocs_task.rb +0 -42
  139. data/lib/3scale_toolbox/tasks/copy_app_plans_task.rb +0 -31
  140. data/lib/3scale_toolbox/tasks/copy_limits_task.rb +0 -36
  141. data/lib/3scale_toolbox/tasks/copy_mapping_rules_task.rb +0 -32
  142. data/lib/3scale_toolbox/tasks/copy_methods_task.rb +0 -36
  143. data/lib/3scale_toolbox/tasks/copy_metrics_task.rb +0 -33
  144. data/lib/3scale_toolbox/tasks/copy_policies_task.rb +0 -13
  145. data/lib/3scale_toolbox/tasks/copy_pricingrules_task.rb +0 -41
  146. data/lib/3scale_toolbox/tasks/copy_service_proxy_task.rb +0 -13
  147. data/lib/3scale_toolbox/tasks/copy_service_settings_task.rb +0 -38
  148. data/lib/3scale_toolbox/tasks/copy_task.rb +0 -66
  149. data/lib/3scale_toolbox/tasks/delete_activedocs_task.rb +0 -22
  150. data/lib/3scale_toolbox/tasks/destroy_mapping_rules_task.rb +0 -22
  151. 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: 601ddede06d5a842020be721015fbc05a8d9c8409a42794961d6c888e60b62ed
4
+ data.tar.gz: fa8c908ff50157b7e438d0a5ad185034e74af219b2b79dd3a1037c120d99111f
5
5
  SHA512:
6
- metadata.gz: f2bf8c3a1f5860a3c6d24fa5fbc976b9b3361ea8ef6a57bbc0707d5f3900a31d8022e9596080bf8129d47116d13d3ab4d2ae7bfc41e246d179adf0f757c7c598
7
- data.tar.gz: 3a206838d82a662f56276e7d98291cf74f5bc69eb9f39de239bb3d15f457e62b81e336ee1d0438a508fdecc46f692b49610627ef6413d05788b4c9f1a8c3f2e5
6
+ metadata.gz: e11b9ad812a4b1fec7e9cbfc85ef7b39ce4ca688b06bfd95c8f927624661b23828ce4650d95b082e2314ecf8fdc8c9eb8b76af2ab88f536515f1154255f77e19
7
+ data.tar.gz: bb33acecf3213159343cbf9aba66d8c41e0d5c45842c3d80a3610af1b9cf92c3c7f16d3062372f58dcdaa313e6dcc0bc7dd197c9f53687a59b5734ada9152f77
@@ -31,12 +31,12 @@ 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
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.4'
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
@@ -1,9 +1,7 @@
1
1
  # 3scale toolbox
2
2
  [![CircleCI](https://circleci.com/gh/3scale/3scale_toolbox.svg?style=svg)](https://circleci.com/gh/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.
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).
@@ -12,7 +10,10 @@ See the LICENSE and NOTICE files that should have been provided along with this
12
10
  * [Requirements](#requirements)
13
11
  * [Installation](#installation)
14
12
  * [Usage](#usage)
15
- * [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)
16
+ * [Export/Import product](docs/export-import-product.md)
16
17
  * [Import from CSV](docs/import-csv.md)
17
18
  * [Import from OpenAPI definition](docs/openapi.md)
18
19
  * [Export/Import Application Plan](docs/export-import-app-plan.md)
@@ -21,15 +22,17 @@ See the LICENSE and NOTICE files that should have been provided along with this
21
22
  * Create, Apply, List, Delete [Method](docs/method.md)
22
23
  * Create, Apply, List, Show, Delete [Service](docs/service.md)
23
24
  * Create, Apply, List, Delete [ActiveDocs](docs/activedocs.md)
24
- * List, Show, Promote [Proxy Configuration](docs/proxy-config.md)
25
+ * List, Show, Promote, Export, Deploy [Proxy Configuration](docs/proxy-config.md)
25
26
  * [Copy Policy Registry](docs/copy-policy-registry.md)
26
27
  * Create, Apply, List, Show, Delete, Suspend, Resume [Applications](docs/applications.md)
28
+ * [Export/Import Product Policy Chain](docs/export-import-policy-chain.md)
27
29
  * [Remotes](docs/remotes.md)
28
30
  * [Development](#development)
29
31
  * [Testing](#testing)
30
32
  * [Develop your own core command](#develop-core-command)
31
33
  * [Licenses](#licenses)
32
34
  * [Plugins](#plugins)
35
+ * [Error Reporting](docs/errors.md)
33
36
  * [Troubleshooting](#troubleshooting)
34
37
  * [Contributing](#contributing)
35
38
 
@@ -38,6 +41,7 @@ Supported Ruby interpreters
38
41
 
39
42
  * MRI 2.5
40
43
  * MRI 2.6
44
+ * MRI 2.7
41
45
 
42
46
  ## Installation
43
47
  Install the toolbox:
@@ -73,16 +77,18 @@ COMMANDS
73
77
  activedocs activedocs super command
74
78
  application application super command
75
79
  application-plan application-plan super command
80
+ backend backend super command
76
81
  copy copy super command
77
82
  help show help
78
83
  import import super command
79
84
  method method super command
80
85
  metric metric super command
81
86
  policy-registry policy-registry super command
87
+ product product super command
82
88
  proxy-config proxy-config super command
83
89
  remote remotes super command
84
90
  service services super command
85
- update [DEPRECTATED] update super command
91
+ update [DEPRECATED] update super command
86
92
 
87
93
  OPTIONS
88
94
  -c --config-file=<value> 3scale toolbox configuration file (default:
@@ -117,7 +123,7 @@ rake spec:integration
117
123
 
118
124
  Integration tests can be run locally or against a real 3scale account.
119
125
  When details of the account are set via environment variables,
120
- integration tests are run agains given account.
126
+ integration tests are run against the given account.
121
127
  Otherwise, tests are run locally with mocked 3scale clients.
122
128
 
123
129
  The easiest way to set everything up is it to have a `.env` file in the root of the project with the following environment variables (set your own values):
@@ -160,7 +166,7 @@ end
160
166
  A few things worth highlighting:
161
167
  - Your module must include the *ThreeScaleToolbox::Command* module. It allows your command to be added to the toobox command tree.
162
168
  - You must implement the `command` module function and return an instance of `Cri::Command` from [cri](https://github.com/ddfreyne/cri)
163
- - `threescale_client` helper method returns *3scale API* client instance. All the process remote parsing, fetching from remote list and client instantiation is done out of the box.
169
+ - `threescale_client` helper method returns *3scale API* client instance. All the process remote parsing, fetching from the remote list and client instantiation is done out of the box.
164
170
 
165
171
  Then register the core command in `lib/3scale_toolbox/commands.rb`
166
172
  ```
@@ -10,17 +10,19 @@ require 'oas_parser'
10
10
  require '3scale/api'
11
11
  require 'json-schema'
12
12
  require 'erb'
13
+ require 'logger'
13
14
 
14
15
  require '3scale_toolbox/version'
15
16
  require '3scale_toolbox/helper'
16
17
  require '3scale_toolbox/error'
18
+ require '3scale_toolbox/remote_cache'
17
19
  require '3scale_toolbox/proxy_logger'
18
20
  require '3scale_toolbox/resource_reader'
19
21
  require '3scale_toolbox/configuration'
20
22
  require '3scale_toolbox/remotes'
21
23
  require '3scale_toolbox/3scale_client_factory'
24
+ require '3scale_toolbox/crds'
22
25
  require '3scale_toolbox/entities'
23
- require '3scale_toolbox/tasks'
24
26
  require '3scale_toolbox/attribute_filters'
25
27
  require '3scale_toolbox/base_command'
26
28
  require '3scale_toolbox/openapi'
@@ -22,10 +22,9 @@ module ThreeScaleToolbox
22
22
  remote = remotes.fetch(remote_str)
23
23
  end
24
24
 
25
- client = remote_client(remote.merge(verify_ssl: verify_ssl))
26
- return ProxyLogger.new(client) if verbose
27
-
28
- client
25
+ client = remote_client(**remote.merge(verify_ssl: verify_ssl))
26
+ client = ProxyLogger.new(client) if verbose
27
+ RemoteCache.new(client)
29
28
  end
30
29
 
31
30
  private
@@ -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,15 @@ 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'
18
+ require '3scale_toolbox/commands/policies_command'
16
19
 
17
20
  module ThreeScaleToolbox
18
21
  module Commands
@@ -31,6 +34,9 @@ module ThreeScaleToolbox
31
34
  ThreeScaleToolbox::Commands::ProxyConfigCommand,
32
35
  ThreeScaleToolbox::Commands::PolicyRegistryCommand,
33
36
  ThreeScaleToolbox::Commands::ApplicationCommand,
37
+ ThreeScaleToolbox::Commands::BackendCommand,
38
+ ThreeScaleToolbox::Commands::ProductCommand,
39
+ ThreeScaleToolbox::Commands::PoliciesCommand,
34
40
  ].freeze
35
41
  end
36
42
  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