Documentation
¶
Index ¶
- Constants
- Variables
- func RoleRank(role string) int
- func Slugify(s string) string
- func ValidResourceType(t string) bool
- func ValidRole(role string) bool
- type Invitation
- type Member
- type Membership
- type Ref
- type Resource
- type Store
- func (s *Store) Accept(token string, userID int64, identities ...string) (*Membership, error)
- func (s *Store) Assign(workspaceID int64, r Resource) error
- func (s *Store) CheckUserRemovable(userID int64) error
- func (s *Store) Create(slug, name string, personal bool, ownerID int64) (*Workspace, error)
- func (s *Store) Delete(slug string) error
- func (s *Store) EnsureDefault(ownerIDs []int64) (*Workspace, error)
- func (s *Store) FoldPersonal() error
- func (s *Store) Get(slug string) (*Workspace, error)
- func (s *Store) GetByID(id int64) (*Workspace, error)
- func (s *Store) Invitations(workspaceID int64) ([]Invitation, error)
- func (s *Store) Invite(workspaceID int64, invitee, role string, invitedBy int64, ttl time.Duration) (*Invitation, string, error)
- func (s *Store) List() ([]Workspace, error)
- func (s *Store) ListForUser(userID int64) ([]Membership, error)
- func (s *Store) Members(workspaceID int64) ([]Member, error)
- func (s *Store) Owner(r Resource) (*Workspace, error)
- func (s *Store) Owners(resourceType string) (map[string]string, error)
- func (s *Store) Release(r Resource) error
- func (s *Store) RemoveMember(workspaceID, userID int64) error
- func (s *Store) RemoveUser(userID int64) error
- func (s *Store) Rename(slug, name string) (*Workspace, error)
- func (s *Store) ResourceRefs(workspaceID int64) ([]Ref, error)
- func (s *Store) ResourceRoles(userID int64, resourceType string) (map[string]string, error)
- func (s *Store) Resources(workspaceID int64, resourceType string) ([]string, error)
- func (s *Store) RevokeInvitation(workspaceID, id int64) error
- func (s *Store) Role(workspaceID, userID int64) (string, error)
- func (s *Store) SetMember(workspaceID, userID int64, role string) error
- type Workspace
Constants ¶
const ( RoleOwner = "owner" RoleAdmin = "admin" RoleMember = "member" DefaultSlug = "default" TypeDeployment = "deployment" TypeCredential = "credential" TypeSecret = "secret" TypeBackupDestination = "backup_destination" TypeScheduledTask = "scheduled_task" InvitationTTL = 7 * 24 * time.Hour )
Variables ¶
var ( ErrNotFound = errors.New("workspace not found") ErrSlugTaken = errors.New("workspace slug is already taken") ErrInvalidSlug = errors.New("workspace slug must use lowercase letters, digits and hyphens") ErrInvalidRole = errors.New("workspace role must be owner, admin or member") ErrInvalidType = errors.New("unknown resource type") ErrProtected = errors.New("the default workspace cannot be deleted") ErrNotEmpty = errors.New("workspace still owns resources") ErrLastOwner = errors.New("a workspace needs at least one owner") ErrInvitationInvalid = errors.New("invitation is invalid or was revoked") ErrInvitationExpired = errors.New("invitation has expired") ErrInviteeMismatch = errors.New("invitation was sent to someone else") )
Functions ¶
func ValidResourceType ¶
Types ¶
type Invitation ¶
type Membership ¶
type Resource ¶
Resource is anything a workspace can own. Ownership is stored by type and identifier, so a new kind of resource needs no schema change.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) Accept ¶
Accept turns an invitation into a membership. The accepting user must be the invitee, matched on username or email without regard to case. A role the user already holds is never lowered.
func (*Store) Assign ¶
Assign makes a workspace the owner of a resource, moving it if another workspace owned it.
func (*Store) CheckUserRemovable ¶
CheckUserRemovable refuses when the user is the only owner of a workspace.
func (*Store) Create ¶
Create adds a workspace with ownerID as its first owner. An empty slug is derived from the name, with a numeric suffix when the name is taken.
func (*Store) EnsureDefault ¶
EnsureDefault creates the default workspace on first use, owned by the given users.
func (*Store) FoldPersonal ¶
FoldPersonal moves everything owned by per-user workspaces, which earlier builds created, into the default workspace and removes them.
func (*Store) Invitations ¶
func (s *Store) Invitations(workspaceID int64) ([]Invitation, error)
func (*Store) Invite ¶
func (s *Store) Invite(workspaceID int64, invitee, role string, invitedBy int64, ttl time.Duration) (*Invitation, string, error)
Invite records an invitation and returns the token to hand to the invitee. Only the token's hash is stored.
func (*Store) ListForUser ¶
func (s *Store) ListForUser(userID int64) ([]Membership, error)
func (*Store) RemoveMember ¶
func (*Store) RemoveUser ¶
RemoveUser drops every membership of a deleted user.
func (*Store) ResourceRoles ¶
ResourceRoles returns, for one resource type, the highest workspace role the user holds over each resource through membership.