bakery

package module
v0.0.0-...-b29d202 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2021 License: BSD-2-Clause Imports: 9 Imported by: 0

README

bakery GoDoc

import "github.com/guregu/bakery"

bakery is a small helper library to assist with wrangling Biscuits. Very experimental, expect this to change as I learn more about Biscuits.

This library lets you organize your Datalog facts, rules, and caveats in a file system. A recipe is a file, containing multiple Datalog statements separated by semicolons. A cookbook is a folder containing multiple recipes. The bakery keeps track of your cookbooks.

Example

import (
	"embed"

	"github.com/biscuit-auth/biscuit-go"
	"github.com/biscuit-auth/biscuit-go/sig"
	"github.com/guregu/bakery"
)

//go:embed bakery
var bakeryFS embed.FS

func main() {
	// a bakery is a collection of cookbooks
	bake, err := bakery.New(bakeryFS, "bakery")
	if err != nil {
		t.Fatal(err)
	}
	
	// a cookbook is a collection of datalog recipes
	cookbook := bake.Cookbook("hierarchy")
	// a recipe is a bundle of datalog data that can be applied to new biscuits, verifiers, etc
	recipe := cookbook.Find("base")

	// create a new biscuit via the "base" recipe
	keys := sig.GenerateKeypair(nil)
	builder := biscuit.NewBuilder(keys)
	recipe.Build(builder) // apply recipe to biscuit builder
	bisc, _ := builder.Build()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bakery

type Bakery struct {
	// contains filtered or unexported fields
}

Bakery is a biscuit factory. Datalog files (recipes) are grouped together by folder (cookbooks).

func New

func New(fsys fs.FS, root string) (*Bakery, error)

New loads a new Bakery from the given file system and root directory. It will recursively walk through folders, looking for datalog files (recipes). Datalog files will be grouped by their parent folder, which becomes the name of the cookbook.

func (*Bakery) Cookbook

func (b *Bakery) Cookbook(name string) Cookbook

Cookbook looks up a cookbook by name, corresponding to the directory name.

type Cookbook

type Cookbook []*Recipe

Cookbook is a list of recipes.

func (Cookbook) Find

func (cb Cookbook) Find(name string) *Recipe

Find looks up a recipe with the given name. Recipe names have their file extension removed, so "foo.datalog" is found by Find("foo").

func (Cookbook) Merged

func (cb Cookbook) Merged() *Recipe

Merged returns a recipe that is the result of merging all of this cookbook's recipes.

type Recipe

type Recipe struct {
	Name    string
	Facts   []biscuit.Fact
	Rules   []biscuit.Rule
	Caveats []biscuit.Caveat
}

Recipe is a collection of datalog objects. Think of it like a biscuit template, a cookie sheet if you will.

func NewRecipe

func NewRecipe(name string, r io.Reader) (*Recipe, error)

NewRecipe loads a biscuit recipe with the given name from r. Recipes are Datalog files. Multiple Datalog statements may be separated via newline terminated semicolons.

func (*Recipe) Apply

func (r *Recipe) Apply(b biscuit.Verifier)

Apply adds all of this recipe's facts, rules, and caveats to the given verifier.

func (*Recipe) Build

func (r *Recipe) Build(b biscuit.Builder) error

Build adds all of this recipe's facts, rules, and caveats as authority data to the given builder.

func (*Recipe) BuildBlock

func (r *Recipe) BuildBlock(b biscuit.BlockBuilder) error

BuildBlock adds all of this recipe's facts, rules, and caveats to the given block builder.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL