model

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuditActorSystem = "System"

	AuditActorTypeUser   = "User"
	AuditActorTypeSystem = "System"
	AuditActorTypeMCP    = "MCP"
)

Define actor types

View Source
const (
	AuditEventSystemStart = "System Start"

	// Auth
	AuditEventAuthFailed = "Login Failed"
	AuditEventAuthOk     = "Login Success"

	// Groups
	AuditEventGroupCreate = "Group Create"
	AuditEventGroupUpdate = "Group Update"
	AuditEventGroupDelete = "Group Delete"

	// Roles
	AuditEventRoleCreate = "Role Create"
	AuditEventRoleUpdate = "Role Update"
	AuditEventRoleDelete = "Role Delete"

	// Spaces
	AuditEventSpaceCreate    = "Space Create"
	AuditEventSpaceUpdate    = "Space Update"
	AuditEventSpaceDelete    = "Space Delete"
	AuditEventSpaceTransfer  = "Space Transfer"
	AuditEventSpaceShare     = "Space Shared"
	AuditEventSpaceStopShare = "Space Stop Share"

	// Templates
	AuditEventTemplateCreate = "Template Create"
	AuditEventTemplateUpdate = "Template Update"
	AuditEventTemplateDelete = "Template Delete"

	// Variables
	AuditEventVarCreate = "Variable Create"
	AuditEventVarUpdate = "Variable Update"
	AuditEventVarDelete = "Variable Delete"

	// Users
	AuditEventUserCreate = "User Create"
	AuditEventUserUpdate = "User Update"
	AuditEventUserDelete = "User Delete"

	// Volumes
	AuditEventVolumeCreate = "Volume Create"
	AuditEventVolumeUpdate = "Volume Update"
	AuditEventVolumeDelete = "Volume Delete"

	// Scripts
	AuditEventScriptCreate  = "Script Create"
	AuditEventScriptUpdate  = "Script Update"
	AuditEventScriptDelete  = "Script Delete"
	AuditEventScriptExecute = "Script Execute"

	// Skills
	AuditEventSkillCreate = "Skill Create"
	AuditEventSkillUpdate = "Skill Update"
	AuditEventSkillDelete = "Skill Delete"

	// Stack Definitions
	AuditEventStackDefCreate = "Stack Definition Create"
	AuditEventStackDefUpdate = "Stack Definition Update"
	AuditEventStackDefDelete = "Stack Definition Delete"
)

Define events

View Source
const (
	PermissionManageUsers               = iota // Can Manage Users
	PermissionManageTemplates                  // Can Manage Templates
	PermissionManageSpaces                     // Can Manage Spaces
	PermissionManageVolumes                    // Can Manage Volumes
	PermissionManageGroups                     // Can Manage Groups
	PermissionManageRoles                      // Can Manage Roles
	PermissionManageVariables                  // Can Manage Variables
	PermissionUseSpaces                        // Can Use Spaces
	PermissionUseTunnels                       // Can Use Tunnels
	PermissionViewAuditLogs                    // Can View Audit Logs
	PermissionTransferSpaces                   // Can Transfer Spaces
	PermissionShareSpaces                      // Can Share Spaces
	PermissionClusterInfo                      // Can View Cluster Info
	PermissionUseVNC                           // Can use VNC
	PermissionUseWebTerminal                   // Can use the web terminal
	PermissionUseSSH                           // Can use ssh connections
	PermissionUseCodeServer                    // Can use code-server
	PermissionUseVSCodeTunnel                  // Can use VSCode Tunnel
	PermissionUseLogs                          // Can use the log window
	PermissionRunCommands                      // Can run commands in spaces
	PermissionCopyFiles                        // Can copy files to/from spaces
	PermissionUseMCPServer                     // Can use MCP server
	PermissionUseWebAssistant                  // Can use web-based AI assistant
	PermissionManageScripts                    // Can Manage System/Global Scripts
	PermissionExecuteScripts                   // Can Execute System/Global Scripts
	PermissionManageOwnScripts                 // Can Manage Own Scripts
	PermissionExecuteOwnScripts                // Can Execute Own Scripts
	PermissionManageGlobalSkills               // Can Manage Global Skills
	PermissionManageOwnSkills                  // Can Manage Own Skills
	PermissionSetSpaceDependencies             // Can configure space dependencies in the UI
	PermissionUseSpaceStartupScript            // Can configure user startup script in the space form UI
	PermissionDownloadAuditLogs                // Can Download Audit Logs
	PermissionManageStackDefinitions           // Can create/edit/delete global (system) stack definitions
	PermissionManageOwnStackDefinitions        // Can create/edit/delete personal stack definitions
	PermissionUseStackDefinitions              // Can create instances from stack definitions
)

Permissions

View Source
const (
	WebSessionCookie      = "__KNOT_WEBUI_SESSION"
	SessionExpiryDuration = 2 * time.Hour
)
View Source
const (
	SpaceUsageBucketMinute = "minute"
	SpaceUsageBucketDay    = "day"

	SpaceUsageMinuteRetention = 1 * time.Hour
	SpaceUsageDayRetention    = 7 * 24 * time.Hour
)
View Source
const (
	PlatformManual    = "manual"
	PlatformDocker    = "docker"
	PlatformPodman    = "podman"
	PlatformNomad     = "nomad"
	PlatformApple     = "apple"
	PlatformContainer = "container"

	LeafNodeZone = "<leaf-node>"

	HealthCheckNone    = "none"
	HealthCheckAgent   = "agent"
	HealthCheckTCP     = "tcp"
	HealthCheckHTTP    = "http"
	HealthCheckProgram = "program"
	HealthCheckCustom  = "custom"
)
View Source
const (
	MaxTokenAge = 14 * 24 * time.Hour // 2 weeks
)
View Source
const (
	RoleAdminUUID = "00000000-0000-0000-0000-000000000000"
)

Roles

Variables

