proxes 0.3.1 → 0.3.2

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: 1c294e375262e708cfc0ef3645d3b6b9399f25e0
4
- data.tar.gz: 48d1100105c1f9dc9582107c5d6d7af0d34c45fc
3
+ metadata.gz: d8ddd26a93e1cfb0468e7579d07f31b65763ba61
4
+ data.tar.gz: f7e3267ea6534ae304ece5be57826bb6ae3fa446
5
5
  SHA512:
6
- metadata.gz: 15ccea3a78653a32eb3e36204c5e411b38f56d045d392cc738a496c9c8289bb461909f3093ec92542c1f01482fcd3bfc6101825a259752245fd861defe039275
7
- data.tar.gz: 65807f0075dd7910d19fa1424351963d3dd5a2fb944b72a7e2ab3cf98024479d095cbda3aa76237811b3298959ee108fd8cfeb72665936142ddc6651a730fb82
6
+ metadata.gz: b833d8d7dc5aae7b024f5ba3a78671e38cc7f60e1d0101d4d447d20bddeaebbd6b378619f6320d6908d7eb6c9ec825a81ae46aed687296d4426bc836bf34582a
7
+ data.tar.gz: e28229e229241ffe38770b4526d0feba9a9e7581520273d82acb6f9ffb0e770d96c3e73a4f00da26de60de0964ff99716931ddc256f27bb9f70df12098db44c3
data/Gemfile.dev.lock CHANGED
@@ -9,7 +9,7 @@ GIT
9
9
  PATH
10
10
  remote: .
11
11
  specs:
12
- proxes (0.2.0)
12
+ proxes (0.3.2)
13
13
  bcrypt
14
14
  elasticsearch
15
15
  haml
@@ -18,7 +18,7 @@ PATH
18
18
  omniauth-identity
19
19
  pundit
20
20
  rack-contrib
21
- rack-proxy
21
+ rake (~> 10.0)
22
22
  sequel
23
23
  sinatra
24
24
  sinatra-contrib
@@ -44,12 +44,12 @@ GEM
44
44
  database_cleaner (1.5.3)
45
45
  diff-lcs (1.2.5)
46
46
  docile (1.1.5)
47
- elasticsearch (5.0.1)
48
- elasticsearch-api (= 5.0.1)
49
- elasticsearch-transport (= 5.0.1)
50
- elasticsearch-api (5.0.1)
47
+ elasticsearch (5.0.3)
48
+ elasticsearch-api (= 5.0.3)
49
+ elasticsearch-transport (= 5.0.3)
50
+ elasticsearch-api (5.0.3)
51
51
  multi_json
52
- elasticsearch-transport (5.0.1)
52
+ elasticsearch-transport (5.0.3)
53
53
  faraday
54
54
  multi_json
55
55
  factory_girl (4.8.0)
@@ -60,7 +60,7 @@ GEM
60
60
  git-version-bump (0.15.1)
61
61
  haml (4.0.7)
62
62
  tilt
63
- hashie (3.4.6)
63
+ hashie (3.5.5)
64
64
  i18n (0.7.0)
65
65
  json (2.0.2)
66
66
  listen (3.1.5)
@@ -72,9 +72,9 @@ GEM
72
72
  minitest (5.10.1)
73
73
  multi_json (1.12.1)
74
74
  multipart-post (2.0.0)
75
- omniauth (1.3.2)
76
- hashie (>= 1.2, < 4)
77
- rack (>= 1.0, < 3)
75
+ omniauth (1.6.1)
76
+ hashie (>= 3.4.6, < 3.6.0)
77
+ rack (>= 1.6.2, < 3)
78
78
  omniauth-identity (1.1.1)
79
79
  bcrypt-ruby (~> 3.0)
80
80
  omniauth (~> 1.0)
@@ -93,8 +93,6 @@ GEM
93
93
  rack (~> 1.4)
94
94
  rack-protection (1.5.3)
95
95
  rack
96
- rack-proxy (0.6.0)
97
- rack
98
96
  rack-test (0.6.3)
99
97
  rack (>= 1.0)
100
98
  racksh (1.0.0)
@@ -118,13 +116,13 @@ GEM
118
116
  rspec-support (~> 3.5.0)
119
117
  rspec-support (3.5.0)
120
118
  ruby_dep (1.5.0)
