3scale_toolbox 0.14.0 → 0.15.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 +2 -1
- data/README.md +21 -3
- data/lib/3scale_toolbox.rb +5 -1
- 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/commands/activedocs_command/apply_command.rb +1 -1
- data/lib/3scale_toolbox/commands/activedocs_command/list_command.rb +18 -1
- data/lib/3scale_toolbox/commands/import_command/openapi.rb +26 -5
- 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 +7 -11
- 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/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/tasks/copy_service_proxy_task.rb +1 -0
- data/lib/3scale_toolbox/version.rb +1 -1
- data/licenses.xml +161 -1
- data/resources/oas3_meta_schema.json +1654 -0
- metadata +24 -6
- 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
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 3scale_toolbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michal Cichra
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-01-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -123,6 +123,20 @@ dependencies:
|
|
123
123
|
- - "~>"
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '2.8'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: oas_parser
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0.20'
|
133
|
+
type: :runtime
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0.20'
|
126
140
|
description: 3scale tools to manage your API from the terminal.
|
127
141
|
email:
|
128
142
|
- michal@3scale.net
|
@@ -139,6 +153,9 @@ files:
|
|
139
153
|
- exe/3scale
|
140
154
|
- lib/3scale_toolbox.rb
|
141
155
|
- lib/3scale_toolbox/3scale_client_factory.rb
|
156
|
+
- lib/3scale_toolbox/attribute_filters.rb
|
157
|
+
- lib/3scale_toolbox/attribute_filters/attribute_filter.rb
|
158
|
+
- lib/3scale_toolbox/attribute_filters/service_id_from_ref_filter.rb
|
142
159
|
- lib/3scale_toolbox/base_command.rb
|
143
160
|
- lib/3scale_toolbox/cli.rb
|
144
161
|
- lib/3scale_toolbox/cli/error_handler.rb
|
@@ -171,7 +188,6 @@ files:
|
|
171
188
|
- lib/3scale_toolbox/commands/import_command/openapi/method.rb
|
172
189
|
- lib/3scale_toolbox/commands/import_command/openapi/operation.rb
|
173
190
|
- lib/3scale_toolbox/commands/import_command/openapi/step.rb
|
174
|
-
- lib/3scale_toolbox/commands/import_command/openapi/threescale_api_spec.rb
|
175
191
|
- lib/3scale_toolbox/commands/import_command/openapi/update_policies_step.rb
|
176
192
|
- lib/3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step.rb
|
177
193
|
- lib/3scale_toolbox/commands/import_command/openapi/update_service_proxy_step.rb
|
@@ -239,11 +255,12 @@ files:
|
|
239
255
|
- lib/3scale_toolbox/entities/service.rb
|
240
256
|
- lib/3scale_toolbox/error.rb
|
241
257
|
- lib/3scale_toolbox/helper.rb
|
258
|
+
- lib/3scale_toolbox/openapi.rb
|
259
|
+
- lib/3scale_toolbox/openapi/oas3.rb
|
260
|
+
- lib/3scale_toolbox/openapi/swagger.rb
|
242
261
|
- lib/3scale_toolbox/proxy_logger.rb
|
243
262
|
- lib/3scale_toolbox/remotes.rb
|
244
263
|
- lib/3scale_toolbox/resource_reader.rb
|
245
|
-
- lib/3scale_toolbox/swagger.rb
|
246
|
-
- lib/3scale_toolbox/swagger/swagger.rb
|
247
264
|
- lib/3scale_toolbox/tasks.rb
|
248
265
|
- lib/3scale_toolbox/tasks/bump_proxy_version_task.rb
|
249
266
|
- lib/3scale_toolbox/tasks/copy_activedocs_task.rb
|
@@ -262,6 +279,7 @@ files:
|
|
262
279
|
- lib/3scale_toolbox/tasks/helper_task.rb
|
263
280
|
- lib/3scale_toolbox/version.rb
|
264
281
|
- licenses.xml
|
282
|
+
- resources/oas3_meta_schema.json
|
265
283
|
- resources/swagger_meta_schema.json
|
266
284
|
homepage: https://github.com/3scale/3scale_toolbox
|
267
285
|
licenses:
|
@@ -275,7 +293,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
275
293
|
requirements:
|
276
294
|
- - ">="
|
277
295
|
- !ruby/object:Gem::Version
|
278
|
-
version: '2.
|
296
|
+
version: '2.5'
|
279
297
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
280
298
|
requirements:
|
281
299
|
- - ">="
|
@@ -1,80 +0,0 @@
|
|
1
|
-
module ThreeScaleToolbox
|
2
|
-
module Commands
|
3
|
-
module ImportCommand
|
4
|
-
module OpenAPI
|
5
|
-
class ThreeScaleApiSpec
|
6
|
-
attr_reader :openapi
|
7
|
-
|
8
|
-
def initialize(openapi, base_path = nil)
|
9
|
-
@openapi = openapi
|
10
|
-
@base_path = base_path
|
11
|
-
end
|
12
|
-
|
13
|
-
def title
|
14
|
-
openapi.info.title
|
15
|
-
end
|
16
|
-
|
17
|
-
def description
|
18
|
-
openapi.info.description
|
19
|
-
end
|
20
|
-
|
21
|
-
def host
|
22
|
-
openapi.host
|
23
|
-
end
|
24
|
-
|
25
|
-
def schemes
|
26
|
-
Array(openapi.schemes)
|
27
|
-
end
|
28
|
-
|
29
|
-
def backend_version
|
30
|
-
# default authentication mode if no security requirement
|
31
|
-
return '1' if security.nil?
|
32
|
-
|
33
|
-
case security.type
|
34
|
-
when 'oauth2'
|
35
|
-
'oidc'
|
36
|
-
when 'apiKey'
|
37
|
-
'1'
|
38
|
-
else
|
39
|
-
raise ThreeScaleToolbox::Error, "Unexpected security scheme type #{security.type}"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def security
|
44
|
-
@security ||= parse_security
|
45
|
-
end
|
46
|
-
|
47
|
-
def operations
|
48
|
-
openapi.operations.map do |op|
|
49
|
-
Operation.new(
|
50
|
-
base_path: base_path,
|
51
|
-
public_base_path: public_base_path,
|
52
|
-
path: op.path,
|
53
|
-
verb: op.verb,
|
54
|
-
operationId: op.operation_id,
|
55
|
-
description: op.description,
|
56
|
-
)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def public_base_path
|
61
|
-
@base_path || base_path
|
62
|
-
end
|
63
|
-
|
64
|
-
def base_path
|
65
|
-
openapi.base_path || '/'
|
66
|
-
end
|
67
|
-
|
68
|
-
private
|
69
|
-
|
70
|
-
def parse_security
|
71
|
-
raise ThreeScaleToolbox::Error, 'Invalid OAS: multiple security requirements' \
|
72
|
-
if openapi.global_security_requirements.size > 1
|
73
|
-
|
74
|
-
openapi.global_security_requirements.first
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require '3scale_toolbox/swagger/swagger'
|
@@ -1,123 +0,0 @@
|
|
1
|
-
require 'json-schema'
|
2
|
-
|
3
|
-
module ThreeScaleToolbox
|
4
|
-
module Swagger
|
5
|
-
META_SCHEMA_PATH = File.expand_path('../../../resources/swagger_meta_schema.json', __dir__)
|
6
|
-
|
7
|
-
def self.build(raw_specification, validate: true)
|
8
|
-
if validate
|
9
|
-
meta_schema = JSON.parse(File.read(META_SCHEMA_PATH))
|
10
|
-
JSON::Validator.validate!(meta_schema, raw_specification)
|
11
|
-
end
|
12
|
-
|
13
|
-
Specification.new(raw_specification)
|
14
|
-
end
|
15
|
-
|
16
|
-
class Info
|
17
|
-
attr_reader :title, :description
|
18
|
-
|
19
|
-
def initialize(title:, description:)
|
20
|
-
@title = title
|
21
|
-
@description = description
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class Operation
|
26
|
-
attr_reader :verb, :operation_id, :path, :description
|
27
|
-
|
28
|
-
def initialize(verb:, operation_id:, path:, description:)
|
29
|
-
@verb = verb
|
30
|
-
@operation_id = operation_id
|
31
|
-
@path = path
|
32
|
-
@description = description
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
class SecurityRequirement
|
37
|
-
attr_reader :id, :type, :name, :in_f, :flow, :scopes
|
38
|
-
|
39
|
-
def initialize(id:, type:, name: nil, in_f: nil, flow: nil, scopes: [])
|
40
|
-
@id = id
|
41
|
-
@type = type
|
42
|
-
@name = name
|
43
|
-
@in_f = in_f
|
44
|
-
@flow = flow
|
45
|
-
@scopes = scopes
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
class Specification
|
50
|
-
attr_reader :raw
|
51
|
-
|
52
|
-
def initialize(raw_resource)
|
53
|
-
@raw = raw_resource
|
54
|
-
end
|
55
|
-
|
56
|
-
def base_path
|
57
|
-
raw['basePath']
|
58
|
-
end
|
59
|
-
|
60
|
-
def host
|
61
|
-
raw['host']
|
62
|
-
end
|
63
|
-
|
64
|
-
def schemes
|
65
|
-
raw['schemes']
|
66
|
-
end
|
67
|
-
|
68
|
-
def info
|
69
|
-
@info ||= parse_info(raw['info'])
|
70
|
-
end
|
71
|
-
|
72
|
-
def operations
|
73
|
-
@operations ||= parse_operations
|
74
|
-
end
|
75
|
-
|
76
|
-
def global_security_requirements
|
77
|
-
@global_security_requirements ||= parse_global_security_reqs
|
78
|
-
end
|
79
|
-
|
80
|
-
private
|
81
|
-
|
82
|
-
def parse_operations
|
83
|
-
raw['paths'].flat_map do |path, path_obj|
|
84
|
-
path_obj.flat_map do |method, operation|
|
85
|
-
next unless %w[get head post put patch delete trace options].include? method
|
86
|
-
|
87
|
-
Operation.new(verb: method, path: path, description: operation['description'],
|
88
|
-
operation_id: operation['operationId'])
|
89
|
-
end.compact
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def parse_info(info)
|
94
|
-
Info.new(title: info['title'], description: info['description'])
|
95
|
-
end
|
96
|
-
|
97
|
-
def parse_global_security_reqs
|
98
|
-
security_requirements.flat_map do |sec_req|
|
99
|
-
sec_req.map do |sec_item_name, sec_item|
|
100
|
-
sec_def = fetch_security_definition(sec_item_name)
|
101
|
-
SecurityRequirement.new(id: sec_item_name, type: sec_def['type'],
|
102
|
-
name: sec_def['name'], in_f: sec_def['in'],
|
103
|
-
flow: sec_def['flow'], scopes: sec_item)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def fetch_security_definition(name)
|
109
|
-
security_definitions.fetch(name) do |el|
|
110
|
-
raise ThreeScaleToolbox::Error, "Swagger parsing error: #{el} not found in security definitions"
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
def security_requirements
|
115
|
-
raw['security'] || []
|
116
|
-
end
|
117
|
-
|
118
|
-
def security_definitions
|
119
|
-
raw['securityDefinitions'] || {}
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|