View Source
var PermissionNames = []PermissionName{
	{PermissionViewAuditLogs, "Audit", "View Audit Logs"},
	{PermissionDownloadAuditLogs, "Audit", "Download Audit Logs"},

	{PermissionClusterInfo, "System", "View Cluster Info"},

	{PermissionManageGroups, "User Management", "Manage Groups"},
	{PermissionManageRoles, "User Management", "Manage Roles"},
	{PermissionManageUsers, "User Management", "Manage Users"},

	{PermissionManageSpaces, "Resource Management", "Manage Spaces"},
	{PermissionManageTemplates, "Resource Management", "Manage Templates"},
	{PermissionManageVariables, "Resource Management", "Manage Variables"},
	{PermissionManageVolumes, "Resource Management", "Manage Volumes"},

	{PermissionUseMCPServer, "AI Tools", "Use MCP Server"},
	{PermissionUseWebAssistant, "AI Tools", "Use Web Assistant"},

	{PermissionManageScripts, "Scripting", "Manage System Scripts"},
	{PermissionExecuteScripts, "Scripting", "Execute System Scripts"},
	{PermissionManageOwnScripts, "Scripting", "Manage Own Scripts"},
	{PermissionExecuteOwnScripts, "Scripting", "Execute Own Scripts"},

	{PermissionManageGlobalSkills, "Skills", "Manage Global Skills"},
	{PermissionManageOwnSkills, "Skills", "Manage Own Skills"},

	{PermissionManageStackDefinitions, "Stacks", "Manage Global Stack Definitions"},
	{PermissionManageOwnStackDefinitions, "Stacks", "Manage Own Stack Definitions"},
	{PermissionUseStackDefinitions, "Stacks", "Use Stack Definitions"},

	{PermissionUseSpaces, "Space Operations", "Use Spaces"},
	{PermissionSetSpaceDependencies, "Space Operations", "Set Space Dependencies"},
	{PermissionUseSpaceStartupScript, "Space Operations", "Use User Startup Script"},
	{PermissionShareSpaces, "Space Operations", "Share Spaces"},
	{PermissionTransferSpaces, "Space Operations", "Transfer Spaces"},
	{PermissionUseTunnels, "Space Operations", "Use Tunnels"},
	{PermissionUseCodeServer, "Space Operations", "Use Code Server"},
	{PermissionUseLogs, "Space Operations", "View Logs"},
	{PermissionUseSSH, "Space Operations", "Use SSH"},
	{PermissionUseVNC, "Space Operations", "Use VNC"},
	{PermissionUseVSCodeTunnel, "Space Operations", "Use VSCode Tunnel"},
	{PermissionUseWebTerminal, "Space Operations", "Use Web Terminal"},
	{PermissionRunCommands, "Space Operations", "Run Commands"},
	{PermissionCopyFiles, "Space Operations", "Copy Files"},
}

Functions

func BucketStartForKind added in v0.24.0

func BucketStartForKind(bucketStart time.Time, bucketKind string) time.Time

func DeleteRoleFromCache

func DeleteRoleFromCache(roleId string)

func FilterVars

func FilterVars(variables []*TemplateVar) map[string]interface{}

func GetUserPermissions added in v0.23.0

func GetUserPermissions(user *User) []uint16

GetUserPermissions returns all permission integers for a user (resolves from roles)

func NormalizeSpaceUsageBucketKind added in v0.24.0

func NormalizeSpaceUsageBucketKind(bucketKind string) string

func RequestProperties added in v0.24.0

func RequestProperties(r *http.Request, properties *map[string]interface{}) *map[string]interface{}

RequestProperties extracts source_ip and user_agent from an HTTP request and merges them into an existing properties map, or creates a new one.

func ResolveVariables

func ResolveVariables(srcString string, t *Template, space *Space, user *User, variables map[string]interface{}) (string, error)

Parse an input string and resolve knot variables

func RoleExists

func RoleExists(roleId string) bool

func SaveRoleToCache

func SaveRoleToCache(role *Role)

func SetRoleCache

func SetRoleCache(roles []*Role)

func SpaceUsageRetentionForKind added in v0.24.0

func SpaceUsageRetentionForKind(bucketKind string) time.Duration

func SpaceUsageSampleIdForKind added in v0.24.0

func SpaceUsageSampleIdForKind(spaceId, bucketKind string, bucketStart time.Time) string

Types

type AltNameEntry added in v0.25.0

type AltNameEntry struct {
	Name string `json:"name"`
	Port uint16 `json:"port"`
}

func (*AltNameEntry) Scan added in v0.25.0

func (a *AltNameEntry) Scan(value interface{}) error

Scan implements the sql.Scanner interface.

func (AltNameEntry) Value added in v0.25.0

func (a AltNameEntry) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type AuditLogEntry

type AuditLogEntry struct {
	Id         int64                  `json:"audit_log_id" db:"audit_log_id,pk"`
	Zone       string                 `json:"zone" db:"zone"`
	Actor      string                 `json:"actor" db:"actor"`
	ActorType  string                 `json:"actor_type" db:"actor_type"`
	Event      string                 `json:"event" db:"event"`
	When       time.Time              `json:"created_at" db:"created_at"`
	Details    string                 `json:"details" db:"details"`
	Properties map[string]interface{} `json:"properties" db:"properties,json"`
}

func NewAuditLogEntry

func NewAuditLogEntry(actor, actorType, event, details string, properties *map[string]interface{}) *AuditLogEntry

func (*AuditLogEntry) MatchesFilter added in v0.24.0

func (e *AuditLogEntry) MatchesFilter(filter *AuditLogFilter) bool

MatchesFilter returns true if the entry matches the given filter criteria.

type AuditLogFilter added in v0.24.0

type AuditLogFilter struct {
	Query     string
	Actor     string
	ActorType string
	Event     string
	From      *time.Time
	To        *time.Time
}

type CSIVolume

type CSIVolume struct {
	Id           string                `yaml:"id" json:"ID"`
	Name         string                `yaml:"name" json:"Name"`
	Namespace    string                `yaml:"namespace" json:"Namespace"`
	PuluginId    string                `yaml:"plugin_id" json:"PluginID"`
	Type         string                `yaml:"type" json:"Type"`
	MountOptions CSIVolumeMountOptions `yaml:"mount_options" json:"MountOptions"`
	CapacityMin  interface{}           `yaml:"capacity_min,omitempty" json:"RequestedCapacityMin,omitempty"`
	CapacityMax  interface{}           `yaml:"capacity_max,omitempty" json:"RequestedCapacityMax,omitempty"`
	Capabilities []CSIVolumeCapability `yaml:"capabilities,omitempty" json:"RequestedCapabilities,omitempty"`
	Secrets      map[string]string     `yaml:"secrets,omitempty" json:"Secrets,omitempty"`
	Parameters   map[string]string     `yaml:"parameters,omitempty" json:"Parameters,omitempty"`
}

