models

package
v0.0.36 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WorkspaceConfigSourceGit      = "git"
	WorkspaceConfigSourceTemplate = "template"
)
View Source
const WorkspaceStatusDeleting = "deleting"
View Source
const WorkspaceStatusError = "error"
View Source
const WorkspaceStatusRunning = "running"
View Source
const WorkspaceStatusStarting = "starting"

workspace status

View Source
const WorkspaceStatusStopped = "stopped"
View Source
const WorkspaceStatusStopping = "stopping"

Variables

This section is empty.

Functions

func CountAllUsers added in v0.0.35

func CountAllUsers() (count int64, err error)

func CountPublishedWorkspaceTemplateVersionsByTemplate added in v0.0.30

func CountPublishedWorkspaceTemplateVersionsByTemplate(template WorkspaceTemplate) (int64, error)

func CountWorkspaceTemplateVersionsByTemplate added in v0.0.30

func CountWorkspaceTemplateVersionsByTemplate(template WorkspaceTemplate) (int64, error)

func DeleteTemplate added in v0.0.30

func DeleteTemplate(wt WorkspaceTemplate) error

func DeleteTemplateVersion added in v0.0.30

func DeleteTemplateVersion(tv WorkspaceTemplateVersion) error

func HashPassword

func HashPassword(password string) (string, error)

func ListWorkspaceTemplateVersionsByTemplate added in v0.0.30

func ListWorkspaceTemplateVersionsByTemplate(template WorkspaceTemplate) (*[]WorkspaceTemplateVersion, error)

func RemoveExpiredAuthorizationCodes

func RemoveExpiredAuthorizationCodes() error

remove expired authorization codes

func UpdateWorkspaceTemplate added in v0.0.30

func UpdateWorkspaceTemplate(wt WorkspaceTemplate) error

update workspace template

func ValidatePassword

func ValidatePassword(password string) error

Types

type AuthorizationCode

