model

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuditActorSystem = "System"

	AuditActorTypeUser   = "User"
	AuditActorTypeSystem = "System"
)

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

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
)

Permissions

View Source
const (
	WebSessionCookie      = "__KNOT_WEBUI_SESSION"
	SessionExpiryDuration = 2 * time.Hour
)
View Source
const (
	PlatformManual = "manual"
	PlatformDocker = "docker"
	PlatformPodman = "podman"
	PlatformNomad  = "nomad"

	LeafNodeZone = "<leaf-node>"
)
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"},

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

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

	{PermissionShareSpaces, "Resource Management", "Share Spaces"},
	{PermissionTransferSpaces, "Resource Management", "Transfer Spaces"},
	{PermissionManageSpaces, "Resource Management", "Manage Spaces"},
	{PermissionManageTemplates, "Resource Management", "Manage Templates"},
	{PermissionManageVariables, "Resource Management", "Manage Variables"},
	{PermissionManageVolumes, "Resource Management", "Manage Volumes"},

	{PermissionUseSpaces, "Resource Usage", "Use Spaces"},
	{PermissionUseTunnels, "Resource Usage", "Use Tunnels"},
	{PermissionUseCodeServer, "Resource Usage", "Use Code Server"},
	{PermissionUseLogs, "Resource Usage", "View Logs"},
	{PermissionUseSSH, "Resource Usage", "Use SSH"},
	{PermissionUseVNC, "Resource Usage", "Use VNC"},
	{PermissionUseVSCodeTunnel, "Resource Usage", "Use VSCode Tunnel"},
	{PermissionUseWebTerminal, "Resource Usage", "Use Web Terminal"},
}

Functions

func DeleteRoleFromCache

func DeleteRoleFromCache(roleId string)

func FilterVars

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

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)

Types

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

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 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 PermissionName

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

type Quota

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

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 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 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"`
	SharedWithUserId string             `json:"shared_with_user_id" db:"shared_with_user_id" msgpack:"shared_with_user_id"`
	Name             string             `json:"name" db:"name" msgpack:"name"`
	Description      string             `json:"description" db:"description" msgpack:"description"`
	Note             string             `json:"note" db:"note" msgpack:"note"`
	Zone             string             `json:"zone" db:"zone" msgpack:"zone"`
	Shell            string             `json:"shell" db:"shell" msgpack:"shell"`
	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"` // Flags if the space is pending a state change, starting or stopping
	IsDeleted        bool               `json:"is_deleted" db:"is_deleted" msgpack:"is_deleted"`
	AltNames         []string           `json:"alt_names" msgpack:"alt_names"`
	CustomFields     []SpaceCustomField `json:"custom_fields" db:"custom_fields,json" msgpack:"custom_fields"`
	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 *[]string, zone string, iconURL string, customFields []SpaceCustomField) *Space

func (*Space) MaxUptimeReached

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

type SpaceCustomField

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

type SpaceVolume

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

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 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"`
	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"`
	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,
	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) UpdateHash

func (template *Template) UpdateHash()

type TemplateCustomField

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

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"`
	GitHubUsername  string        `json:"github_username" db:"github_username" msgpack:"github_username"`
	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) 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) SetPassword

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

Set the password for the user

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"`
	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