model

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
	ErrInvalid  = errors.New("invalid")
)

Functions

func Usernames added in v1.0.9

func Usernames(users []WorkspaceUser) []string

Usernames returns a slice of just the usernames from a WorkspaceUser slice.

Types

type ID

type ID int64

func ParseID

func ParseID(s string) (ID, error)

func (ID) Hash

func (id ID) Hash() string

Hash is a short, consistent hash for the ID.

type MailingListService added in v1.0.10

type MailingListService interface {
	// Subscribe adds an admin to the mailing list.
	Subscribe(ctx context.Context, username, email string) error
	// Unsubscribe removes an admin from the mailing list.
	Unsubscribe(ctx context.Context, username string) error
	// IsSubscribed checks if an admin is subscribed.
	IsSubscribed(ctx context.Context, username string) (bool, error)
	// ListSubscribers returns all subscribed admins.
	ListSubscribers(ctx context.Context) ([]Subscriber, error)
}

MailingListService manages admin notification subscriptions.

type Nodegroup

type Nodegroup string
const (
	NodegroupUndergraduate Nodegroup = "undergraduate"
	NodegroupGraduate      Nodegroup = "graduate"
)

func (Nodegroup) Valid

func (n Nodegroup) Valid() bool

type Resource

type Resource string
const (
	ResCPURequest       Resource = "requests.cpu"
	ResCPULimit         Resource = "limits.cpu"
	ResMemoryRequest    Resource = "requests.memory"
	ResMemoryLimit      Resource = "limits.memory"
	ResStorageRequest   Resource = "requests.storage"
	ResGPURequest       Resource = "requests.nvidia.com/gpu"
	ResGPUMemoryRequest Resource = "requests.nvidia.com/gpumem"
)

func (Resource) Valid

func (r Resource) Valid() bool

type Subscriber added in v1.0.10

type Subscriber struct {
	Username string
	Email    string
}

Subscriber represents an admin subscribed to email notifications.

type Workspace

type Workspace struct {
	ID

	Created   bool
	Enabled   bool
	Nodegroup Nodegroup
	Userdata  string

	Quotas map[Resource]uint64
	Users  []WorkspaceUser

	Request *WorkspaceUpdate
}

func (*Workspace) InitialRequest

func (ws *Workspace) InitialRequest() *WorkspaceUpdate

InitialRequest returns the initial request for a new workspace. It has the same attributes as the workspace itself, but enabled.

func (Workspace) Valid

func (ws Workspace) Valid() bool

type WorkspaceService

type WorkspaceService interface {
	// Accept user-provided fields only.
	CreateWorkspace(ctx context.Context, ws *Workspace, creatorEmail string) (*Workspace, error)

	// Full scan every workspace.
	ListAllWorkspaces(ctx context.Context) ([]*Workspace, error)
	// Only list workspaces for a given user (accepted invitations only).
	ListUserWorkspaces(ctx context.Context, user string) ([]*Workspace, error)
	// List all created workspaces.
	ListCreatedWorkspaces(ctx context.Context) ([]*Workspace, error)
	// List workspaces where user has pending invitation (email is NULL).
	ListUserInvitations(ctx context.Context, user string) ([]*Workspace, error)

	GetWorkspace(ctx context.Context, id ID) (*Workspace, error)
	// Return ErrNotFound if not owned.
	GetUserWorkspace(ctx context.Context, id ID, user string) (*Workspace, error)

	// Immediately apply any changes, for admins.
	UpdateWorkspace(ctx context.Context, upd *WorkspaceUpdate) (*Workspace, error)
	// Requetst an update, for uesrs. Ignore admin-controlled fields.
	RequestUpdateWorkspace(ctx context.Context, upd *WorkspaceUpdate) (*Workspace, error)

	// Accept a workspace invitation (sets email for the user).
	AcceptInvitation(ctx context.Context, workspaceID ID, username, email string) error
	// Decline a workspace invitation (removes user from workspace).
	DeclineInvitation(ctx context.Context, workspaceID ID, username string) error

	DeleteWorkspace(ctx context.Context, id ID) error
}

type WorkspaceUpdate

type WorkspaceUpdate struct {
	WorkspaceID ID
	ByUser      string

	Enabled   bool
	Nodegroup Nodegroup
	Userdata  string

	Quotas map[Resource]uint64
	Users  []string
}

func (WorkspaceUpdate) Valid

func (ws WorkspaceUpdate) Valid() bool

type WorkspaceUser added in v1.0.9

type WorkspaceUser struct {
	Username string
	Email    string // empty = pending invitation
}

WorkspaceUser represents a user in a workspace with their acceptance status. Email being empty indicates a pending invitation.

func (WorkspaceUser) IsAccepted added in v1.0.9

func (u WorkspaceUser) IsAccepted() bool

IsAccepted returns true if the user has accepted the workspace invitation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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