type AuthorizationCode struct {
	ID        uint   `gorm:"primarykey"`
	Code      string `gorm:"column:code; size:255"`
	TokenID   uint   `gorm:"column:token_id;"`
	Token     *Token
	ExpiresAt time.Time      `gorm:"column:expires_at;"`
	CreatedAt time.Time      `gorm:"column:created_at;"`
	UpdatedAt time.Time      `gorm:"column:updated_at;"`
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

func GenerateAuthorizationCode

func GenerateAuthorizationCode(token Token, expiration time.Time) (ac AuthorizationCode, err error)

generate authorization code

type File added in v0.0.30

type File struct {
	ID        uint           `gorm:"column:id; primarykey" json:"-"`
	Filepath  string         `gorm:"column:filepath; not null" json:"-"` // relative path
	CreatedAt time.Time      `gorm:"column:created_at;" json:"-"`
	UpdatedAt time.Time      `gorm:"column:updated_at;" json:"-"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}

func (*File) Exists added in v0.0.30

func (f *File) Exists() bool

func (*File) GetAbsolutePath added in v0.0.30

func (f *File) GetAbsolutePath() string

get the absolute location of the file create parent directory if it does not exists

type GitWorkspaceSource

type GitWorkspaceSource struct {
	ID             uint           `gorm:"primarykey" json:"id"`
	RepositoryURL  string         `gorm:"column:repository_url; type:text;not null;" json:"repository_url"`
	RefName        string         `gorm:"column:ref_name; size:255; not null;" json:"ref_name"`
	ConfigFilePath string         `gorm:"column:config_file_path; type:text;" json:"config_file_relative_path"` // path of the configuration files relative to the root of the repo
	SourcesID      uint           `gorm:"column:sources_id;"`
	Sources        *File          `json:"-"`
	CreatedAt      time.Time      `gorm:"column:created_at;" json:"-"`
	UpdatedAt      time.Time      `gorm:"column:updated_at;" json:"-"`
	DeletedAt      gorm.DeletedAt `gorm:"index" json:"-"`
}

type Group

type Group struct {
	ID        uint           `gorm:"primarykey"`
	Name      string         `gorm:"column:name; size:255;unique"`
	CreatedAt time.Time      `gorm:"column:created_at;"`
	UpdatedAt time.Time      `gorm:"column:updated_at;"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}

type Runner

type Runner struct {
	ID            uint           `gorm:"primarykey" json:"id"`
	Name          string         `gorm:"column:name; size:255;unique;not null;" json:"name"`
	Token         string         `gorm:"column:token; size:255;unique;not null;" json:"-"`
	Port          uint           `gorm:"column:port; default:0;" json:"-"`
	Type          string         `gorm:"column:type; size:255;" json:"type"`
	Restricted    bool           `gorm:"column:restricted; default:false;" json:"-"`
	AllowedGroups []Group        `gorm:"many2many:runner_allowed_groups;" json:"-"`
	UsePublicUrl  bool           `gorm:"column:use_public_url; default:false;" json:"use_public_url"`
	PublicUrl     string         `gorm:"column:public_url; type:text;" json:"public_url"`
	LastContact   *time.Time     `gorm:"column:last_contact;" json:"last_contact"`
	Version       string         `gorm:"column:version; default:''; size:255;" json:"version"`
	CreatedAt     time.Time      `gorm:"column:created_at;" json:"-"`
	UpdatedAt     time.Time      `gorm:"column:updated_at;" json:"-"`
	DeletedAt     gorm.DeletedAt `gorm:"index" json:"-"`
}

type Token

type Token struct {
	gorm.Model
	ID             uint       `gorm:"primarykey"`
	Token          string     `gorm:"column:token; size:255;unique;"`
	ExpirationDate *time.Time `gorm:"column:expiration_date;"`
	UserID         uint       `gorm:"column:user_id;"`
	User           User       `gorm:"constraint:OnDelete:CASCADE;"`
}

func CreateToken

func CreateToken(user User, duration time.Duration) (Token, error)

type User

type User struct {
	ID                uint           `gorm:"primarykey" json:"-"`
	Email             string         `gorm:"column:email; size:255; unique; not null;" json:"email"`
	Password          string         `gorm:"column:password; not null;" json:"-"`
	FirstName         string         `gorm:"column:first_name; size:255;" json:"first_name"`
	LastName          string         `gorm:"column:last_name; size:255;" json:"last_name"`
	Groups            []Group        `gorm:"many2many:user_groups;" json:"groups"`
	SshPrivateKey     string         `gorm:"column:ssh_private_key; not null;" json:"-"`
	SshPublicKey      string         `gorm:"column:ssh_public_key; not null;" json:"-"`
	IsSuperuser       bool           `gorm:"column:is_superuser; column:is_superuser; default:false" json:"is_superuser"`
	IsTemplateManager bool           `gorm:"column:is_template_manager; default:false" json:"is_template_manager"`
	CreatedAt         time.Time      `json:"-"`
	UpdatedAt         time.Time      `json:"-"`
	DeletedAt         gorm.DeletedAt `gorm:"index" json:"-"`
}

func CreateUser added in v0.0.35

func CreateUser(email, firstName, lastName, password string, isSuperUser, isTemplateManager bool) (user *User, err error)

func RetrieveUserByEmail added in v0.0.35

func RetrieveUserByEmail(email string) (user *User, err error)

func (*User) BeforeSave

func (u *User) BeforeSave(tx *gorm.DB) (err error)

func (*User) CheckPassword

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

type Workspace

type Workspace struct {
	ID                   uint                      `gorm:"primarykey" json:"id"`
	Name                 string                    `gorm:"column:name; size:255; not null;" json:"name"`
	UserID               uint                      `gorm:"column:user_id;" json:"-"`
	User                 *User                     `gorm:"constraint:OnDelete:CASCADE;" json:"user"`
	Status               string                    `gorm:"column:status; size:30; not null;" json:"status"`
	Type                 string                    `gorm:"column:type; size:255; not null;" json:"type"`
	RunnerID             uint                      `gorm:"column:runner_id;" json:"-"`
	Runner               *Runner                   `gorm:"constraint:OnDelete:CASCADE;" json:"runner"`
	ConfigSource         string                    `gorm:"column:config_source; size:20; not null;" json:"config_source"` // template/git
	TemplateVersionID    *uint                     `gorm:"column:template_version_id;" json:"-"`
	TemplateVersion      *WorkspaceTemplateVersion `gorm:"constraint:OnDelete:CASCADE;" json:"template_version"`
	GitSourceID          *uint                     `gorm:"column:git_source_id;" json:"-"`
	GitSource            *GitWorkspaceSource       `gorm:"constraint:OnDelete:CASCADE;" json:"git_source"`
	EnvironmentVariables []string                  `gorm:"column:environment_variables; serializer:json" json:"environment_variables"`
	CreatedAt            time.Time                 `json:"created_at"`
	UpdatedAt            time.Time                 `json:"updated_at"`
	DeletedAt            gorm.DeletedAt            `gorm:"index" json:"-"`
}

func ListWorkspacesByTemplate added in v0.0.30

func ListWorkspacesByTemplate(wt WorkspaceTemplate) ([]Workspace, error)

func (*Workspace) AppendLogs

func (w *Workspace) AppendLogs(logs string) error

func (*Workspace) ClearLogs

func (w *Workspace) ClearLogs() error

func (*Workspace) GetDefaultEnvironmentVariables

func (w *Workspace) GetDefaultEnvironmentVariables() []string

Retrieve list of environement variables to exported by default to workspace This variables are informations related to workspace such as workspace name, owner email, first name and last name

func (*Workspace) GetLogsFilePath

func (w *Workspace) GetLogsFilePath() (string, error)

func (*Workspace) RetrieveLogs

func (w *Workspace) RetrieveLogs() (string, error)

type WorkspaceContainer

type WorkspaceContainer struct {
	ID                uint           `gorm:"primarykey" json:"-"`
	WorkspaceID       uint           `gorm:"column:workspace_id;" json:"-"`
	Workspace         Workspace      `gorm:"constraint:OnDelete:CASCADE;" json:"-"`
	ContainerID       string         `gorm:"column:container_id; size:255" json:"container_id"`
	ContainerName     string         `gorm:"column:container_name; size:255" json:"container_name"`
	ContainerImage    string         `gorm:"column:container_image; size:255" json:"container_image"`
	ContainerUserID   uint           `gorm:"column:container_user_id;" json:"container_user_id"`
	ContainerUserName string         `gorm:"size:255" json:"container_user_name"`
	AgentLastContact  *time.Time     `gorm:"column:agent_last_contact;" json:"agent_last_contact"`
	WorkspacePath     string         `gorm:"column:workspace_path; size:255" json:"workspace_path"`
	CreatedAt         time.Time      `gorm:"column:created_at;" json:"created_at"`
	UpdatedAt         time.Time      `gorm:"column:updated_at;" json:"updated_at"`
	DeletedAt         gorm.DeletedAt `gorm:"index" json:"-"`
}

type WorkspaceContainerPort

type WorkspaceContainerPort struct {
	ID          uint               `gorm:"primarykey" json:"-"`
	ContainerID uint               `gorm:"column:container_id;" json:"-"`
	Container   WorkspaceContainer `gorm:"constraint:OnDelete:CASCADE;" json:"-"`
	ServiceName string             `gorm:"column:service_name; size:255; not null;" json:"service_name"`
	PortNumber  uint               `gorm:"column:port_number; not null;" json:"port_number"`
	Public      bool               `gorm:"column:public; default:false;" json:"public"`
	CreatedAt   time.Time          `gorm:"column:created_at;" json:"created_at"`
	UpdatedAt   time.Time          `gorm:"column:updated_at;" json:"updated_at"`
	DeletedAt   gorm.DeletedAt     `gorm:"index" json:"-"`
}

type WorkspaceTemplate

type WorkspaceTemplate struct {
	ID          uint           `gorm:"primarykey"  json:"id"`
	Name        string         `gorm:"column:name; size:255;unique;not null;"  json:"name"`
	Type        string         `gorm:"column:type; size:255;"  json:"type"`
	Description string         `gorm:"column:description;" json:"description"`
	Icon        string         `gorm:"column:icon; type:text;" json:"icon"`
	CreatedAt   time.Time      `gorm:"index" json:"-"`
	UpdatedAt   time.Time      `gorm:"index" json:"-"`
	DeletedAt   gorm.DeletedAt `gorm:"index" json:"-"`
}

func CreateWorkspaceTemplate added in v0.0.30

func CreateWorkspaceTemplate(name string, templateType string, description string, icon string) (*WorkspaceTemplate, error)

create new template

func RetrieveWorkspaceTemplateByID added in v0.0.30

func RetrieveWorkspaceTemplateByID(id uint) (*WorkspaceTemplate, error)

Retrieve workspace template by id return nil if object is not found

func RetrieveWorkspaceTemplateByName added in v0.0.30

func RetrieveWorkspaceTemplateByName(name string) (*WorkspaceTemplate, error)

Retrieve workspace template by name return nil if object is not found

type WorkspaceTemplateVersion

type WorkspaceTemplateVersion struct {
	ID             uint               `gorm:"primarykey" json:"id"`
	TemplateID     uint               `gorm:"column:template_id;" json:"template"`
	Template       *WorkspaceTemplate `gorm:"constraint:OnDelete:CASCADE;not null;" json:"-"`
	Name           string             `gorm:"column:name; size:255;not null;" json:"name"`
	ConfigFilePath string             `gorm:"column:config_file_path; type:text;" json:"config_file_relative_path"`
	SourcesID      uint               `gorm:"column:sources_id;" json:"-"`
	Sources        *File              `json:"-"`
	Published      bool               `gorm:"column:published; default:false" json:"published"`
	PublishedOn    *time.Time         `gorm:"column:published_on; default:null" json:"published_on"`
	EditedByID     uint               `gorm:"column:edited_by_id;" json:"-"`
	EditedBy       *User              `gorm:"constraint:OnDelete:SET NULL;" json:"-"`
	EditedOn       time.Time          `gorm:"column:edited_on;" json:"edited_on"`
	CreatedAt      time.Time          `json:"-"`
	UpdatedAt      time.Time          `json:"-"`
	DeletedAt      gorm.DeletedAt     `gorm:"index" json:"-"`
}

func CreateTemplateVersion added in v0.0.30

func CreateTemplateVersion(template WorkspaceTemplate, name string, user User, configFilePath string) (*WorkspaceTemplateVersion, error)

func RetrieveLatestTemplateVersionByTemplate added in v0.0.30

func RetrieveLatestTemplateVersionByTemplate(template WorkspaceTemplate) (*WorkspaceTemplateVersion, error)

func RetrieveWorkspaceTemplateVersionsByIdByTemplate added in v0.0.30

func RetrieveWorkspaceTemplateVersionsByIdByTemplate(template WorkspaceTemplate, versionId uint) (*WorkspaceTemplateVersion, error)

func UpdateTemplateVersion added in v0.0.30

func UpdateTemplateVersion(
	template WorkspaceTemplate,
	tv WorkspaceTemplateVersion,
	name string,
	published bool,
	user User,
	configFilePath string,
) (*WorkspaceTemplateVersion, error)

Jump to

Keyboard shortcuts

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