3scale_toolbox 0.12.4 → 0.17.0
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 +4 -3
- data/README.md +31 -10
- data/lib/3scale_toolbox.rb +5 -2
- data/lib/3scale_toolbox/attribute_filters.rb +2 -0
- data/lib/3scale_toolbox/attribute_filters/attribute_filter.rb +9 -0
- data/lib/3scale_toolbox/attribute_filters/service_id_from_ref_filter.rb +30 -0
- 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 +5 -1
- data/lib/3scale_toolbox/commands/activedocs_command/apply_command.rb +34 -11
- data/lib/3scale_toolbox/commands/activedocs_command/create_command.rb +22 -7
- data/lib/3scale_toolbox/commands/activedocs_command/list_command.rb +21 -11
- 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 +52 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb +40 -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 +45 -0
- data/lib/3scale_toolbox/commands/backend_command/copy_command/task.rb +89 -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/openapi.rb +29 -7
- data/lib/3scale_toolbox/commands/import_command/openapi/create_activedocs_step.rb +4 -17
- data/lib/3scale_toolbox/commands/import_command/openapi/create_service_step.rb +1 -5
- data/lib/3scale_toolbox/commands/import_command/openapi/mapping_rule.rb +3 -2
- data/lib/3scale_toolbox/commands/import_command/openapi/step.rb +43 -5
- data/lib/3scale_toolbox/commands/import_command/openapi/update_policies_step.rb +9 -10
- data/lib/3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step.rb +2 -17
- data/lib/3scale_toolbox/commands/import_command/openapi/update_service_proxy_step.rb +10 -10
- data/lib/3scale_toolbox/commands/methods_command/apply_command.rb +26 -4
- data/lib/3scale_toolbox/commands/methods_command/create_command.rb +23 -1
- data/lib/3scale_toolbox/commands/methods_command/list_command.rb +11 -9
- 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/import/import_plan_limits_step.rb +11 -12
- data/lib/3scale_toolbox/commands/plans_command/import/import_plan_pricing_rules_step.rb +11 -12
- data/lib/3scale_toolbox/commands/plans_command/list_command.rb +8 -13
- data/lib/3scale_toolbox/commands/plans_command/show_command.rb +6 -14
- data/lib/3scale_toolbox/commands/product_command.rb +22 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command.rb +78 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command/copy_backends_task.rb +71 -0
- data/lib/3scale_toolbox/commands/product_command/copy_command/delete_target_backend_usages_task.rb +48 -0
- data/lib/3scale_toolbox/commands/proxy_config_command.rb +3 -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 +46 -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 +39 -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 +40 -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 +44 -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 +48 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/destroy_mapping_rules_task.rb +34 -0
- data/lib/3scale_toolbox/commands/service_command/copy_command/task.rb +99 -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 +26 -0
- data/lib/3scale_toolbox/entities.rb +5 -0
- data/lib/3scale_toolbox/entities/application_plan.rb +31 -4
- data/lib/3scale_toolbox/entities/backend.rb +152 -0
- data/lib/3scale_toolbox/entities/backend_mapping_rule.rb +76 -0
- data/lib/3scale_toolbox/entities/backend_method.rb +90 -0
- data/lib/3scale_toolbox/entities/backend_metric.rb +88 -0
- data/lib/3scale_toolbox/entities/backend_usage.rb +99 -0
- data/lib/3scale_toolbox/entities/service.rb +18 -3
- data/lib/3scale_toolbox/error.rb +53 -0
- data/lib/3scale_toolbox/helper.rb +20 -0
- data/lib/3scale_toolbox/openapi.rb +2 -0
- data/lib/3scale_toolbox/openapi/oas3.rb +232 -0
- data/lib/3scale_toolbox/openapi/swagger.rb +192 -0
- data/lib/3scale_toolbox/proxy_logger.rb +1 -1
- data/lib/3scale_toolbox/version.rb +1 -1
- data/licenses.xml +190 -20
- data/resources/oas3_meta_schema.json +1654 -0
- metadata +69 -30
- data/lib/3scale_toolbox/commands/copy_command/copy_service.rb +0 -142
- data/lib/3scale_toolbox/commands/import_command/openapi/threescale_api_spec.rb +0 -80
- data/lib/3scale_toolbox/swagger.rb +0 -1
- data/lib/3scale_toolbox/swagger/swagger.rb +0 -123
- 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 -12
- 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: 5065a7adfb9986662d24bb6b27a74d710400af999968086f52188477cc1670f3
|
4
|
+
data.tar.gz: d8ce25654cdae1d44e02900507c9b69b649fccbce69be0b234861ffd8611aa16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc9c2335031b36bd08fa916c4aa0bef4c65228c8bc6ff91fdb9769ee737541d23473738c51c627b5c2e8ec91a837a00a5570030fdd8aa767b1e61798669a63f9
|
7
|
+
data.tar.gz: 0a9733d12ea3a912e50cd47c1083d960b8b4e0065976e5ef9ed0fb572ee2ce25570d0dd52725cd34d3324d683f8ec67f36c6f838e6c30a864720df4bb62b7824
|
data/3scale_toolbox.gemspec
CHANGED
@@ -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', '~>
|
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.
|
37
|
+
spec.required_ruby_version = '>= 2.5'
|
38
38
|
|
39
|
-
spec.add_dependency '3scale-api', '~>
|
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
|
-
[![
|
3
|
-
|
4
|
-
|
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
|
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
|
-
|
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 [
|
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
|
|
data/lib/3scale_toolbox.rb
CHANGED
@@ -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/
|
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,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
|
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,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', "
|
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
|
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
|