Documentation
¶
Overview ¶
Package store defines the storage interfaces of Sforza and their implementations: a GORM-backed store (SQLite, PostgreSQL, MySQL) and a local JSON file store.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrConflict = errors.New("already exists") )
Sentinel errors returned by store implementations.
Functions ¶
This section is empty.
Types ¶
type Resource ¶
type Resource struct {
Name string `json:"name"`
}
Resource is a logical domain entity that groups operations.
type Role ¶
type Role struct {
Name string `json:"name"`
}
Role is a named set of (operation, scope) assignments within a tenant.
type RoleGrant ¶
RoleGrant is one (role, operation, scope) triple, used by permission resolution to attribute RESTRICTED grants to the roles providing them.
type Shared ¶
type Shared interface {
}
Shared is the global store holding resources, operations and users.
type Stores ¶
type Stores struct {
// contains filtered or unexported fields
}
Stores holds the shared store plus one store per tenant.
func Open ¶
Open connects every configured store and runs migrations where needed. Opening is idempotent, so repeated startups are safe.
type Tenant ¶
type Tenant interface {
CreateRole(name string) error // ErrConflict
EnsureRole(name string) error
RoleExists(name string) (bool, error)
RenameRole(name, newName string) error // ErrNotFound / ErrConflict
DeleteRole(name string) error // ErrNotFound; cascades everything
ListRoles() ([]Role, error)
AssignRole(sub, role string) error // ErrNotFound when the role is missing; idempotent
UnassignRole(sub, role string) error // ErrNotFound when not assigned
UserRoles(sub string) ([]string, error)
SetRolePermission(role, operation string, scope model.Scope) error // upsert; ErrNotFound role
RemoveRolePermission(role, operation string) error // ErrNotFound; cascades IDs
RolePermissions(role string) ([]model.OperationScope, error) // ErrNotFound role
HasRolePermission(role, operation string) (bool, error) // ErrNotFound role
SetUserPermission(sub, operation string, scope model.Scope) error // upsert
RemoveUserPermission(sub, operation string) error // ErrNotFound; cascades IDs
UserPermissions(sub string) ([]model.OperationScope, error)
HasUserPermission(sub, operation string) (bool, error)
AddRoleRestrictedIDs(role, operation string, ids []string) error // idempotent
RemoveRoleRestrictedIDs(role, operation string, ids []string) error
RoleRestrictedIDs(roles []string, operation string) ([]string, error) // deduplicated union
AddUserRestrictedIDs(sub, operation string, ids []string) error // idempotent
RemoveUserRestrictedIDs(sub, operation string, ids []string) error
UserRestrictedIDs(sub, operation string) ([]string, error)
// RoleGrants returns every (role, operation, scope) triple of the given roles.
RoleGrants(roles []string) ([]RoleGrant, error)
}
Tenant is the per-tenant store holding roles, assignments, permissions and restricted record IDs.