MCPcopy
hub / github.com/ory/keto / FromQuery

Method FromQuery

internal/relationtuple/uuid_mapping.go:68–135  ·  view source on GitHub ↗
(ctx context.Context, apiQuery *ketoapi.RelationQuery)

Source from the content-addressed store, hash-verified

66}
67
68func (m *Mapper) FromQuery(ctx context.Context, apiQuery *ketoapi.RelationQuery) (res *RelationQuery, err error) {
69 ctx, span := trace.SpanFromContext(ctx).TracerProvider().Tracer("keto/internal/relationtuple").Start(ctx, "Mapper.FromQuery")
70 defer otelx.End(span, &err)
71
72 onSuccess := newSuccess(&err)
73 defer onSuccess.apply()
74
75 var s []string
76 var u []uuid.UUID
77 res = &RelationQuery{
78 Relation: apiQuery.Relation,
79 }
80
81 nm, err := m.D.Config(ctx).NamespaceManager()
82 if err != nil {
83 return nil, err
84 }
85
86 if apiQuery.Namespace != nil {
87 n, err := nm.GetNamespaceByName(ctx, *apiQuery.Namespace)
88 if err != nil {
89 return nil, err
90 }
91 res.Namespace = new(n.Name)
92 }
93 if apiQuery.Object != nil {
94 s = append(s, *apiQuery.Object)
95 onSuccess.do(func(i int) func() {
96 return func() {
97 res.Object = new(u[i])
98 }
99 }(len(s) - 1))
100 }
101 if apiQuery.SubjectID != nil {
102 s = append(s, *apiQuery.SubjectID)
103 onSuccess.do(func(i int) func() {
104 return func() {
105 res.Subject = &SubjectID{u[i]}
106 }
107 }(len(s) - 1))
108 }
109 if apiQuery.SubjectSet != nil {
110 s = append(s, apiQuery.SubjectSet.Object)
111 n, err := nm.GetNamespaceByName(ctx, apiQuery.SubjectSet.Namespace)
112 if err != nil {
113 return nil, err
114 }
115 onSuccess.do(func(i int) func() {
116 return func() {
117 res.Subject = &SubjectSet{
118 Namespace: n.Name,
119 Object: u[i],
120 Relation: apiQuery.SubjectSet.Relation,
121 }
122 }
123 }(len(s) - 1))
124 }
125

Callers 6

TestMapperFunction · 0.80
ListRelationTuplesMethod · 0.80
getRelationsMethod · 0.80
DeleteRelationTuplesMethod · 0.80
deleteRelationsMethod · 0.80
TestWriteHandlersFunction · 0.80

Calls 10

newSuccessFunction · 0.85
doMethod · 0.80
TracerMethod · 0.65
NamespaceManagerMethod · 0.65
ConfigMethod · 0.65
GetNamespaceByNameMethod · 0.65
MappingManagerMethod · 0.65
MapStringsToUUIDsMethod · 0.65
applyMethod · 0.45

Tested by 2

TestMapperFunction · 0.64
TestWriteHandlersFunction · 0.64