aserto 0.0.3 → 0.0.6

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: a85bdfae072c313aeb99cc709595cd5f7af5b3421bfcb9378cab65c1b3cd24ec
4
- data.tar.gz: 3c77d880673ebfa56b9ad47e597a4e2d79e657521f08cc2d8f93d8d3f0bfecf5
3
+ metadata.gz: ec7d824cf97fc0b087d9f9294e06b82612b74220d2c9960766d83330d56ed1e5
4
+ data.tar.gz: 334ede61a8065c965dfd26654cb759ff0a9548231cedc057ec97f3647a5f9476
5
5
  SHA512:
6
- metadata.gz: eb416ffe02aa2cb41e01e71589f059889002fbfcbedef3c7a53ea621c742d482f2fbeb1c6655958514128b574c876d9899183855de0cb42ce0be76c685e374bc
7
- data.tar.gz: 0e1b38f26f94c81acf25bc67177c5fba47f25b057d717e995723ad8c7160fd01cd3c4cf8fc6ddc6f7a802f5279a94f567621b63118e9b4dc6f8ac3d3f5a5eec8
6
+ metadata.gz: da1e51625ff33aecce4324ef811cfc5d65e445fd3062ee80a9f810f697a0ca25468170ffa12dceba8c46a02db7a8b80f3d562041e33de888f3a4d13c8d64abf2
7
+ data.tar.gz: 9300d6917c93634d4a7059579ea20568bcb2c350306ac37c614d188046be94e4587cf50d133a129376c35c140ee5807c245dac180f0a0445690210348510c94a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.6
@@ -56,7 +56,7 @@ module Aserto
56
56
  )
57
57
  rescue GRPC::BadStatus => e
58
58
  Aserto.logger.error(e.inspect)
59
- false
59
+ return false
60
60
  end
61
61
 
62
62
  decision = response.decisions.find { |el| el.decision == decision }
data/lib/aserto/errors.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Aserto
4
4
  class Error < StandardError; end
5
+ class InvalidResourceMapping < Error; end
5
6
 
6
7
  class AccessDenied < Error
7
8
  attr_reader :action, :conditions
@@ -3,7 +3,27 @@
3
3
  module Aserto
4
4
  module ResourceMapper
5
5
  class << self
6
- def execute(_request)
6
+ def execute(request)
7
+ if defined? ::Rails
8
+ params = request.params
9
+ return {} unless params.is_a?(Hash) && !params.empty?
10
+
11
+ require_relative "rails/utils"
12
+
13
+ route = Aserto::Rails::Utils.route(request)
14
+ path = route[:path] if route
15
+ return {} unless path
16
+
17
+ fields = path.split("/")
18
+ .select { |part| part.starts_with?(":") }
19
+ .map { |field| field.sub(":", "") }
20
+ return {} if fields.empty?
21
+
22
+ require "google/protobuf/well_known_types"
23
+ return Google::Protobuf::Struct.from_hash(fields.to_h { |field| [field, params[field]] })
24
+
25
+ end
26
+
7
27
  {}
8
28
  end
9
29
  end
data/lib/aserto.rb CHANGED
@@ -51,7 +51,17 @@ module Aserto
51
51
  def with_resource_mapper
52
52
  Aserto::ResourceMapper.class_eval do |klass|
53
53
  klass.define_singleton_method(:execute) do |request|
54
- yield(request) if block_given?
54
+ if block_given?
55
+ result = yield(request)
56
+ unless result.is_a?(Hash)
57
+ raise Aserto::InvalidResourceMapping, "block must return a hash, got: #{result.class}"
58
+ end
59
+
60
+ require "google/protobuf/well_known_types"
61
+
62
+ result.transform_keys!(&:to_s)
63
+ Google::Protobuf::Struct.from_hash(result)
64
+ end
55
65
  end
56
66
  end
57
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aserto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aserto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-26 00:00:00.000000000 Z
11
+ date: 2022-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aserto-grpc-authz