model

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AGENT_STATE_PING_INTERVAL = 4 * time.Second
	AGENT_STATE_GC_INTERVAL   = 5 * time.Second
	AGENT_STATE_TIMEOUT       = 15 * time.Second
)
View Source
const (
	PermissionManageUsers     = iota // Can Manage Users
	PermissionManageTemplates        // Can Manage Templates
	PermissionManageSpaces           // Can Manage Spaces
	PermissionManageVolumes          // Can Manage Volumes
)

Permissions

View Source
const (
	RoleAdmin           = "00000000-0000-0000-0000-000000000000"
	RoleUserManager     = "00000000-0000-0000-0000-000000000001"
	RoleTemplateManager = "00000000-0000-0000-0000-000000000002"
	RoleSpaceManager    = "00000000-0000-0000-0000-000000000003"
	RoleVolumeManager   = "00000000-0000-0000-0000-000000000004"
)

Roles

View Source
const MANUAL_TEMPLATE_ID = "00000000-0000-0000-0000-000000000000"
View Source
const WEBUI_SESSION_COOKIE = "__KNOT_WEBUI_SESSION"

Variables

View Source
var RoleNames = []RoleName{
	{RoleAdmin, "Admin"},
	{RoleUserManager, "User Manager"},
	{RoleTemplateManager, "Template Manager"},
	{RoleSpaceManager, "Space Manager"},
	{RoleVolumeManager, "Volume Manager"},
}

Functions

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

Types

type AgentState

type AgentState struct {
	Id            string    `json:"space_id"`
	AgentVersion  string    `json:"agent_version"`
	AccessToken   string    `json:"access_token"`
	HasCodeServer bool      `json:"has_code_server"`
	SSHPort       int       `json:"ssh_port"`
	VNCHttpPort   int       `json:"vnc_http_port"`
	HasTerminal   bool      `json:"has_terminal"`
	TcpPorts      []int     `json:"tcp_ports"`
	HttpPorts     []int     `json:"http_ports"`
	ExpiresAfter  time.Time `json:"expires_after"`
}

Struct holding the state of an agent

func NewAgentState

func NewAgentState(spaceId string) *AgentState

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" json:"RequestedCapacityMin"`
	CapacityMax  interface{}           `yaml:"capacity_max" json:"RequestedCapacityMax"`
	Capabilities []CSIVolumeCapability `yaml:"capabilities" json:"RequestedCapabilities"`
	Secrets      map[string]string     `yaml:"secrets" json:"Secrets"`
	Parameters   map[string]string     `yaml:"parameters" json:"Parameters"`
}

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{}, applySpaceSizes bool) (*CSIVolumes, error)

type Group

type Group struct {
	Id            string    `json:"group_id"`
	Name          string    `json:"name"`
	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) *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 RoleName

type RoleName struct {
	RoleID   string `json:"id_role"`
	RoleName string `json:"role_name"`
}

Mapping of role IDs to names

type Session

type Session struct {
	Id           string                 `json:"session_id"`
	Ip           string                 `json:"ip"`
	UserId       string                 `json:"user_id"`
	UserAgent    string                 `json:"user_agent"`
	Values       map[string]interface{} `json:"data"`
	ExpiresAfter time.Time              `json:"expires_after"`
}

Session object

func NewSession

func NewSession(r *http.Request, userId 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"`
	AgentURL       string                 `json:"agent_url"`
	Shell          string                 `json:"shell"`
	TemplateHash   string                 `json:"template_hash"`
	NomadNamespace string                 `json:"nomad_namespace"`
	NomadJobId     string                 `json:"nomad_job_id"`
	VolumeData     map[string]SpaceVolume `json:"volume_data"`
	VolumeSizes    map[string]int64       `json:"volume_sizes"`
	IsDeployed     bool                   `json:"is_deployed"`
	AltNames       []string               `json:"alt_names"`
	CreatedAt      time.Time              `json:"created_at"`
	UpdatedAt      time.Time              `json:"updated_at"`
}

Space object

func NewSpace

func NewSpace(name string, userId string, agentURL string, templateId string, shell string, volSizes *map[string]int64, altNames *[]string) *Space

func (*Space) GetAgentURL

func (space *Space) GetAgentURL() string

func (*Space) GetStorageSize

func (space *Space) GetStorageSize(template *Template) (int, error)

Get the storage size for the space in GB

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"`
	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) *Template

func (*Template) GetVolumes

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

func (*Template) UpdateHash

func (template *Template) UpdateHash()

type TemplateVar

type TemplateVar struct {
	Id            string    `json:"templatevar_id"`
	Name          string    `json:"name"`
	Value         string    `json:"value"`
	Protected     bool      `json:"protected"`
	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, value string, protected 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"`
	Name         string    `json:"name"`
	ExpiresAfter time.Time `json:"expires_after"`
}

Session object

func NewToken

func NewToken(name string, userId string) *Token

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"`
	Roles           JSONDbArray `json:"roles"`
	Groups          JSONDbArray `json:"groups"`
	Active          bool        `json:"active"`
	MaxSpaces       int         `json:"max_spaces"`
	MaxDiskSpace    int         `json:"max_disk_space"`
	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 int, maxDiskSpace int) *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 int) 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"`
	Definition    string    `json:"definition"`
	Active        bool      `json:"active"`
	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) *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