121
- sequel (4.42.1)
119
+ sequel (4.44.0)
122
120
  simplecov (0.12.0)
123
121
  docile (~> 1.1.0)
124
122
  json (>= 1.8, < 3)
125
123
  simplecov-html (~> 0.10.0)
126
124
  simplecov-html (0.10.0)
127
- sinatra (1.4.7)
125
+ sinatra (1.4.8)
128
126
  rack (~> 1.5)
129
127
  rack-protection (~> 1.4)
130
128
  tilt (>= 1.3, < 3)
@@ -140,10 +138,10 @@ GEM
140
138
  slop (3.6.0)
141
139
  sqlite3 (1.3.12)
142
140
  thread_safe (0.3.5)
143
- tilt (2.0.6)
141
+ tilt (2.0.7)
144
142
  tzinfo (1.2.2)
145
143
  thread_safe (~> 0.1)
146
- wisper (1.6.1)
144
+ wisper (2.0.0)
147
145
 
148
146
  PLATFORMS
149
147
  ruby
@@ -156,11 +154,10 @@ DEPENDENCIES
156
154
  pry-byebug
157
155
  rack-test
158
156
  racksh
159
- rake (~> 10.0)
160
157
  rerun!
161
158
  rspec (~> 3.0)
162
159
  simplecov
163
160
  sqlite3
164
161
 
165
162
  BUNDLED WITH
166
- 1.13.7
163
+ 1.14.6
data/config.ru CHANGED
@@ -4,19 +4,13 @@ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
4
4
 
5
5
  raise 'Unconfigured' unless ENV['ELASTICSEARCH_URL']
6
6
 
7
- use Rack::Static, urls: ['/css', '/js'], root: 'public'
8
- use Rack::MethodOverride
7
+ require 'proxes'
8
+ require 'proxes/omniauth'
9
9
  use Rack::Session::Cookie,
10
10
  key: '_ProxES_session',
11
11
  #:secure=>!TEST_MODE, # Uncomment if only allowing https:// access
12
12
  secret: File.read('.session_secret')
13
13
 
14
- require 'proxes'
15
- require 'omniauth'
16
- require 'omniauth-identity'
17
- require 'proxes/models/identity'
18
- require 'proxes/controllers/auth_identity'
19
- # OmniAuth.config.test_mode = true
20
14
  use OmniAuth::Builder do
21
15
  # The identity provider is used by the App.
22
16
  provider :identity,
@@ -36,10 +30,12 @@ end
36
30
 
37
31
  # Proxy all Elasticsearch requests
38
32
  require 'proxes/security'
33
+ require 'proxes/forwarder'
39
34
  map '/' do
40
35
  # Security
41
36
  use ProxES::Security, ProxES::Services::Logger.instance
37
+ use Rack::ContentLength
42
38
 
43
39
  # Forward requests to ES
44
- run Rack::Proxy.new(backend: ENV['ELASTICSEARCH_URL'])
40
+ run ProxES::Forwarder.new(backend: ENV['ELASTICSEARCH_URL'])
45
41
  end
@@ -5,7 +5,7 @@ require 'proxes/policies/audit_log_policy'
5
5
 
6
6
  module ProxES
7
7
  class AuditLogs < Component
8
- set model_class: ProxES::AuditLog
8
+ set model_class: AuditLog
9
9
 
10
10
  get '/new' do
11
11
  halt 404
@@ -5,6 +5,6 @@ require 'proxes/policies/permission_policy'
5
5
 
6
6
  module ProxES
7
7
  class Permissions < Component
8
- set model_class: ProxES::Permission
8
+ set model_class: Permission
9
9
  end
10
10
  end
@@ -5,6 +5,6 @@ require 'proxes/policies/role_policy'
5
5
 
6
6
  module ProxES
7
7
  class Roles < Component
8
- set model_class: ProxES::Role
8
+ set model_class: Role
9
9
  end
10
10
  end
@@ -7,7 +7,7 @@ require 'proxes/policies/identity_policy'
7
7
 
8
8
  module ProxES
9
9
  class Users < Component
10
- set model_class: ProxES::User
10
+ set model_class: User
11
11
  set track_actions: true
12
12
 
13
13
  # New
