proxes 0.2.0 → 0.3.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
  SHA1:
3
- metadata.gz: f09dfca277df91363c5c406d7f7a2a04538ac709
4
- data.tar.gz: 272207ef5bc8708b42cc5cfb41790e68ee54ffb2
3
+ metadata.gz: 7b504f6a2dcb6fa6d41872ad0d203d5a57324567
4
+ data.tar.gz: 203323938f3a6ad123d14a9bd7934af90f40912f
5
5
  SHA512:
6
- metadata.gz: b0ac4a096a65c81667622c772e049352f15cd7bb78bbda5f4c5641968ebcf8f95cf441ec66f200e1aa4e8ae119475addd2840b9f62d9825a5fc07a05fe6b925a
7
- data.tar.gz: 0c19669d5c38423cdf8b1f81f0f0d287a20378c7e848b296d200c0a8539454871746654c67e464a2fba978f0a75cd7d546e3eee81a57fb0c7996fcb9fe3dd450
6
+ metadata.gz: 5d14a2a8d057c7f9c8b94b2c05e72de6d6df3f91719ef41bd93fc5af069960fe8c039f315c6e1394fbaec3b5f8c91b533d498df6a0f7cd524f7a45bd8809a0c4
7
+ data.tar.gz: '0490f5333bbc15dce6c32e9bc6e87dfba9314090482e83a14e7f8753d54512edb765b6d571be5f6d8b03af625a61ffd1f011a06539be5ff5f56c1f61f2305cae'
@@ -1,7 +1,11 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
+ - 2.4.0
4
5
  - 2.3.3
6
+ - 2.2.6
7
+ - 2.1.10
8
+ - 2.0.0
5
9
  - 1.9.3
6
10
  gemfile: Gemfile.ci
7
11
  env:
data/Gemfile.ci CHANGED
@@ -6,8 +6,9 @@ gemspec
6
6
  gem 'sqlite3'
7
7
  gem 'simplecov'
8
8
  gem 'codeclimate-test-reporter', '~> 1.0.0'
9
- if RUBY_VERSION < '1.9.3'
9
+ if RUBY_VERSION < '2.1'
10
10
  gem 'activesupport', '<4.0.0'
11
+ gem 'omniauth', '~>1.4.2'
11
12
  elsif RUBY_VERSION < '2.2.0'
12
13
  gem 'activesupport', '<5.0.0'
13
14
  else
data/README.md CHANGED
@@ -47,7 +47,8 @@ gem install proxes
47
47
 
