proxes 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +0 -0
  3. data/.gitignore +0 -0
  4. data/.pryrc +6 -0
  5. data/.rspec +0 -0
  6. data/.rubocop.yml +0 -0
  7. data/.ruby-version +0 -0
  8. data/.travis.yml +0 -0
  9. data/Gemfile +0 -0
  10. data/Gemfile.ci +0 -0
  11. data/Gemfile.dev +1 -1
  12. data/Gemfile.dev.lock +14 -3
  13. data/LICENSE.txt +1 -1
  14. data/README.md +7 -3
  15. data/Rakefile +0 -0
  16. data/Vagrantfile +0 -0
  17. data/config.ru +2 -0
  18. data/config/logger.yml +1 -0
  19. data/gulpfile.js +0 -0
  20. data/lib/proxes.rb +1 -1
  21. data/lib/proxes/app.rb +7 -6
  22. data/lib/proxes/container.rb +106 -0
  23. data/lib/proxes/controllers/application.rb +9 -1
  24. data/lib/proxes/controllers/audit_logs.rb +0 -0
  25. data/lib/proxes/controllers/auth_identity.rb +1 -0
  26. data/lib/proxes/controllers/component.rb +25 -6
  27. data/lib/proxes/controllers/permissions.rb +0 -0
  28. data/lib/proxes/controllers/roles.rb +0 -0
  29. data/lib/proxes/controllers/users.rb +35 -9
  30. data/lib/proxes/db.rb +0 -0
  31. data/lib/proxes/helpers/authentication.rb +0 -0
  32. data/lib/proxes/helpers/component.rb +4 -0
  33. data/lib/proxes/helpers/indices.rb +0 -0
  34. data/lib/proxes/helpers/pundit.rb +0 -0
  35. data/lib/proxes/helpers/views.rb +0 -0
  36. data/lib/proxes/helpers/wisper.rb +14 -0
  37. data/lib/proxes/listener.rb +21 -0
  38. data/lib/proxes/loggers/elasticsearch.rb +0 -0
  39. data/lib/proxes/models/audit_log.rb +3 -3
  40. data/lib/proxes/models/base.rb +3 -0
  41. data/lib/proxes/models/identity.rb +2 -2
  42. data/lib/proxes/models/permission.rb +2 -2
  43. data/lib/proxes/models/role.rb +2 -2
  44. data/lib/proxes/models/user.rb +2 -2
  45. data/lib/proxes/policies/application_policy.rb +0 -0
  46. data/lib/proxes/policies/audit_log_policy.rb +0 -0
  47. data/lib/proxes/policies/identity_policy.rb +0 -0
  48. data/lib/proxes/policies/permission_policy.rb +0 -0
  49. data/lib/proxes/policies/request/root_policy.rb +0 -0
  50. data/lib/proxes/policies/request/search_policy.rb +0 -0
  51. data/lib/proxes/policies/request/snapshot_policy.rb +0 -0
  52. data/lib/proxes/policies/request/stats_policy.rb +0 -0
  53. data/lib/proxes/policies/request_policy.rb +0 -2
  54. data/lib/proxes/policies/role_policy.rb +0 -0
  55. data/lib/proxes/policies/token_policy.rb +0 -0
  56. data/lib/proxes/policies/user_policy.rb +0 -0
  57. data/lib/proxes/rake_tasks.rb +0 -0
  58. data/lib/proxes/request.rb +0 -0
  59. data/lib/proxes/request/root.rb +0 -0
  60. data/lib/proxes/request/search.rb +0 -0
  61. data/lib/proxes/request/snapshot.rb +0 -0
  62. data/lib/proxes/request/stats.rb +0 -0
  63. data/lib/proxes/security.rb +0 -0
  64. data/lib/proxes/seed.rb +0 -1
  65. data/lib/proxes/services/logger.rb +0 -0
  66. data/lib/proxes/version.rb +1 -1
  67. data/migrate/001_tables.rb +0 -0
  68. data/migrate/002_audit_log.rb +1 -1
  69. data/package.json +0 -0
  70. data/proxes.gemspec +2 -0
  71. data/public/js/bundle.js +0 -0
  72. data/src/scripts/app.js +1 -6
  73. data/views/404.haml +0 -0
  74. data/views/audit_logs/index.haml +4 -1
  75. data/views/error.haml +0 -0
  76. data/views/getting_started.haml +0 -0
  77. data/views/identity/login.haml +0 -0
  78. data/views/identity/register.haml +0 -0
  79. data/views/index.haml +0 -0
  80. data/views/layout.haml +0 -0
  81. data/views/partials/delete_form.haml +0 -0
  82. data/views/partials/form_control.haml +0 -0
  83. data/views/partials/navbar.haml +0 -0
  84. data/views/partials/notifications.haml +0 -0
  85. data/views/partials/pager.haml +0 -0
  86. data/views/partials/sidebar.haml +0 -0
  87. data/views/permissions/display.haml +0 -0
  88. data/views/permissions/edit.haml +0 -0
  89. data/views/permissions/form.haml +0 -0
  90. data/views/permissions/index.haml +0 -0
  91. data/views/permissions/new.haml +0 -0
  92. data/views/roles/display.haml +0 -0
  93. data/views/roles/edit.haml +0 -0
  94. data/views/roles/form.haml +0 -0
  95. data/views/roles/index.haml +0 -0
  96. data/views/roles/new.haml +0 -0
  97. data/views/users/display.haml +0 -0
  98. data/views/users/edit.haml +0 -0
  99. data/views/users/identity.haml +0 -0
  100. data/views/users/index.haml +0 -0
  101. data/views/users/new.haml +0 -0
  102. data/views/users/profile.haml +0 -0
  103. data/views/users/user.haml +0 -0
  104. metadata +35 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 881537e84abeabfb6dda5cb8fbf1569887ca9b1d
