MCPcopy Index your code
hub / github.com/Permify/permify / LookupEntity

Method LookupEntity

internal/invoke/invoke.go:231–267  ·  view source on GitHub ↗

LookupEntity is a method that implements the LookupEntity interface. It calls the Run method of the LookupEntityEngine with the provided context and PermissionLookupEntityRequest, and returns a PermissionLookupEntityResponse and an error if any.

(ctx context.Context, request *base.PermissionLookupEntityRequest)

Source from the content-addressed store, hash-verified

229// It calls the Run method of the LookupEntityEngine with the provided context and PermissionLookupEntityRequest,
230// and returns a PermissionLookupEntityResponse and an error if any.
231func (invoker *DirectInvoker) LookupEntity(ctx context.Context, request *base.PermissionLookupEntityRequest) (response *base.PermissionLookupEntityResponse, err error) {
232 ctx, span := internal.Tracer.Start(ctx, "lookup-entity", trace.WithAttributes(
233 attribute.KeyValue{Key: "tenant_id", Value: attribute.StringValue(request.GetTenantId())},
234 attribute.KeyValue{Key: "entity_type", Value: attribute.StringValue(request.GetEntityType())},
235 attribute.KeyValue{Key: "permission", Value: attribute.StringValue(request.GetPermission())},
236 attribute.KeyValue{Key: "subject", Value: attribute.StringValue(tuple.SubjectToString(request.GetSubject()))},
237 ))
238 defer span.End()
239
240 // Set SnapToken if not provided
241 if request.GetMetadata().GetSnapToken() == "" { // Check if the request has a SnapToken.
242 var st token.SnapToken
243 st, err = invoker.dataReader.HeadSnapshot(ctx, request.GetTenantId()) // Retrieve the head snapshot from the relationship reader.
244 if err != nil {
245 span.RecordError(err)
246 span.SetStatus(otelCodes.Error, err.Error())
247 return response, err
248 }
249 request.Metadata.SnapToken = st.Encode().String() // Set the SnapToken in the request metadata.
250 }
251
252 // Set SchemaVersion if not provided
253 if request.GetMetadata().GetSchemaVersion() == "" { // Check if the request has a SchemaVersion.
254 request.Metadata.SchemaVersion, err = invoker.schemaReader.HeadVersion(ctx, request.GetTenantId()) // Retrieve the head schema version from the schema reader.
255 if err != nil {
256 span.RecordError(err)
257 span.SetStatus(otelCodes.Error, err.Error())
258 return response, err
259 }
260 }
261
262 resp, err := invoker.lo.LookupEntity(ctx, request)
263
264 invoker.lookupEntityHistogram.Record(ctx, 1)
265
266 return resp, err
267}
268
269// LookupEntityStream is a method that implements the LookupEntityStream interface.
270// It calls the Stream method of the LookupEntityEngine with the provided context, PermissionLookupEntityRequest, and Permission_LookupEntityStreamServer,

Callers

nothing calls this directly

Calls 15

EncodeMethod · 0.95
SubjectToStringFunction · 0.92
StartMethod · 0.80
GetEntityTypeMethod · 0.80
HeadSnapshotMethod · 0.65
StringMethod · 0.65
HeadVersionMethod · 0.65
LookupEntityMethod · 0.65
GetTenantIdMethod · 0.45
GetPermissionMethod · 0.45
GetSubjectMethod · 0.45
GetSnapTokenMethod · 0.45

Tested by

no test coverage detected