type CSIVolumeCapability

type CSIVolumeCapability struct {
	AccessMode     string `yaml:"access_mode" json:"AccessMode"`
	AttachmentMode string `yaml:"attachment_mode" json:"AttachmentMode"`
}

type CSIVolumeMountOptions

type CSIVolumeMountOptions struct {
	FsType     string   `yaml:"fs_type" json:"FsType"`
	MountFlags []string `yaml:"mount_flags" json:"MountFlags"`
}

type CSIVolumes

type CSIVolumes struct {
	Volumes []CSIVolume `yaml:"volumes" json:"Volumes"`
}

func LoadVolumesFromYaml

func LoadVolumesFromYaml(yamlData string, t *Template, space *Space, user *User, variables map[string]interface{}) (*CSIVolumes, error)

type CfgValue

type CfgValue struct {
	Name  string `json:"name" db:"name,pk" msgpack:"name"`
	Value string `json:"value" db:"value" msgpack:"value"`
}

CfgValue object

type ExternalProvider added in v0.23.7

type ExternalProvider struct {
	ProviderUID  string `json:"provider_uid"`            // provider's own stable user ID (e.g. GitHub integer ID)
	Username     string `json:"username"`                // human-readable handle, may change
	Token        string `json:"token"`                   // encrypted access token
	RefreshToken string `json:"refresh_token,omitempty"` // encrypted refresh token
}

ExternalProvider holds the identity and token for a linked OAuth provider.

type Group

type Group struct {
	Id            string        `json:"group_id" db:"group_id,pk" msgpack:"group_id"`
	Name          string        `json:"name" db:"name" msgpack:"name"`
	MaxSpaces     uint32        `json:"max_spaces" db:"max_spaces" msgpack:"max_spaces"`
	ComputeUnits  uint32        `json:"compute_units" db:"compute_units" msgpack:"compute_units"`
	StorageUnits  uint32        `json:"storage_units" db:"storage_units" msgpack:"storage_units"`
	MaxTunnels    uint32        `json:"max_tunnels" db:"max_tunnels" msgpack:"max_tunnels"`
	IsDeleted     bool          `json:"is_deleted" db:"is_deleted" msgpack:"is_deleted"`
	CreatedUserId string        `json:"created_user_id" db:"created_user_id" msgpack:"created_user_id"`
	CreatedAt     time.Time     `json:"created_at" db:"created_at" msgpack:"created_at"`
	UpdatedUserId string        `json:"updated_user_id" db:"updated_user_id" msgpack:"updated_user_id"`
	UpdatedAt     hlc.Timestamp `json:"updated_at" db:"updated_at" msgpack:"updated_at"`
}

Group object

func NewGroup

func NewGroup(name string, userId string, maxSpaces uint32, computeUnits uint32, storageUnits uint32, maxTunnels uint32) *Group

type LocalStorageSpec added in v0.25.0

type LocalStorageSpec struct {
	Volumes map[string]LocalVolumeEntry `yaml:"volumes"`
	Paths   PathList                    `yaml:"paths"`
}

func LoadLocalStorageFromYaml added in v0.25.0

func LoadLocalStorageFromYaml(yamlData string, t *Template, space *Space, user *User, variables map[string]interface{}) (*LocalStorageSpec, error)

type LocalVolumeEntry added in v0.25.0

type LocalVolumeEntry struct {
	Size string `yaml:"size,omitempty"`
}

type ManagedPathsSpec added in v0.25.0

type ManagedPathsSpec struct {
	Paths PathList `yaml:"paths"`
}

func LoadManagedPathsFromYaml added in v0.25.0

func LoadManagedPathsFromYaml(yamlData string, t *Template, space *Space, user *User, variables map[string]interface{}) (*ManagedPathsSpec, error)

type PathList added in v0.25.0

type PathList []string

func (*PathList) UnmarshalYAML added in v0.25.0

func (paths *PathList) UnmarshalYAML(value *yaml.Node) error

type PermissionName

type PermissionName struct {
	Id    int    `json:"id"`
	Group string `json:"group"`
	Name  string `json:"name"`
}

type PortForwardEntry added in v0.24.0

type PortForwardEntry struct {
	LocalPort  uint16 `json:"local_port"`
	Space      string `json:"space"`
	RemotePort uint16 `json:"remote_port"`
}

func (*PortForwardEntry) Scan added in v0.24.0

func (pf *PortForwardEntry) Scan(value interface{}) error

Scan implements the sql.Scanner interface.

func (PortForwardEntry) Value added in v0.24.0

func (pf PortForwardEntry) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type Quota

type Quota struct {
	ComputeUnits uint32
	StorageUnits uint32
	MaxSpaces    uint32
	MaxTunnels   uint32
}

type Response added in v0.23.0

type Response struct {
	Id                 string                 `json:"response_id" db:"response_id,pk" msgpack:"response_id"`
	Status             ResponseStatus         `json:"status" db:"status" msgpack:"status"`
	Request            map[string]interface{} `json:"request" db:"request,json" msgpack:"request"`
	Response           map[string]interface{} `json:"response" db:"response,json" msgpack:"response"`
	Error              string                 `json:"error,omitempty" db:"error_text" msgpack:"error"`
	PreviousResponseId string                 `json:"previous_response_id,omitempty" db:"previous_response_id" msgpack:"previous_response_id"`
	UserId             string                 `json:"user_id" db:"user_id" msgpack:"user_id"`
	SpaceId            string                 `json:"space_id,omitempty" db:"space_id" msgpack:"space_id"`
	ExpiresAt          *time.Time             `json:"expires_at,omitempty" db:"expires_at" msgpack:"expires_at"`
	IsDeleted          bool                   `json:"is_deleted" db:"is_deleted" msgpack:"is_deleted"`
	CreatedAt          time.Time              `json:"created_at" db:"created_at" msgpack:"created_at"`
	UpdatedAt          hlc.Timestamp          `json:"updated_at" db:"updated_at" msgpack:"updated_at"`
}

Response object for OpenAI Responses API

func NewResponse added in v0.23.0

func NewResponse(userId string, spaceId string, ttl time.Duration) *Response

NewResponse creates a new Response object

func (*Response) GetRequest added in v0.23.0

func (r *Response) GetRequest(data interface{}) error

GetRequest populates the request data into a structure

func (*Response) GetResponse added in v0.23.0

func (r *Response) GetResponse(data interface{}) error

GetResponse populates the response data into a structure

func (*Response) SetRequest added in v0.23.0

func (r *Response) SetRequest(data interface{}) error

SetRequest sets the request data from a JSON-serializable structure

func (*Response) SetResponse added in v0.23.0

func (r *Response) SetResponse(data interface{}) error

SetResponse sets the response data from a JSON-serializable structure

type ResponseStatus added in v0.23.0

type ResponseStatus string

ResponseStatus represents the status of a response

const (
	StatusPending    ResponseStatus = "pending"
	StatusInProgress ResponseStatus = "in_progress"
	StatusCompleted  ResponseStatus = "completed"
	StatusCancelled  ResponseStatus = "cancelled"
	StatusFailed     ResponseStatus = "failed"
)

type Role

type Role struct {
	Id            string        `json:"role_id" db:"role_id,pk" msgpack:"role_id"`
	Name          string        `json:"name" db:"name" msgpack:"name"`
	Permissions   []uint16      `json:"permissions" db:"permissions,json" msgpack:"permissions"`
	IsDeleted     bool          `json:"is_deleted" db:"is_deleted" msgpack:"is_deleted"`
	CreatedUserId string        `json:"created_user_id" db:"created_user_id" msgpack:"created_user_id"`
	CreatedAt     time.Time     `json:"created_at" db:"created_at" msgpack:"created_at"`
	UpdatedUserId string        `json:"updated_user_id" db:"updated_user_id" msgpack:"updated_user_id"`
	UpdatedAt     hlc.Timestamp `json:"updated_at" db:"updated_at" msgpack:"updated_at"`
}

Role

func GetRolesFromCache

func GetRolesFromCache() []*Role

func NewRole

func NewRole(name string, permissions []uint16, userId string) *Role

type Script added in v0.23.0

type Script struct {
	Id                 string        `json:"script_id" db:"script_id,pk"`
	UserId             string        `json:"user_id" db:"user_id"`
	Name               string        `json:"name" db:"name"`
	Description        string        `json:"description" db:"description"`
	Content            string        `json:"content" db:"content"`
	Groups             []string      `json:"groups" db:"groups,json"`
	Zones              []string      `json:"zones" db:"zones,json"`
	Active             bool          `json:"active" db:"active"`
	ScriptType         string        `json:"script_type" db:"script_type"`
	MCPInputSchemaToml string        `json:"mcp_input_schema_toml" db:"mcp_input_schema_toml"`
	MCPKeywords        []string      `json:"mcp_keywords" db:"mcp_keywords,json"`
	Discoverable       bool          `json:"discoverable" db:"discoverable"`
	IsDeleted          bool          `json:"is_deleted" db:"is_deleted"`
	IsManaged          bool          `json:"is_managed" db:"is_managed"`
	CreatedUserId      string        `json:"created_user_id" db:"created_user_id"`
	CreatedAt          time.Time     `json:"created_at" db:"created_at"`
	UpdatedUserId      string        `json:"updated_user_id" db:"updated_user_id"`
	UpdatedAt          hlc.Timestamp `json:"updated_at" db:"updated_at"`
}

func NewScript added in v0.23.0

func NewScript(
	name string,
	description string,
	content string,
	groups []string,
	zones []string,
	active bool,
	scriptType string,
	mcpInputSchemaToml string,
	mcpKeywords []string,
	discoverable bool,
	ownerUserId string,
	createdUserId string,
) *Script

func (*Script) IsGlobalScript added in v0.23.0

func (script *Script) IsGlobalScript() bool

IsGlobalScript returns true if the script is a system/global script (UserId is empty)

func (*Script) IsUserScript added in v0.23.0

func (script *Script) IsUserScript() bool

IsUserScript returns true if the script is a user script (UserId is not empty)

func (*Script) IsValidForZone added in v0.23.0

func (script *Script) IsValidForZone(zone string) bool

IsValidForZone determines whether the script is valid for execution in the specified zone. The function evaluates zone restrictions based on the script's Zones configuration. If no zones are specified, the script is considered valid for all zones (global). Zone names prefixed with '!' are treated as exclusions (negated zones). The function first checks for exclusions, then checks for explicit inclusions.

zone is the target zone name to validate against the script's zone restrictions.

Returns true if the script can be executed in the specified zone, false otherwise.

type Session

type Session struct {
	Id           string        `json:"session_id" db:"session_id,pk"`
	Ip           string        `json:"ip" db:"ip"`
	UserId       string        `json:"user_id" db:"user_id"`
	UserAgent    string        `json:"user_agent" db:"user_agent"`
	ExpiresAfter time.Time     `json:"expires_after" db:"expires_after"`
	UpdatedAt    hlc.Timestamp `json:"updated_at" db:"updated_at"`
	IsDeleted    bool          `json:"is_deleted" db:"is_deleted"`
}

Session object

func NewSession

func NewSession(r *http.Request, userId string) *Session

type Skill added in v0.23.0

type Skill struct {
	Id            string        `json:"skill_id" db:"skill_id,pk"`
	UserId        string        `json:"user_id" db:"user_id"`
	Name          string        `json:"name" db:"name"`
	Description   string        `json:"description" db:"description"`
	Content       string        `json:"content" db:"content"`
	Groups        []string      `json:"groups" db:"groups,json"`
	Zones         []string      `json:"zones" db:"zones,json"`
	Active        bool          `json:"active" db:"active"`
	IsDeleted     bool          `json:"is_deleted" db:"is_deleted"`
	IsManaged     bool          `json:"is_managed" db:"is_managed"`
	CreatedUserId string        `json:"created_user_id" db:"created_user_id"`
	CreatedAt     time.Time     `json:"created_at" db:"created_at"`
	UpdatedUserId string        `json:"updated_user_id" db:"updated_user_id"`
	UpdatedAt     hlc.Timestamp `json:"updated_at" db:"updated_at"`
}

