api_valve 0.8.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0077e2b67d1a99fcde84633c66f4bb2eb6cbd9b65e45b46a1bbc6f22f0a7bf47
4
- data.tar.gz: e880e13b437165fa6678638fa7e8a632115a7587bf9024fdf86f81399c12ac75
3
+ metadata.gz: efc4ab150d52d51871f9f354981bc593ee5498ceb18a8360903dc852e7236ac1
4
+ data.tar.gz: 6e7a6baf1e21e480d37b9051d7af404bb597665571aa0904d5fad58e09c5852c
5
5
  SHA512:
6
- metadata.gz: 5802ab4c218221aabbb6921337165090911137ca5d42e66551706e7ab99cd0e9fe69000246ecbdf733605ae8b1bbab3aa8bc5b812786e6ba2450adeeb327fb25
7
- data.tar.gz: d7e2f3dbe1b9fb27e2db8a5444adf05abb044dd6e5947fa8ecb0f729091bd2e96f24daf154f810333c4286feee99424a45a2cedd76831174386e3bb922abd00d
6
+ metadata.gz: 141e76749cc7dc127434882786ab90f7574a9e5fe0c826b7932e3ac9b4949821c05d79080fc91a2643af5d0893e39c8694769f2516fd3fc16765c46e38db443b
7
+ data.tar.gz: 706c645a89c86349fdd91b7bd7ee74530636dd71df43fafe999e4a479575aee37f6217dc47a41b1c9c591806826886ecf82c1b16b6771f1c493a6c05f13765ec
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # ApiValve
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/api_valve.svg)](https://badge.fury.io/rb/api_valve)
4
- ![](https://github.com/mkon/api_valve/workflows/Test/badge.svg?branch=master)
4
+ ![](https://github.com/mkon/api_valve/workflows/Test/badge.svg?branch=main)
5
5
  [![Depfu](https://badges.depfu.com/badges/1f5892cc85d02997050e0a4d077c7dc4/overview.svg)](https://depfu.com/github/mkon/api_valve?project_id=5958)
6
6
 
7
7
  Extensible rack application that serves as lightweight API reverse proxy.
@@ -16,7 +16,7 @@ module ApiValve
16
16
 
17
17
  def status
18
18
  status = @error.try(:http_status)
19
- return status if status&.is_a?(Integer)
19
+ return status if status.is_a?(Integer)
20
20
 
21
21
  Rack::Utils::SYMBOL_TO_STATUS_CODE[status] || 500
22
22
  end
@@ -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.dig('match_data')
89
+ return path unless options['match_data']
90
90
 
91
- path % options.dig('match_data').named_captures.symbolize_keys
91
+ path % options['match_data'].named_captures.symbolize_keys
92
92
  end
93
93
 
94
94
  def x_forwarded_for
@@ -9,7 +9,7 @@ module ApiValve
9
9
  include ActiveSupport::TaggedLogging::Formatter
10
10
  end
11
11
 
12
- def initialize(target = STDOUT)
12
+ def initialize(target = $stdout)
13
13
  super(target)
14
14
  self.formatter = Formatter.new
15
15
  end
@@ -1,10 +1,9 @@
1
1
  module ApiValve
2
2
  class Proxy
3
3
  module Builder
4
- # Creates a n instance from a config hash and takes optional block
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,12 +15,12 @@ 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, nil, '-').result if path.fnmatch? '*.erb'
18
+ yaml = ERB.new(yaml, trim_mode: '-').result if path.fnmatch? '*.erb'
20
19
  from_yaml yaml
21
20
  end
22
21
 
23
22
  def from_yaml(string)
24
- from_hash YAML.load(string) # rubocop:disable Security/YAMLLoad
23
+ from_hash YAML.safe_load(string, permitted_classes: ApiValve.safe_load_classes)
25
24
  end
26
25
 
27
26
  def from_hash(config)
@@ -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), proc { |request, match_data|
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, {}, ->(*_args) { raise ApiValve.const_get(with) })
47
+ route_set.append(methods, path_regexp, {}) { raise ApiValve.const_get(with) }
48
48
  end
49
49
 
50
50
  protected
@@ -32,54 +32,54 @@ module ApiValve
32
32
  [route, match_data]
33
33
  end
34
34
 
35
- def delete(path = nil, options = {}, prok = nil)
36
- push :delete, path, options, prok || Proc.new
35
+ def delete(path = nil, options = {}, &block)
36
+ push :delete, path, options, &block
37
37
  end
38
38
 
39
- def get(path = nil, options = {}, prok = nil)
40
- push :get, path, options, prok || Proc.new
39
+ def get(path = nil, options = {}, &block)
40
+ push :get, path, options, &block
41
41
  end
42
42
 
43
- def head(path = nil, options = {}, prok = nil)
44
- push :head, path, options, prok || Proc.new
43
+ def head(path = nil, options = {}, &block)
44
+ push :head, path, options, &block
45
45
  end
46
46
 
47
- def patch(path = nil, options = {}, prok = nil)
48
- push :patch, path, options, prok || Proc.new
47
+ def patch(path = nil, options = {}, &block)
48
+ push :patch, path, options, &block
49
49
  end
50
50
 
51
- def post(path = nil, options = {}, prok = nil)
52
- push :post, path, options, prok || Proc.new
51
+ def post(path = nil, options = {}, &block)
52
+ push :post, path, options, &block
53
53
  end
54
54
 
55
- def put(path = nil, options = {}, prok = nil)
56
- push :put, path, options, prok || Proc.new
55
+ def put(path = nil, options = {}, &block)
56
+ push :put, path, options, &block
57
57
  end
58
58
 
59
- def any(path = nil, options = {}, prok = nil)
60
- append METHODS, path, options, prok || Proc.new
59
+ def any(path = nil, options = {}, &block)
60
+ append METHODS, path, options, &block
61
61
  end
62
62
 
63
- def push(methods, regexp, options = {}, prok = nil)
64
- add_route :push, methods, regexp, options, prok || Proc.new
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 = {}, prok = nil)
70
- add_route :unshift, methods, regexp, options, prok || Proc.new
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 = Hash[METHODS.map { |v| [v, []] }].with_indifferent_access.freeze
74
+ @routes = METHODS.to_h { |v| [v, []] }.with_indifferent_access.freeze
75
75
  end
76
76
 
77
77
  private
78
78
 
79
- def add_route(how, methods, regexp, options, prok)
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, prok)
82
+ @routes[method].public_send how, Route.new(regexp, options, block)
83
83
  end
84
84
  end
85
85
  end
data/lib/api_valve.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'active_support'
1
2
  require 'active_support/callbacks'
2
3
  require 'active_support/configurable'
3
4
  require 'active_support/core_ext/class'
@@ -5,6 +6,7 @@ require 'active_support/core_ext/hash'
5
6
  require 'active_support/core_ext/object'
6
7
  require 'active_support/core_ext/module'
7
8
  require 'active_support/json'
9
+ require 'active_support/notifications'
8
10
  require 'active_support/rescuable'
9
11
  require 'benchmark'
10
12
  require 'faraday'
@@ -26,7 +28,7 @@ module ApiValve
26
28
  include ActiveSupport::Configurable
27
29
 
28
30
  config_accessor :logger do
29
- Logger.new(STDOUT)
31
+ Logger.new($stdout)
30
32
  end
31
33
 
32
34
  config_accessor :error_responder do
@@ -41,6 +43,10 @@ module ApiValve
41
43
  []
42
44
  end
43
45
 
46
+ config_accessor :safe_load_classes do
47
+ [::Regexp]
48
+ end
49
+
44
50
  # :nocov:
45
51
  def self.configure
46
52
  yield config
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.8.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mkon
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-12 00:00:00.000000000 Z
11
+ date: 2022-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5'
19
+ version: '6.1'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7'
22
+ version: '7.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '5'
29
+ version: '6.1'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7'
32
+ version: '7.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: faraday
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -37,9 +37,9 @@ dependencies:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0.14'
40
- - - "<"
40
+ - - "<="
41
41
  - !ruby/object:Gem::Version
42
- version: '2'
42
+ version: 2.3.0
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -47,9 +47,9 @@ dependencies:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0.14'
50
- - - "<"
50
+ - - "<="
51
51
  - !ruby/object:Gem::Version
52
- version: '2'
52
+ version: 2.3.0
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: multi_json
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -126,28 +126,28 @@ dependencies:
126
126
  requirements:
127
127
  - - '='
128
128
  - !ruby/object:Gem::Version
129
- version: 0.82.0
129
+ version: 1.29.1
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: 0.82.0
136
+ version: 1.29.1
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: 1.39.0
143
+ version: 2.11.1
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: 1.39.0
150
+ version: 2.11.1
151
151
  - !ruby/object:Gem::Dependency
152
152
  name: simplecov
153
153
  requirement: !ruby/object:Gem::Requirement
@@ -190,7 +190,7 @@ dependencies:
190
190
  - - "~>"
191
191
  - !ruby/object:Gem::Version
192
192
  version: '3.4'
193
- description:
193
+ description:
194
194
  email:
195
195
  - konstantin@munteanu.de
196
196
  executables: []
@@ -220,8 +220,9 @@ files:
220
220
  homepage: https://github.com/mkon/api_valve
221
221
  licenses:
222
222
  - MIT
223
- metadata: {}
224
- post_install_message:
223
+ metadata:
224
+ rubygems_mfa_required: 'true'
225
+ post_install_message:
225
226
  rdoc_options: []
226
227
  require_paths:
227
228
  - lib
@@ -229,15 +230,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
229
230
  requirements:
230
231
  - - ">="
231
232
  - !ruby/object:Gem::Version
232
- version: '0'
233
+ version: '2.7'
234
+ - - "<"
235
+ - !ruby/object:Gem::Version
236
+ version: '4'
233
237
  required_rubygems_version: !ruby/object:Gem::Requirement
234
238
  requirements:
235
239
  - - ">="
236
240
  - !ruby/object:Gem::Version
237
241
  version: '0'
238
242
  requirements: []
239
- rubygems_version: 3.0.3
240
- signing_key:
243
+ rubygems_version: 3.3.7
244
+ signing_key:
241
245
  specification_version: 4
242
246
  summary: Lightweight ruby/rack API reverse proxy or gateway
243
247
  test_files: []