Class: Aserto::AuthClient
- Inherits:
-
Object
- Object
- Aserto::AuthClient
- Defined in:
- lib/aserto/auth_client.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #allowed? ⇒ Boolean
- #check(object_id:, object_type:, relation:, options: {}) ⇒ Object
- #enabled? ⇒ Boolean
-
#initialize(request) ⇒ AuthClient
constructor
A new instance of AuthClient.
- #is ⇒ Object
- #visible? ⇒ Boolean
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
#client ⇒ Object (readonly)
Returns the value of attribute client.
11 12 13 |
# File 'lib/aserto/auth_client.rb', line 11 def client @client end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/aserto/auth_client.rb', line 11 def config @config end |
#request ⇒ Object (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
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 [:policy_path] [: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
76 77 78 |
# File 'lib/aserto/auth_client.rb', line 76 def enabled? exec_is(request_is("enabled")) end |
#is ⇒ Object
32 33 34 |
# File 'lib/aserto/auth_client.rb', line 32 def is exec_is(request_is(config.decision)) end |
#visible? ⇒ Boolean
72 73 74 |
# File 'lib/aserto/auth_client.rb', line 72 def visible? exec_is(request_is("visible")) end |