Documentation
¶
Overview ¶
Package sqlite provides a SQLite Store implementation for embedded/edge use.
Busy timeout ¶
SQLite is single-writer: a second connection that tries to write while another holds the lock fails immediately with SQLITE_BUSY unless a busy_timeout is configured, in which case it retries for that long before giving up. busy_timeout is a per-connection setting, and grove's sqlite driver opens a pool of connections (default size 10), so setting it after the pool exists, as Store's WithBusyTimeout option does, only reaches whichever connection that call happens to land on.
For a setting that reliably reaches every connection the pool ever opens, set it in the DSN instead, using modernc.org/sqlite's _pragma query parameter, which is applied at connection-open time:
file:warden.db?_pragma=busy_timeout(5000)
Combine with other pragmas by repeating the parameter:
file:warden.db?_pragma=busy_timeout(5000)&_pragma=foreign_keys(1)
Index ¶
- Variables
- type Option
- type Store
- func (s *Store) AttachPermission(ctx context.Context, tenantID string, roleID id.RoleID, ref permission.Ref) error
- func (s *Store) CheckDirectRelation(ctx context.Context, tenantID string, namespacePaths []string, ...) (bool, error)
- func (s *Store) Close() error
- func (s *Store) CountAssignments(ctx context.Context, filter *assignment.ListFilter) (int64, error)
- func (s *Store) CountCheckLogs(ctx context.Context, filter *checklog.QueryFilter) (int64, error)
- func (s *Store) CountPermissions(ctx context.Context, filter *permission.ListFilter) (int64, error)
- func (s *Store) CountPolicies(ctx context.Context, filter *policy.ListFilter) (int64, error)
- func (s *Store) CountRelations(ctx context.Context, filter *relation.ListFilter) (int64, error)
- func (s *Store) CountResourceTypes(ctx context.Context, filter *resourcetype.ListFilter) (int64, error)
- func (s *Store) CountRoles(ctx context.Context, filter *role.ListFilter) (int64, error)
- func (s *Store) CreateAssignment(ctx context.Context, a *assignment.Assignment) error
- func (s *Store) CreateCheckLog(ctx context.Context, e *checklog.Entry) error
- func (s *Store) CreatePermission(ctx context.Context, p *permission.Permission) error
- func (s *Store) CreatePolicy(ctx context.Context, p *policy.Policy) error
- func (s *Store) CreateRelation(ctx context.Context, t *relation.Tuple) error
- func (s *Store) CreateResourceType(ctx context.Context, rt *resourcetype.ResourceType) error
- func (s *Store) CreateRole(ctx context.Context, r *role.Role) error
- func (s *Store) DeleteAssignment(ctx context.Context, tenantID string, assID id.AssignmentID) error
- func (s *Store) DeleteAssignmentsByRole(ctx context.Context, tenantID string, roleID id.RoleID) error
- func (s *Store) DeleteAssignmentsBySubject(ctx context.Context, tenantID, subjectKind, subjectID string) error
- func (s *Store) DeleteAssignmentsByTenant(ctx context.Context, tenantID string) error
- func (s *Store) DeleteCheckLogsBySubject(ctx context.Context, tenantID, subjectKind, subjectID string) (int64, error)
- func (s *Store) DeleteCheckLogsByTenant(ctx context.Context, tenantID string) error
- func (s *Store) DeleteExpiredAssignments(ctx context.Context, now time.Time) (int64, error)
- func (s *Store) DeleteExpiredAssignmentsForTenant(ctx context.Context, tenantID string, now time.Time) (int64, error)
- func (s *Store) DeletePermission(ctx context.Context, tenantID string, permID id.PermissionID) error
- func (s *Store) DeletePermissionsByTenant(ctx context.Context, tenantID string) error
- func (s *Store) DeletePoliciesByTenant(ctx context.Context, tenantID string) error
- func (s *Store) DeletePolicy(ctx context.Context, tenantID string, polID id.PolicyID) error
- func (s *Store) DeleteRelation(ctx context.Context, tenantID string, relID id.RelationID) error
- func (s *Store) DeleteRelationTuple(ctx context.Context, ...) error
- func (s *Store) DeleteRelationsByObject(ctx context.Context, tenantID, objectType, objectID string) error
- func (s *Store) DeleteRelationsBySubject(ctx context.Context, tenantID, subjectType, subjectID string) error
- func (s *Store) DeleteRelationsByTenant(ctx context.Context, tenantID string) error
- func (s *Store) DeleteResourceType(ctx context.Context, tenantID string, rtID id.ResourceTypeID) error
- func (s *Store) DeleteResourceTypesByTenant(ctx context.Context, tenantID string) error
- func (s *Store) DeleteRole(ctx context.Context, tenantID string, roleID id.RoleID) error
- func (s *Store) DeleteRolesByTenant(ctx context.Context, tenantID string) error
- func (s *Store) DetachPermission(ctx context.Context, tenantID string, roleID id.RoleID, ref permission.Ref) error
- func (s *Store) GetAssignment(ctx context.Context, tenantID string, assID id.AssignmentID) (*assignment.Assignment, error)
- func (s *Store) GetCheckLog(ctx context.Context, tenantID string, logID id.CheckLogID) (*checklog.Entry, error)
- func (s *Store) GetPermission(ctx context.Context, tenantID string, permID id.PermissionID) (*permission.Permission, error)
- func (s *Store) GetPermissionByName(ctx context.Context, tenantID, namespacePath, name string) (*permission.Permission, error)
- func (s *Store) GetPolicy(ctx context.Context, tenantID string, polID id.PolicyID) (*policy.Policy, error)
- func (s *Store) GetPolicyByName(ctx context.Context, tenantID, namespacePath, name string) (*policy.Policy, error)
- func (s *Store) GetRelation(ctx context.Context, tenantID string, relID id.RelationID) (*relation.Tuple, error)
- func (s *Store) GetResourceType(ctx context.Context, tenantID string, rtID id.ResourceTypeID) (*resourcetype.ResourceType, error)
- func (s *Store) GetResourceTypeByName(ctx context.Context, tenantID, namespacePath, name string) (*resourcetype.ResourceType, error)
- func (s *Store) GetRole(ctx context.Context, tenantID string, roleID id.RoleID) (*role.Role, error)
- func (s *Store) GetRoleBySlug(ctx context.Context, tenantID, namespacePath, slug string) (*role.Role, error)
- func (s *Store) GetRoles(ctx context.Context, tenantID string, roleIDs []id.RoleID) ([]*role.Role, error)
- func (s *Store) ListActivePolicies(ctx context.Context, tenantID string, namespacePaths []string) ([]*policy.Policy, error)
- func (s *Store) ListAssignments(ctx context.Context, filter *assignment.ListFilter) ([]*assignment.Assignment, error)
- func (s *Store) ListCheckLogs(ctx context.Context, filter *checklog.QueryFilter) ([]*checklog.Entry, error)
- func (s *Store) ListChildRoles(ctx context.Context, tenantID, parentSlug string) ([]*role.Role, error)
- func (s *Store) ListExpiringAssignments(ctx context.Context, tenantID string, before time.Time, limit int) ([]*assignment.Assignment, error)
- func (s *Store) ListPermissions(ctx context.Context, filter *permission.ListFilter) ([]*permission.Permission, error)
- func (s *Store) ListPermissionsByRole(ctx context.Context, tenantID string, roleID id.RoleID) ([]*permission.Permission, error)
- func (s *Store) ListPermissionsBySubject(ctx context.Context, tenantID, subjectKind, subjectID string) ([]*permission.Permission, error)
- func (s *Store) ListPolicies(ctx context.Context, filter *policy.ListFilter) ([]*policy.Policy, error)
- func (s *Store) ListRelationObjects(ctx context.Context, ...) ([]*relation.Tuple, error)
- func (s *Store) ListRelationSubjects(ctx context.Context, tenantID string, namespacePaths []string, ...) ([]*relation.Tuple, error)
- func (s *Store) ListRelations(ctx context.Context, filter *relation.ListFilter) ([]*relation.Tuple, error)
- func (s *Store) ListResourceTypes(ctx context.Context, filter *resourcetype.ListFilter) ([]*resourcetype.ResourceType, error)
- func (s *Store) ListRolePermissions(ctx context.Context, tenantID string, roleID id.RoleID) ([]*permission.Permission, error)
- func (s *Store) ListRolePermissionsForRoles(ctx context.Context, tenantID string, roleIDs []id.RoleID) (map[id.RoleID][]*permission.Permission, error)
- func (s *Store) ListRoles(ctx context.Context, filter *role.ListFilter) ([]*role.Role, error)
- func (s *Store) ListRolesForSubject(ctx context.Context, tenantID string, namespacePaths []string, ...) ([]id.RoleID, error)
- func (s *Store) ListRolesForSubjectOnResource(ctx context.Context, tenantID string, namespacePaths []string, ...) ([]id.RoleID, error)
- func (s *Store) ListSubjectsForRole(ctx context.Context, tenantID string, roleID id.RoleID) ([]*assignment.Assignment, error)
- func (s *Store) Migrate(ctx context.Context) error
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) PurgeCheckLogs(ctx context.Context, before time.Time) (int64, error)
- func (s *Store) PurgeCheckLogsForTenant(ctx context.Context, tenantID string, before time.Time) (int64, error)
- func (s *Store) SetPolicyVersion(ctx context.Context, tenantID string, polID id.PolicyID, version int) error
- func (s *Store) SetRolePermissions(ctx context.Context, tenantID string, roleID id.RoleID, refs []permission.Ref) error
- func (s *Store) UpdatePermission(ctx context.Context, p *permission.Permission) error
- func (s *Store) UpdatePolicy(ctx context.Context, p *policy.Policy) error
- func (s *Store) UpdatePolicyIfVersion(ctx context.Context, p *policy.Policy, expected int) error
- func (s *Store) UpdateResourceType(ctx context.Context, rt *resourcetype.ResourceType) error
- func (s *Store) UpdateRole(ctx context.Context, r *role.Role) error
Constants ¶
This section is empty.
Variables ¶
var Migrations = migrate.NewGroup("warden")
Migrations is the grove migration group for the Warden store (SQLite).
Functions ¶
This section is empty.
Types ¶
type Option ¶ added in v1.7.0
type Option func(*storeConfig)
Option configures a Store at construction time.
func WithBusyTimeout ¶ added in v1.7.0
WithBusyTimeout returns an Option that sets SQLite's busy_timeout (how long a writer waits on a locked database before returning SQLITE_BUSY) for the connection New acquires immediately to apply it.
This pragma is per-connection, and grove's sqlite driver hands out connections from a pool (default size 10; see sqlitedriver.SqliteDB.Open), so a single SET issued here is not guaranteed to reach every connection the pool later opens. For a guarantee that covers the whole pool, prefer the DSN form documented in this package's doc comment (file:foo.db?_pragma=busy_timeout(5000)), which modernc.org/sqlite applies to every physical connection at open time. WithBusyTimeout is a best-effort supplement for callers who only control the *grove.DB handle.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a SQLite implementation of the composite Warden store.
func New ¶
New creates a new SQLite store. See WithBusyTimeout for the caveats of setting busy_timeout after the pool already exists.
func (*Store) AttachPermission ¶
func (*Store) CheckDirectRelation ¶
func (*Store) CountAssignments ¶
func (s *Store) CountAssignments(ctx context.Context, filter *assignment.ListFilter) (int64, error)
func (*Store) CountCheckLogs ¶
func (*Store) CountPermissions ¶
func (s *Store) CountPermissions(ctx context.Context, filter *permission.ListFilter) (int64, error)
func (*Store) CountPolicies ¶
func (*Store) CountRelations ¶
func (*Store) CountResourceTypes ¶
func (s *Store) CountResourceTypes(ctx context.Context, filter *resourcetype.ListFilter) (int64, error)
func (*Store) CountRoles ¶
func (*Store) CreateAssignment ¶
func (s *Store) CreateAssignment(ctx context.Context, a *assignment.Assignment) error
func (*Store) CreateCheckLog ¶
func (*Store) CreatePermission ¶
func (s *Store) CreatePermission(ctx context.Context, p *permission.Permission) error
func (*Store) CreatePolicy ¶
func (*Store) CreateRelation ¶
func (*Store) CreateResourceType ¶
func (s *Store) CreateResourceType(ctx context.Context, rt *resourcetype.ResourceType) error
func (*Store) DeleteAssignment ¶
func (*Store) DeleteAssignmentsByRole ¶
func (*Store) DeleteAssignmentsBySubject ¶
func (*Store) DeleteAssignmentsByTenant ¶
func (*Store) DeleteCheckLogsBySubject ¶ added in v1.7.0
func (*Store) DeleteCheckLogsByTenant ¶
func (*Store) DeleteExpiredAssignments ¶
func (*Store) DeleteExpiredAssignmentsForTenant ¶ added in v1.7.0
func (*Store) DeletePermission ¶
func (*Store) DeletePermissionsByTenant ¶
func (*Store) DeletePoliciesByTenant ¶
func (*Store) DeletePolicy ¶
func (*Store) DeleteRelation ¶
func (*Store) DeleteRelationTuple ¶
func (*Store) DeleteRelationsByObject ¶
func (*Store) DeleteRelationsBySubject ¶
func (*Store) DeleteRelationsByTenant ¶
func (*Store) DeleteResourceType ¶
func (*Store) DeleteResourceTypesByTenant ¶
func (*Store) DeleteRole ¶
DeleteRole removes a role. Assignments and grants go with it via the foreign-key cascades in the schema.
func (*Store) DeleteRolesByTenant ¶
func (*Store) DetachPermission ¶
func (*Store) GetAssignment ¶
func (s *Store) GetAssignment(ctx context.Context, tenantID string, assID id.AssignmentID) (*assignment.Assignment, error)
func (*Store) GetCheckLog ¶
func (*Store) GetPermission ¶
func (s *Store) GetPermission(ctx context.Context, tenantID string, permID id.PermissionID) (*permission.Permission, error)
func (*Store) GetPermissionByName ¶
func (s *Store) GetPermissionByName(ctx context.Context, tenantID, namespacePath, name string) (*permission.Permission, error)
func (*Store) GetPolicyByName ¶
func (*Store) GetRelation ¶ added in v1.7.0
func (*Store) GetResourceType ¶
func (s *Store) GetResourceType(ctx context.Context, tenantID string, rtID id.ResourceTypeID) (*resourcetype.ResourceType, error)
func (*Store) GetResourceTypeByName ¶
func (s *Store) GetResourceTypeByName(ctx context.Context, tenantID, namespacePath, name string) (*resourcetype.ResourceType, error)
func (*Store) GetRoleBySlug ¶
func (*Store) ListActivePolicies ¶
func (*Store) ListAssignments ¶
func (s *Store) ListAssignments(ctx context.Context, filter *assignment.ListFilter) ([]*assignment.Assignment, error)
func (*Store) ListCheckLogs ¶
func (*Store) ListChildRoles ¶
func (*Store) ListExpiringAssignments ¶ added in v1.7.0
func (s *Store) ListExpiringAssignments(ctx context.Context, tenantID string, before time.Time, limit int) ([]*assignment.Assignment, error)
func (*Store) ListPermissions ¶
func (s *Store) ListPermissions(ctx context.Context, filter *permission.ListFilter) ([]*permission.Permission, error)
func (*Store) ListPermissionsByRole ¶
func (s *Store) ListPermissionsByRole(ctx context.Context, tenantID string, roleID id.RoleID) ([]*permission.Permission, error)
func (*Store) ListPermissionsBySubject ¶
func (s *Store) ListPermissionsBySubject(ctx context.Context, tenantID, subjectKind, subjectID string) ([]*permission.Permission, error)
func (*Store) ListPolicies ¶
func (*Store) ListRelationObjects ¶
func (*Store) ListRelationSubjects ¶
func (*Store) ListRelations ¶
func (*Store) ListResourceTypes ¶
func (s *Store) ListResourceTypes(ctx context.Context, filter *resourcetype.ListFilter) ([]*resourcetype.ResourceType, error)
func (*Store) ListRolePermissions ¶
func (s *Store) ListRolePermissions(ctx context.Context, tenantID string, roleID id.RoleID) ([]*permission.Permission, error)
func (*Store) ListRolePermissionsForRoles ¶ added in v1.7.0
func (*Store) ListRolesForSubject ¶
func (*Store) ListRolesForSubjectOnResource ¶
func (*Store) ListSubjectsForRole ¶
func (s *Store) ListSubjectsForRole(ctx context.Context, tenantID string, roleID id.RoleID) ([]*assignment.Assignment, error)
func (*Store) PurgeCheckLogs ¶
func (*Store) PurgeCheckLogsForTenant ¶ added in v1.7.0
func (*Store) SetPolicyVersion ¶
func (*Store) SetRolePermissions ¶
func (*Store) UpdatePermission ¶
func (s *Store) UpdatePermission(ctx context.Context, p *permission.Permission) error
func (*Store) UpdatePolicy ¶
func (*Store) UpdatePolicyIfVersion ¶ added in v1.7.0
UpdatePolicyIfVersion writes p as UpdatePolicy does, only if the stored policy is at version expected. The version check is part of the UPDATE's WHERE clause, so the comparison and the write are one statement. When no row changes, a read picks the error: not found if the policy is absent from p's tenant, a version conflict otherwise. That read only chooses the error; the refusal itself was atomic.
p.UpdatedAt is set only once the write has happened, so a refused caller's struct does not claim a write that did not happen.
func (*Store) UpdateResourceType ¶
func (s *Store) UpdateResourceType(ctx context.Context, rt *resourcetype.ResourceType) error