api_valve 0.8.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/api_valve.rb +2 -1
- data/lib/api_valve/error_responder.rb +1 -1
- data/lib/api_valve/forwarder/request.rb +2 -2
- data/lib/api_valve/logger.rb +1 -1
- data/lib/api_valve/proxy.rb +3 -3
- data/lib/api_valve/proxy/builder.rb +3 -4
- data/lib/api_valve/route_set.rb +21 -21
- metadata +11 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0e6669812fb7067607a8013b6080931d548f23df184bfd4f7a722d0a2ead98d
|
4
|
+
data.tar.gz: 241d1a7a8cac8aa6795418e3dbb54b016262eb476f3cfba5fdfece748ab204da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44e8eba0a335b9740b37cc189f3418358c42bb99245a614b6acf042201096fced3f3eb306814ccb2c628566cf80b78676339f4db47a4a7490476275f746c2013
|
7
|
+
data.tar.gz: d1d4909884073aafce0cbbd9d091d3613c84422d90db4911c4f6bb540c62eba6b80fb6a3a1a5365dedf9166e24db17b4721a8e31ddd9e81e0a516f58e5016df2
|
data/lib/api_valve.rb
CHANGED
@@ -5,6 +5,7 @@ require 'active_support/core_ext/hash'
|
|
5
5
|
require 'active_support/core_ext/object'
|
6
6
|
require 'active_support/core_ext/module'
|
7
7
|
require 'active_support/json'
|
8
|
+
require 'active_support/notifications'
|
8
9
|
require 'active_support/rescuable'
|
9
10
|
require 'benchmark'
|
10
11
|
require 'faraday'
|
@@ -26,7 +27,7 @@ module ApiValve
|
|
26
27
|
include ActiveSupport::Configurable
|
27
28
|
|
28
29
|
config_accessor :logger do
|
29
|
-
Logger.new(
|
30
|
+
Logger.new($stdout)
|
30
31
|
end
|
31
32
|
|
32
33
|
config_accessor :error_responder do
|
@@ -86,9 +86,9 @@ module ApiValve
|
|
86
86
|
|
87
87
|
def override_path(options)
|
88
88
|
return unless (path = options['path'])
|
89
|
-
return path unless options
|
89
|
+
return path unless options['match_data']
|
90
90
|
|
91
|
-
path % options
|
91
|
+
path % options['match_data'].named_captures.symbolize_keys
|
92
92
|
end
|
93
93
|
|
94
94
|
def x_forwarded_for
|
data/lib/api_valve/logger.rb
CHANGED
data/lib/api_valve/proxy.rb
CHANGED
@@ -34,9 +34,9 @@ module ApiValve
|
|
34
34
|
|
35
35
|
def forward(methods, path_regexp = nil, options = {})
|
36
36
|
options = options.with_indifferent_access
|
37
|
-
route_set.append(methods, path_regexp, options.except(:request)
|
37
|
+
route_set.append(methods, path_regexp, options.except(:request)) do |request, match_data|
|
38
38
|
forwarder.call request, {'match_data' => match_data}.merge(options[:request] || {}).with_indifferent_access
|
39
|
-
|
39
|
+
end
|
40
40
|
end
|
41
41
|
|
42
42
|
def forward_all(options = {})
|
@@ -44,7 +44,7 @@ module ApiValve
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def deny(methods, path_regexp = nil, with: 'Error::Forbidden')
|
47
|
-
route_set.append(methods, path_regexp, {}
|
47
|
+
route_set.append(methods, path_regexp, {}) { raise ApiValve.const_get(with) }
|
48
48
|
end
|
49
49
|
|
50
50
|
protected
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module ApiValve
|
2
2
|
class Proxy
|
3
3
|
module Builder
|
4
|
-
# Creates
|
4
|
+
# Creates an instance from a config hash and takes optional block
|
5
5
|
# which is executed in scope of the proxy
|
6
|
-
def build(config)
|
7
|
-
block = Proc.new if block_given? # capture the yield
|
6
|
+
def build(config, &block)
|
8
7
|
from_hash(config).tap do |proxy|
|
9
8
|
proxy.instance_eval(&block) if block
|
10
9
|
end
|
@@ -16,7 +15,7 @@ module ApiValve
|
|
16
15
|
raise "Config not found for #{name.underscore}(.yml|.yml.erb) in #{ApiValve.config_paths.inspect}" unless path
|
17
16
|
|
18
17
|
yaml = File.read(path)
|
19
|
-
yaml = ERB.new(yaml,
|
18
|
+
yaml = ERB.new(yaml, trim_mode: '-').result if path.fnmatch? '*.erb'
|
20
19
|
from_yaml yaml
|
21
20
|
end
|
22
21
|
|
data/lib/api_valve/route_set.rb
CHANGED
@@ -32,54 +32,54 @@ module ApiValve
|
|
32
32
|
[route, match_data]
|
33
33
|
end
|
34
34
|
|
35
|
-
def delete(path = nil, options = {},
|
36
|
-
push :delete, path, options,
|
35
|
+
def delete(path = nil, options = {}, &block)
|
36
|
+
push :delete, path, options, &block
|
37
37
|
end
|
38
38
|
|
39
|
-
def get(path = nil, options = {},
|
40
|
-
push :get, path, options,
|
39
|
+
def get(path = nil, options = {}, &block)
|
40
|
+
push :get, path, options, &block
|
41
41
|
end
|
42
42
|
|
43
|
-
def head(path = nil, options = {},
|
44
|
-
push :head, path, options,
|
43
|
+
def head(path = nil, options = {}, &block)
|
44
|
+
push :head, path, options, &block
|
45
45
|
end
|
46
46
|
|
47
|
-
def patch(path = nil, options = {},
|
48
|
-
push :patch, path, options,
|
47
|
+
def patch(path = nil, options = {}, &block)
|
48
|
+
push :patch, path, options, &block
|
49
49
|
end
|
50
50
|
|
51
|
-
def post(path = nil, options = {},
|
52
|
-
push :post, path, options,
|
51
|
+
def post(path = nil, options = {}, &block)
|
52
|
+
push :post, path, options, &block
|
53
53
|
end
|
54
54
|
|
55
|
-
def put(path = nil, options = {},
|
56
|
-
push :put, path, options,
|
55
|
+
def put(path = nil, options = {}, &block)
|
56
|
+
push :put, path, options, &block
|
57
57
|
end
|
58
58
|
|
59
|
-
def any(path = nil, options = {},
|
60
|
-
append METHODS, path, options,
|
59
|
+
def any(path = nil, options = {}, &block)
|
60
|
+
append METHODS, path, options, &block
|
61
61
|
end
|
62
62
|
|
63
|
-
def push(methods, regexp, options = {},
|
64
|
-
add_route :push, methods, regexp, options,
|
63
|
+
def push(methods, regexp, options = {}, &block)
|
64
|
+
add_route :push, methods, regexp, options, &block
|
65
65
|
end
|
66
66
|
|
67
67
|
alias append push
|
68
68
|
|
69
|
-
def unshift(methods, regexp = nil, options = {},
|
70
|
-
add_route :unshift, methods, regexp, options,
|
69
|
+
def unshift(methods, regexp = nil, options = {}, &block)
|
70
|
+
add_route :unshift, methods, regexp, options, &block
|
71
71
|
end
|
72
72
|
|
73
73
|
def reset_routes
|
74
|
-
@routes =
|
74
|
+
@routes = METHODS.map { |v| [v, []] }.to_h.with_indifferent_access.freeze
|
75
75
|
end
|
76
76
|
|
77
77
|
private
|
78
78
|
|
79
|
-
def add_route(how, methods, regexp, options,
|
79
|
+
def add_route(how, methods, regexp, options, &block)
|
80
80
|
methods = METHODS if methods.to_s == 'any'
|
81
81
|
Array.wrap(methods).each do |method|
|
82
|
-
@routes[method].public_send how, Route.new(regexp, options,
|
82
|
+
@routes[method].public_send how, Route.new(regexp, options, block)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_valve
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mkon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -126,28 +126,28 @@ dependencies:
|
|
126
126
|
requirements:
|
127
127
|
- - '='
|
128
128
|
- !ruby/object:Gem::Version
|
129
|
-
version:
|
129
|
+
version: 1.18.2
|
130
130
|
type: :development
|
131
131
|
prerelease: false
|
132
132
|
version_requirements: !ruby/object:Gem::Requirement
|
133
133
|
requirements:
|
134
134
|
- - '='
|
135
135
|
- !ruby/object:Gem::Version
|
136
|
-
version:
|
136
|
+
version: 1.18.2
|
137
137
|
- !ruby/object:Gem::Dependency
|
138
138
|
name: rubocop-rspec
|
139
139
|
requirement: !ruby/object:Gem::Requirement
|
140
140
|
requirements:
|
141
141
|
- - '='
|
142
142
|
- !ruby/object:Gem::Version
|
143
|
-
version:
|
143
|
+
version: 2.4.0
|
144
144
|
type: :development
|
145
145
|
prerelease: false
|
146
146
|
version_requirements: !ruby/object:Gem::Requirement
|
147
147
|
requirements:
|
148
148
|
- - '='
|
149
149
|
- !ruby/object:Gem::Version
|
150
|
-
version:
|
150
|
+
version: 2.4.0
|
151
151
|
- !ruby/object:Gem::Dependency
|
152
152
|
name: simplecov
|
153
153
|
requirement: !ruby/object:Gem::Requirement
|
@@ -229,14 +229,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
229
229
|
requirements:
|
230
230
|
- - ">="
|
231
231
|
- !ruby/object:Gem::Version
|
232
|
-
version: '
|
232
|
+
version: '2.6'
|
233
|
+
- - "<"
|
234
|
+
- !ruby/object:Gem::Version
|
235
|
+
version: '3.1'
|
233
236
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
234
237
|
requirements:
|
235
238
|
- - ">="
|
236
239
|
- !ruby/object:Gem::Version
|
237
240
|
version: '0'
|
238
241
|
requirements: []
|
239
|
-
rubygems_version: 3.0.3
|
242
|
+
rubygems_version: 3.0.3.1
|
240
243
|
signing_key:
|
241
244
|
specification_version: 4
|
242
245
|
summary: Lightweight ruby/rack API reverse proxy or gateway
|