Documentation
¶
Overview ¶
Package model holds the one table every shareable record in the platform is reached through, and the vocabulary that table is written in.
Sharing used to be a thing each vertical did for itself: a pair of tables per shareable record — one for user grants, one for group grants — plus its own permission type and its own copy of the rule for resolving them. Adding a shareable record meant two more tables and a third copy of the resolver.
Here the resource and the subject are each a (type, id) pair in one table, so a new shareable record adds a constant and nothing else. The package sits below every vertical and imports none of them; a vertical says what its resources are by implementing the guard the sharing service asks for.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessPermission ¶
type AccessPermission string
AccessPermission is what a grant confers, on any shareable record.
One type for every vertical: the storages, products, virtual directories and cluster configs all distinguished READ from WRITE and nothing else, so what used to be three identical string types is this one.
const ( AccessPermissionRead AccessPermission = "READ" AccessPermissionWrite AccessPermission = "WRITE" AccessPermissionNone AccessPermission = "" )
func (AccessPermission) Allows ¶
func (current AccessPermission) Allows(want AccessPermission) bool
Allows reports whether holding current is enough to do something requiring want. WRITE implies READ; nothing implies WRITE.
func (AccessPermission) Valid ¶
func (p AccessPermission) Valid() bool
Valid reports whether p is a recognised permission. The empty string is recognised: it is what "grants nothing" resolves to.
type PrincipalType ¶
type PrincipalType string
PrincipalType names what kind of subject a share is granted to.
A USER share reaches exactly that account. A GROUP share reaches every active member of the group, which is resolved at access time rather than stored, so adding someone to a group grants them what the group already holds.
const ( PrincipalTypeUser PrincipalType = "USER" PrincipalTypeGroup PrincipalType = "GROUP" )
func (PrincipalType) Valid ¶
func (t PrincipalType) Valid() bool
Valid reports whether t is a recognised principal type.
type ResourceType ¶
type ResourceType string
ResourceType names the kind of record a sharing row opens up.
The id alone is not enough to identify a resource: the kinds have separate id spaces, so a row is addressed by the pair.
const ( ResourceTypeDataProduct ResourceType = "DATA_PRODUCT" ResourceTypeSCPDataStorage ResourceType = "SCP_DATA_STORAGE" ResourceTypeVirtualDataDirectory ResourceType = "VIRTUAL_DATA_DIRECTORY" ResourceTypeSlurmClusterConfig ResourceType = "SLURM_CLUSTER_CONFIG" )
func (ResourceType) Valid ¶
func (t ResourceType) Valid() bool
Valid reports whether t is a recognised resource type.
type Sharing ¶
type Sharing struct {
ID string `gorm:"column:resource_sharing_id;primaryKey;type:varchar(36)" json:"resourceSharingId"`
ResourceType ResourceType `` /* 142-byte string literal not displayed */
ResourceID string `` /* 138-byte string literal not displayed */
PrincipalType PrincipalType `gorm:"column:principal_type;type:varchar(32);not null;uniqueIndex:uk_resource_sharing" json:"principalType"`
PrincipalID string `gorm:"column:principal_id;type:varchar(255);not null;index;uniqueIndex:uk_resource_sharing" json:"principalId"`
Permission AccessPermission `gorm:"column:permission;type:varchar(32)" json:"permission"`
}
Sharing grants one principal access to one record.
Neither id can carry a foreign key: a column cannot reference four resource tables, nor users and groups at once. The database will therefore not refuse a share of a record that has been deleted, so whatever deletes a resource deletes its shares in the same transaction, and whatever deletes a group withdraws what it was granted. PrincipalID is sized for a user id, the longer of the two.
func (*Sharing) BeforeCreate ¶
BeforeCreate assigns a UUID when none was supplied.
func (*Sharing) BeforeSave ¶
BeforeSave rejects a row that names nothing, or names it with a constant the columns cannot enforce. The types are plain varchars, so this is what keeps an unknown value out of the table.