krakend-openapi-importer 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +14 -2
- data/Gemfile.lock +9 -16
- data/README.md +1 -3
- data/Rakefile +7 -3
- data/exe/krakend-openapi-importer +0 -1
- data/lib/commands/import.rb +4 -5
- data/lib/importer/version.rb +1 -1
- data/lib/importer.rb +2 -4
- data/lib/readers/file_reader.rb +19 -0
- data/lib/readers/json_reader.rb +4 -1
- data/lib/readers/oa3_reader.rb +1 -1
- data/lib/readers/yaml_reader.rb +2 -1
- data/lib/transformers/oa3_transformer.rb +19 -14
- data/lib/transformers/plugins/auth_validator_transformer.rb +25 -0
- data/lib/writers/krakend_writer.rb +15 -7
- metadata +4 -4
- data/.rspec +0 -3
- data/lib/transformers/jwt_validator_transformer.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8982d7b1d96d3d3a4f1213075474be32a5d7a4d95c7671bd9bdd266090027bd3
|
4
|
+
data.tar.gz: c8006aa961b9df1cf3fb5ea9f2a7b1f47874f4757592517bfc6777a48f91f9fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b379be6f47cb870610a66b4471aab2cc9a6cce059724099f2f78c49a509d60cf312bd06d8d123e65196ec6ce4965c5e6d5f2a83d9c5ec50d630920def216d67
|
7
|
+
data.tar.gz: 1581b80a865b139636892bab36ee36353af888e15d5b66259fb92f6c74fb20917928540a200f75d42a844dedfe56052285548aea2d83142b78c3c2c01cf691c0
|
data/Gemfile
CHANGED
@@ -6,5 +6,17 @@ source 'https://rubygems.org'
|
|
6
6
|
gemspec
|
7
7
|
|
8
8
|
gem 'rake', '~> 13.0'
|
9
|
-
|
10
|
-
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem 'fakefs', '~> 2.0'
|
12
|
+
gem 'minitest', '~> 5.13'
|
13
|
+
end
|
14
|
+
|
15
|
+
group :development do
|
16
|
+
gem 'bump', '~> 0.10.0'
|
17
|
+
gem 'rubocop', require: false
|
18
|
+
end
|
19
|
+
|
20
|
+
group :test, :development do
|
21
|
+
gem 'awesome_print'
|
22
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
krakend-openapi-importer (0.
|
4
|
+
krakend-openapi-importer (0.4.0)
|
5
5
|
thor (~> 1.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
ast (2.4.2)
|
11
|
-
|
11
|
+
awesome_print (1.9.2)
|
12
|
+
bump (0.10.0)
|
13
|
+
fakefs (2.0.0)
|
12
14
|
json (2.6.2)
|
15
|
+
minitest (5.13.0)
|
13
16
|
parallel (1.22.1)
|
14
17
|
parser (3.1.2.1)
|
15
18
|
ast (~> 2.4.1)
|
@@ -17,19 +20,6 @@ GEM
|
|
17
20
|
rake (13.0.6)
|
18
21
|
regexp_parser (2.6.1)
|
19
22
|
rexml (3.2.5)
|
20
|
-
rspec (3.10.0)
|
21
|
-
rspec-core (~> 3.10.0)
|
22
|
-
rspec-expectations (~> 3.10.0)
|
23
|
-
rspec-mocks (~> 3.10.0)
|
24
|
-
rspec-core (3.10.1)
|
25
|
-
rspec-support (~> 3.10.0)
|
26
|
-
rspec-expectations (3.10.1)
|
27
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.10.0)
|
29
|
-
rspec-mocks (3.10.2)
|
30
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
-
rspec-support (~> 3.10.0)
|
32
|
-
rspec-support (3.10.2)
|
33
23
|
rubocop (1.39.0)
|
34
24
|
json (~> 2.3)
|
35
25
|
parallel (~> 1.10)
|
@@ -52,9 +42,12 @@ PLATFORMS
|
|
52
42
|
x86_64-darwin-21
|
53
43
|
|
54
44
|
DEPENDENCIES
|
45
|
+
awesome_print
|
46
|
+
bump (~> 0.10.0)
|
47
|
+
fakefs (~> 2.0)
|
55
48
|
krakend-openapi-importer!
|
49
|
+
minitest (~> 5.13)
|
56
50
|
rake (~> 13.0)
|
57
|
-
rspec (~> 3.0)
|
58
51
|
rubocop
|
59
52
|
|
60
53
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -22,9 +22,7 @@ krakend-openapi-importer import SPEC -c CONFIG
|
|
22
22
|
|
23
23
|
```bash
|
24
24
|
Options:
|
25
|
-
-c, --config=CONFIG # Path to importer.yaml config
|
26
|
-
-s, [--syntax=SYNTAX] # Specifies input data syntax: json or yaml. Defaults to json
|
27
|
-
# Default: json
|
25
|
+
-c, [--config=CONFIG] # Path to importer.yaml config
|
28
26
|
```
|
29
27
|
|
30
28
|
## Configuration
|
data/Rakefile
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'bundler/gem_tasks'
|
4
|
-
require '
|
4
|
+
require 'rake/testtask'
|
5
5
|
|
6
|
-
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << 'test'
|
8
|
+
t.libs << 'lib'
|
9
|
+
t.test_files = FileList['test/**/*_test.rb']
|
10
|
+
end
|
7
11
|
|
8
|
-
task default: :
|
12
|
+
task default: :test
|
data/lib/commands/import.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'pathname'
|
3
4
|
require 'yaml'
|
4
5
|
require_relative '../readers/oa3_reader'
|
6
|
+
require_relative '../readers/yaml_reader'
|
5
7
|
require_relative '../transformers/oa3_transformer'
|
6
8
|
require_relative '../writers/krakend_writer'
|
7
9
|
|
8
10
|
module KrakendOpenAPI
|
9
11
|
# Import Command
|
10
12
|
class ImportCommand
|
11
|
-
def initialize(spec:,
|
13
|
+
def initialize(spec:, config:)
|
12
14
|
@spec = spec
|
13
|
-
@
|
14
|
-
@config = config
|
15
|
-
|
16
|
-
@importer_config = YAML.safe_load(File.read("#{Dir.pwd}/#{@config}"))
|
15
|
+
@importer_config = config ? YamlReader.new(config).read : {}
|
17
16
|
end
|
18
17
|
|
19
18
|
def execute
|
data/lib/importer/version.rb
CHANGED
data/lib/importer.rb
CHANGED
@@ -7,11 +7,9 @@ module KrakendOpenAPI
|
|
7
7
|
# Importer CLI
|
8
8
|
class Importer < Thor
|
9
9
|
desc 'import SPEC', 'Import OpenAPI spec from SPEC file. Writes KrakenD config to output.json'
|
10
|
-
method_option :config, aliases: '-c', desc: 'Path to importer.yaml config'
|
11
|
-
method_option :syntax, aliases: '-s', default: 'json',
|
12
|
-
desc: 'Specifies input data syntax: json or yaml. Defaults to json'
|
10
|
+
method_option :config, aliases: '-c', desc: 'Path to importer.yaml config'
|
13
11
|
def import(spec)
|
14
|
-
ImportCommand.new(spec: spec,
|
12
|
+
ImportCommand.new(spec: spec, config: options[:config]).execute
|
15
13
|
end
|
16
14
|
end
|
17
15
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KrakendOpenAPI
|
4
|
+
# Reads absolute/relative files
|
5
|
+
class FileReader
|
6
|
+
def initialize(file_path)
|
7
|
+
@file_path = file_path
|
8
|
+
end
|
9
|
+
|
10
|
+
def read
|
11
|
+
pwd = File.expand_path(Dir.pwd)
|
12
|
+
if Pathname.new(@file_path).absolute?
|
13
|
+
File.read(@file_path)
|
14
|
+
else
|
15
|
+
File.read(File.expand_path(@file_path, pwd))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/readers/json_reader.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'json'
|
4
|
+
require_relative './file_reader'
|
5
|
+
|
3
6
|
module KrakendOpenAPI
|
4
7
|
# Reads JSON files
|
5
8
|
class JsonReader
|
@@ -8,7 +11,7 @@ module KrakendOpenAPI
|
|
8
11
|
end
|
9
12
|
|
10
13
|
def read
|
11
|
-
JSON.parse(
|
14
|
+
JSON.parse(KrakendOpenAPI::FileReader.new(@file_path).read)
|
12
15
|
end
|
13
16
|
end
|
14
17
|
end
|
data/lib/readers/oa3_reader.rb
CHANGED
data/lib/readers/yaml_reader.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'yaml'
|
4
|
+
require_relative './file_reader'
|
4
5
|
|
5
6
|
module KrakendOpenAPI
|
6
7
|
# Reads YAML files
|
@@ -10,7 +11,7 @@ module KrakendOpenAPI
|
|
10
11
|
end
|
11
12
|
|
12
13
|
def read
|
13
|
-
YAML.safe_load(
|
14
|
+
YAML.safe_load(KrakendOpenAPI::FileReader.new(@file_path).read)
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative './
|
3
|
+
require_relative './plugins/auth_validator_transformer'
|
4
4
|
|
5
5
|
module KrakendOpenAPI
|
6
6
|
# Transforms OpenAPI paths to KrakenD endpoints
|
@@ -24,25 +24,30 @@ module KrakendOpenAPI
|
|
24
24
|
roles = operation['x-jwt-roles']&.length ? operation['x-jwt-roles'] : @importer_config['all_roles']
|
25
25
|
|
26
26
|
plugins = []
|
27
|
-
plugins
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
if @importer_config['defaults']&.dig('plugins', 'auth_validator')
|
28
|
+
plugins << Plugins::AuthValidatorTransformer
|
29
|
+
.new
|
30
|
+
.transform_to_hash(roles: roles,
|
31
|
+
config: @importer_config['defaults']['plugins']['auth_validator'])
|
32
|
+
end
|
31
33
|
|
32
34
|
endpoint = {
|
33
35
|
endpoint: path,
|
34
36
|
method: method.upcase,
|
35
|
-
output_encoding: @importer_config['defaults']
|
36
|
-
input_headers: @importer_config['defaults']
|
37
|
-
input_query_strings: @importer_config['defaults']
|
38
|
-
backend: [{ url_pattern: path, encoding: @importer_config['defaults']
|
39
|
-
}
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
output_encoding: @importer_config['defaults']&.dig('endpoint', 'output_encoding'),
|
38
|
+
input_headers: @importer_config['defaults']&.dig('endpoint', 'input_headers'),
|
39
|
+
input_query_strings: @importer_config['defaults']&.dig('endpoint', 'input_query_strings'),
|
40
|
+
backend: [{ url_pattern: path, encoding: @importer_config['defaults']&.dig('backend', 0, 'encoding') }.compact]
|
41
|
+
}.compact
|
42
|
+
|
43
|
+
if plugins&.length&.> 0
|
44
|
+
extra_config = plugins.each_with_object({}) do |plugin, memo|
|
45
|
+
memo[plugin[:name].to_sym] = plugin[:value]
|
46
|
+
end
|
47
|
+
|
48
|
+
endpoint[:extra_config] = extra_config
|
43
49
|
end
|
44
50
|
|
45
|
-
endpoint[:extra_config] = extra_config
|
46
51
|
endpoint
|
47
52
|
end
|
48
53
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KrakendOpenAPI
|
4
|
+
module Plugins
|
5
|
+
# Transforms Auth Validator plugin definition
|
6
|
+
class AuthValidatorTransformer
|
7
|
+
def transform_to_hash(roles:, config:)
|
8
|
+
raise(StandardError, 'Roles are empty') if roles.empty?
|
9
|
+
|
10
|
+
{
|
11
|
+
name: 'auth/validator',
|
12
|
+
value: {
|
13
|
+
'alg': config['alg'],
|
14
|
+
'jwk_url': config['jwk_url'],
|
15
|
+
'cache': config['cache'],
|
16
|
+
'operation_debug': config['operation_debug'],
|
17
|
+
'roles_key_is_nested': config['roles_key_is_nested'],
|
18
|
+
'roles_key': config['roles_key'],
|
19
|
+
'roles': roles
|
20
|
+
}.compact
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -8,18 +8,26 @@ module KrakendOpenAPI
|
|
8
8
|
def initialize(endpoints, importer_config)
|
9
9
|
@endpoints = endpoints
|
10
10
|
@importer_config = importer_config
|
11
|
-
@
|
12
|
-
@file_path = "#{Dir.pwd}/#{@output}"
|
11
|
+
@output_file_path = @importer_config['output'] || 'output.json'
|
13
12
|
end
|
14
13
|
|
15
14
|
def write
|
16
15
|
pretty_output = !!@importer_config['pretty'] # rubocop:disable Style/DoubleNegation
|
17
16
|
json_generate = pretty_output ? ->(obj) { JSON.pretty_generate(obj) } : ->(obj) { JSON.dump(obj) }
|
18
|
-
File.write(
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
File.write(file_path, json_generate.call({
|
18
|
+
'$schema': 'https://www.krakend.io/schema/v3.json',
|
19
|
+
version: 3,
|
20
|
+
endpoints: @endpoints
|
21
|
+
}))
|
22
|
+
end
|
23
|
+
|
24
|
+
def file_path
|
25
|
+
pwd = File.expand_path(Dir.pwd)
|
26
|
+
if Pathname.new(@output_file_path).absolute?
|
27
|
+
@output_file_path
|
28
|
+
else
|
29
|
+
File.expand_path(@output_file_path, pwd)
|
30
|
+
end
|
23
31
|
end
|
24
32
|
end
|
25
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: krakend-openapi-importer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Semenenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -35,7 +35,6 @@ extra_rdoc_files: []
|
|
35
35
|
files:
|
36
36
|
- ".github/workflows/main.yml"
|
37
37
|
- ".gitignore"
|
38
|
-
- ".rspec"
|
39
38
|
- ".ruby-version"
|
40
39
|
- Gemfile
|
41
40
|
- Gemfile.lock
|
@@ -49,11 +48,12 @@ files:
|
|
49
48
|
- lib/commands/import.rb
|
50
49
|
- lib/importer.rb
|
51
50
|
- lib/importer/version.rb
|
51
|
+
- lib/readers/file_reader.rb
|
52
52
|
- lib/readers/json_reader.rb
|
53
53
|
- lib/readers/oa3_reader.rb
|
54
54
|
- lib/readers/yaml_reader.rb
|
55
|
-
- lib/transformers/jwt_validator_transformer.rb
|
56
55
|
- lib/transformers/oa3_transformer.rb
|
56
|
+
- lib/transformers/plugins/auth_validator_transformer.rb
|
57
57
|
- lib/writers/krakend_writer.rb
|
58
58
|
homepage: https://hypercoder.net
|
59
59
|
licenses:
|
data/.rspec
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module KrakendOpenAPI
|
4
|
-
# Transforms OpenAPI paths to KrakenD endpoints
|
5
|
-
class JwtValidatorTransformer
|
6
|
-
def transform_to_hash(roles:, config:)
|
7
|
-
{
|
8
|
-
name: 'auth/validator',
|
9
|
-
value: {
|
10
|
-
'alg': config['alg'],
|
11
|
-
'jwk_url': config['jwk_url'],
|
12
|
-
'cache': config['cache'],
|
13
|
-
'operation_debug': config['operation_debug'],
|
14
|
-
'roles_key_is_nested': config['roles_key_is_nested'],
|
15
|
-
'roles_key': config['roles_key'],
|
16
|
-
'roles': roles
|
17
|
-
}
|
18
|
-
}
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|