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.
- checksums.yaml +4 -4
- data/3scale_toolbox.gemspec +2 -2
- data/README.md +15 -9
- data/lib/3scale_toolbox.rb +3 -1
- data/lib/3scale_toolbox/3scale_client_factory.rb +3 -4
- data/lib/3scale_toolbox/cli.rb +4 -0
- data/lib/3scale_toolbox/cli/custom_table_printer.rb +32 -0
- data/lib/3scale_toolbox/cli/error_handler.rb +17 -14
- data/lib/3scale_toolbox/cli/json_printer.rb +13 -0
- data/lib/3scale_toolbox/cli/output_flag.rb +20 -0
- data/lib/3scale_toolbox/cli/yaml_printer.rb +13 -0
- data/lib/3scale_toolbox/commands.rb +7 -1
- data/lib/3scale_toolbox/commands/activedocs_command/apply_command.rb +33 -10
- data/lib/3scale_toolbox/commands/activedocs_command/create_command.rb +22 -7
- data/lib/3scale_toolbox/commands/activedocs_command/list_command.rb +10 -17
- data/lib/3scale_toolbox/commands/application_command/apply_command.rb +27 -4
- data/lib/3scale_toolbox/commands/application_command/create_command.rb +16 -1
- data/lib/3scale_toolbox/commands/application_command/list_command.rb +10 -13
- data/lib/3scale_toolbox/commands/application_command/show_command.rb +8 -14
- data/lib/3scale_toolbox/commands/backend_command.rb +22 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command.rb +65 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_mapping_rules_task.rb +36 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb +35 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_metrics_task.rb +30 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb +46 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/task.rb +67 -0
- data/lib/3scale_toolbox/commands/copy_command.rb +2 -2
- data/lib/3scale_toolbox/commands/copy_command/service_command.rb +40 -0
- data/lib/3scale_toolbox/commands/import_command/issuer_type_transformer.rb +16 -0
- data/lib/3scale_toolbox/commands/import_command/openapi.rb +6 -2
- data/lib/3scale_toolbox/commands/import_command/openapi/create_mapping_rule_step.rb +2 -1
- data/lib/3scale_toolbox/commands/import_command/openapi/create_method_step.rb +5 -14
- data/lib/3scale_toolbox/commands/import_command/openapi/step.rb +4 -0
- data/lib/3scale_toolbox/commands/import_command/openapi/update_service_proxy_step.rb +1 -0
- data/lib/3scale_toolbox/commands/methods_command/apply_command.rb +28 -8
- data/lib/3scale_toolbox/commands/methods_command/create_command.rb +23 -3
- data/lib/3scale_toolbox/commands/methods_command/delete_command.rb +1 -1
- data/lib/3scale_toolbox/commands/methods_command/list_command.rb +7 -13
- data/lib/3scale_toolbox/commands/metrics_command/apply_command.rb +26 -4
- data/lib/3scale_toolbox/commands/metrics_command/create_command.rb +23 -1
- data/lib/3scale_toolbox/commands/metrics_command/list_command.rb +7 -12
- data/lib/3scale_toolbox/commands/plans_command/apply_command.rb +36 -7
- data/lib/3scale_toolbox/commands/plans_command/create_command.rb +23 -1
- data/lib/3scale_toolbox/commands/plans_command/export/read_plan_limits_step.rb +1 -1
- data/lib/3scale_toolbox/commands/plans_command/export/read_plan_methods_step.rb +2 -2
- data/lib/3scale_toolbox/commands/plans_command/export/read_plan_metrics_step.rb +2 -2
- data/lib/3scale_toolbox/commands/plans_command/export/read_plan_pricing_rules_step.rb +1 -2
- data/lib/3scale_toolbox/commands/plans_command/export/step.rb +8 -20
- data/lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb +12 -14
- data/lib/3scale_toolbox/commands/plans_command/import/import_plan_metrics_step.rb +6 -13
- data/lib/3scale_toolbox/commands/plans_command/import/import_plan_pricing_rules_step.rb +12 -20
- data/lib/3scale_toolbox/commands/plans_command/import/step.rb +2 -22
- data/lib/3scale_toolbox/commands/plans_command/list_command.rb +8 -13
- data/lib/3scale_toolbox/commands/plans_command/show_command.rb +7 -15
- data/lib/3scale_toolbox/commands/policies_command.rb +24 -0
- data/lib/3scale_toolbox/commands/policies_command/export_command.rb +98 -0
- data/lib/3scale_toolbox/commands/policies_command/import_command.rb +61 -0
- data/lib/3scale_toolbox/commands/product_command.rb +26 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command.rb +82 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command/copy_backends_task.rb +88 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command/delete_target_backend_usages_task.rb +48 -0
- data/lib/3scale_toolbox/commands/product_command/export_command.rb +81 -0
- data/lib/3scale_toolbox/commands/product_command/import_command.rb +125 -0
- data/lib/3scale_toolbox/commands/proxy_config_command.rb +5 -0
- data/lib/3scale_toolbox/commands/proxy_config_command/deploy_command.rb +54 -0
- data/lib/3scale_toolbox/commands/proxy_config_command/export_command.rb +74 -0
- data/lib/3scale_toolbox/commands/proxy_config_command/helper.rb +15 -0
- data/lib/3scale_toolbox/commands/proxy_config_command/list_command.rb +13 -29
- data/lib/3scale_toolbox/commands/proxy_config_command/show_command.rb +20 -23
- data/lib/3scale_toolbox/commands/service_command.rb +7 -5
- data/lib/3scale_toolbox/commands/service_command/apply_command.rb +69 -58
- data/lib/3scale_toolbox/commands/service_command/copy_command.rb +95 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/bump_proxy_version_task.rb +36 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_activedocs_task.rb +49 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_app_plans_task.rb +35 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_limits_task.rb +38 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb +35 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_methods_task.rb +37 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_metrics_task.rb +37 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_policies_task.rb +17 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_pricingrules_task.rb +41 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/copy_service_proxy_task.rb +32 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb +49 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/destroy_mapping_rules_task.rb +38 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/task.rb +85 -0
- data/lib/3scale_toolbox/commands/service_command/create_command.rb +58 -44
- data/lib/3scale_toolbox/commands/service_command/delete_command.rb +31 -33
- data/lib/3scale_toolbox/commands/service_command/list_command.rb +24 -34
- data/lib/3scale_toolbox/commands/service_command/show_command.rb +39 -44
- data/lib/3scale_toolbox/commands/update_command.rb +3 -3
- data/lib/3scale_toolbox/commands/update_command/{update_service.rb → service_command.rb} +22 -18
- data/lib/3scale_toolbox/commands/update_command/service_command/copy_service_settings_task.rb +35 -0
- data/lib/3scale_toolbox/commands/update_command/service_command/delete_activedocs_task.rb +24 -0
- data/lib/3scale_toolbox/crds.rb +16 -0
- data/lib/3scale_toolbox/crds/application_plan_dump.rb +19 -0
- data/lib/3scale_toolbox/crds/backend_dump.rb +39 -0
- data/lib/3scale_toolbox/crds/backend_mapping_rule_dump.rb +26 -0
- data/lib/3scale_toolbox/crds/backend_method_dump.rb +12 -0
- data/lib/3scale_toolbox/crds/backend_metric_dump.rb +13 -0
- data/lib/3scale_toolbox/crds/backend_parser.rb +55 -0
- data/lib/3scale_toolbox/crds/backend_usage_dump.rb +11 -0
- data/lib/3scale_toolbox/crds/limit_dump.rb +37 -0
- data/lib/3scale_toolbox/crds/mapping_rule_dump.rb +26 -0
- data/lib/3scale_toolbox/crds/method_dump.rb +12 -0
- data/lib/3scale_toolbox/crds/metric_dump.rb +13 -0
- data/lib/3scale_toolbox/crds/pricing_rule_dump.rb +38 -0
- data/lib/3scale_toolbox/crds/product_deployment_parser.rb +329 -0
- data/lib/3scale_toolbox/crds/product_dump.rb +157 -0
- data/lib/3scale_toolbox/crds/product_parser.rb +114 -0
- data/lib/3scale_toolbox/crds/remote.rb +682 -0
- data/lib/3scale_toolbox/entities.rb +8 -0
- data/lib/3scale_toolbox/entities/activedocs.rb +12 -0
- data/lib/3scale_toolbox/entities/application_plan.rb +74 -39
- data/lib/3scale_toolbox/entities/backend.rb +187 -0
- data/lib/3scale_toolbox/entities/backend_mapping_rule.rb +102 -0
- data/lib/3scale_toolbox/entities/backend_method.rb +99 -0
- data/lib/3scale_toolbox/entities/backend_metric.rb +98 -0
- data/lib/3scale_toolbox/entities/backend_usage.rb +105 -0
- data/lib/3scale_toolbox/entities/limit.rb +71 -0
- data/lib/3scale_toolbox/entities/mapping_rule.rb +90 -0
- data/lib/3scale_toolbox/entities/method.rb +33 -19
- data/lib/3scale_toolbox/entities/metric.rb +29 -18
- data/lib/3scale_toolbox/entities/pricing_rule.rb +63 -0
- data/lib/3scale_toolbox/entities/proxy_config.rb +0 -1
- data/lib/3scale_toolbox/entities/service.rb +166 -48
- data/lib/3scale_toolbox/error.rb +53 -0
- data/lib/3scale_toolbox/helper.rb +17 -0
- data/lib/3scale_toolbox/openapi/oas3.rb +1 -1
- data/lib/3scale_toolbox/proxy_logger.rb +5 -1
- data/lib/3scale_toolbox/remote_cache.rb +157 -0
- data/lib/3scale_toolbox/remotes.rb +2 -2
- data/lib/3scale_toolbox/version.rb +1 -1
- data/licenses.xml +113 -45
- metadata +75 -26
- data/lib/3scale_toolbox/commands/copy_command/copy_service.rb +0 -144
- data/lib/3scale_toolbox/tasks.rb +0 -15
- data/lib/3scale_toolbox/tasks/bump_proxy_version_task.rb +0 -32
- data/lib/3scale_toolbox/tasks/copy_activedocs_task.rb +0 -42
- data/lib/3scale_toolbox/tasks/copy_app_plans_task.rb +0 -31
- data/lib/3scale_toolbox/tasks/copy_limits_task.rb +0 -36
- data/lib/3scale_toolbox/tasks/copy_mapping_rules_task.rb +0 -32
- data/lib/3scale_toolbox/tasks/copy_methods_task.rb +0 -36
- data/lib/3scale_toolbox/tasks/copy_metrics_task.rb +0 -33
- data/lib/3scale_toolbox/tasks/copy_policies_task.rb +0 -13
- data/lib/3scale_toolbox/tasks/copy_pricingrules_task.rb +0 -41
- data/lib/3scale_toolbox/tasks/copy_service_proxy_task.rb +0 -13
- data/lib/3scale_toolbox/tasks/copy_service_settings_task.rb +0 -38
- data/lib/3scale_toolbox/tasks/copy_task.rb +0 -66
- data/lib/3scale_toolbox/tasks/delete_activedocs_task.rb +0 -22
- data/lib/3scale_toolbox/tasks/destroy_mapping_rules_task.rb +0 -22
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 601ddede06d5a842020be721015fbc05a8d9c8409a42794961d6c888e60b62ed
|
4
|
+
data.tar.gz: fa8c908ff50157b7e438d0a5ad185034e74af219b2b79dd3a1037c120d99111f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e11b9ad812a4b1fec7e9cbfc85ef7b39ce4ca688b06bfd95c8f927624661b23828ce4650d95b082e2314ecf8fdc8c9eb8b76af2ab88f536515f1154255f77e19
|
7
|
+
data.tar.gz: bb33acecf3213159343cbf9aba66d8c41e0d5c45842c3d80a3610af1b9cf92c3c7f16d3062372f58dcdaa313e6dcc0bc7dd197c9f53687a59b5734ada9152f77
|
data/3scale_toolbox.gemspec
CHANGED
@@ -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', '~>
|
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', '~>
|
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
|
-
|
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
|
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 [
|
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
|
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
|
```
|
data/lib/3scale_toolbox.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/3scale_toolbox/cli.rb
CHANGED
@@ -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
|
-
|
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
|
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
|
-
|
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,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
|
@@ -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
|
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
|
-
|
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
|
31
|
-
|
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
|