rails-acu 1.3.0 → 2.0.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +8 -8
- data/lib/acu/monitor.rb +5 -2
- data/lib/acu/version.rb +1 -1
- data/lib/rails-acu.rb +2 -3
- data/spec/dummy/app/controllers/application_controller.rb +1 -1
- data/spec/dummy/spec/controllers/admin/manage_controller_spec.rb +3 -3
- metadata +1 -2
- data/lib/acu/injectors.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edbbd908c54348250acdd6dee3aa62b88dfb7129
|
4
|
+
data.tar.gz: e9f71d527b9f688669270c5c7a81df819aedc3af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce4b049791e6de8c5285658c5a4334ff26e4d3c20a39e7431ef95f21d4137f338b5cb3eca45de3a49a6f62f12757644a8710fe60f4f21dacd6d05de0d46bad10
|
7
|
+
data.tar.gz: 5359d87f2f690d8e802882b301f575fd466364268663de0bdff90560b20e5c47bd285d1e511cc13a12aaaf962946dbb33b22e08aa8321a06a3805ec0f69aa9d5
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -25,7 +25,7 @@ $ gem install rails-acu
|
|
25
25
|
Then install it in you app using:
|
26
26
|
|
27
27
|
```bash
|
28
|
-
rails generate acu:install
|
28
|
+
$ rails generate acu:install
|
29
29
|
```
|
30
30
|
|
31
31
|
## Usage
|
@@ -87,17 +87,17 @@ We want to grant access to everyone for all of _home_ controller actions in _def
|
|
87
87
|
By default only `:admin` can access to the _admin_ namespace, but we made an exception for 2 actions in the `Admin::ContactController` which everyone can `send_message` to the admin and only clients can ask for `support`.<br />
|
88
88
|
If you back trace it in the above example you can easily find this scenario in the rules, plain and simple.
|
89
89
|
|
90
|
-
###
|
91
|
-
|
90
|
+
### Gaurding the requests
|
91
|
+
For gaurding you application using ACU, you to need to call it in `before_action` callbacks (preferably in you **base controller**). And also occasionally there is some situation that you need to pass the some argument in the entities to be able to determine the entity (i.e you cannot get it from `session`, `global variables/function` or directly from `database`) for such situations you can pass the arguments as you are calling `Acu::Monitor.gaurd` in your `before_action` as below:
|
92
92
|
|
93
93
|
```ruby
|
94
94
|
class ApplicationController < ActionController::Base
|
95
95
|
protect_from_forgery with: :exception
|
96
96
|
|
97
|
-
before_action { Acu::Monitor.by user: some_way_to_fetch_it }
|
97
|
+
before_action { Acu::Monitor.gaurd by: { user: some_way_to_fetch_it } }
|
98
98
|
end
|
99
99
|
```
|
100
|
-
The method `Acu::Monitor.
|
100
|
+
The method `Acu::Monitor.gaurd` accepts a hashed list of agruments named `by`, please note that the keys should be identical to the entities' `args` argument.
|
101
101
|
|
102
102
|
### Some handy helpers
|
103
103
|
Although you can define a binary allow/deny access rule in the `acu_rules.rb` file but there will be some gray area that neither you can allow _full access_ to the resource nor _no access_.<br />
|
@@ -166,11 +166,11 @@ Here are the list of APIs that didn't mentioned above:
|
|
166
166
|
| API | Arguments | Alias | Description |
|
167
167
|
| ----- | :-------: | :------: | ---- |
|
168
168
|
| `Acu::Configs.get` | `name` | N/A | Get the value of the `name`ed config |
|
169
|
-
| `Acu::Monitor.
|
169
|
+
| `Acu::Monitor.args` | `kwargs` | N/A | Set the arguments demaned by blocks in `whois` |
|
170
170
|
| `Acu::Monitor.clear_cache` | None | N/A | Clears the ACU's rule matching cache |
|
171
|
-
| `Acu::Monitor.clear_args` | None | N/A | Clears the argument set by `Acu::Monitor.
|
171
|
+
| `Acu::Monitor.clear_args` | None | N/A | Clears the argument set by `Acu::Monitor.args` and `Acu::Monitor.gaurd` |
|
172
172
|
| `Acu::Monitor.valid_for?` | `entity` | `acu_is?` | Check if the current request is come from the entity or not |
|
173
|
-
| `Acu::Monitor.gaurd` |
|
173
|
+
| `Acu::Monitor.gaurd` | `by` | N/A | Validates the current request, considering the arguments demaned by blocks in `whois` |
|
174
174
|
| `Acu::Rules.define` | `&block` | N/A | Get a block of rules, **Note** that there could be mutliple `Acu::Rules.define` in your project, the rules will all merge together as a one, so you can have mutliple `acu_rule*.rb` file in your `config/initialize` and they will merge together |
|
175
175
|
| `Acu::Rules.reset` | None | N/A | Resets everything in the `Acu::Rules` |
|
176
176
|
| `Acu::Rule.lock` | None | N/A | Freezes the rules, you can set it at the _end of the last_ `acu_rule*.rb` file. |
|
data/lib/acu/monitor.rb
CHANGED
@@ -11,7 +11,7 @@ module Acu
|
|
11
11
|
protected :new
|
12
12
|
attr_reader :kwargs
|
13
13
|
|
14
|
-
def
|
14
|
+
def args kwargs
|
15
15
|
@kwargs = @kwargs.merge(kwargs)
|
16
16
|
end
|
17
17
|
|
@@ -19,7 +19,10 @@ module Acu
|
|
19
19
|
@kwargs = { }
|
20
20
|
end
|
21
21
|
|
22
|
-
def gaurd
|
22
|
+
def gaurd by: { }
|
23
|
+
# assign the args in class scope
|
24
|
+
args by
|
25
|
+
|
23
26
|
# fetch the request & process it
|
24
27
|
_info = process Acu::Listeners.data[:request]
|
25
28
|
|
data/lib/acu/version.rb
CHANGED
data/lib/rails-acu.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rails'
|
2
2
|
require 'active_support'
|
3
|
+
require_relative 'acu/helpers/helpers'
|
3
4
|
|
4
5
|
module Acu
|
5
6
|
|
@@ -9,7 +10,7 @@ module Acu
|
|
9
10
|
files.each { |f| eval "#{command} :#{f.humanize.to_sym}, '#{under}#{f}'" }
|
10
11
|
end
|
11
12
|
|
12
|
-
register 'engine', 'rules', 'monitor', 'listeners', '
|
13
|
+
register 'engine', 'rules', 'monitor', 'listeners', 'configs', 'errors'
|
13
14
|
|
14
15
|
# Default way to set up Acu. Run rails generate devise_install to create
|
15
16
|
# a fresh initializer with all configuration values.
|
@@ -21,6 +22,4 @@ module Acu
|
|
21
22
|
include Errors
|
22
23
|
# include listeners
|
23
24
|
include Listeners
|
24
|
-
# include Injector operations
|
25
|
-
include Injectors
|
26
25
|
end
|
@@ -56,15 +56,15 @@ RSpec.describe Admin::ManageController, type: :controller do
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
59
|
-
Acu::Monitor.
|
59
|
+
Acu::Monitor.args c: :admin
|
60
60
|
get :index
|
61
61
|
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="index".*as `:admin`/
|
62
|
-
Acu::Monitor.
|
62
|
+
Acu::Monitor.args c: :client
|
63
63
|
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
64
64
|
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*\[autherized by :allow_by_default\]/
|
65
65
|
|
66
66
|
[:client, :admin].each do |cc|
|
67
|
-
Acu::Monitor.
|
67
|
+
Acu::Monitor.args c: cc
|
68
68
|
get :show
|
69
69
|
end
|
70
70
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-acu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dariush Hasanpour
|
@@ -51,7 +51,6 @@ files:
|
|
51
51
|
- lib/acu/engine.rb
|
52
52
|
- lib/acu/errors.rb
|
53
53
|
- lib/acu/helpers/helpers.rb
|
54
|
-
- lib/acu/injectors.rb
|
55
54
|
- lib/acu/listeners.rb
|
56
55
|
- lib/acu/monitor.rb
|
57
56
|
- lib/acu/rules.rb
|
data/lib/acu/injectors.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require_relative 'helpers/helpers'
|
2
|
-
|
3
|
-
module Acu
|
4
|
-
module Injectors
|
5
|
-
class << self
|
6
|
-
|
7
|
-
ActiveSupport::Notifications.subscribe "start_processing.action_controller" do |**args|
|
8
|
-
eval(args[:controller]).class_eval do
|
9
|
-
before_action { Monitor::gaurd }
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|