models

package
v0.0.48 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2025 License: MIT Imports: 21 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 CountAllOnlineWorkspaces added in v0.0.47

func CountAllOnlineWorkspaces() (int64, error)

CountAllOnlineWorkspaces counts the number of workspaces that are currently running.

func CountAllUsers added in v0.0.35

func CountAllUsers() (count int64, err error)

CountAllUsers counts the total number of users in the database.

func CountOnlineRunners added in v0.0.47

func CountOnlineRunners() (int64, error)

CountOnlineRunners counts the number of online runners. A runner is considered online if its last contact time is within the last 5 minutes.

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

func DeleteContainerPort(port *WorkspaceContainerPort) error

func DeleteRunner added in v0.0.47

func DeleteRunner(r Runner) error

Delete a runner

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

func DeleteToken(token *Token) error

Delete a token

func DeleteUser added in v0.0.47

func DeleteUser(user *User) error

DeleteUser deletes the given user

func DoesRunnerExistWithUrl added in v0.0.47

func DoesRunnerExistWithUrl(url string) (bool, error)

DoesRunnerExistWithUrl checks if a runner with the given public url exists

func GetLoginCountPerDayInLast7Days added in v0.0.47

func GetLoginCountPerDayInLast7Days() ([]int64, error)

GetLoginCountPerDayInLast7Days returns an array of login counts for each of the last 7 days. The array is ordered from oldest to newest day.

func HashPassword

func HashPassword(password string) (string, error)

func ListUsers added in v0.0.47

func ListUsers(limit int) (users *[]User, err error)

ListUsers retrieves all users from the database ordered by -CreatedAt. Limit specifies the maximum number of users to retrieve. If limit is -1 all users are retrieved.

func ListWorkspaceTemplateVersionsByTemplate added in v0.0.30

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

func RemoveExpiredAuthorizationCodes

func RemoveExpiredAuthorizationCodes() error

remove expired authorization codes

func UpdateImpersonationLog added in v0.0.47

func UpdateImpersonationLog(log *ImpersonationLog) error

UpdateImpersonationLog This method updates the values for a row in the db

func UpdateRunner added in v0.0.47

func UpdateRunner(r Runner) error

Update a runner

func UpdateToken added in v0.0.47

func UpdateToken(token Token) error

Update a token

func UpdateUser added in v0.0.47

func UpdateUser(user *User) error

UpdateUser updates the user's details in the database.

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; not null;" json:"config_file_relative_path"` // path of the configuration files relative to the root of the repo
	SourcesID      *uint          `gorm:"column:sources_id; default: null;" json:"-"`
	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:"-"`
}

func CreateGitWorkspaceSource added in v0.0.42

func CreateGitWorkspaceSource(gitRepoUrl, gitRefName, configSourceFilePath string) (*GitWorkspaceSource, error)

func UpdateGitWorkspaceSource added in v0.0.42

func UpdateGitWorkspaceSource(
	gitSource *GitWorkspaceSource,
	gitRepoUrl,
	gitRefName,
	configSourceFilePath string,
) (*GitWorkspaceSource, error)

UpdateGitWorkspaceSource updates the GitWorkspaceSource with the given parameters.

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

type ImpersonationLog struct {
	ID                      uint       `gorm:"primarykey"`
	TokenID                 *uint      `gorm:"column:token_id;"`
	Token                   *Token     `gorm:"constraint:OnDelete:SET NULL;"`
	ImpersonatorID          uint       `gorm:"column:impersonator_id;not null;"`
	Impersonator            User       `gorm:"constraint:OnDelete:CASCADE;"`
	ImpersonatorIPAddress   string     `gorm:"column:impersonator_ip_address;not null;"`
	ImpersonatedUserID      uint       `gorm:"column:impersonated_user_id;not null;"`
	ImpersonatedUser        User       `gorm:"constraint:OnDelete:CASCADE;"`
	ImpersonationStartedAt  time.Time  `gorm:"column:impersonation_started_at;not null;"`
	ImpersonationFinishedAt *time.Time `gorm:"column:impersonation_finished_at;"`
	UpdatedAt               time.Time
	DeletedAt               gorm.DeletedAt `gorm:"index"`
}

func CreateImpersonationLog added in v0.0.47

func CreateImpersonationLog(
	token Token,
	impersonator User,
	impersonatorIP string,
	impersonatedUser User,
) (*ImpersonationLog, error)

CreateImpersonationLog create an impersonation log

func ListImpersonationLogsByImpersonatedUser added in v0.0.47

func ListImpersonationLogsByImpersonatedUser(user User) ([]ImpersonationLog, error)

List impersonation logs for a user

func RetrieveLatestImpersonationLogByToken added in v0.0.47

func RetrieveLatestImpersonationLogByToken(t Token) (*ImpersonationLog, error)

RetrieveLatestImpersonationLogByToken Retrieve the latest impersonation log related to a token

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"`
	DeletionInProgress bool           `gorm:"column:deletion_in_progress;default:false;not null;"`
	CreatedAt          time.Time      `gorm:"column:created_at;" json:"-"`
	UpdatedAt          time.Time      `gorm:"column:updated_at;" json:"-"`
	DeletedAt          gorm.DeletedAt `gorm:"index" json:"-"`
}