func NewSkill added in v0.23.0

func NewSkill(
	name string,
	description string,
	content string,
	groups []string,
	zones []string,
	ownerUserId string,
	createdUserId string,
) *Skill

func (*Skill) IsGlobalSkill added in v0.23.0

func (skill *Skill) IsGlobalSkill() bool

func (*Skill) IsUserSkill added in v0.23.0

func (skill *Skill) IsUserSkill() bool

func (*Skill) IsValidForZone added in v0.23.0

func (skill *Skill) IsValidForZone(zone string) bool

type Space

type Space struct {
	Id               string             `json:"space_id" db:"space_id,pk" msgpack:"space_id"`
	ParentSpaceId    string             `json:"parent_space_id" db:"parent_space_id" msgpack:"parent_space_id"`
	UserId           string             `json:"user_id" db:"user_id" msgpack:"user_id"`
	TemplateId       string             `json:"template_id" db:"template_id" msgpack:"template_id"`
	Shares           []string           `json:"shares" db:"shares,json" msgpack:"shares"`
	DependsOn        []string           `json:"depends_on" db:"depends_on,json" msgpack:"depends_on"`
	SharedWithUserId string             `json:"-" msgpack:"-"`
	Name             string             `json:"name" db:"name" msgpack:"name"`
	Description      string             `json:"description" db:"description" msgpack:"description"`
	Note             string             `json:"note" db:"note" msgpack:"note"`
	Stack            string             `json:"stack" db:"stack" msgpack:"stack"`
	Zone             string             `json:"zone" db:"zone" msgpack:"zone"`
	NodeId           string             `json:"node_id,omitempty" db:"node_id" msgpack:"node_id,omitempty"`
	Shell            string             `json:"shell" db:"shell" msgpack:"shell"`
	StartupScriptId  string             `json:"startup_script_id" db:"startup_script_id" msgpack:"startup_script_id"`
	TemplateHash     string             `json:"template_hash" db:"template_hash" msgpack:"template_hash"`
	NomadNamespace   string             `json:"nomad_namespace" db:"nomad_namespace" msgpack:"nomad_namespace"`
	ContainerId      string             `json:"container_id" db:"container_id" msgpack:"container_id"`
	IconURL          string             `json:"icon_url" db:"icon_url" msgpack:"icon_url"`
	VolumeData       VolumeDataMap      `json:"volume_data" db:"volume_data" msgpack:"volume_data"`
	SSHHostSigner    string             `json:"ssh_host_signer" db:"ssh_host_signer" msgpack:"ssh_host_signer"`
	IsDeployed       bool               `json:"is_deployed" db:"is_deployed" msgpack:"is_deployed"`
	IsPending        bool               `json:"is_pending" db:"is_pending" msgpack:"is_pending"` // Flags if the space is pending a state change, starting or stopping
	IsDeleting       bool               `json:"is_deleting" db:"is_deleting" msgpack:"is_deleting"`
	IsDeleted        bool               `json:"is_deleted" db:"is_deleted" msgpack:"is_deleted"`
	AltNames         []AltNameEntry     `json:"alt_names" msgpack:"alt_names"`
	CustomFields     []SpaceCustomField `json:"custom_fields" db:"custom_fields,json" msgpack:"custom_fields"`
	PortForwards     []PortForwardEntry `json:"port_forwards" db:"port_forwards,json" msgpack:"port_forwards"`
	StartedAt        time.Time          `json:"started_at" db:"started_at" msgpack:"started_at"`
	CreatedAt        time.Time          `json:"created_at" db:"created_at" msgpack:"created_at"`
	UpdatedAt        hlc.Timestamp      `json:"updated_at" db:"updated_at" msgpack:"updated_at"`
}

Space object

func NewSpace

func NewSpace(name string, description string, userId string, templateId string, shell string, altNames *[]AltNameEntry, zone string, iconURL string, customFields []SpaceCustomField) *Space

func (*Space) IsSharedWith added in v0.24.0

func (s *Space) IsSharedWith(userId string) bool

func (*Space) MaxUptimeReached

func (s *Space) MaxUptimeReached(template *Template) bool

func (*Space) NormalizeDependsOn added in v0.24.0

func (s *Space) NormalizeDependsOn()

func (*Space) NormalizeShares added in v0.24.0

func (s *Space) NormalizeShares()

func (*Space) SetSingleShare added in v0.24.0

func (s *Space) SetSingleShare(userId string)

func (*Space) SharedUserIds added in v0.24.0

func (s *Space) SharedUserIds() []string

type SpaceCustomField

type SpaceCustomField struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type SpaceUsageSample added in v0.24.0