4
- data.tar.gz: e05d7e590df108ce8f318e18b28af1ae5dc2f60b
3
+ metadata.gz: f09dfca277df91363c5c406d7f7a2a04538ac709
4
+ data.tar.gz: 272207ef5bc8708b42cc5cfb41790e68ee54ffb2
5
5
  SHA512:
6
- metadata.gz: 5791483864ee3fd55f76b487ff796b7e3c26f0a08afe303367436d1d492bcbc72185f941f75a578deb4c257df195c7d2dfd6e4fbda5c97df4adc00551167844d
7
- data.tar.gz: 6c04c5cb9173d22d6bc4a5bfeaaa31c3ab1e4f91dac9179a441a9230fd6f296917f64ad8842aab537857fde8a727a67814ef34297e5e1c8bc18ef9c1c7874e77
6
+ metadata.gz: b0ac4a096a65c81667622c772e049352f15cd7bb78bbda5f4c5641968ebcf8f95cf441ec66f200e1aa4e8ae119475addd2840b9f62d9825a5fc07a05fe6b925a
7
+ data.tar.gz: 0c19669d5c38423cdf8b1f81f0f0d287a20378c7e848b296d200c0a8539454871746654c67e464a2fba978f0a75cd7d546e3eee81a57fb0c7996fcb9fe3dd450
File without changes
data/.gitignore CHANGED
File without changes
data/.pryrc ADDED
@@ -0,0 +1,6 @@
1
+ if defined?(PryByebug)
2
+ Pry.commands.alias_command 'c', 'continue'
3
+ Pry.commands.alias_command 's', 'step'
4
+ Pry.commands.alias_command 'n', 'next'
5
+ Pry.commands.alias_command 'f', 'finish'
6
+ end
data/.rspec CHANGED
File without changes
File without changes
File without changes
File without changes
data/Gemfile CHANGED
File without changes
data/Gemfile.ci CHANGED
File without changes
@@ -6,5 +6,5 @@ gemspec
6
6
  gem 'rerun', git: 'https://github.com/alexch/rerun.git', branch: 'master'
7
7
  gem 'sqlite3'
8
8
  gem 'simplecov'
9
- gem 'pry', '~> 0.10.4'
9
+ gem 'pry-byebug'
10
10
 
@@ -9,7 +9,7 @@ GIT
9
9
  PATH
10
10
  remote: .
11
11
  specs:
12
- proxes (0.1.0)
12
+ proxes (0.2.0)
13
13
  bcrypt
14
14
  elasticsearch
15
15
  haml
@@ -17,12 +17,14 @@ PATH
17
17
  omniauth
18
18
  omniauth-identity
19
19
  pundit
20
+ rack-contrib
20
21
  rack-proxy
21
22
  sequel
22
23
  sinatra
23
24
  sinatra-contrib
24
25
  sinatra-flash
25
26
  tilt (>= 2)
27
+ wisper
26
28
 
27
29
  GEM
28
30
  remote: https://rubygems.org/
@@ -36,6 +38,7 @@ GEM
36
38
  bcrypt (3.1.11)
37
39
  bcrypt-ruby (3.1.5)
38
40
  bcrypt (>= 3.1.3)
41
+ byebug (9.0.6)
39
42
  coderay (1.1.1)
40
43
  concurrent-ruby (1.0.4)
41
44
  database_cleaner (1.5.3)
@@ -54,6 +57,7 @@ GEM
54
57
  faraday (0.11.0)
55
58
  multipart-post (>= 1.2, < 3)
56
59
  ffi (1.9.14)
60
+ git-version-bump (0.15.1)
57
61
  haml (4.0.7)
58
62
  tilt
59
63
  hashie (3.4.6)
@@ -78,9 +82,15 @@ GEM
78
82
  coderay (~> 1.1.0)
79
83
  method_source (~> 0.8.1)
80
84
  slop (~> 3.4)
85
+ pry-byebug (3.4.2)
86
+ byebug (~> 9.0)
87
+ pry (~> 0.10)
81
88
  pundit (1.1.0)
82
89
  activesupport (>= 3.0.0)
83
90
  rack (1.6.5)
91
+ rack-contrib (1.4.0)
92
+ git-version-bump (~> 0.15)
93
+ rack (~> 1.4)
84
94
  rack-protection (1.5.3)
85
95
  rack
86
96
  rack-proxy (0.6.0)
@@ -130,9 +140,10 @@ GEM
130
140
  slop (3.6.0)
131
141
  sqlite3 (1.3.12)
132
142
  thread_safe (0.3.5)
133
- tilt (2.0.5)
143
+ tilt (2.0.6)
134
144
  tzinfo (1.2.2)
135
145
  thread_safe (~> 0.1)
146
+ wisper (1.6.1)
136
147
 
137
148
  PLATFORMS
138
149
  ruby
@@ -142,7 +153,7 @@ DEPENDENCIES
142
153
  database_cleaner
143
154
  factory_girl
144
155
  proxes!
145
- pry (~> 0.10.4)
156
+ pry-byebug
146
157
  rack-test
147
158
  racksh
148
159
  rake (~> 10.0)
@@ -1,4 +1,4 @@
1
- Copyright (c) Jade IT cc
1
+ Copyright (c) 2017 Jade IT cc
2
2
 
3
3
  ProxES is an Open Source project licensed under the terms of
4
4
  the LGPLv3 license. Please see <http://www.gnu.org/licenses/lgpl-3.0.html>
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # ProxES
6
6
 
7
- ProxES provides a simple management interface and security layer to Elasticsearch.
7
+ ProxES provides a management interface and security layer for Elasticsearch.
8
8
 
9
9
  ## Components
10
10
 
@@ -75,9 +75,13 @@ gulp deploy
75
75
 
76
76
  ## Contributing
77
77
 
78
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/proxes.
78
+ Bug reports and pull requests are welcome on GitHub at https://github.com/EagerELK/proxes.
79
79
 
80
80
  ## License
81
81
 
