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

Method checkDirect

internal/check/engine.go:169–210  ·  view source on GitHub ↗

checkDirect checks if the relation tuple is in the database directly.

(r *relationTuple, restDepth int)

Source from the content-addressed store, hash-verified

167
168// checkDirect checks if the relation tuple is in the database directly.
169func (e *Engine) checkDirect(r *relationTuple, restDepth int) checkgroup.CheckFunc {
170 if restDepth <= 0 {
171 e.d.Logger().
172 WithField("method", "checkDirect").
173 Debug("reached max-depth, therefore this query will not be further expanded")
174 return checkgroup.UnknownMemberFunc
175 }
176 return func(ctx context.Context, resultCh chan<- checkgroup.Result) {
177 e.d.Logger().
178 WithField("request", r.String()).
179 Trace("check direct")
180 found, err := e.d.RelationTupleManager().ExistsRelationTuples(
181 ctx,
182 r.ToQuery(),
183 )
184
185 switch {
186 case err != nil:
187 e.d.Logger().
188 WithField("method", "checkDirect").
189 WithError(err).
190 Error("failed to look up direct access in db")
191 resultCh <- checkgroup.Result{
192 Membership: checkgroup.NotMember,
193 }
194
195 case found:
196 resultCh <- checkgroup.Result{
197 Membership: checkgroup.IsMember,
198 Tree: &ketoapi.Tree[*relationtuple.RelationTuple]{
199 Type: ketoapi.TreeNodeLeaf,
200 Tuple: r,
201 },
202 }
203
204 default:
205 resultCh <- checkgroup.Result{
206 Membership: checkgroup.NotMember,
207 }
208 }
209 }
210}
211
212// checkIsAllowed checks if the relation tuple is allowed (there is a path from
213// the relation tuple subject to the namespace, object and relation) either

Callers 1

checkIsAllowedMethod · 0.95

Calls 9

DebugMethod · 0.80
WithFieldMethod · 0.80
WithErrorMethod · 0.80
LoggerMethod · 0.65
StringMethod · 0.65
ExistsRelationTuplesMethod · 0.65
RelationTupleManagerMethod · 0.65
ToQueryMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected