| 66 | } |
| 67 | |
| 68 | func (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 | |