model

package
v0.12.3 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

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
)

Permissions

View Source
const (
	RoleAdminUUID = "00000000-0000-0000-0000-000000000000"
)

Roles

View Source
const WEBUI_SESSION_COOKIE = "__KNOT_WEBUI_SESSION"

Variables

View Source
var PermissionNames = []PermissionName{
	{PermissionManageGroups, "Manage Groups"},
	{PermissionManageRoles, "Manage Roles"},
	{PermissionManageSpaces, "Manage Spaces"},
	{PermissionManageTemplates, "Manage Templates"},
	{PermissionManageUsers, "Manage Users"},
	{PermissionManageVariables, "Manage Variables"},
	{PermissionManageVolumes, "Manage Volumes"},
	{PermissionUseSpaces, "Can Use Spaces"},
	{PermissionUseTunnels, "Can Use Tunnels"},
}

Functions

func DeleteRoleFromCache added in v0.12.0

func DeleteRoleFromCache(roleId string)

func FilterVars added in v0.10.0

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 added in v0.12.0

func SaveRoleToCache(role *Role)

func SetRoleCache added in v0.12.0

func SetRoleCache(roles []*Role)

Types

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 Group

type Group struct {
	Id            string    `json:"group_id"`
	Name          string    `json:"name"`
	MaxSpaces     uint32    `json:"max_spaces"`
	ComputeUnits  uint32    `json:"compute_units"`
	StorageUnits  uint32    `json:"storage_units"`
	MaxTunnels    uint32    `json:"max_tunnels"`
	CreatedUserId string    `json:"created_user_id"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedUserId string    `json:"updated_user_id"`
	UpdatedAt     time.Time `json:"updated_at"`
}

Group object

func NewGroup

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

type JSONDbArray

type JSONDbArray []string

func (*JSONDbArray) Scan

func (m *JSONDbArray) Scan(src interface{}) error

func (JSONDbArray) Value

func (m JSONDbArray) Value() (driver.Value, error)

type JSONDbScheduleDays added in v0.12.0

type JSONDbScheduleDays []TemplateScheduleDays

func (*JSONDbScheduleDays) Scan added in v0.12.0

func (m *JSONDbScheduleDays) Scan(src interface{}) error

func (JSONDbScheduleDays) Value added in v0.12.0

func (m JSONDbScheduleDays) Value() (driver.Value, error)

type JSONDbUIntArray added in v0.12.0

type JSONDbUIntArray []uint16

func (*JSONDbUIntArray) Scan added in v0.12.0

func (m *JSONDbUIntArray) Scan(src interface{}) error

func (JSONDbUIntArray) Value added in v0.12.0

func (m JSONDbUIntArray) Value() (driver.Value, error)

type PermissionName added in v0.12.0

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

type Role added in v0.12.0

type Role struct {
	Id            string          `json:"role_id"`
	Name          string          `json:"name"`
	Permissions   JSONDbUIntArray `json:"permissions"`
	CreatedUserId string          `json:"created_user_id"`
	CreatedAt     time.Time       `json:"created_at"`
	UpdatedUserId string          `json:"updated_user_id"`
	UpdatedAt     time.Time       `json:"updated_at"`
}

Role

func GetRoleFromCache added in v0.12.0

func GetRoleFromCache(roleId string) *Role

func GetRolesFromCache added in v0.12.0

func GetRolesFromCache() []*Role

func NewRole added in v0.12.0

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

type Session

type Session struct {
	Id              string    `json:"session_id"`
	Ip              string    `json:"ip"`
	UserId          string    `json:"user_id"`
	RemoteSessionId string    `json:"remote_session_id"`
	UserAgent       string    `json:"user_agent"`
	ExpiresAfter    time.Time `json:"expires_after"`
}

Session object

func NewSession

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

type Space

type Space struct {
	Id             string                 `json:"space_id"`
	UserId         string                 `json:"user_id"`
	TemplateId     string                 `json:"template_id"`
	Name           string                 `json:"name"`
	Shell          string                 `json:"shell"`
	Location       string                 `json:"location"`
	TemplateHash   string                 `json:"template_hash"`
	NomadNamespace string                 `json:"nomad_namespace"`
	ContainerId    string                 `json:"container_id"`
	VolumeData     map[string]SpaceVolume `json:"volume_data"`
	IsDeployed     bool                   `json:"is_deployed"`
	IsPending      bool                   `json:"is_pending"` // Flags if the space is pending a state change, starting or stopping
	IsDeleting     bool                   `json:"is_deleting"`
	AltNames       []string               `json:"alt_names"`
	SSHHostSigner  string                 `json:"ssh_host_signer"`
	CreatedAt      time.Time              `json:"created_at"`
	UpdatedAt      time.Time              `json:"updated_at"`
}

Space object

func NewSpace

func NewSpace(name string, userId string, templateId string, shell string, altNames *[]string) *Space

type SpaceVolume

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

type Template

type Template struct {
	Id               string             `json:"template_id"`
	Name             string             `json:"name"`
	Description      string             `json:"description"`
	Hash             string             `json:"hash"`
	Job              string             `json:"job"`
	Volumes          string             `json:"volumes"`
	Groups           JSONDbArray        `json:"groups"`
	LocalContainer   bool               `json:"local_container"`
	IsManual         bool               `json:"is_manual"`
	WithTerminal     bool               `json:"with_terminal"`
	WithVSCodeTunnel bool               `json:"with_vscode_tunnel"`
	WithCodeServer   bool               `json:"with_code_server"`
	WithSSH          bool               `json:"with_ssh"`
	ComputeUnits     uint32             `json:"compute_units"`
	StorageUnits     uint32             `json:"storage_units"`
	ScheduleEnabled  bool               `json:"schedule_enabled"`
	Schedule         JSONDbScheduleDays `json:"schedule"`
	CreatedUserId    string             `json:"created_user_id"`
	CreatedAt        time.Time          `json:"created_at"`
	UpdatedUserId    string             `json:"updated_user_id"`
	UpdatedAt        time.Time          `json:"updated_at"`
}

Template object

func NewTemplate

func NewTemplate(name string, description string, job string, volumes string, userId string, groups []string, localContainer bool, isManual bool, withTerminal bool, withVSCodeTunnel bool, withCodeServer bool, withSSH bool, computeUnits uint32, storageUnits uint32, scheduleEnabled bool, schedule *[]TemplateScheduleDays) *Template

func (*Template) AllowedBySchedule added in v0.12.0

func (template *Template) AllowedBySchedule() bool

func (*Template) GetVolumes

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

func (*Template) UpdateHash

func (template *Template) UpdateHash()

type TemplateScheduleDays added in v0.12.0

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"`
	Name          string    `json:"name"`
	Location      string    `json:"location"`
	Value         string    `json:"value"`
	Protected     bool      `json:"protected"`
	Local         bool      `json:"local"`
	Restricted    bool      `json:"restricted"`
	CreatedUserId string    `json:"created_user_id"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedUserId string    `json:"updated_user_id"`
	UpdatedAt     time.Time `json:"updated_at"`
}

Template Variable object

func NewTemplateVar

func NewTemplateVar(name string, location 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"`
	UserId       string    `json:"user_id"`
	SessionId    string    `json:"session_id"`
	Name         string    `json:"name"`
	ExpiresAfter time.Time `json:"expires_after"`
}

