store

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

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

View Source
var (
	ErrNotFound = errors.New("not found")
	ErrConflict = errors.New("already exists")
)

Sentinel errors returned by store implementations.

Functions

This section is empty.

Types

type Operation

type Operation struct {
	Name     string `json:"name"`
	Resource string `json:"resource"`
}

Operation is an action on a resource, named "resource:action".

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

type RoleGrant struct {
	Role      string
	Operation string
	Scope     model.Scope
}

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 {
	EnsureUser(sub string) error
	ListUsers() ([]User, error)

	CreateResource(name string) error // ErrConflict when it exists
	EnsureResource(name string) error
	DeleteResource(name string) error // ErrNotFound; cascades operations
	ListResources() ([]Resource, error)

	CreateOperation(name, resource string) error // ErrConflict; ensures the resource
	EnsureOperation(name, resource string) error
	DeleteOperation(name string) error // ErrNotFound
	ListOperations() ([]Operation, error)
	OperationExists(name string) (bool, error)
}

Shared is the global store holding resources, operations and users.

type Stores

type Stores struct {
	Shared Shared
	// contains filtered or unexported fields
}

Stores holds the shared store plus one store per tenant.

func Open

func Open(cfg config.Storage) (*Stores, error)

Open connects every configured store and runs migrations where needed. Opening is idempotent, so repeated startups are safe.

func (*Stores) Tenant

func (s *Stores) Tenant(id string) (Tenant, bool)

Tenant returns the store for the given tenant ID, or false when the tenant is not configured.

func (*Stores) TenantIDs

func (s *Stores) TenantIDs() []string

TenantIDs returns the sorted list of configured tenant IDs.

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.

type User

type User struct {
	Sub string `json:"sub"`
}

User is a lazily provisioned principal identified by its OIDC sub claim.

Jump to

Keyboard shortcuts

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