type SpaceUsageSample struct {
	Id                    string        `json:"space_usage_id" db:"space_usage_id,pk" msgpack:"space_usage_id"`
	SpaceId               string        `json:"space_id" db:"space_id" msgpack:"space_id"`
	UserId                string        `json:"user_id" db:"user_id" msgpack:"user_id"`
	BucketKind            string        `json:"bucket_kind" db:"bucket_kind" msgpack:"bucket_kind"`
	BucketStart           time.Time     `json:"bucket_start" db:"bucket_start" msgpack:"bucket_start"`
	CPUPercent            float64       `json:"cpu_percent" db:"cpu_percent" msgpack:"cpu_percent"`
	MemoryUsedBytes       uint64        `json:"memory_used_bytes" db:"memory_used_bytes" msgpack:"memory_used_bytes"`
	MemoryLimitBytes      uint64        `json:"memory_limit_bytes" db:"memory_limit_bytes" msgpack:"memory_limit_bytes"`
	DiskUsedBytes         uint64        `json:"disk_used_bytes" db:"disk_used_bytes" msgpack:"disk_used_bytes"`
	DiskLimitBytes        uint64        `json:"disk_limit_bytes" db:"disk_limit_bytes" msgpack:"disk_limit_bytes"`
	ActivityWriteCount    uint32        `json:"activity_write_count" db:"activity_write_count" msgpack:"activity_write_count"`
	ActivityCreateCount   uint32        `json:"activity_create_count" db:"activity_create_count" msgpack:"activity_create_count"`
	ActivityDeleteCount   uint32        `json:"activity_delete_count" db:"activity_delete_count" msgpack:"activity_delete_count"`
	ActivityRenameCount   uint32        `json:"activity_rename_count" db:"activity_rename_count" msgpack:"activity_rename_count"`
	ActivityDistinctPaths uint32        `json:"activity_distinct_paths" db:"activity_distinct_paths" msgpack:"activity_distinct_paths"`
	ActivitySpaceStarts   uint32        `json:"activity_space_starts" db:"activity_space_starts" msgpack:"activity_space_starts"`
	ActivitySpaceStops    uint32        `json:"activity_space_stops" db:"activity_space_stops" msgpack:"activity_space_stops"`
	ActivitySpaceCreates  uint32        `json:"activity_space_creates" db:"activity_space_creates" msgpack:"activity_space_creates"`
	ActivitySpaceDeletes  uint32        `json:"activity_space_deletes" db:"activity_space_deletes" msgpack:"activity_space_deletes"`
	LastActivityAt        *time.Time    `json:"last_activity_at,omitempty" db:"last_activity_at" msgpack:"last_activity_at,omitempty"`
	CreatedAt             time.Time     `json:"created_at" db:"created_at" msgpack:"created_at"`
	UpdatedAt             hlc.Timestamp `json:"updated_at" db:"updated_at" msgpack:"updated_at"`
}

func NewSpaceUsageSample added in v0.24.0

func NewSpaceUsageSample(spaceId, userId, bucketKind string, bucketStart time.Time) *SpaceUsageSample

type SpaceVolume

type SpaceVolume struct {
	Id        string `json:"id"`
	Namespace string `json:"Namespace"`
	Type      string `json:"type,omitempty"`
}

func (*SpaceVolume) Scan

func (sv *SpaceVolume) Scan(value interface{}) error

Scan implements the sql.Scanner interface.

func (SpaceVolume) Value

func (sv SpaceVolume) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type StackComponent added in v0.24.0

type StackComponent struct {
	Name            string             `json:"name" db:"name"`
	TemplateId      string             `json:"template_id" db:"template_id"`
	Description     string             `json:"description" db:"description"`
	Shell           string             `json:"shell" db:"shell"`
	StartupScriptId string             `json:"startup_script_id" db:"startup_script_id"`
	DependsOn       []string           `json:"depends_on" db:"depends_on,json"`
	CustomFields    []StackCustomField `json:"custom_fields" db:"custom_fields,json"`
	PortForwards    []StackPortForward `json:"port_forwards" db:"port_forwards,json"`
}

type StackCustomField added in v0.24.0

type StackCustomField struct {
	Name  string `json:"name" db:"name"`
	Value string `json:"value" db:"value"`
}

type StackDefinition added in v0.24.0

type StackDefinition struct {
	Id            string           `json:"stack_definition_id" db:"stack_definition_id,pk"`
	UserId        string           `json:"user_id" db:"user_id"`
	Name          string           `json:"name" db:"name"`
	Description   string           `json:"description" db:"description"`
	Groups        []string         `json:"groups" db:"groups,json"`
	Zones         []string         `json:"zones" db:"zones,json"`
	Active        bool             `json:"active" db:"active"`
	IsDeleted     bool             `json:"is_deleted" db:"is_deleted"`
	IsManaged     bool             `json:"is_managed" db:"is_managed"`
	Components    []StackComponent `json:"components" db:"components,json"`
	CreatedUserId string           `json:"created_user_id" db:"created_user_id"`
	CreatedAt     time.Time        `json:"created_at" db:"created_at"`
	UpdatedUserId string           `json:"updated_user_id" db:"updated_user_id"`
	UpdatedAt     hlc.Timestamp    `json:"updated_at" db:"updated_at"`
}

func NewStackDefinition added in v0.24.0

func NewStackDefinition(
	name string,
	description string,
	groups []string,
	zones []string,
	active bool,
	components []StackComponent,
	ownerUserId string,
	createdUserId string,
) *StackDefinition

func (*StackDefinition) IsGlobal added in v0.24.0

func (sd *StackDefinition) IsGlobal() bool

IsGlobal returns true if the definition is a system/global definition (UserId is empty)

func (*StackDefinition) IsValidForZone added in v0.24.0

func (sd *StackDefinition) IsValidForZone(zone string) bool

IsValidForZone determines whether the stack definition is valid for the specified zone. Follows the same !-prefix negation logic as Script.IsValidForZone.

type StackPortForward added in v0.24.0

type StackPortForward struct {
	ToSpace    string `json:"to_space" db:"to_space"`
	LocalPort  int    `json:"local_port" db:"local_port"`
	RemotePort int    `json:"remote_port" db:"remote_port"`
}

type Template

