endpoint-flux 1.1.1 → 1.1.2
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.lock +1 -1
- data/endpoint_flux.gemspec +4 -3
- data/lib/endpoint_flux/rails/concerns/endpoint_controller.rb +11 -0
- data/lib/endpoint_flux/request.rb +3 -1
- data/lib/endpoint_flux/version.rb +1 -1
- data/spec/lib/endpoint_flux/rails/concerns/endpoint_controller_spec.rb +75 -0
- data/spec/lib/endpoint_flux/request_spec.rb +44 -0
- metadata +11 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3d775f0aa474f44316f38322c81f8c2719659c6b88bd0ea4e363c1c4e3719c9
|
4
|
+
data.tar.gz: cbc3962cba9f2c453a6fa68b570108a80aeffdda33a00bb6f2607faa58699361
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6babb40f498026c950cbee97e8d7cd9971bbc8b1c88552606d410e318ac5522807e03c8669682772a3a3ebca6a50439d0a69399d60df081e5b2ff5f6bb9843b2
|
7
|
+
data.tar.gz: 4a065804095484a0ec712aae7898b123d5ad0ab0478ce641da1d42d2288ba71a7905fe216dadd73e0e36b3e1ac03bb22926ff9e2455bdc3dbf9882ef10c48d50
|
data/Gemfile.lock
CHANGED
data/endpoint_flux.gemspec
CHANGED
@@ -5,13 +5,14 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.version = EndpointFlux::VERSION
|
6
6
|
s.summary = 'EndpointFlux!'
|
7
7
|
s.description = 'A simple way to organise API endpoints'
|
8
|
-
s.authors = ['Arturs Kreipans']
|
8
|
+
s.authors = ['Arturs Kreipans https://github.com/fragallia']
|
9
9
|
s.files = `git ls-files`.split($\)
|
10
10
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
11
11
|
s.require_paths = ['lib']
|
12
12
|
s.homepage = 'http://rubygems.org/gems/endpoint-flux'
|
13
13
|
s.license = 'MIT'
|
14
|
+
s.required_ruby_version = '~> 2.5'
|
14
15
|
|
15
|
-
s.add_development_dependency 'byebug'
|
16
|
-
s.add_development_dependency 'rspec'
|
16
|
+
s.add_development_dependency 'byebug' '~> 9.0'
|
17
|
+
s.add_development_dependency 'rspec' '~> 3.5'
|
17
18
|
end
|
@@ -19,6 +19,7 @@ module EndpointFlux
|
|
19
19
|
def request_object
|
20
20
|
::EndpointFlux::Request.new(
|
21
21
|
headers: headers.merge('Authorization' => request.headers['authorization']),
|
22
|
+
remote_ip: remote_ip,
|
22
23
|
params: endpoint_params
|
23
24
|
)
|
24
25
|
end
|
@@ -26,6 +27,16 @@ module EndpointFlux
|
|
26
27
|
def endpoint_params
|
27
28
|
params.permit!.except(:controller, :action, :format).to_h.deep_symbolize_keys
|
28
29
|
end
|
30
|
+
|
31
|
+
def remote_ip
|
32
|
+
ip = request.remote_ip.to_s
|
33
|
+
|
34
|
+
if ip == '127.0.0.1'
|
35
|
+
ip = request.env['HTTP_X_FORWARDED_FOR']
|
36
|
+
end
|
37
|
+
|
38
|
+
ip
|
39
|
+
end
|
29
40
|
end
|
30
41
|
end
|
31
42
|
end
|
@@ -1,13 +1,15 @@
|
|
1
1
|
module EndpointFlux
|
2
2
|
class Request
|
3
|
-
def initialize(headers: {}, params: {}, namespace: nil)
|
3
|
+
def initialize(headers: {}, remote_ip: '', params: {}, namespace: nil)
|
4
4
|
@headers = headers
|
5
|
+
@remote_ip = remote_ip
|
5
6
|
@params = params
|
6
7
|
@namespace = namespace
|
7
8
|
end
|
8
9
|
|
9
10
|
attr_accessor :params
|
10
11
|
attr_accessor :headers
|
12
|
+
attr_accessor :remote_ip
|
11
13
|
attr_accessor :namespace
|
12
14
|
attr_accessor :endpoint
|
13
15
|
attr_accessor :scope
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module ActiveSupport
|
2
|
+
module Concern ; end
|
3
|
+
end
|
4
|
+
|
5
|
+
require 'spec_helper'
|
6
|
+
require 'endpoint_flux/rails/concerns/endpoint_controller'
|
7
|
+
require 'ostruct'
|
8
|
+
|
9
|
+
class RemoteIpDummyClass
|
10
|
+
include EndpointFlux::Rails::Concerns::EndpointController
|
11
|
+
|
12
|
+
def headers
|
13
|
+
{}
|
14
|
+
end
|
15
|
+
|
16
|
+
def request
|
17
|
+
OpenStruct.new(
|
18
|
+
headers: { 'authorization' => 'authorization header' },
|
19
|
+
remote_ip: '172.18.0.1',
|
20
|
+
env: { 'HTTP_X_FORWARDED_FOR' => '172.18.0.2' }
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class LocalIpDummyClass
|
26
|
+
include EndpointFlux::Rails::Concerns::EndpointController
|
27
|
+
|
28
|
+
def headers
|
29
|
+
{}
|
30
|
+
end
|
31
|
+
|
32
|
+
def request
|
33
|
+
OpenStruct.new(
|
34
|
+
headers: { 'authorization' => 'authorization header' },
|
35
|
+
remote_ip: '127.0.0.1',
|
36
|
+
env: { 'HTTP_X_FORWARDED_FOR' => '172.18.0.2' }
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
RSpec.describe EndpointFlux::Rails::Concerns::EndpointController do
|
42
|
+
describe '#request_object' do
|
43
|
+
before do
|
44
|
+
allow(subject).to receive(:endpoint_params).and_return({})
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'remote ip' do
|
48
|
+
subject { RemoteIpDummyClass.new }
|
49
|
+
|
50
|
+
it 'sets property as remote_ip' do
|
51
|
+
expect(
|
52
|
+
::EndpointFlux::Request
|
53
|
+
).to receive(:new).with(headers: { 'Authorization' => 'authorization header' },
|
54
|
+
params: subject.endpoint_params,
|
55
|
+
remote_ip: subject.request.remote_ip)
|
56
|
+
|
57
|
+
subject.request_object
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'local ip' do
|
62
|
+
subject { LocalIpDummyClass.new }
|
63
|
+
|
64
|
+
it 'sets property as HTTP_X_FORWARDED_FOR' do
|
65
|
+
expect(
|
66
|
+
::EndpointFlux::Request
|
67
|
+
).to receive(:new).with(headers: { 'Authorization' => 'authorization header' },
|
68
|
+
params: subject.endpoint_params,
|
69
|
+
remote_ip: subject.request.env['HTTP_X_FORWARDED_FOR'])
|
70
|
+
|
71
|
+
subject.request_object
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe EndpointFlux::Request do
|
4
|
+
it { should respond_to :headers }
|
5
|
+
it { should respond_to :remote_ip }
|
6
|
+
it { should respond_to :params }
|
7
|
+
it { should respond_to :namespace }
|
8
|
+
it { should respond_to :endpoint }
|
9
|
+
it { should respond_to :scope }
|
10
|
+
|
11
|
+
describe '#initialize' do
|
12
|
+
context 'when all params specified' do
|
13
|
+
let(:params) { { param: :val } }
|
14
|
+
let(:headers) { { header: :val } }
|
15
|
+
let(:remote_ip) { '127.0.0.1' }
|
16
|
+
let(:namespace) { 'namespace' }
|
17
|
+
|
18
|
+
it 'should set args' do
|
19
|
+
request = EndpointFlux::Request.new(
|
20
|
+
params: params,
|
21
|
+
headers: headers,
|
22
|
+
remote_ip: remote_ip,
|
23
|
+
namespace: namespace
|
24
|
+
)
|
25
|
+
|
26
|
+
expect(request.params).to eq params
|
27
|
+
expect(request.headers).to eq headers
|
28
|
+
expect(request.remote_ip).to eq remote_ip
|
29
|
+
expect(request.namespace).to eq namespace
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when params missed' do
|
33
|
+
it 'should set default values' do
|
34
|
+
request = EndpointFlux::Request.new
|
35
|
+
|
36
|
+
expect(request.params).to be_empty
|
37
|
+
expect(request.headers).to be_empty
|
38
|
+
expect(request.remote_ip).to eq ''
|
39
|
+
expect(request.namespace).to be_nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: endpoint-flux
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Arturs Kreipans
|
7
|
+
- Arturs Kreipans https://github.com/fragallia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: byebug
|
14
|
+
name: byebug~> 9.0
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec
|
28
|
+
name: rspec~> 3.5
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -87,6 +87,8 @@ files:
|
|
87
87
|
- spec/lib/endpoint/middlewares_spec.rb
|
88
88
|
- spec/lib/endpoint/perform_spec.rb
|
89
89
|
- spec/lib/endpoint/rescue_from_spec.rb
|
90
|
+
- spec/lib/endpoint_flux/rails/concerns/endpoint_controller_spec.rb
|
91
|
+
- spec/lib/endpoint_flux/request_spec.rb
|
90
92
|
- spec/lib/exceptions/forbidden_spec.rb
|
91
93
|
- spec/lib/exceptions/not_found_spec.rb
|
92
94
|
- spec/lib/exceptions/service_unavailable_spec.rb
|
@@ -111,9 +113,9 @@ require_paths:
|
|
111
113
|
- lib
|
112
114
|
required_ruby_version: !ruby/object:Gem::Requirement
|
113
115
|
requirements:
|
114
|
-
- - "
|
116
|
+
- - "~>"
|
115
117
|
- !ruby/object:Gem::Version
|
116
|
-
version: '
|
118
|
+
version: '2.5'
|
117
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
120
|
requirements:
|
119
121
|
- - ">="
|
@@ -137,6 +139,8 @@ test_files:
|
|
137
139
|
- spec/lib/endpoint/middlewares_spec.rb
|
138
140
|
- spec/lib/endpoint/perform_spec.rb
|
139
141
|
- spec/lib/endpoint/rescue_from_spec.rb
|
142
|
+
- spec/lib/endpoint_flux/rails/concerns/endpoint_controller_spec.rb
|
143
|
+
- spec/lib/endpoint_flux/request_spec.rb
|
140
144
|
- spec/lib/exceptions/forbidden_spec.rb
|
141
145
|
- spec/lib/exceptions/not_found_spec.rb
|
142
146
|
- spec/lib/exceptions/service_unavailable_spec.rb
|