Module: Aserto

Defined in:
lib/aserto.rb,
lib/aserto/config.rb,
lib/aserto/errors.rb,
lib/aserto/version.rb,
lib/aserto/auth_client.rb,
lib/aserto/rails/utils.rb,
lib/aserto/authorization.rb,
lib/aserto/sinatra/utils.rb,
lib/aserto/identity_mapper.rb,
lib/aserto/resource_mapper.rb,
lib/aserto/directory/client.rb,
lib/aserto/directory/v3/model.rb,
lib/aserto/policy_path_mapper.rb,
lib/aserto/directory/v2/client.rb,
lib/aserto/directory/v3/client.rb,
lib/aserto/directory/v3/config.rb,
lib/aserto/directory/v3/reader.rb,
lib/aserto/directory/v3/writer.rb,
lib/aserto/identity_mapper/jwt.rb,
lib/aserto/identity_mapper/sub.rb,
lib/aserto/identity_mapper/base.rb,
lib/aserto/identity_mapper/none.rb,
lib/aserto/directory/v2/requests.rb,
lib/aserto/directory/v3/exporter.rb,
lib/aserto/directory/v3/importer.rb,
lib/aserto/identity_mapper/manual.rb,
lib/aserto/directory/interceptors/headers.rb

Defined Under Namespace

Modules: Directory, IdentityMapper, PolicyPathMapper, Rails, ResourceMapper, Sinatra Classes: AccessDenied, AuthClient, Authorization, Config, Error, InvalidIdentityType, InvalidResourceMapping

Constant Summary collapse

VERSION =
File.read(
  File.join(__dir__, "..", "..", "VERSION")
).chomp

Class Method Summary collapse

Class Method Details

.config(options = {}) ⇒ Object



19
20
21
# File 'lib/aserto.rb', line 19

def config(options = {})
  @config ||= Config.new(options)
end

.configure {|config| ... } ⇒ Object

Yields:



27
28
29
# File 'lib/aserto.rb', line 27

def configure
  yield config
end

.loggerObject



23
24
25
# File 'lib/aserto.rb', line 23

def logger
  config.logger
end

.with_identity_mapperObject

Allows the initializer to provide a custom implementation for the IdentityMapper

Aserto.with_identity_mapper do |request|

{
  sub: "test",
  type: :none
}

end



80
81
82
83
84
85
86
# File 'lib/aserto.rb', line 80

def with_identity_mapper
  Aserto::IdentityMapper.class_eval do |klass|
    klass.define_singleton_method(:execute) do |request|
      yield(request) if block_given?
    end
  end
end

.with_policy_path_mapperObject

Allows the initializer to provide a custom implementation for the PolicyPathMapper

Aserto.with_policy_path_mapper do |policy_root, request|

method = request.request_method
path = request.path_info
"custom => #{policy_root}.#{method}.#{path}"

end



39
40
41
42
43
44
45
# File 'lib/aserto.rb', line 39

def with_policy_path_mapper
  Aserto::PolicyPathMapper.class_eval do |klass|
    klass.define_singleton_method(:execute) do |policy_root, request|
      yield(policy_root, request) if block_given?
    end
  end
end

.with_resource_mapperObject

Allows the initializer to provide a custom implementation for the ResourceMapper

Aserto.with_resource_mapper do |request|

{ resource:  request.path_info }

end



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/aserto.rb', line 53

def with_resource_mapper
  Aserto::ResourceMapper.class_eval do |klass|
    klass.define_singleton_method(:execute) do |request|
      return unless block_given?

      result = yield(request)
      unless result.is_a?(Hash)
        raise Aserto::InvalidResourceMapping, "block must return a hash, got: #{result.class}"
      end

      require "google/protobuf/well_known_types"

      result.transform_keys!(&:to_s)
      Google::Protobuf::Struct.from_hash(result)
    end
  end
end