type Template struct {
	Id                       string                 `json:"template_id" db:"template_id,pk"`
	Name                     string                 `json:"name" db:"name"`
	Description              string                 `json:"description" db:"description"`
	Hash                     string                 `json:"hash" db:"hash"`
	Platform                 string                 `json:"platform" db:"platform"`
	IconURL                  string                 `json:"icon_url" db:"icon_url"`
	Job                      string                 `json:"job" db:"job"`
	Volumes                  string                 `json:"volumes" db:"volumes"`
	Groups                   []string               `json:"groups" db:"groups,json"`
	Active                   bool                   `json:"active" db:"active"`
	WithTerminal             bool                   `json:"with_terminal" db:"with_terminal"`
	WithVSCodeTunnel         bool                   `json:"with_vscode_tunnel" db:"with_vscode_tunnel"`
	WithCodeServer           bool                   `json:"with_code_server" db:"with_code_server"`
	WithSSH                  bool                   `json:"with_ssh" db:"with_ssh"`
	WithRunCommand           bool                   `json:"with_run_command" db:"with_run_command"`
	AllowNodeMigration       bool                   `json:"allow_node_migration" db:"allow_node_migration"`
	StartupScriptId          string                 `json:"startup_script_id" db:"startup_script_id"`
	ShutdownScriptId         string                 `json:"shutdown_script_id" db:"shutdown_script_id"`
	ComputeUnits             uint32                 `json:"compute_units" db:"compute_units"`
	StorageUnits             uint32                 `json:"storage_units" db:"storage_units"`
	ScheduleEnabled          bool                   `json:"schedule_enabled" db:"schedule_enabled"`
	AutoStart                bool                   `json:"auto_start" db:"auto_start"`
	IsDeleted                bool                   `json:"is_deleted" db:"is_deleted"`
	IsManaged                bool                   `json:"is_managed" db:"is_managed"`
	Schedule                 []TemplateScheduleDays `json:"schedule" db:"schedule,json"`
	Zones                    []string               `json:"zones" db:"zones,json"`
	CustomFields             []TemplateCustomField  `json:"custom_fields" db:"custom_fields,json"`
	MaxUptime                uint32                 `json:"max_uptime" db:"max_uptime"`
	MaxUptimeUnit            string                 `json:"max_uptime_unit" db:"max_uptime_unit"`
	HealthCheckType          string                 `json:"health_check_type" db:"health_check_type"`
	HealthCheckConfig        string                 `json:"health_check_config" db:"health_check_config"`
	HealthCheckSkipSSLVerify bool                   `json:"health_check_skip_ssl_verify" db:"health_check_skip_ssl_verify"`
	HealthCheckTimeout       uint32                 `json:"health_check_timeout" db:"health_check_timeout"`
	HealthCheckInterval      uint32                 `json:"health_check_interval" db:"health_check_interval"`
	HealthCheckMaxFailures   uint32                 `json:"health_check_max_failures" db:"health_check_max_failures"`
	HealthCheckAutoRestart   bool                   `json:"health_check_auto_restart" db:"health_check_auto_restart"`
	DisableUserActivity      bool                   `json:"disable_user_activity" db:"disable_user_activity"`
	Ports                    []TemplatePort         `json:"ports" db:"ports,json"`
	CreatedUserId            string                 `json:"created_user_id" db:"created_user_id"`
	CreatedAt                time.Time              `json:"created_at" db:"created_at"`
	UpdatedUserId            string                 `json:"updated_user_id" db:"updated_user_id"`
	UpdatedAt                hlc.Timestamp          `json:"updated_at" db:"updated_at"`
}

Template object

func NewTemplate

func NewTemplate(
	name string,
	description string,
	job string,
	volumes string,
	userId string,
	groups []string,
	platform string,
	withTerminal bool,
	withVSCodeTunnel bool,
	withCodeServer bool,
	withSSH bool,
	withRunCommand bool,
	allowNodeMigration bool,
	startupScriptId string,
	shutdownScriptId string,
	computeUnits uint32,
	storageUnits uint32,
	scheduleEnabled bool,
	schedule *[]TemplateScheduleDays,
	zones []string,
	autoStart bool,
	active bool,
	maxUptime uint32,
	maxUptimeUnit string,
	iconURL string,
	customFields []TemplateCustomField,
) *Template

func (*Template) AllowedBySchedule

func (template *Template) AllowedBySchedule() bool

func (*Template) GetVolumes

func (template *Template) GetVolumes(space *Space, user *User, variables map[string]interface{}) (*CSIVolumes, error)

func (*Template) IsLocalContainer

func (template *Template) IsLocalContainer() bool

func (*Template) IsManual

func (template *Template) IsManual() bool

func (*Template) IsValidForZone added in v0.19.0

func (template *Template) IsValidForZone(zone string) bool

IsValidForZone determines whether the template is valid for deployment in the specified zone. The function evaluates zone restrictions based on the template's Zones configuration. If no zones are specified, the template is considered valid for all zones. Zone names prefixed with '!' are treated as exclusions (negated zones). The function first checks for exclusions, then checks for explicit inclusions.

zone is the target zone name to validate against the template's zone restrictions.

Returns true if the template can be deployed in the specified zone, false otherwise.

func (*Template) UpdateHash

func (template *Template) UpdateHash()

type TemplateCustomField

type TemplateCustomField struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

type TemplatePort added in v0.25.0

type TemplatePort struct {
	Name     string `json:"name"`
	Port     uint16 `json:"port"`
	Protocol string `json:"protocol"`
}

type TemplateScheduleDays

type TemplateScheduleDays struct {
	Enabled bool   `json:"enabled"`
	From    string `json:"from"`
	To      string `json:"to"`
}

type TemplateVar

type TemplateVar struct {
	Id            string        `json:"templatevar_id" db:"templatevar_id,pk"`
	Name          string        `json:"name" db:"name"`
	Zones         []string      `json:"zones" db:"zones,json"`
	Value         string        `json:"value" db:"value"`
	Protected     bool          `json:"protected" db:"protected"`
	Local         bool          `json:"local" db:"local"`
	Restricted    bool          `json:"restricted" db:"restricted"`
	IsDeleted     bool          `json:"is_deleted" db:"is_deleted"`
	IsManaged     bool          `json:"is_managed" db:"is_managed"`
	CreatedUserId string        `json:"created_user_id" db:"created_user_id"`
	CreatedAt     time.Time     `json:"created_at" db:"created_at"`
	UpdatedUserId string        `json:"updated_user_id" db:"updated_user_id"`
	UpdatedAt     hlc.Timestamp `json:"updated_at" db:"updated_at"`
}

Template Variable object

func NewTemplateVar

func NewTemplateVar(name string, zones []string, local bool, value string, protected bool, restricted bool, userId string) *TemplateVar

func (*TemplateVar) DecryptSetValue

func (templateVar *TemplateVar) DecryptSetValue(text string)

func (*TemplateVar) GetValueEncrypted

func (templateVar *TemplateVar) GetValueEncrypted() string

type Token

type Token struct {
	Id           string        `json:"token_id" db:"token_id,pk"`
	UserId       string        `json:"user_id" db:"user_id"`
	Name         string        `json:"name" db:"name"`
	ExpiresAfter time.Time     `json:"expires_after" db:"expires_after"`
	UpdatedAt    hlc.Timestamp `json:"updated_at" db:"updated_at"`
	IsDeleted    bool          `json:"is_deleted" db:"is_deleted"`
}

