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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 110bfadb9580417402ed8e47ae66a39c2d2347ac
4
- data.tar.gz: 48eb4c42bf8de55da0dea02bf8607ba6540c7d52
3
+ metadata.gz: ad607a464e38ed6387d1be30475a61c26eb81689
4
+ data.tar.gz: 429939f8285054543348f46233871807ee8eade7
5
5
  SHA512:
6
- metadata.gz: 2fffacb9260796bff10b93befcb696e0e4bbd65a4759b0cbd7a69f09b0c81b7c72618cecf4ebc0fc9c11cc0981b2ce194a99e757db40fd55ffd3e6da7a2cb8ca
7
- data.tar.gz: befa0e27737533a6a1d50c3a0c5070ecb85931a582c735ce41c0993ad9fed5d3a4f803b729e8a1aff39b491b6a7b4baa877623e8559a4c899c6a3c01acc38f59
6
+ metadata.gz: 381152117b4e243e830d2bfe5db85f0e574c9c8ffacc441d970fb88ea5c8d44983bfef3b7cb88868757cd41ef417f7331c7c5412f6534331ab6289ae65af7abe
7
+ data.tar.gz: 837409d7f0f4c9782ecf433f402fe98d8528bcdb15beffbbecdddb969865e344877adb81f73e47f1d7fc6719868434c61562bd38fe53b40fc21ebdabb2db239c
@@ -11,6 +11,7 @@ services:
11
11
  - elasticsearch
12
12
  before_script:
13
13
  - sleep 10
14
+ - bundle exec rake ditty:prep
14
15
  before_install: gem install bundler -v 1.12.5
15
16
  addons:
16
17
  code_climate:
data/Gemfile.ci CHANGED
@@ -4,6 +4,7 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'codeclimate-test-reporter', '~> 1.0.0'
7
+ gem 'ditty', git: 'https://github.com/EagerELK/ditty.git', branch: 'master'
7
8
  gem 'dotenv'
8
9
  gem 'rspec'
9
10
  gem 'rubocop'
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
- controllers = File.expand_path('../../../proxes/controllers', __FILE__)
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
- require 'proxes/models/permission'
29
-
33
+ load
30
34
  [
31
35
  { order: 2, link: '/permissions/', text: 'Permissions', target: ::ProxES::Permission, icon: 'check-square' }
32
36
  ]
@@ -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
- target_response = http.request(target_request)
15
+ response = http.request(request_from(env))
35
16
 
36
- headers = (target_response.respond_to?(:headers) && target_response.headers) || self.class.normalize_headers(target_response.to_hash)
37
- body = target_response.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
- [target_response.code, headers, body]
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
@@ -5,7 +5,7 @@ require 'ditty/models/user'
5
5
  require 'ditty/models/role'
6
6
 
7
7
  module ProxES
8
- class Permission < Sequel::Model
8
+ class Permission < ::Sequel::Model
9
9
  include ::Ditty::Base
10
10
 
11
11
  many_to_one :role, class: ::Ditty::Role
@@ -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 ' + env['ELASTICSEARCH_URL']
58
+ error 'Could not reach Elasticsearch at ' + ENV['ELASTICSEARCH_URL']
54
59
  rescue Errno::ECONNREFUSED
55
- error 'Elasticsearch not listening at ' + env['ELASTICSEARCH_URL']
60
+ error 'Elasticsearch not listening at ' + ENV['ELASTICSEARCH_URL']
56
61
  end
57
62
 
58
63
  def call(env)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProxES
4
- VERSION = '0.8.0'.freeze
4
+ VERSION = '0.8.1'.freeze
5
5
  end
@@ -2,11 +2,12 @@
2
2
 
3
3
  Sequel.migration do
4
4
  change do
5
- create_table :audit_logs do
5
+ create_table :permissions do
6
6
  primary_key :id
7
- foreign_key :user_id, :users, null: true
8
- String :action
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.0
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-02 00:00:00.000000000 Z
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/20170207_base_tables.rb
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
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- Sequel.migration do
4
- change do
5
- alter_table :audit_logs do
6
- add_column :details, String, text: true
7
- end
8
- end
9
- end