service

package
v1.0.0-alpha1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 10 Imported by: 1 module, 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 service resolves what a caller may do with a shareable record, and manages the grants that decide it.

Both halves used to exist once per vertical. The resolver in particular was copied verbatim between data and compute, which meant a change to the rule — "an inactive group membership grants nothing", say — had to be made twice and could be made inconsistently. There is one copy here, and the verticals say what their resources are by implementing ResourceGuard.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Strongest

func Strongest(have, candidate model.AccessPermission) model.AccessPermission

Strongest returns the stronger of two grants. WRITE beats READ; anything beats nothing.

Types

type Access

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

Access resolves what the calling principal may do with a shared record.

Strongest of ownership, a share naming the caller, and a share naming a group they are an active member of. Platform admins are treated as owners. "Control" — deleting a record and managing its shares — is not reachable through a share, because deciding who else gets access stays with the owner.

func NewAccess

func NewAccess(members *iamrepo.GroupMemberRepository) Access

NewAccess returns a resolver over the membership lookup.

func (Access) PermissionOf

func (a Access) PermissionOf(ctx context.Context, ownerID *string, shares []model.Sharing) (model.AccessPermission, bool, error)

PermissionOf returns the caller's effective permission and whether they control the record.

ownerID is nil for a record that has no owner at all, and for one whose ownership the caller has already decided — a virtual directory, whose owner is resolved over a whole lineage before the shares are pooled. In both cases only admins and the shares reach it.

func (Access) WithTx

func (a Access) WithTx(tx *gorm.DB) Access

WithTx binds the membership lookup to tx, for checks made from inside a transaction.

type ResourceGuard

type ResourceGuard interface {
	ResourceType() model.ResourceType

	// Label names the kind in error messages, as a caller would recognise it.
	Label() string

	// RequireControlled loads the resource and checks the caller may manage its
	// shares, returning the user ids that already own it. A share with one of those as
	// its subject would grant nothing, so the service refuses it.
	RequireControlled(ctx context.Context, id string) (owners []string, err error)
}

ResourceGuard is everything the sharing service needs to know about the kind of record it is opening up: what to tag the rows with, what to call it when something goes wrong, and whether the caller may manage its shares at all.

One implementation per shareable record, living in the vertical that owns it — which is what keeps this package from importing any of them.

type Service

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

Service manages who, besides the owner, may reach one kind of record.

One service for every shareable record. What used to be a service of eight methods per record — four per subject kind, the two halves differing only in which table they wrote — is four methods here, with the subject kind a field on the row.

Only an owner (or a platform admin) may read or change a share list: it names who holds a record, which is more than a grantee needs to know.

func NewService

func NewService(
	guard ResourceGuard,
	db *gorm.DB,
	sharing *repository.Repository,
	groups *iamrepo.GroupRepository,
	users *iamrepo.UserRepository,
) *Service

NewService returns a sharing service for the resource kind guard describes.

func (*Service) List

func (s *Service) List(ctx context.Context, resourceID string) ([]dto.ShareResponse, error)

List returns every share of one resource, of either principal kind.

func (*Service) Revoke

func (s *Service) Revoke(ctx context.Context, resourceID, sharingID string) error

Revoke withdraws a principal's access.

func (*Service) Share

func (s *Service) Share(ctx context.Context, resourceID string, req *dto.ShareRequest) (*dto.ShareResponse, error)

Share grants one principal access to one resource.

The principal has to exist, and has to not already hold the record: sharing with an owner is refused rather than stored, because it would grant nothing they do not already have.

func (*Service) Update

func (s *Service) Update(ctx context.Context, resourceID, sharingID string, req *dto.ShareUpdate) (*dto.ShareResponse, error)

Update changes what an existing share grants.

Jump to

Keyboard shortcuts

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