func CreateRunner added in v0.0.47

func CreateRunner(
	runnerName string,
	runnerType string,
	usePublicUrl bool,
	publicUrl string,
) (*Runner, error)

Create a new runner

func ListRunners added in v0.0.47

func ListRunners(limit int, offset int) ([]Runner, error)

ListRunners retrieves a list of runners with pagination support. If limit is -1, it retrieves all runners.

func RetrieveRunnerByID added in v0.0.42

func RetrieveRunnerByID(id uint) (*Runner, error)

RetrieveRunnerByID retrieves a runner by its ID

func RetrieveRunnerByName added in v0.0.47

func RetrieveRunnerByName(name string) (*Runner, error)

RetrieveRunnerByName retrieves a runner by its name

type Token

type Token struct {
	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;"`
	ImpersonatedUserID *uint      `gorm:"column:impersonated_user_id;"`
	ImpersonatedUser   *User      `gorm:"constraint:OnDelete:CASCADE;"`
	CreatedAt          time.Time
	UpdatedAt          time.Time
	DeletedAt          gorm.DeletedAt `gorm:"index"`
}

func CreateToken

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

CreateToken create a token for a user

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"`
	DeletionInProgress bool           `gorm:"column:deletion_in_progress;default:false;not null;"`
	CreatedAt          time.Time      `json:"-"`
	UpdatedAt          time.Time      `json:"-"`
	DeletedAt          gorm.DeletedAt `gorm:"index" json:"-"`
}

func CreateUser added in v0.0.35

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

CreateUser creates a new user in the database with the provided details. The password is hashed before storing it in the database.

func RetrieveUserByEmail added in v0.0.35

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

RetrieveUserByEmail retrieves a user by their email address.

func (*User) BeforeSave

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

func (*User) CheckPassword

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

func (*User) GetLastLogin added in v0.0.47

func (u *User) GetLastLogin() (*time.Time, error)

GetLastLogin retrieves the last login time of the user by checking the most recent token creation time. If the user has never logged in, it returns nil.

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

func CreateWorkspace(
	name string,
	user *User,
	workspaceType string,
	runner *Runner,
	configSource string,
	templateVersion *WorkspaceTemplateVersion,
	gitSource *GitWorkspaceSource,
	environmentVariables []string,
) (*Workspace, error)

Create a new workspace, this function will add new row to the database. It will not start the workspace, it will only create the database entry.

func ListUserWorkspaces added in v0.0.42

func ListUserWorkspaces(user User) ([]Workspace, error)

Filter workspaces by owner

func ListWorkspacesByRunner added in v0.0.47

func ListWorkspacesByRunner(r Runner) ([]Workspace, error)

Retrieve workspaces that are using this runner

func ListWorkspacesByTemplate added in v0.0.30

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

func RetrieveWorkspaceById added in v0.0.48

func RetrieveWorkspaceById(id uint) (*Workspace, error)

Retrieve a workspace by workspace id . If workspace does not exist return nil.

func RetrieveWorkspaceByUserAndId added in v0.0.42

func RetrieveWorkspaceByUserAndId(user User, id uint) (*Workspace, error)

Retrieve a workspace by workspace id and owner. If workspace does not exist return nil.

func UpdateWorkspace added in v0.0.42

func UpdateWorkspace(
	workspace *Workspace,
	name string,
	status string,
	runner *Runner,
	configSource string,
	templateVersion *WorkspaceTemplateVersion,
	gitSource *GitWorkspaceSource,
	environmentVariables []string,
) (*Workspace, error)

Update a workspace

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

func ListWorkspaceContainersByWorkspace added in v0.0.42

func ListWorkspaceContainersByWorkspace(workspace Workspace) ([]WorkspaceContainer, error)

ListWorkspaceContainersByWorkspace retrieves all containers for a given workspace.

func RetrieveWorkspaceContainerByName added in v0.0.42

func RetrieveWorkspaceContainerByName(workspace Workspace, containerName string) (*WorkspaceContainer, error)

RetrieveWorkspaceContainerByName retrieves a specific container by name in a workspace.

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

func CreateContainerPort added in v0.0.42

func CreateContainerPort(
	container WorkspaceContainer,
	serviceName string,
	portNumber uint,
	public bool,
) (*WorkspaceContainerPort, error)

func ListContainerPortsByWorkspaceContainer added in v0.0.42

func ListContainerPortsByWorkspaceContainer(container WorkspaceContainer) ([]WorkspaceContainerPort, error)

func RetrieveContainerPortByPortNumber added in v0.0.42

func RetrieveContainerPortByPortNumber(
	container WorkspaceContainer,
	portNumber uint,
) (*WorkspaceContainerPort, error)

func RetrieveContainerPortByServiceName added in v0.0.42

func RetrieveContainerPortByServiceName(
	container WorkspaceContainer,
	serviceName string,
) (*WorkspaceContainerPort, error)

func UpdateContainerPort added in v0.0.42

func UpdateContainerPort(
	port *WorkspaceContainerPort,
	serviceName string,
	portNumber uint,
	public bool,
) (*WorkspaceContainerPort, error)

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_id"`
	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 RetrieveWorkspaceTemplateVersionsById added in v0.0.42

func RetrieveWorkspaceTemplateVersionsById(versionId uint) (*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