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

Method FromTuple

internal/relationtuple/uuid_mapping.go:198–266  ·  view source on GitHub ↗
(ctx context.Context, ts ...*ketoapi.RelationTuple)

Source from the content-addressed store, hash-verified

196}
197
198func (m *Mapper) FromTuple(ctx context.Context, ts ...*ketoapi.RelationTuple) (res []*RelationTuple, err error) {
199 ctx, span := trace.SpanFromContext(ctx).TracerProvider().Tracer("keto/internal/relationtuple").Start(ctx, "Mapper.FromTuple")
200 defer otelx.End(span, &err)
201
202 onSuccess := newSuccess(&err)
203 defer onSuccess.apply()
204
205 res = make([]*RelationTuple, 0, len(ts))
206 s := make([]string, 0, len(ts)*2)
207 var u []uuid.UUID
208
209 nm, err := m.D.Config(ctx).NamespaceManager()
210 if err != nil {
211 return nil, err
212 }
213
214 for _, t := range ts {
215 t := t
216 n, err := nm.GetNamespaceByName(ctx, t.Namespace)
217 if err != nil {
218 return nil, err
219 }
220 mt := RelationTuple{
221 Namespace: n.Name,
222 Relation: t.Relation,
223 }
224 i := len(res)
225
226 if err := t.Validate(); err != nil {
227 return nil, err
228 }
229 if t.SubjectID != nil {
230 s = append(s, *t.SubjectID)
231 onSuccess.do(func() {
232 mt.Subject = &SubjectID{u[i*2]}
233 })
234 } else if t.SubjectSet != nil {
235 n, err := nm.GetNamespaceByName(ctx, t.SubjectSet.Namespace)
236 if err != nil {
237 return nil, err
238 }
239 s = append(s, t.SubjectSet.Object)
240 onSuccess.do(func() {
241 mt.Subject = &SubjectSet{
242 Namespace: n.Name,
243 Object: u[i*2],
244 Relation: t.SubjectSet.Relation,
245 }
246 })
247 }
248
249 s = append(s, t.Object)
250 onSuccess.do(func() {
251 mt.Object = u[i*2+1]
252 })
253
254 res = append(res, &mt)
255 }

Callers 12

TestMigrationsFunction · 0.80
TestMapperFunction · 0.80
BenchmarkReadOnlyMapperFunction · 0.80
createRelationMethod · 0.80
patchRelationTuplesMethod · 0.80
TestWriteHandlersFunction · 0.80
MapAndWriteTuplesFunction · 0.80
BatchCheckMethod · 0.80
getCheckMethod · 0.80
postCheckMethod · 0.80
CheckMethod · 0.80

Calls 11

newSuccessFunction · 0.85
ValidateMethod · 0.80
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 4

TestMigrationsFunction · 0.64
TestMapperFunction · 0.64
BenchmarkReadOnlyMapperFunction · 0.64
TestWriteHandlersFunction · 0.64