authz

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package authz is api's rights: OpenFGA, a library in api's own process, on its store in the database openfga (R04, R31). The model is section 3.1's, which the binary embeds; migrate puts it in the store, and the server only checks that the store holds it. Code asks a right and writes the tuple owner through Rights.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoStore is a database openfga with no store of api in it.
	ErrNoStore = errors.New("authz: no store api: run api migrate")
	// ErrModelDiffers is a store whose latest model is not the one api embeds.
	ErrModelDiffers = errors.New("authz: the store's model is not api's: run api migrate")
)

The refusals of Open, each of which migrate puts right.

Functions

This section is empty.

Types

type Migrated

type Migrated struct {
	// Applied is how many of OpenFGA's migrations it applied, and Version the
	// version the schema is at.
	Applied int
	Version int64
	// StoreCreated and ModelWritten say whether it made the store api and wrote
	// the model, which it does only when the store has none, or no model that
	// says what the embedded one says.
	StoreCreated bool
	ModelWritten bool
}

Migrated is what a run of Migrate did.

func Migrate

func Migrate(ctx context.Context, url string) (Migrated, error)

Migrate brings the database openfga at url — the direct connection — to what api needs: OpenFGA's schema, the store api, and in it the model api embeds (R31). The schema's migrations are OpenFGA's own files, which goose runs under its advisory lock of the session as it runs api's (R29), rather than by OpenFGA's RunMigrations: that one takes no lock, works on goose's global state, and its package brings a MySQL driver under MPL-2.0 into the binary.

type Right string

A Right is what a request asks on a learner's profile (architecture 3.1).

const (
	// CanLearn is for the learning requests.
	CanLearn Right = "can_learn"
	// CanManage is for an adult's actions on the profile.
	CanManage Right = "can_manage"
	// CanView is for reading the progress.
	CanView Right = "can_view"
)

The rights of the model.

type Rights

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

Rights is the port of api's rights, on the store api with its model.

func Open

func Open(ctx context.Context, url string) (*Rights, error)

Open opens the rights on the database at url — the pooler's, for serve — and finds the store and, among its models, the one api embeds. It writes neither: a store that is missing, or holds no such model, is a migrate that did not run, and Open refuses it (R31). The model is found among all of the store's, not only as the latest, so that a revision still serving while a newer one rolls out — or one rolled back to — starts on its own model.

func (*Rights) Can

func (r *Rights) Can(ctx context.Context, accountID string, right Right, profileID string) (bool, error)

Can says whether the account has the right on the profile. A profile that is not there, and one that is another account's, both say no, so that the answer tells nothing of a profile the account does not own (architecture 3.1).

func (*Rights) Close

func (r *Rights) Close()

Close closes the server, and its datastore with it.

func (*Rights) DeleteOwned

func (r *Rights) DeleteOwned(ctx context.Context, accountID string, profileIDs []string) error

DeleteOwned deletes the account's tuples of the profiles, as many at once as OpenFGA takes, skipping those that are not there (R21; R27 canvas-api).

func (*Rights) DeleteOwner

func (r *Rights) DeleteOwner(ctx context.Context, accountID, profileID string) error

DeleteOwner deletes the tuple of the profile, after the transaction that deleted it (R21). A tuple that is not there is no error.

func (*Rights) OwnedProfiles

func (r *Rights) OwnedProfiles(ctx context.Context, accountID string) ([]string, error)

OwnedProfiles is the IDs of the profiles the account owns by its tuples, which the deletion of an account reads them by (R21).

func (*Rights) WriteOwner

func (r *Rights) WriteOwner(ctx context.Context, accountID, profileID string) error

WriteOwner writes the tuple: the account owns the profile. A repeat is no error. It is written inside the transaction of the database api that makes the profile, before its COMMIT (architecture 3.1; R31).

Jump to

Keyboard shortcuts

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