48
48
  1. Add the components to your rack config file. See the included [`config.ru`](https://github.com/EagerELK/proxes/blob/master/config.ru) file for an example setup
49
49
  2. Add the ProxES rake tasks to your Rakefile: `require 'proxes/rake_tasks'`
50
- 3. Create and populate the DB:
50
+ 3. Set the DB connection as the `DATABASE_URL` ENV variable: `DATABASE_URL=sqlite://development.db`
51
+ 4. Create and populate the DB:
51
52
 
52
53
  ```bash
53
54
  bundle exec rake proxes:migrate
data/config.ru CHANGED
@@ -14,7 +14,6 @@ Sequel.extension :migration
14
14
  Sequel::Migrator.check_current(DB, './migrate')
15
15
 
16
16
  use Rack::Static, urls: ['/css', '/js'], root: 'public'
17
- use Rack::MethodOverride
18
17
  use Rack::Session::Cookie,
19
18
  key: '_ProxES_session',
20
19
  #:secure=>!TEST_MODE, # Uncomment if only allowing https:// access
@@ -1,4 +1,3 @@
1
1
  ---
2
2
  - name: default
3
3
  class: Logger
4
- options: 'logs/proxes.log'
@@ -25,6 +25,10 @@ module ProxES
25
25
  def map(&block)
26
26
  @mutex.synchronize{@hash.map(&block)}
27
27
  end
28
+
29
+ def inject(memo, &block)
30
+ @mutex.synchronize{@hash.inject(memo, &block)}
31
+ end
28
32
  end
29
33
 
30
34
  # Ripped off from Roda - https://github.com/jeremyevans/roda
@@ -80,12 +84,19 @@ module ProxES
80
84
  nil
81
85
  end
82
86
 
87
+ # Return a hash of controllers with their routes as keys: `{ '/users' => ProxES::Controllers::Users }`
83
88
  def routes
84
- {} # Return a hash of controllers with their routes as keys: `{ '/users' => ProxES::Controllers::Users }`
89
+ Plugins.plugins.inject({}) do |memo, plugin|
90
+ memo.merge!(plugin[1].route_mappings) if plugin[1].respond_to?(:route_mappings)
91
+ memo
92
+ end
85
93
  end
86
94
 
87
- def nav_items
88
- [] # Return an ordered list of navigation items: `[{order:0, link:'/users/' text:'Users'}, {order:1, link:'/roles/', text:'Roles'}]
95
+ # Return an ordered list of navigation items: `[{order:0, link:'/users/', text:'Users'}, {order:1, link:'/roles/', text:'Roles'}]
96
+ def navigation
97
+ Plugins.plugins.map do |_key, plugin|
98
+ plugin.nav_items if plugin.respond_to?(:nav_items)
99
+ end.flatten.sort_by { |h| h[:order] }
89
100
  end
90
101
 
91
102
  def migrations
@@ -13,12 +13,13 @@ module ProxES
13
13
  class Application < Sinatra::Base
14
14
  set :root, ::File.expand_path(::File.dirname(__FILE__) + '/../../../')
15
15
  # The order here is important, since Wisper has a deprecated method respond_with method
16
- helpers Wisper::Publisher, ProxES::Helpers::Wisper
17
- helpers ProxES::Helpers::Pundit, ProxES::Helpers::Views, ProxES::Helpers::Authentication
16
+ helpers Wisper::Publisher, Helpers::Wisper
17
+ helpers Helpers::Pundit, Helpers::Views, Helpers::Authentication
18
18
 
19
19
  register Sinatra::Flash, Sinatra::RespondWith
20
20
 
21
21
  use Rack::PostBodyContentTypeParser
22
+ use Rack::MethodOverride
22
23
 
23
24
  configure :production do
24
25
  disable :show_exceptions
@@ -41,7 +42,7 @@ module ProxES
41
42
  haml :error, locals: { title: 'Something went wrong', message: error }
42
43
  end
43
44
 
44
- error ::ProxES::Helpers::NotAuthenticated do
45
+ error Helpers::NotAuthenticated do
45
46
  flash[:warning] = 'Please log in first.'
46
47
  redirect '/auth/identity'
47
48
  end
@@ -4,7 +4,7 @@ require 'proxes/helpers/component'
4
4
 
5
5
  module ProxES
6
6
  class Component < Application
7
- helpers ProxES::Helpers::Component
7
+ helpers Helpers::Component
8
8
  set base_path: nil
9
9
  set dehumanized: nil
10
10
  set view_location: nil
@@ -105,10 +105,24 @@ module ProxES
105
105
  success = entity.valid? && entity.save
106
106
  log_action("#{dehumanized}_update".to_sym) if success && settings.track_actions
107
107
  if success
108
- flash[:success] = "#{heading} Updated"
109
- redirect "#{base_path}/#{entity.id}"
108
+ respond_to do |format|
109
+ format.html do
110
+ flash[:success] = "#{heading} Updated"
111
+ redirect "#{base_path}/#{entity.id}"
112
+ end
113
+ format.json do
114
+ content_type 'application/json'
115
+ headers 'Location' => "#{base_path}/#{entity.id}"
116
+ body entity.to_hash.to_json
117
+ status 200
118
+ end
119
+ end
110
120
  else
111
- haml :"#{view_location}/edit", locals: { entity: entity, title: heading(:edit) }
121
+ respond_to do |format|
122
+ format.html do
123
+ haml :"#{view_location}/edit", locals: { entity: entity, title: heading(:edit) }
124
+ end
125
+ end
112
126
  end
113
127
  end
114
128
 
@@ -120,8 +134,17 @@ module ProxES
120
134
  entity.destroy
121
135
 
122
136
  log_action("#{dehumanized}_delete".to_sym) if settings.track_actions
123
- flash[:success] = "#{heading} Deleted"
124
- redirect base_path.to_s
137
+ respond_to do |format|
138
+ format.html do
139
+ flash[:success] = "#{heading} Deleted"
140
+ redirect base_path.to_s
141
+ end
142
+ format.json do
143
+ content_type 'application/json'
144
+ headers 'Location' => '/_proxes/users'
145
+ status 204
146
+ end
147
+ end
125
148
  end
126
149
  end
127
150
  end
@@ -16,8 +16,8 @@ module ProxES
16
16
 
17
17
  locals = {
18
18
  title: heading(:new),
19
- entity: ProxES::User.new,
20
- identity: ProxES::Identity.new
19
+ entity: User.new,
20
+ identity: Identity.new
21
21
  }
22
22
  haml :"#{view_location}/new", locals: locals, layout_opts: { locals: locals }
23
23
  end
@@ -93,8 +93,18 @@ module ProxES
93
93
  roles.each { |role_id| entity.add_role(role_id) } if roles
94
94
  entity.check_roles
95
95
  log_action("#{dehumanized}_update".to_sym) if settings.track_actions
96
- flash[:success] = "#{heading} Updated"
97
- redirect "/_proxes/users/#{entity.id}"
96
+ respond_to do |format|
97
+ format.html do
98
+ flash[:success] = "#{heading} Updated"
99
+ redirect "/_proxes/users/#{entity.id}"
100
+ end
101
+ format.json do
102
+ content_type 'application/json'
103
+ headers 'Location' => "/_proxes/users/#{entity.id}"
104
+ body entity.to_hash.to_json
105
+ status 200
106
+ end
107
+ end
98
108
  else
99
109
  haml :"#{view_location}/edit", locals: { entity: entity, title: heading(:edit) }
100
110
  end
@@ -119,7 +129,7 @@ module ProxES
119
129
  end
120
130
 
121
131
  # Delete
122
- delete '/:id' do |id|
132
+ delete '/:id', provides: [:html, :json] do |id|
123
133
  entity = dataset[id.to_i]
124
134
  halt 404 unless entity
125
135
  authorize entity, :delete
@@ -129,8 +139,17 @@ module ProxES
129
139
  entity.destroy
130
140
 
131
141
  log_action("#{dehumanized}_delete".to_sym) if settings.track_actions
132
- flash[:success] = "#{heading} Deleted"
133
- redirect '/_proxes/users'
142
+ respond_to do |format|
143
+ format.html do
144
+ flash[:success] = "#{heading} Deleted"
145
+ redirect '/_proxes/users'
146
+ end
147
+ format.json do
148
+ content_type 'application/json'
149
+ headers 'Location' => '/_proxes/users'
150
+ status 204
151
+ end
152
+ end
134
153
  end
135
154
 
136
155
  # Profile
@@ -8,7 +8,7 @@ module ProxES
8
8
  include ::Pundit
9
9
 
10
10
  def authorize(record, query = nil)
11
- if record.is_a?(::ProxES::Request)
11
+ if record.is_a?(Request)
12
12
  query = record.request_method.downcase
13
13
  elsif query.nil?
14
14
  raise ArgumentError, 'Pundit cannot determine the query'
@@ -1,7 +1,3 @@
1
- # Use this to restrict users, clusters, etc.
2
- # Also add a check to ensure that this is running, so that if people try to
3
- # bypass it it gets picked up
4
- # Also run regular async checks as another check
5
1
  require 'wisper'
6
2
 
7
3
  module ProxES
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  module ProxES
3
3
  class Request
4
- class RootPolicy < ProxES::RequestPolicy
5
- class Scope < ProxES::RequestPolicy::Scope
4
+ class RootPolicy < RequestPolicy
5
+ class Scope < RequestPolicy::Scope
6
6
  def resolve
7
7
  scope
8
8
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  module ProxES
3
3
  class Request
4
- class SearchPolicy < ProxES::RequestPolicy
5
- class Scope < ProxES::RequestPolicy::Scope
4
+ class SearchPolicy < RequestPolicy
5
+ class Scope < RequestPolicy::Scope
6
6
  def resolve
7
7
  patterns = ProxES::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) }
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  module ProxES
3
3
  class Request
4
- class SnapshotPolicy < ProxES::RequestPolicy
5
- class Scope < ProxES::RequestPolicy::Scope
4
+ class SnapshotPolicy < RequestPolicy
5
+ class Scope < RequestPolicy::Scope
6
6
  def resolve
7
7
  scope
8
8
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  module ProxES
3
3
  class Request
4
- class StatsPolicy < ProxES::RequestPolicy
5
- class Scope < ProxES::RequestPolicy::Scope
4
+ class StatsPolicy < RequestPolicy
5
+ class Scope < RequestPolicy::Scope
6
6
  def resolve
7
7
  patterns = ProxES::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) }
@@ -0,0 +1,35 @@
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
+ module ProxES
10
+ class ProxES
11
+ def self.migration_folder
12
+ File.expand_path('../../../migrate', __FILE__)
13
+ end
14
+
15
+ def self.route_mappings
16
+ {
17
+ '/' => App,
18
+ '/users' => Users,
19
+ '/roles' => Roles,
20
+ '/permissions' => Permissions,
21
+ '/audit-logs' => AuditLogs,
22
+ }
23
+ end
24
+
25
+ def self.nav_items
26
+ [
27
+ { order: 0, link:'/users/', text: 'Users', target: User, icon: 'user' },
28
+ { order: 1, link:'/roles/', text: 'Roles', target: Role, icon: 'group' },
29
+ { order: 2, link:'/permissions/', text: 'Permissions', target: Permission, icon: 'check-square' },
30
+ ]
31
+ end
32
+ end
33
+ end
34
+
35
+ ProxES::Container::Plugins.register_plugin(:proxes, ProxES::ProxES)
@@ -13,7 +13,7 @@ module ProxES
13
13
  end
14
14
  begin
15
15
  require 'proxes/request/' + endpoint.downcase
16
- ProxES::Request.const_get(endpoint).new(env)
16
+ Request.const_get(endpoint).new(env)
17
17
  rescue LoadError
18
18
  self.new(env)
19
19
  end
@@ -4,7 +4,7 @@ require 'proxes/request'
4
4
 
5
5
  module ProxES
6
6
  class Request
7
- class Root < ProxES::Request
7
+ class Root < Request
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ require 'proxes/request'
4
4
 
5
5
  module ProxES
6
6
  class Request
7
- class Search < ProxES::Request
7
+ class Search < Request
8
8
  attr_reader :index, :type
9
9
  attr_reader :type
10
10
 
@@ -4,7 +4,7 @@ require 'proxes/request'
4
4
 
5
5
  module ProxES
6
6
  class Request
7
- class Snapshot < ProxES::Request
7
+ class Snapshot < Request
8
8
  attr_reader :repository
9
9
 
10
10
  def parse
@@ -4,7 +4,7 @@ require 'proxes/request'
4
4
 
5
5
  module ProxES
6
6
  class Request
7
- class Stats < ProxES::Request
7
+ class Stats < Request
8
8
  attr_reader :index
9
9
 
10
10
  def index=(idx)
@@ -11,12 +11,12 @@ module ProxES
11
11
  class Security
12
12
  attr_reader :env, :logger
13
13
 
14
- include ProxES::Helpers::Authentication
15
- include ProxES::Helpers::Pundit
14
+ include Helpers::Authentication
15
+ include Helpers::Pundit
16
16
 
17
17
  def initialize(app, logger = nil)
18
18
  @app = app
19
- @logger = logger || ProxES::Services::Logger.instance
19
+ @logger = logger || Services::Logger.instance
20
20
  end
21
21
 
22
22
  def error(message, code = 500)
