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 ¶
- Variables
- type Migrated
- type Right
- type Rights
- func (r *Rights) Can(ctx context.Context, accountID string, right Right, profileID string) (bool, error)
- func (r *Rights) Close()
- func (r *Rights) DeleteOwned(ctx context.Context, accountID string, profileIDs []string) error
- func (r *Rights) DeleteOwner(ctx context.Context, accountID, profileID string) error
- func (r *Rights) OwnedProfiles(ctx context.Context, accountID string) ([]string, error)
- func (r *Rights) WriteOwner(ctx context.Context, accountID, profileID string) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
type Right string
A Right is what a request asks on a learner's profile (architecture 3.1).
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 ¶
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) DeleteOwned ¶
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 ¶
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 ¶
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 ¶
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).