82
- The gem is available as open source under the terms of the [LGPLv3 license](http://www.gnu.org/licenses/lgpl-3.0.html).
82
+ The ProxES gem is an Open Source project licensed under the terms of
83
+ the LGPLv3 license. Please see [LGPLv3 license](http://www.gnu.org/licenses/lgpl-3.0.html)
84
+ for license text.
83
85
 
86
+ A commercial-friendly license allowing private forks and modifications of
87
+ ProxES is available. Please contact info@jadeit.co.za more detail.
data/Rakefile CHANGED
File without changes
File without changes
data/config.ru CHANGED
@@ -7,6 +7,8 @@ raise 'Unconfigured' unless ENV['ELASTICSEARCH_URL']
7
7
 
8
8
  require 'proxes'
9
9
  require 'proxes/db'
10
+ require 'proxes/app'
11
+ require 'proxes/listener'
10
12
 
11
13
  Sequel.extension :migration
12
14
  Sequel::Migrator.check_current(DB, './migrate')
@@ -1,3 +1,4 @@
1
1
  ---
2
2
  - name: default
3
3
  class: Logger
4
+ options: 'logs/proxes.log'
File without changes
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
  require 'proxes/version'
3
- require 'proxes/app'
3
+ require 'proxes/container'
@@ -18,6 +18,10 @@ module ProxES
18
18
  post '/auth/identity/new' do
19
19
  identity = Identity.new(params['identity'])
20
20
  if identity.valid? && identity.save
21
+ user = User.find_or_create(email: identity.username)
22
+ user.add_identity identity
23
+
24
+ log_action(:identity_register, user: user)
21
25
  flash[:info] = 'Successfully Registered. Please log in'
22
26
  redirect '/auth/identity'
23
27
  else
@@ -27,19 +31,16 @@ module ProxES
27
31
  end
28
32
 
29
33
  post '/auth/identity/callback' do
30
- user = User.find_or_create(email: env['omniauth.auth']['info']['email'])
31
-
32
- identity = Identity.find(username: user.email)
33
- user.add_identity identity unless identity.user == user
34
-
34
+ user = User.find(email: env['omniauth.auth']['info']['email'])
35
35
  self.current_user = user
36
+ log_action(:identity_login, user: user)
36
37
  flash[:success] = 'Logged In'
37
38
  redirect '/_proxes'
38
39
  end
39
40
 
40
41
  delete '/auth/identity' do
42
+ log_action(:identity_logout)
41
43
  logout
42
-
43
44
  flash[:info] = 'Logged Out'
44
45
 
45
46
  redirect '/_proxes'
@@ -0,0 +1,106 @@
1
+ module ProxES
2
+ class Container
3
+ class ContainerError < StandardError; end
4
+
5
+ # A thread safe cache class, offering only #[] and #[]= methods,
6
+ # each protected by a mutex.
7
+ # Ripped off from Roda - https://github.com/jeremyevans/roda
8
+ class PluginCache
9
+ # Create a new thread safe cache.
10
+ def initialize
11
+ @mutex = Mutex.new
12
+ @hash = {}
13
+ end
14
+
15
+ # Make getting value from underlying hash thread safe.
16
+ def [](key)
17
+ @mutex.synchronize{@hash[key]}
18
+ end
19
+
20
+ # Make setting value in underlying hash thread safe.
21
+ def []=(key, value)
22
+ @mutex.synchronize{@hash[key] = value}
23
+ end
24
+
25
+ def map(&block)
26
+ @mutex.synchronize{@hash.map(&block)}
27
+ end
28
+ end
29
+
30
+ # Ripped off from Roda - https://github.com/jeremyevans/roda
31
+ module Plugins
32
+ # Stores registered plugins
33
+ @plugins = PluginCache.new
34
+
35
+ # If the registered plugin already exists, use it. Otherwise,
36
+ # require it and return it. This raises a LoadError if such a
37
+ # plugin doesn't exist, or a ContainerError if it exists but it does
38
+ # not register itself correctly.
39
+ def self.load_plugin(name)
40
+ h = @plugins
41
+ unless plugin = h[name]
42
+ require "proxes/plugins/#{name}"
43
+ raise ContainerError, "Plugin #{name} did not register itself correctly in ProxES::Container::Plugins" unless plugin = h[name]
44
+ end
45
+ plugin
46
+ end
47
+
48
+ # Register the given plugin with Container, so that it can be loaded using #plugin
49
+ # with a symbol. Should be used by plugin files. Example:
50
+ #
51
+ # ProxES::Container::Plugins.register_plugin(:plugin_name, PluginModule)
52
+ def self.register_plugin(name, mod)
53
+ @plugins[name] = mod
54
+ end
55
+
56
+ def self.plugins
57
+ @plugins
58
+ end
59
+
60
+ module Base
61
+ module ClassMethods
62
+ # Load a new plugin into the current class. A plugin can be a module
63
+ # which is used directly, or a symbol represented a registered plugin
64
+ # which will be required and then used. Returns nil.
65
+ #
66
+ # Container.plugin PluginModule
67
+ # Container.plugin :csrf
68
+ def plugin(plugin, *args, &block)
69
+ raise ContainerError, "Cannot add a plugin to a frozen Container class" if frozen?
70
+ plugin = Plugins.load_plugin(plugin) if plugin.is_a?(Symbol)
71
+ plugin.load_dependencies(self, *args, &block) if plugin.respond_to?(:load_dependencies)
72
+ include(plugin::InstanceMethods) if defined?(plugin::InstanceMethods)
73
+ extend(plugin::ClassMethods) if defined?(plugin::ClassMethods)
74
+ plugin.configure(self, *args, &block) if plugin.respond_to?(:configure)
75
+
76
+ # One option is to add controllers / nav on registration:
77
+ @controllers.merge(plugin.controllers) if plugin.respond_to?(:controllers)
78
+ @navigation << plugin.navigation if plugin.respond_to?(:navigation)
79
+
80
+ nil
81
+ end
82
+
83
+ def routes
84
+ {} # Return a hash of controllers with their routes as keys: `{ '/users' => ProxES::Controllers::Users }`
85
+ end
86
+
87
+ def nav_items
88
+ [] # Return an ordered list of navigation items: `[{order:0, link:'/users/' text:'Users'}, {order:1, link:'/roles/', text:'Roles'}]
89
+ end
90
+
91
+ def migrations
92
+ Plugins.plugins.map do |_key, plugin|
93
+ plugin.migration_folder if plugin.respond_to?(:migration_folder)
94
+ end
95
+ end
96
+ end
97
+
98
+ module InstanceMethods
99
+ end
100
+ end
101
+ end
102
+
103
+ extend Plugins::Base::ClassMethods
104
+ plugin Plugins::Base
105
+ end
106
+ end
@@ -1,17 +1,25 @@
1
1
  # frozen_string_literal: true
2
+ require 'wisper'
2
3
  require 'sinatra/base'
3
4
  require 'sinatra/flash'
4
5
  require 'sinatra/respond_with'
5
6
  require 'proxes/helpers/views'
6
7
  require 'proxes/helpers/pundit'
8
+ require 'proxes/helpers/wisper'
7
9
  require 'proxes/helpers/authentication'
10
+ require 'rack/contrib'
8
11
 
9
12
  module ProxES
10
13
  class Application < Sinatra::Base
11
14
  set :root, ::File.expand_path(::File.dirname(__FILE__) + '/../../../')
12
- register Sinatra::Flash, Sinatra::RespondWith
15
+ # The order here is important, since Wisper has a deprecated method respond_with method
16
+ helpers Wisper::Publisher, ProxES::Helpers::Wisper
13
17
  helpers ProxES::Helpers::Pundit, ProxES::Helpers::Views, ProxES::Helpers::Authentication
14
18
 
19
+ register Sinatra::Flash, Sinatra::RespondWith
20
+
21
+ use Rack::PostBodyContentTypeParser
22
+
15
23
  configure :production do
16
24
  disable :show_exceptions
17
25
  end
File without changes
@@ -9,6 +9,7 @@ module ProxES
9
9
 
10
10
  # Failed Login
11
11
  post '/_proxes/auth/identity/callback' do
12
+ broadcast(:identity_failed_login)
12
13
  flash[:warning] = 'Invalid credentials. Please try again.'
13
14
  redirect '/auth/identity'
14
15
  end
@@ -6,7 +6,9 @@ module ProxES
6
6
  class Component < Application
7
7
  helpers ProxES::Helpers::Component
8
8
  set base_path: nil
9
+ set dehumanized: nil
9
10
  set view_location: nil
11
+ set track_actions: false
10
12
 
11
13
  # List
12
14
  get '/', provides: [:html, :json] do
@@ -15,6 +17,7 @@ module ProxES
15
17
  actions = {}
16
18
  actions["#{base_path}/new"] = "New #{heading}" if policy(settings.model_class).create?
17
19
 
20
+ log_action("#{dehumanized}_list".to_sym) if settings.track_actions
18
21
  respond_to do |format|
19
22
  format.html do
20
23
  haml :"#{view_location}/index",
@@ -44,11 +47,22 @@ module ProxES
44
47
  authorize settings.model_class, :create
45
48
 
46
49
  entity = settings.model_class.new(permitted_attributes(settings.model_class, :create))
47
- if entity.valid? && entity.save
48
- flash[:success] = "#{heading} Created"
49
- redirect "#{base_path}/#{entity.id}"
50
- else
51
- haml :"#{view_location}/new", locals: { entity: entity, title: heading(:new) }
50
+ success = entity.valid? && entity.save
51
+
52
+ log_action("#{dehumanized}_create".to_sym) if success && settings.track_actions
53
+ respond_to do |format|
54
+ format.html do
55
+ if success
56
+ flash[:success] = "#{heading} Created"
57
+ redirect "#{base_path}/#{entity.id}"
58
+ else
59
+ haml :"#{view_location}/new", locals: { entity: entity, title: heading(:new) }
60
+ end
61
+ end
62
+ format.json do
63
+ headers 'Content-Type' => 'application/json'
64
+ redirect "#{base_path}/#{entity.id}", 201 if success
65
+ end
52
66
  end
53
67
  end
54
68
 
@@ -61,6 +75,7 @@ module ProxES
61
75
  actions = {}
62
76
  actions["#{base_path}/#{entity.id}/edit"] = "Edit #{heading}" if policy(entity).update?
63
77
 
78
+ log_action("#{dehumanized}_read".to_sym) if settings.track_actions
64
79
  respond_to do |format|
65
80
  format.html do
66
81
  haml :"#{view_location}/display",
@@ -86,7 +101,10 @@ module ProxES
86
101
  authorize entity, :update
87
102
 
88
103
  entity.set(permitted_attributes(settings.model_class, :update))
89
- if entity.valid? && entity.save
104
+
105
+ success = entity.valid? && entity.save
106
+ log_action("#{dehumanized}_update".to_sym) if success && settings.track_actions
107
+ if success
90
108
  flash[:success] = "#{heading} Updated"
91
109
  redirect "#{base_path}/#{entity.id}"
92
110
  else
@@ -101,6 +119,7 @@ module ProxES
101
119
 
102
120
  entity.destroy
103
121
 
122
+ log_action("#{dehumanized}_delete".to_sym) if settings.track_actions
104
123
  flash[:success] = "#{heading} Deleted"
105
124
  redirect base_path.to_s
106
125
  end
File without changes
File without changes
@@ -8,6 +8,7 @@ require 'proxes/policies/identity_policy'
8
8
  module ProxES
9
9
  class Users < Component
10
10
  set model_class: ProxES::User
11
+ set track_actions: true
11
12
 
12
13
  # New
13
14
  get '/new' do
@@ -40,19 +41,41 @@ module ProxES
40
41
  identity.save
41
42
  user.save
42
43
  user.add_identity identity
43
- roles.each do |role_id|
44
- user.add_role(role_id) unless user.roles.map(&:id).include? role_id.to_i
45
- end if roles
44
+ if roles
45
+ roles.each do |role_id|
46
+ user.add_role(role_id) unless user.roles.map(&:id).include? role_id.to_i
47
+ end
48
+ end
46
49
  user.check_roles
47
50
  end
48
51
 
49
- flash[:success] = 'User created'
50
- redirect "/_proxes/users/#{user.id}"
52
+ log_action("#{dehumanized}_create".to_sym) if settings.track_actions
53
+ respond_to do |format|
54
+ format.html do
55
+ flash[:success] = 'User created'
56
+ redirect "/_proxes/users/#{user.id}"
57
+ end
58
+ format.json do
59
+ headers 'Content-Type' => 'application/json'
60
+ redirect "/_proxes/users/#{user.id}", 201
61
+ end
62
+ end
51
63
  else
52
- flash.now[:danger] = 'Could not create the user'
53
- locals[:entity] = user
54
- locals[:identity] = identity
55
- haml :"#{view_location}/new", locals: locals
64
+ respond_to do |format|
65
+ format.html do
66
+ flash.now[:danger] = 'Could not create the user'
67
+ locals[:entity] = user
68
+ locals[:identity] = identity
69
+ haml :"#{view_location}/new", locals: locals
70
+ end
71
+ format.json do
72
+ headers \
73
+ 'Content-Type' => 'application/json',
74
+ 'Content-Location' => "#{view_location}/new"
75
+ body ''
76
+ status 402
77
+ end
78
+ end
56
79
  end
57
80
  end
58
81
 
@@ -69,6 +92,7 @@ module ProxES
69
92
  entity.remove_all_roles
70
93
  roles.each { |role_id| entity.add_role(role_id) } if roles
71
94
  entity.check_roles
95
+ log_action("#{dehumanized}_update".to_sym) if settings.track_actions
72
96
  flash[:success] = "#{heading} Updated"
73
97
  redirect "/_proxes/users/#{entity.id}"
74
98
  else
@@ -86,6 +110,7 @@ module ProxES
86
110
  values = permitted_attributes(Identity, :create)
87
111
  identity.set values
88
112
  if identity.valid? && identity.save
113
+ log_action("#{dehumanized}_update_password".to_sym) if settings.track_actions
89
114
  flash[:success] = "Password Updated"
90
115
  redirect '/_proxes/users/profile'
91
116
  else
@@ -103,6 +128,7 @@ module ProxES
103
128
  entity.remove_all_roles
104
129
  entity.destroy
105
130
 
131
+ log_action("#{dehumanized}_delete".to_sym) if settings.track_actions
106
132
  flash[:success] = "#{heading} Deleted"
107
133
  redirect '/_proxes/users'
108
134
  end
File without changes
File without changes
@@ -28,6 +28,10 @@ module ProxES
28
28
  @headings[action]
29
29
  end
30
30
 
31
+ def dehumanized
32
+ settings.dehumanized || ActiveSupport::Inflector.underscore(heading)
33
+ end
34
+
31
35
  def base_path
32
36
  settings.base_path || "/_proxes/#{heading(:list).downcase}"
33
37
  end
File without changes
File without changes
File without changes
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ require 'wisper'
3
+ require 'proxes/request'
4
+
5
+ module ProxES
6
+ module Helpers
7
+ module Wisper
8
+ def log_action(action, args = {})
9
+ args[:user] ||= current_user
10
+ broadcast(action, args)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,21 @@
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
+ require 'wisper'
6
+
7
+ module ProxES
8
+ class Listener
9
+ def method_missing(method, *args, &block)
10
+ vals = { action: method }
11
+ vals[:user] = args[0][:user] if (args[0] && args[0].has_key?(:user))
12
+ AuditLog.create vals
13
+ end
14
+
15
+ def respond_to_missing?(method, include_private = false)
16
+ true
17
+ end
18
+ end
19
+ end
20
+
21
+ Wisper.subscribe(ProxES::Listener.new)
File without changes
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
- require 'sequel'
2
+ require 'proxes/models/base'
3
3
 
4
4
  module ProxES
5
- class AuditLog < Sequel::Model
5
+ class AuditLog < Base
6
6
  many_to_one :user
7
7
 
8
8
  def validate
9
- validates_presence [:user_id, :action]
9
+ validates_presence [:action]
10
10
  end
11
11
  end
12
12
  end
@@ -0,0 +1,3 @@
1
+ require 'sequel'
2
+
3
+ ProxES::Base = Class.new(Sequel::Model)
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
- require 'sequel'
2
+ require 'proxes/models/base'
3
3
  require 'omniauth-identity'
4
4
  require 'active_support'
5
5
  require 'active_support/core_ext/object/blank'
6
6
 
7
7
  module ProxES
8
- class Identity < Sequel::Model
8
+ class Identity < Base
9
9
  many_to_one :user
10
10
 
11
11
  attr_accessor :password, :password_confirmation
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
- require 'sequel'
2
+ require 'proxes/models/base'
3
3
 
4
4
  module ProxES
5
- class Permission < Sequel::Model
5
+ class Permission < Base
6
6
  many_to_one :role
7
7
 
8
8
  def validate
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
- require 'sequel'
2
+ require 'proxes/models/base'
3
3
 
4
4
  module ProxES
5
- class Role < Sequel::Model
5
+ class Role < Base
6
6
  many_to_many :users
7
7
  one_to_many :permissions
8
8
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require 'sequel'
2
+ require 'proxes/models/base'
3
3
  require 'bcrypt'
4
4
  require 'digest/md5'
5
5
  require 'active_support'
@@ -7,7 +7,7 @@ require 'active_support/core_ext/object/blank'
7
7
 
8
8
  # Why not store this in Elasticsearch?
9
9
  module ProxES
10
- class User < Sequel::Model
10
+ class User < Base
11
11
  one_to_many :identity
12
12
  many_to_many :roles
13
13
  one_to_many :audit_logs
File without changes
File without changes
File without changes
File without changes
@@ -18,8 +18,6 @@ module ProxES
18
18
  def method_missing(method_sym, *arguments, &block)
19
19
  if method_sym.to_s[-1] == '?'
20
20
  return false if user.nil?
21
- require 'pry'
22
- # binding.pry
23
21
 
24
22
  if record.indices?
25
23
  patterns = ProxES::Permission.where(verb: 'INDEX', role: user.roles).map do |permission|
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -3,7 +3,6 @@ require 'proxes/models/role'
3
3
  require 'proxes/models/permission'
4
4
 
5
5
  ProxES::Role.find_or_create(name: 'user')
6
- ProxES::Role.find_or_create(name: 'admin')
7
6
  sa = ProxES::Role.find_or_create(name: 'super_admin')
8
7
  %w(GET POST PUT DELETE HEAD OPTIONS).each do |verb|
9
8
  ProxES::Permission.find_or_create(role: sa, verb: verb, pattern: '.*')
File without changes
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ProxES
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
File without changes
@@ -3,7 +3,7 @@ Sequel.migration do
3
3
  change do
4
4
  create_table :audit_logs do
5
5
  primary_key :id
6
- foreign_key :user_id, :users
6
+ foreign_key :user_id, :users, null: true
7
7
  String :action
8
8
  DateTime :created_at
9
9
  end
File without changes
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency 'factory_girl'
30
30
 
31
31
  spec.add_dependency 'rack-proxy'
32
+ spec.add_dependency 'rack-contrib'
32
33
  spec.add_dependency 'sinatra'
33
34
  spec.add_dependency 'sinatra-flash'
34
35
  spec.add_dependency 'sinatra-contrib'
@@ -40,5 +41,6 @@ Gem::Specification.new do |spec|
40
41
  spec.add_dependency 'omniauth'
41
42
  spec.add_dependency 'omniauth-identity'
42
43
  spec.add_dependency 'haml'
44
+ spec.add_dependency 'wisper'
43
45
  spec.add_dependency 'tilt', '>= 2'
44
46
  end
File without changes
@@ -2,9 +2,4 @@ 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"/>, document.getElementById('react-dashboard'));
6
-
7
- // ReactDOM.render(
8
- // <Health store={new ESStore()}/>,
9
- // document.getElementById('indexlist')
10
- // );
5
+ ReactDOM.render(<ProxesComponents pollInterval="30000" elasticsearch_url="./"/>, document.getElementById('react-dashboard'));
File without changes
@@ -11,7 +11,10 @@
11
11
  -list.each do |entity|
12
12
  %tr
13
13
  %td
14
- %a{ href: "/_proxes/users/#{entity.user.id}" }= entity.user.email
14
+ -if entity.user
15
+ %a{ href: "/_proxes/users/#{entity.user.id}" }= entity.user.email
16
+ -else
17
+ None
15
18
  %td
16
19
  = entity.action
17
20
  %td
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
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.1.0
4
+ version: 0.2.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-01-30 00:00:00.000000000 Z
11
+ date: 2017-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rack-contrib
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'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: sinatra
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -276,6 +290,20 @@ dependencies:
276
290
  - - ">="
277
291
  - !ruby/object:Gem::Version
278
292
  version: '0'
293
+ - !ruby/object:Gem::Dependency
294
+ name: wisper
295
+ requirement: !ruby/object:Gem::Requirement
296
+ requirements:
297
+ - - ">="
298
+ - !ruby/object:Gem::Version
299
+ version: '0'
300
+ type: :runtime
301
+ prerelease: false
302
+ version_requirements: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - ">="
305
+ - !ruby/object:Gem::Version
306
+ version: '0'
279
307
  - !ruby/object:Gem::Dependency
280
308
  name: tilt
281
309
  requirement: !ruby/object:Gem::Requirement
@@ -300,6 +328,7 @@ extra_rdoc_files: []
300
328
  files:
301
329
  - ".codeclimate.yml"
302
330
  - ".gitignore"
331
+ - ".pryrc"
303
332
  - ".rspec"
304
333
  - ".rubocop.yml"
305
334
  - ".ruby-version"
@@ -319,6 +348,7 @@ files:
319
348
  - gulpfile.js
320
349
  - lib/proxes.rb
321
350
  - lib/proxes/app.rb
351
+ - lib/proxes/container.rb
322
352
  - lib/proxes/controllers/application.rb
323
353
  - lib/proxes/controllers/audit_logs.rb
324
354
  - lib/proxes/controllers/auth_identity.rb
@@ -332,8 +362,11 @@ files:
332
362
  - lib/proxes/helpers/indices.rb
333
363
  - lib/proxes/helpers/pundit.rb
334
364
  - lib/proxes/helpers/views.rb
365
+ - lib/proxes/helpers/wisper.rb
366
+ - lib/proxes/listener.rb
335
367
  - lib/proxes/loggers/elasticsearch.rb
336
368
  - lib/proxes/models/audit_log.rb
369
+ - lib/proxes/models/base.rb
337
370
  - lib/proxes/models/identity.rb
338
371
  - lib/proxes/models/permission.rb
339
372
  - lib/proxes/models/role.rb