Session object

func NewToken

func NewToken(name string, userId string) *Token

type Usage

type Usage struct {
	ComputeUnits               uint32
	StorageUnits               uint32
	NumberSpaces               int
	NumberSpacesDeployed       int
	NumberSpacesDeployedInZone int
}

type User

type User struct {
	Id                    string                      `json:"user_id" db:"user_id,pk" msgpack:"user_id"`
	Username              string                      `json:"username" db:"username" msgpack:"username"`
	Email                 string                      `json:"email" db:"email" msgpack:"email"`
	Password              string                      `json:"password" db:"password" msgpack:"password"`
	TOTPSecret            string                      `json:"totp_secret" db:"totp_secret" msgpack:"totp_secret"`
	ServicePassword       string                      `json:"service_password" db:"service_password" msgpack:"service_password"`
	SSHPublicKey          string                      `json:"ssh_public_key" db:"ssh_public_key" msgpack:"ssh_public_key"`
	SSHPrivateKey         string                      `json:"ssh_private_key" db:"ssh_private_key" msgpack:"ssh_private_key"`
	GitHubUsername        string                      `json:"github_username" db:"github_username" msgpack:"github_username"`
	ExternalAuthProviders map[string]ExternalProvider `json:"external_auth_providers" db:"external_auth_providers,json" msgpack:"external_auth_providers"`
	Roles                 []string                    `json:"roles" db:"roles,json" msgpack:"roles"`
	Groups                []string                    `json:"groups" db:"groups,json" msgpack:"groups"`
	Active                bool                        `json:"active" db:"active" msgpack:"active"`
	IsDeleted             bool                        `json:"is_deleted" db:"is_deleted" msgpack:"is_deleted"`
	MaxSpaces             uint32                      `json:"max_spaces" db:"max_spaces" msgpack:"max_spaces"`
	ComputeUnits          uint32                      `json:"compute_units" db:"compute_units" msgpack:"compute_units"`
	StorageUnits          uint32                      `json:"storage_units" db:"storage_units" msgpack:"storage_units"`
	MaxTunnels            uint32                      `json:"max_tunnels" db:"max_tunnels" msgpack:"max_tunnels"`
	PreferredShell        string                      `json:"preferred_shell" db:"preferred_shell" msgpack:"preferred_shell"`
	Timezone              string                      `json:"timezone" db:"timezone" msgpack:"timezone"`
	LastLoginAt           *time.Time                  `json:"last_login_at" db:"last_login_at" msgpack:"last_login_at"`
	UpdatedAt             hlc.Timestamp               `json:"updated_at" db:"updated_at" msgpack:"updated_at"`
	CreatedAt             time.Time                   `json:"created_at" db:"created_at" msgpack:"created_at"`
}

User object

func NewUser

func NewUser(username string, email string, password string, roles []string, groups []string, sshPublicKey string, preferredShell string, timezone string, maxSpaces uint32, githubUsername string, computeUnits uint32, storageUnits uint32, maxTunnels uint32) *User

func (*User) CheckPassword

func (u *User) CheckPassword(password string) bool

Check the password for the user

func (*User) ClearOAuthTokens added in v0.24.0

func (u *User) ClearOAuthTokens(providerID string)

func (*User) GetOAuthRefreshToken added in v0.24.0

func (u *User) GetOAuthRefreshToken(providerID, encryptionKey string) string

GetOAuthRefreshToken returns the decrypted OAuth refresh token for the given provider, or empty string.

func (*User) GetOAuthToken added in v0.23.7

func (u *User) GetOAuthToken(providerID, encryptionKey string) string

GetOAuthToken returns the decrypted OAuth access token for the given provider, or empty string.

func (*User) GetSSHPrivateKeyDecrypted added in v0.25.0

func (u *User) GetSSHPrivateKeyDecrypted(encryptionKey string) string

func (*User) HasAnyGroup

func (u *User) HasAnyGroup(groups *[]string) bool

func (*User) HasPermission

func (u *User) HasPermission(permission uint16) bool

func (*User) IsAdmin

func (u *User) IsAdmin() bool

func (*User) SetOAuthTokens added in v0.24.0

func (u *User) SetOAuthTokens(providerID, token, refreshToken, encryptionKey string)

SetOAuthTokens stores encrypted OAuth tokens for the given provider. Refresh tokens are preserved when the provider omits them on a later login.

func (*User) SetPassword

func (u *User) SetPassword(password string) error

Set the password for the user

func (*User) SetSSHPrivateKeyEncrypted added in v0.25.0

func (u *User) SetSSHPrivateKeyEncrypted(privateKey string, encryptionKey string)

ClearOAuthTokens removes the stored tokens for the given provider.

type Volume

type Volume struct {
	Id            string        `json:"volume_id" db:"volume_id,pk"`
	Name          string        `json:"name" db:"name"`
	Zone          string        `json:"zone" db:"zone"`
	NodeId        string        `json:"node_id" db:"node_id"`
	Platform      string        `json:"platform" db:"platform"`
	Definition    string        `json:"definition" db:"definition"`
	Active        bool          `json:"active" db:"active"`
	IsDeleted     bool          `json:"is_deleted" db:"is_deleted"`
	CreatedUserId string        `json:"created_user_id" db:"created_user_id"`
	CreatedAt     time.Time     `json:"created_at" db:"created_at"`
	UpdatedUserId string        `json:"updated_user_id" db:"updated_user_id"`
	UpdatedAt     hlc.Timestamp `json:"updated_at" db:"updated_at"`
}

Template object

func NewVolume

func NewVolume(name string, definition string, userId string, platform string) *Volume

func (*Volume) GetVolume

func (volume *Volume) GetVolume(variables map[string]interface{}) (*CSIVolumes, error)

type VolumeDataMap

type VolumeDataMap map[string]SpaceVolume

VolumeDataMap is a custom type that implements the sql.Scanner and driver.Valuer interfaces

func (*VolumeDataMap) Scan

func (v *VolumeDataMap) Scan(value interface{}) error

Scan implements the sql.Scanner interface.

func (VolumeDataMap) Value

func (v VolumeDataMap) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

Jump to

Keyboard shortcuts

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