aserto-rails 0.20.2 → 0.30.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
  SHA256:
3
- metadata.gz: c73023472e4a2c16c1d7f2d54302cfd533a63f592f2ca039c26ecdbc00945adc
4
- data.tar.gz: 5ba34c354dd5e34970da2e76114055eaf14b58a7e72507a6df63966fac7fcecd
3
+ metadata.gz: 8d645132ed1cd5757c6c1d8c795b0cddab950f2be5cf90ef74411a86567b470d
4
+ data.tar.gz: f9cb34952224a4195a3322afc81f6f4e138d2c845fb9da6e55fe0ae7dac54f3b
5
5
  SHA512:
6
- metadata.gz: b5883461dedf1448f933c1dbdc02d66d526e437c16e8696f70e5d7023cf03efe537674bbb32ce6a66420f26ee2609d7e100d0dc9a974909c56d6164ab47196b7
7
- data.tar.gz: 133daa61ff2ee17d32746948b14974f9bbb81a5119399fa8826a31034fdb8785fc5ec495dabbd904cce923d767db80f45465ec66f2ad509f851c7511008c3dba
6
+ metadata.gz: 124e32e4d2c36f91b07509414eead1811dfe92401137d027bec6ebd677baf01e2cc35502b4918760f220470a13fd8a85e36d7960bdbf52f454473f362d6fca47
7
+ data.tar.gz: f1f984fcae8dbbf6d457c0681d8d7bd01524716bddb466f3902c11e076b0b1f40342e5e2385214f21d75a720c4ea675e139eee30c5c286184a3078d287297a46
data/README.md CHANGED
@@ -10,7 +10,7 @@ Aserto authorization library for Ruby and Ruby on Rails.
10
10
  Built on top of [aserto](https://github.com/aserto-dev/aserto-ruby) and [aserto-grpc-authz](https://github.com/aserto-dev/ruby-grpc-authz).
11
11
 
12
12
  ## Prerequisites
13
- * [Ruby](https://www.ruby-lang.org/en/downloads/) 2.7 or newer.
13
+ * [Ruby](https://www.ruby-lang.org/en/downloads/) 3.0 or newer.
14
14
  * [Rails](https://rubyonrails.org/) 6 or newer.
15
15
  * An [Aserto](https://console.aserto.com) account.
16
16
 
@@ -138,6 +138,8 @@ end
138
138
 
139
139
  ## Controller helpers
140
140
 
141
+ ### aserto_authorize!
142
+
141
143
  The `aserto_authorize!` method in the controller will raise an exception if the user is not able to perform the given action.
142
144
 
143
145
  ```ruby
@@ -167,6 +169,38 @@ class PostsController < ApplicationController
167
169
  end
168
170
  ```
169
171
 
172
+ ### check!
173
+
174
+ The `check!` method in the controller will raise an exception if the user is not able to perform the given action.
175
+
176
+ ```ruby
177
+ def show
178
+ # only users in the "evil_genius" group are allowed to get this resource
179
+ check!(object_id: "evil_genius", object_type: "group", relation: "member")
180
+ @post = Post.find(params[:id])
181
+ end
182
+ ```
183
+
184
+ Setting this for every action can be tedious, therefore the `aserto_check_resource` method is provided to
185
+ automatically authorize all actions in a RESTful style resource controller.
186
+ It will use a before action to load the resource into an instance variable and authorize it for every action.
187
+
188
+ ```ruby
189
+ class PostsController < ApplicationController
190
+ aserto_authorize_resource
191
+ # aserto_check_resource only: %i[show], params: { object_id: "evil_genius", object_type: "group", relation: "member" }
192
+ # aserto_check_resource except: %i[index], params: { object_id: "evil_genius", object_type: "group", relation: "member" }
193
+
194
+ def show
195
+ # getting a single post authorized
196
+ end
197
+
198
+ def index
199
+ # getting all posts is authorized
200
+ end
201
+ end
202
+ ```
203
+
170
204
  ## Check Permissions
171
205
 
172
206
  The current user's permissions can then be checked using the `allowed?`, `visible?` and `enabled?` methods in views and controllers.
@@ -181,7 +215,7 @@ The current user's permissions can then be checked using the `allowed?`, `visibl
181
215
  Prerequisites:
182
216
 
183
217
  - go >= 1.17 to run mage
184
- - Ruby >= 2.7.0 to run the code
218
+ - Ruby >= 3.0 to run the code
185
219
 
186
220
 
187
221
  Run `bundle install` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.20.2
1
+ 0.30.1
@@ -8,6 +8,10 @@ module Aserto
8
8
  aserto_resource_class.add_before_action(self, :authorize_resource, *args)
9
9
  end
10
10
 
11
+ def aserto_check_resource(*args)
12
+ aserto_resource_class.add_before_action(self, :check_resource, *args)
13
+ end
14
+
11
15
  def aserto_resource_class
12
16
  ControllerResource
13
17
  end
@@ -38,6 +42,23 @@ module Aserto
38
42
  raise Aserto::AccessDenied unless Aserto::AuthClient.new(request).is
39
43
  end
40
44
 
45
+ #
46
+ # Authorization call based on check relation
47
+ #
48
+ # @param [String] object_id
49
+ # @param [String] object_type
50
+ # @param [String] relation
51
+ #
52
+ # @return [nil]
53
+ #
54
+ # @raise Aserto::AccessDenied
55
+ #
56
+ def check!(object_id:, object_type:, relation:, options: {})
57
+ raise Aserto::AccessDenied unless Aserto::AuthClient.new(request).check(
58
+ object_id: object_id, object_type: object_type, relation: relation, options: options
59
+ )
60
+ end
61
+
41
62
  private
42
63
 
43
64
  def augment_request!(action, path, resource)
@@ -10,6 +10,22 @@ module Aserto
10
10
  @name = args.first
11
11
  end
12
12
 
13
+ #
14
+ # Authorization call based on check relation
15
+ #
16
+ # @param [String] object_id
17
+ # @param [String] object_type
18
+ # @param [String] relation
19
+ #
20
+ # @return [nil]
21
+ #
22
+ # @raise Aserto::AccessDenied
23
+ #
24
+ def check_resource
25
+ client = Aserto::AuthClient.new(@controller.request)
26
+ raise Aserto::AccessDenied unless client.check(**(@options[:params] || {}))
27
+ end
28
+
13
29
  def authorize_resource
14
30
  raise Aserto::AccessDenied unless Aserto::AuthClient.new(@controller.request).is
15
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aserto-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.2
4
+ version: 0.30.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aserto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-23 00:00:00.000000000 Z
11
+ date: 2024-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aserto
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.20.5
19
+ version: 0.30.6
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.20.5
26
+ version: 0.30.6
27
27
  description: Aserto authorization library for Ruby and Ruby on Rails
28
28
  email:
29
29
  - aserto@aserto.com