Help us shape the future of Go! Take the 2026 Go Developer Survey

workspace

package
v0.4.0-beta.12 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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 RoleRank

func RoleRank(role string) int

RoleRank orders roles so that a higher rank includes every lower one.

func Slugify

func Slugify(s string) string

func ValidResourceType

func ValidResourceType(t string) bool

func ValidRole

func ValidRole(role string) bool

Types

type Invitation

type Invitation struct {
	ID        int64     `json:"id"`
	Invitee   string    `json:"invitee"`
	Role      string    `json:"role"`
	InvitedBy int64     `json:"invited_by"`
	ExpiresAt time.Time `json:"expires_at"`
	CreatedAt time.Time `json:"created_at"`
}

type Member

type Member struct {
	UserID    int64     `json:"user_id"`
	Role      string    `json:"role"`
	CreatedAt time.Time `json:"created_at"`
}

type Membership

type Membership struct {
	Workspace
	Role string `json:"role"`
}

type Ref

type Ref struct {
	Type string `json:"type"`
	ID   string `json:"id"`
}

func (Ref) ResourceID

func (r Ref) ResourceID() string

func (Ref) ResourceType

func (r Ref) ResourceType() string

type Resource

type Resource interface {
	ResourceType() string
	ResourceID() string
}

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 NewStore

func NewStore(db *sql.DB) (*Store, error)

func (*Store) Accept

func (s *Store) Accept(token string, userID int64, identities ...string) (*Membership, error)

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

func (s *Store) Assign(workspaceID int64, r Resource) error

Assign makes a workspace the owner of a resource, moving it if another workspace owned it.

func (*Store) CheckUserRemovable

func (s *Store) CheckUserRemovable(userID int64) error

CheckUserRemovable refuses when the user is the only owner of a workspace.

func (*Store) Create

func (s *Store) Create(slug, name string, personal bool, ownerID int64) (*Workspace, error)

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) Delete

func (s *Store) Delete(slug string) error

Delete removes an empty workspace with its members and invitations.

func (*Store) EnsureDefault

func (s *Store) EnsureDefault(ownerIDs []int64) (*Workspace, error)

EnsureDefault creates the default workspace on first use, owned by the given users.

func (*Store) FoldPersonal

func (s *Store) FoldPersonal() error

FoldPersonal moves everything owned by per-user workspaces, which earlier builds created, into the default workspace and removes them.

func (*Store) Get

func (s *Store) Get(slug string) (*Workspace, error)

func (*Store) GetByID

func (s *Store) GetByID(id int64) (*Workspace, error)

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) List

func (s *Store) List() ([]Workspace, error)

func (*Store) ListForUser

func (s *Store) ListForUser(userID int64) ([]Membership, error)

func (*Store) Members

func (s *Store) Members(workspaceID int64) ([]Member, error)

func (*Store) Owner

func (s *Store) Owner(r Resource) (*Workspace, error)

Owner returns the workspace that owns a resource, or ErrNotFound.

func (*Store) Owners

func (s *Store) Owners(resourceType string) (map[string]string, error)

Owners maps every owned resource of one type to its workspace slug.

func (*Store) Release

func (s *Store) Release(r Resource) error

func (*Store) RemoveMember

func (s *Store) RemoveMember(workspaceID, userID int64) error

func (*Store) RemoveUser

func (s *Store) RemoveUser(userID int64) error

RemoveUser drops every membership of a deleted user.

func (*Store) Rename

func (s *Store) Rename(slug, name string) (*Workspace, error)

func (*Store) ResourceRefs

func (s *Store) ResourceRefs(workspaceID int64) ([]Ref, error)

func (*Store) ResourceRoles

func (s *Store) ResourceRoles(userID int64, resourceType string) (map[string]string, error)

ResourceRoles returns, for one resource type, the highest workspace role the user holds over each resource through membership.

func (*Store) Resources

func (s *Store) Resources(workspaceID int64, resourceType string) ([]string, error)

func (*Store) RevokeInvitation

func (s *Store) RevokeInvitation(workspaceID, id int64) error

func (*Store) Role

func (s *Store) Role(workspaceID, userID int64) (string, error)

func (*Store) SetMember

func (s *Store) SetMember(workspaceID, userID int64, role string) error

SetMember adds a member or changes their role. Demoting the last owner is refused.

type Workspace

type Workspace struct {
	ID        int64     `json:"id"`
	Slug      string    `json:"slug"`
	Name      string    `json:"name"`
	Personal  bool      `json:"personal"`
	CreatedAt time.Time `json:"created_at"`
	Logo string `json:"logo,omitempty"`
}

Jump to

Keyboard shortcuts

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