Class: Aserto::AuthClient

Inherits:
Object
  • Object
show all
Defined in:
lib/aserto/auth_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ AuthClient

Returns a new instance of AuthClient.



23
24
25
26
27
28
29
30
# File 'lib/aserto/auth_client.rb', line 23

def initialize(request)
  @request = request
  @config = Aserto.config
  @client = @config.client || Aserto::Authorizer::V2::Authorizer::Stub.new(
    config.service_url,
    load_creds
  )
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



11
12
13
# File 'lib/aserto/auth_client.rb', line 11

def client
  @client
end

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/aserto/auth_client.rb', line 11

def config
  @config
end

#requestObject (readonly)

Returns the value of attribute request.



11
12
13
# File 'lib/aserto/auth_client.rb', line 11

def request
  @request
end

Instance Method Details

#allowed?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/aserto/auth_client.rb', line 68

def allowed?
  exec_is(request_is("allowed"))
end

#check(object_id:, object_type:, relation:, options: {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/aserto/auth_client.rb', line 36

def check(object_id:, object_type:, relation:, options: {})
  resource_context_fields = {
    object_id: object_id,
    object_type: object_type,
    relation: relation
  }

  check_resource_context = Google::Protobuf::Struct
                           .from_hash(resource_context_fields.transform_keys!(&:to_s))

  policy_path = if options[:policy_path]
                  options[:policy_path]
                else
                  config.policy_root ? "#{config.policy_root}.check" : "rebac.check"
                end

  request = Aserto::Authorizer::V2::IsRequest.new(
    {
      policy_context: Aserto::Authorizer::V2::Api::PolicyContext.new(
        {
          path: policy_path,
          decisions: [config.decision]
        }
      ),
      policy_instance: policy_instance,
      identity_context: identity_context,
      resource_context: check_resource_context
    }
  )
  exec_is(request)
end

#enabled?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/aserto/auth_client.rb', line 76

def enabled?
  exec_is(request_is("enabled"))
end

#isObject



32
33
34
# File 'lib/aserto/auth_client.rb', line 32

def is
  exec_is(request_is(config.decision))
end

#visible?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/aserto/auth_client.rb', line 72

def visible?
  exec_is(request_is("visible"))
end