@@ -0,0 +1,40 @@
1
+ require 'net/http'
2
+ require 'rack'
3
+
4
+ module ProxES
5
+ # A lot of code in this comes from Rack::Proxy
6
+ class Forwarder
7
+ attr_reader :backend, :streaming
8
+
9
+ def initialize(opts= {})
10
+ @backend = URI(opts[:backend]) if opts[:backend]
11
+ end
12
+
13
+ def call(env)
14
+ source_request = Rack::Request.new(env)
15
+ full_path = source_request.fullpath == "" ? URI.parse(env['REQUEST_URI']).request_uri : source_request.fullpath
16
+ target_request = Net::HTTP.const_get(source_request.request_method.capitalize).new(full_path)
17
+
18
+ http = Net::HTTP.new(backend.host, backend.port)
19
+ target_response = http.request(target_request)
20
+
21
+ headers = (target_response.respond_to?(:headers) && target_response.headers) || self.class.normalize_headers(target_response.to_hash)
22
+ body = target_response.body || [""]
23
+ body = [body] unless body.respond_to?(:each)
24
+
25
+ # Not sure where this is coming from, but it causes timeouts on the client
26
+ headers.delete('transfer-encoding')
27
+
28
+ [target_response.code, headers, body]
29
+ end
30
+
31
+ class << self
32
+ def normalize_headers(headers)
33
+ mapped = headers.map do |k, v|
34
+ [k, if v.is_a? Array then v.join("\n") else v end]
35
+ end
36
+ Rack::Utils::HeaderHash.new Hash[mapped]
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,4 @@
1
+ require 'omniauth'
2
+ require 'omniauth-identity'
3
+ require 'proxes/models/identity'
4
+ require 'proxes/controllers/auth_identity'
@@ -4,7 +4,7 @@ module ProxES
4
4
  class SearchPolicy < RequestPolicy
5
5
  class Scope < RequestPolicy::Scope
6
6
  def resolve
7
- patterns = ProxES::Permission.where(verb: 'INDEX', role: user.roles).map do |permission|
7
+ patterns = Permission.where(verb: 'INDEX', role: user.roles).map do |permission|
8
8
  permission.pattern.gsub(/\{user.(.*)\}/) { |match| user.send(Regexp.last_match[1].to_sym) }
9
9
  end
10
10
  filter scope.index, patterns
@@ -4,7 +4,7 @@ module ProxES
4
4
  class StatsPolicy < RequestPolicy
5
5
  class Scope < RequestPolicy::Scope
6
6
  def resolve
7
- patterns = ProxES::Permission.where(verb: 'INDEX', role: user.roles).map do |permission|
7
+ patterns = Permission.where(verb: 'INDEX', role: user.roles).map do |permission|
8
8
  permission.pattern.gsub(/\{user.(.*)\}/) { |match| user.send(Regexp.last_match[1].to_sym) }
9
9
  end
10
10
  filter scope.index, patterns
@@ -20,13 +20,13 @@ module ProxES
20
20
  return false if user.nil?
21
21
 
22
22
  if record.indices?
23
- patterns = ProxES::Permission.where(verb: 'INDEX', role: user.roles).map do |permission|
23
+ patterns = Permission.where(verb: 'INDEX', role: user.roles).map do |permission|
24
24
  permission.pattern.gsub(/\{user.(.*)\}/) { |match| user.send(Regexp.last_match[1].to_sym) }
25
25
  end
26
26
  return filter(record.index, patterns).count.positive?
27
27
  else
28
28
  # Give me all the user's permissions that match the verb
