proxes 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Gemfile.ci +1 -0
- data/Rakefile +7 -4
- data/lib/ditty/components/proxes.rb +8 -4
- data/lib/proxes/forwarder.rb +29 -23
- data/lib/proxes/models/permission.rb +1 -1
- data/lib/proxes/security.rb +7 -2
- data/lib/proxes/version.rb +1 -1
- data/migrate/{20170208_audit_log.rb → 20170207_permissions.rb} +4 -3
- metadata +3 -5
- data/migrate/20170207_base_tables.rb +0 -48
- data/migrate/20170416_audit_log_details.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad607a464e38ed6387d1be30475a61c26eb81689
|
4
|
+
data.tar.gz: 429939f8285054543348f46233871807ee8eade7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 381152117b4e243e830d2bfe5db85f0e574c9c8ffacc441d970fb88ea5c8d44983bfef3b7cb88868757cd41ef417f7331c7c5412f6534331ab6289ae65af7abe
|
7
|
+
data.tar.gz: 837409d7f0f4c9782ecf433f402fe98d8528bcdb15beffbbecdddb969865e344877adb81f73e47f1d7fc6719868434c61562bd38fe53b40fc21ebdabb2db239c
|
data/.travis.yml
CHANGED
data/Gemfile.ci
CHANGED
data/Rakefile
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'dotenv/load'
|
4
|
-
|
5
3
|
require 'rake'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
require 'ditty/rake_tasks'
|
6
|
+
|
7
|
+
require 'ditty'
|
6
8
|
require 'proxes'
|
7
9
|
|
10
|
+
Ditty.component :app
|
11
|
+
Ditty.component :proxes
|
12
|
+
|
8
13
|
begin
|
9
14
|
require 'rspec/core/rake_task'
|
10
15
|
RSpec::Core::RakeTask.new(:spec)
|
11
16
|
task default: :spec
|
12
17
|
rescue LoadError
|
13
18
|
end
|
14
|
-
|
15
|
-
require 'ditty/rake_tasks'
|
@@ -4,6 +4,12 @@ require 'ditty'
|
|
4
4
|
|
5
5
|
module Ditty
|
6
6
|
class ProxES
|
7
|
+
def self.load
|
8
|
+
controllers = File.expand_path('../../../proxes/controllers', __FILE__)
|
9
|
+
Dir.glob("#{controllers}/*.rb").each { |f| require f }
|
10
|
+
require 'proxes/models/permission'
|
11
|
+
end
|
12
|
+
|
7
13
|
def self.migrations
|
8
14
|
File.expand_path('../../../../migrate', __FILE__)
|
9
15
|
end
|
@@ -17,16 +23,14 @@ module Ditty
|
|
17
23
|
end
|
18
24
|
|
19
25
|
def self.routes
|
20
|
-
|
21
|
-
Dir.glob("#{controllers}/*.rb").each { |f| require f }
|
26
|
+
load
|
22
27
|
{
|
23
28
|
'/permissions' => ::ProxES::Permissions
|
24
29
|
}
|
25
30
|
end
|
26
31
|
|
27
32
|
def self.navigation
|
28
|
-
|
29
|
-
|
33
|
+
load
|
30
34
|
[
|
31
35
|
{ order: 2, link: '/permissions/', text: 'Permissions', target: ::ProxES::Permission, icon: 'check-square' }
|
32
36
|
]
|
data/lib/proxes/forwarder.rb
CHANGED
@@ -10,37 +10,43 @@ module ProxES
|
|
10
10
|
@backend = URI(opts[:backend]) if opts[:backend]
|
11
11
|
end
|
12
12
|
|
13
|
-
def body(request)
|
14
|
-
return nil unless request.body
|
15
|
-
return nil if request.body.is_a? Puma::NullIO
|
16
|
-
return request.body.string if request.body.is_a? StringIO
|
17
|
-
return request.body.read if request.body.is_a? Tempfile
|
18
|
-
request.body
|
19
|
-
end
|
20
|
-
|
21
13
|
def call(env)
|
22
|
-
source_request = Rack::Request.new(env)
|
23
|
-
full_path = source_request.fullpath == '' ? URI.parse(env['REQUEST_URI']).request_uri : source_request.fullpath
|
24
|
-
target_request = Net::HTTP.const_get(source_request.request_method.capitalize).new(full_path)
|
25
|
-
|
26
|
-
request_body = body(source_request)
|
27
|
-
if request_body
|
28
|
-
target_request.body = request_body
|
29
|
-
target_request.content_length = request_body.length
|
30
|
-
target_request.content_type = source_request.content_type if source_request.content_type
|
31
|
-
end
|
32
|
-
|
33
14
|
http = Net::HTTP.new(backend.host, backend.port)
|
34
|
-
|
15
|
+
response = http.request(request_from(env))
|
35
16
|
|
36
|
-
headers = (
|
37
|
-
body =
|
17
|
+
headers = (response.respond_to?(:headers) && response.headers) || self.class.normalize_headers(response.to_hash)
|
18
|
+
body = response.body || ['']
|
38
19
|
body = [body] unless body.respond_to?(:each)
|
39
20
|
|
40
21
|
# Not sure where this is coming from, but it causes timeouts on the client
|
41
22
|
headers.delete('transfer-encoding')
|
42
23
|
|
43
|
-
|
24
|
+
# Ensure that the content length rack middleware kicks in
|
25
|
+
headers.delete('content-length')
|
26
|
+
|
27
|
+
[response.code, headers, body]
|
28
|
+
end
|
29
|
+
|
30
|
+
def request_from(env)
|
31
|
+
source = Rack::Request.new(env)
|
32
|
+
full_path = source.fullpath == '' ? URI.parse(env['REQUEST_URI']).request_uri : source.fullpath
|
33
|
+
target = Net::HTTP.const_get(source.request_method.capitalize).new(full_path)
|
34
|
+
|
35
|
+
body = body_from(source)
|
36
|
+
if body
|
37
|
+
target.body = body
|
38
|
+
target.content_length = body.length
|
39
|
+
target.content_type = source.content_type if source.content_type
|
40
|
+
end
|
41
|
+
target
|
42
|
+
end
|
43
|
+
|
44
|
+
def body_from(request)
|
45
|
+
return nil unless request.body
|
46
|
+
return nil if request.body.is_a? Puma::NullIO
|
47
|
+
return request.body.string if request.body.is_a? StringIO
|
48
|
+
return request.body.read if request.body.is_a? Tempfile
|
49
|
+
request.body
|
44
50
|
end
|
45
51
|
|
46
52
|
class << self
|
data/lib/proxes/security.rb
CHANGED
@@ -27,10 +27,15 @@ module ProxES
|
|
27
27
|
[code, headers, ['{"error":"' + message + '"}']]
|
28
28
|
end
|
29
29
|
|
30
|
+
def redirect(destination, code = 302)
|
31
|
+
[code, { 'Location' => destination}, []]
|
32
|
+
end
|
33
|
+
|
30
34
|
def check(request)
|
31
35
|
check_basic request
|
32
36
|
authorize request, request.request_method.downcase
|
33
37
|
rescue Pundit::NotAuthorizedError
|
38
|
+
return redirect '/_proxes/' if request.get_header('HTTP_ACCEPT').include? 'text/html'
|
34
39
|
log_action(:es_request_denied, details: "#{request.request_method.upcase} #{request.fullpath} (#{request.class.name})")
|
35
40
|
logger.debug "Access denied for #{current_user ? current_user.email : 'Anonymous User'} by security layer: #{request.request_method.upcase} #{request.fullpath} (#{request.class.name})"
|
36
41
|
error 'Not Authorized', 401
|
@@ -50,9 +55,9 @@ module ProxES
|
|
50
55
|
broadcast(:call_completed, endpoint: request.endpoint, duration: Time.now.to_f - start)
|
51
56
|
result
|
52
57
|
rescue Errno::EHOSTUNREACH
|
53
|
-
error 'Could not reach Elasticsearch at ' +
|
58
|
+
error 'Could not reach Elasticsearch at ' + ENV['ELASTICSEARCH_URL']
|
54
59
|
rescue Errno::ECONNREFUSED
|
55
|
-
error 'Elasticsearch not listening at ' +
|
60
|
+
error 'Elasticsearch not listening at ' + ENV['ELASTICSEARCH_URL']
|
56
61
|
end
|
57
62
|
|
58
63
|
def call(env)
|
data/lib/proxes/version.rb
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
|
3
3
|
Sequel.migration do
|
4
4
|
change do
|
5
|
-
create_table :
|
5
|
+
create_table :permissions do
|
6
6
|
primary_key :id
|
7
|
-
|
8
|
-
String :
|
7
|
+
String :verb
|
8
|
+
String :pattern
|
9
9
|
DateTime :created_at
|
10
|
+
foreign_key :role_id, :roles
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proxes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jurgens du Toit
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -429,9 +429,7 @@ files:
|
|
429
429
|
- lib/proxes/request/stats.rb
|
430
430
|
- lib/proxes/security.rb
|
431
431
|
- lib/proxes/version.rb
|
432
|
-
- migrate/
|
433
|
-
- migrate/20170208_audit_log.rb
|
434
|
-
- migrate/20170416_audit_log_details.rb
|
432
|
+
- migrate/20170207_permissions.rb
|
435
433
|
- migrate/20170416_user_specific_permissions.rb
|
436
434
|
- package.json
|
437
435
|
- proxes.gemspec
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
Sequel.migration do
|
4
|
-
change do
|
5
|
-
create_table :users do
|
6
|
-
primary_key :id
|
7
|
-
String :name
|
8
|
-
String :surname
|
9
|
-
String :email
|
10
|
-
DateTime :created_at
|
11
|
-
DateTime :updated_at
|
12
|
-
unique [:email]
|
13
|
-
end
|
14
|
-
|
15
|
-
create_table :identities do
|
16
|
-
primary_key :id
|
17
|
-
foreign_key :user_id, :users
|
18
|
-
String :username
|
19
|
-
String :crypted_password
|
20
|
-
DateTime :created_at
|
21
|
-
DateTime :updated_at
|
22
|
-
unique [:username]
|
23
|
-
end
|
24
|
-
|
25
|
-
create_table :roles do
|
26
|
-
primary_key :id
|
27
|
-
String :name
|
28
|
-
DateTime :created_at
|
29
|
-
DateTime :updated_at
|
30
|
-
unique [:name]
|
31
|
-
end
|
32
|
-
|
33
|
-
create_table :permissions do
|
34
|
-
primary_key :id
|
35
|
-
String :verb
|
36
|
-
String :pattern
|
37
|
-
DateTime :created_at
|
38
|
-
foreign_key :role_id, :roles
|
39
|
-
end
|
40
|
-
|
41
|
-
create_table :roles_users do
|
42
|
-
DateTime :created_at
|
43
|
-
foreign_key :user_id, :users
|
44
|
-
foreign_key :role_id, :roles
|
45
|
-
unique %i[user_id role_id]
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|