@@ -26,7 +26,7 @@ module ProxES
26
26
  def call(env)
27
27
  @env = env
28
28
 
29
- request = ProxES::Request.from_env(env)
29
+ request = Request.from_env(env)
30
30
 
31
31
  logger.debug '==========================BEFORE================================================'
32
32
  logger.debug '= ' + "Request: #{request.fullpath}".ljust(76) + ' ='
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ProxES
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency 'database_cleaner'
29
29
  spec.add_development_dependency 'factory_girl'
30
30
 
31
+ spec.add_dependency 'rake', '~> 10.0'
31
32
  spec.add_dependency 'rack-proxy'
32
33
  spec.add_dependency 'rack-contrib'
33
34
  spec.add_dependency 'sinatra'
@@ -2,4 +2,9 @@ import React from 'react';
2
2
  import ReactDOM from 'react-dom';
3
3
  import ProxesComponents from 'react-proxes-components/react-proxes-components';
4
4
 
5
- ReactDOM.render(<ProxesComponents pollInterval="30000" elasticsearch_url="./"/>, document.getElementById('react-dashboard'));
5
+ ReactDOM.render(<ProxesComponents pollInterval="30000"/>, document.getElementById('react-dashboard'));
6
+
7
+ // ReactDOM.render(
8
+ // <Health store={new ESStore()}/>,
9
+ // document.getElementById('indexlist')
10
+ // );
@@ -4,23 +4,12 @@
4
4
  %a{ href: '/_proxes' }
5
5
  %i.fa.fa-dashboard.fa-fw
6
6
  Dashboard
7
- - if current_user.super_admin?
8
- %li
9
- %a{ href: '/_proxes/users' }
10
- %i.fa.fa-user.fa-fw
11
- Users
12
- %li
13
- %a{ href: '/_proxes/roles' }
14
- %i.fa.fa-group.fa-fw
15
- Roles
16
- %li
17
- %a{ href: '/_proxes/permissions' }
18
- %i.fa.fa-check-square-o.fa-fw
19
- Permissions
20
- %li
21
- %a{ href: '/_proxes/settings' }
22
- %i.fa.fa-cog.fa-fw
23
- Settings
7
+ - ProxES::Container.navigation.each do |item|
8
+ - if policy(item[:target]).list?
9
+ %li
10
+ %a{ href: "/_proxes#{item[:link]}" }
11
+ %i.fa.fa-fw{ class: "fa-#{item[:icon]}" }
12
+ = item[:text]
24
13
  - else
25
14
  %li.active
26
15
  %a{ href: '/auth/identity' }
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.2.0
4
+ version: 0.3.0
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-02-09 00:00:00.000000000 Z
11
+ date: 2017-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '10.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '10.0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rack-proxy
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -383,6 +397,7 @@ files:
383
397
  - lib/proxes/policies/role_policy.rb
384
398
  - lib/proxes/policies/token_policy.rb
385
399
  - lib/proxes/policies/user_policy.rb
400
+ - lib/proxes/proxes.rb
386
401
  - lib/proxes/rake_tasks.rb
387
402
  - lib/proxes/request.rb
388
403
  - lib/proxes/request/root.rb
@@ -393,8 +408,8 @@ files:
393
408
  - lib/proxes/seed.rb
394
409
  - lib/proxes/services/logger.rb
395
410
  - lib/proxes/version.rb
396
- - migrate/001_tables.rb
397
- - migrate/002_audit_log.rb
411
+ - migrate/20170207_01_base_tables.rb
412
+ - migrate/20170207_02_audit_log.rb
398
413
  - package.json
399
414
  - proxes.gemspec
400
415
  - public/js/bundle.js
@@ -450,7 +465,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
450
465
  version: '0'
451
466
  requirements: []
452
467
  rubyforge_project:
453
- rubygems_version: 2.6.8
468
+ rubygems_version: 2.6.10
454
469
  signing_key:
455
470
  specification_version: 4
456
471
  summary: Rack wrapper around Elasticsearch to provide security and management features