Session object

func NewToken

func NewToken(name string, userId string) *Token

type Usage added in v0.12.0

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

type User

type User struct {
	Id              string      `json:"user_id"`
	Username        string      `json:"username"`
	Email           string      `json:"email"`
	Password        string      `json:"password"`
	ServicePassword string      `json:"service_password"`
	SSHPublicKey    string      `json:"ssh_public_key"`
	GitHubUsername  string      `json:"github_username"`
	Roles           JSONDbArray `json:"roles"`
	Groups          JSONDbArray `json:"groups"`
	Active          bool        `json:"active"`
	MaxSpaces       uint32      `json:"max_spaces"`
	ComputeUnits    uint32      `json:"compute_units"`
	StorageUnits    uint32      `json:"storage_units"`
	MaxTunnels      uint32      `json:"max_tunnels"`
	PreferredShell  string      `json:"preferred_shell"`
	Timezone        string      `json:"timezone"`
	LastLoginAt     *time.Time  `json:"last_login_at"`
	UpdatedAt       time.Time   `json:"updated_at"`
	CreatedAt       time.Time   `json:"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 *JSONDbArray) bool

func (*User) HasPermission

func (u *User) HasPermission(permission uint16) 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"`
	Name           string    `json:"name"`
	Location       string    `json:"location"`
	Definition     string    `json:"definition"`
	Active         bool      `json:"active"`
	LocalContainer bool      `json:"local_container"`
	CreatedUserId  string    `json:"created_user_id"`
	CreatedAt      time.Time `json:"created_at"`
	UpdatedUserId  string    `json:"updated_user_id"`
	UpdatedAt      time.Time `json:"updated_at"`
}

Template object

func NewVolume

func NewVolume(name string, definition string, userId string, localContainer bool) *Volume

func (*Volume) GetVolume

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

Jump to

Keyboard shortcuts

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