Skip to content

Commit d4b5df8

Browse files
committed
feat: retrieve facts by name
Fix #160
1 parent 03f848b commit d4b5df8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

biscuit.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,37 @@ func (b *Biscuit) Seal(rng io.Reader) (*Biscuit, error) {
294294
}, nil
295295
}
296296

297+
func (b *Biscuit) Lookup(factName string) []string {
298+
symbols := b.symbols.Clone()
299+
datalogFactName := symbols.Sym(factName)
300+
301+
if b.authority.facts == nil {
302+
return nil
303+
}
304+
305+
for _, f := range *b.authority.facts {
306+
if f.Name != datalogFactName {
307+
continue
308+
}
309+
310+
terms := make([]string, len(f.Terms))
311+
for i, term := range f.Terms {
312+
switch t := term.(type) {
313+
case datalog.String:
314+
terms[i] = symbols.Str(t)
315+
case datalog.Variable:
316+
terms[i] = symbols.Var(t)
317+
default:
318+
terms[i] = t.String()
319+
}
320+
}
321+
322+
return terms
323+
}
324+
325+
return nil
326+
}
327+
297328
type (
298329
// A PublickKeyByIDProjection inspects an optional ID for a public key and returns the
299330
// corresponding public key, if any. If it doesn't recognize the ID or can't find the public

0 commit comments

Comments
 (0)