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 ¶
- func Strongest(have, candidate model.AccessPermission) model.AccessPermission
- type Access
- type ResourceGuard
- type Service
- func (s *Service) List(ctx context.Context, resourceID string) ([]dto.ShareResponse, error)
- func (s *Service) Revoke(ctx context.Context, resourceID, sharingID string) error
- func (s *Service) Share(ctx context.Context, resourceID string, req *dto.ShareRequest) (*dto.ShareResponse, error)
- func (s *Service) Update(ctx context.Context, resourceID, sharingID string, req *dto.ShareUpdate) (*dto.ShareResponse, error)
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.
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) 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.