29
- ProxES::Permission.where(verb: method_sym[0..-2].upcase, role: user.roles).each do |permission|
29
+ Permission.where(verb: method_sym[0..-2].upcase, role: user.roles).each do |permission|
30
30
  return true if record.path =~ %r{#{permission.pattern}}
31
31
  end
32
32
  end
data/lib/proxes/proxes.rb CHANGED
@@ -1,11 +1,4 @@
1
1
  # frozen_string_literal: true
2
- require 'proxes'
3
- require 'proxes/db'
4
- require 'proxes/controllers/users'
5
- require 'proxes/controllers/roles'
6
- require 'proxes/controllers/permissions'
7
- require 'proxes/controllers/audit_logs'
8
-
9
2
  module ProxES
10
3
  class ProxES
11
4
  def self.migration_folder
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  require 'proxes/services/logger'
3
- require 'rack-proxy'
4
3
  require 'proxes/request'
5
4
  require 'proxes/policies/request_policy'
6
5
  require 'proxes/helpers/pundit'
data/lib/proxes/seed.rb CHANGED
@@ -4,6 +4,6 @@ require 'proxes/models/permission'
4
4
 
5
5
  ProxES::Role.find_or_create(name: 'user')
6
6
  sa = ProxES::Role.find_or_create(name: 'super_admin')
7
- %w(GET POST PUT DELETE HEAD OPTIONS).each do |verb|
7
+ %w(GET POST PUT DELETE HEAD OPTIONS INDEX).each do |verb|
8
8
  ProxES::Permission.find_or_create(role: sa, verb: verb, pattern: '.*')
9
9
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ProxES
3
- VERSION = '0.3.1'
3
+ VERSION = '0.3.2'
4
4
  end
data/proxes.gemspec CHANGED
@@ -21,7 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ['lib']
22
22
 
23
23
  spec.add_development_dependency 'bundler', '~> 1.12'
24
- spec.add_development_dependency 'rake', '~> 10.0'
25
24
  spec.add_development_dependency 'rspec', '~> 3.0'
26
25
  spec.add_development_dependency 'racksh'
27
26
  spec.add_development_dependency 'rack-test'
@@ -29,7 +28,6 @@ Gem::Specification.new do |spec|
29
28
  spec.add_development_dependency 'factory_girl'
30
29
 
31
30
  spec.add_dependency 'rake', '~> 10.0'
32
- spec.add_dependency 'rack-proxy'
33
31
  spec.add_dependency 'rack-contrib'
34
32
  spec.add_dependency 'sinatra'
35
33
  spec.add_dependency 'sinatra-flash'
data/public/js/bundle.js CHANGED
@@ -28977,7 +28977,7 @@ var _reactProxesComponents2 = _interopRequireDefault(_reactProxesComponents);
28977
28977
 
28978
28978
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
28979
28979
 
28980
- _reactDom2.default.render(_react2.default.createElement(_reactProxesComponents2.default, { pollInterval: '30000' }), document.getElementById('react-dashboard'));
28980
+ _reactDom2.default.render(_react2.default.createElement(_reactProxesComponents2.default, { pollInterval: '30000', elasticsearch_url: './' }), document.getElementById('react-dashboard'));
28981
28981
 
28982
28982
  // ReactDOM.render(
28983
28983
  // <Health store={new ESStore()}/>,
data/views/layout.haml CHANGED
@@ -45,4 +45,4 @@
45
45
  %script{ type: 'text/javascript', src: 'https://cdnjs.cloudflare.com/ajax/libs/metisMenu/2.5.2/metisMenu.min.js' }
46
46
  %script{ type: 'text/javascript', src: 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js' }
47
47
  %script{ type: 'text/javascript', src: 'https://cdnjs.cloudflare.com/ajax/libs/react/15.4.1/react.min.js' }
48
- %script{ type: 'text/javascript', src: '/js/bundle.js' }
48
+ %script{ type: 'text/javascript', src: '/_proxes/js/bundle.js' }
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.3.1
4
+ version: 0.3.2
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-03-24 00:00:00.000000000 Z
11
+ date: 2017-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.12'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '10.0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -122,20 +108,6 @@ dependencies:
122
108
  - - "~>"
123
109
  - !ruby/object:Gem::Version
124
110
  version: '10.0'
125
- - !ruby/object:Gem::Dependency
126
- name: rack-proxy
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :runtime
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
111
  - !ruby/object:Gem::Dependency
140
112
  name: rack-contrib
141
113
  requirement: !ruby/object:Gem::Requirement
@@ -371,6 +343,7 @@ files:
371
343
  - lib/proxes/controllers/roles.rb
372
344
  - lib/proxes/controllers/users.rb
373
345
  - lib/proxes/db.rb
346
+ - lib/proxes/forwarder.rb
374
347
  - lib/proxes/helpers/authentication.rb
375
348
  - lib/proxes/helpers/component.rb
376
349
  - lib/proxes/helpers/indices.rb
@@ -385,6 +358,7 @@ files:
385
358
  - lib/proxes/models/permission.rb
386
359
  - lib/proxes/models/role.rb
387
360
  - lib/proxes/models/user.rb
361
+ - lib/proxes/omniauth.rb
388
362
  - lib/proxes/policies/application_policy.rb
389
363
  - lib/proxes/policies/audit_log_policy.rb
390
364
  - lib/proxes/policies/identity_policy.rb