models

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package models defines shared data types and domain models for k8shelld.

Index

Constants

This section is empty.

Variables

View Source
var RESTAPIUnixSocket = "/var/run/k8shelld.sock"

Functions

This section is empty.

Types

type Group

type Group struct {
	Name string
	Gid  int
}

Group represents a supplementary group.

type InitScriptState

type InitScriptState struct {
	Name       string           `json:"name"`
	Status     InitScriptStatus `json:"status"`
	StartedAt  *time.Time       `json:"started_at,omitempty"`
	FinishedAt *time.Time       `json:"finished_at,omitempty"`
	HasError   bool             `json:"has_error"`
}

InitScriptState holds the observable state of one init script.

type InitScriptStatus

type InitScriptStatus string

InitScriptStatus represents the lifecycle state of an init script.

const (
	InitScriptPending   InitScriptStatus = "pending"
	InitScriptRunning   InitScriptStatus = "running"
	InitScriptCompleted InitScriptStatus = "completed"
)

type InitTracker

type InitTracker struct {
	// contains filtered or unexported fields
}

InitTracker is a thread-safe store for the lifecycle state of all init scripts.

func NewInitTracker

func NewInitTracker() *InitTracker

NewInitTracker returns an empty InitTracker.

func (*InitTracker) AllDone

func (t *InitTracker) AllDone() bool

AllDone reports whether every registered script has reached the completed state.

func (*InitTracker) GetAll

func (t *InitTracker) GetAll() []InitScriptState

GetAll returns a snapshot copy of all script states.

func (*InitTracker) HasAny

func (t *InitTracker) HasAny() bool

HasAny reports whether any scripts have been registered.

func (*InitTracker) HasPendingOrRunning

func (t *InitTracker) HasPendingOrRunning() bool

HasPendingOrRunning reports whether at least one script is still pending or running.

func (*InitTracker) RegisterAll

func (t *InitTracker) RegisterAll(names []string)

RegisterAll pre-populates the tracker with all script names in pending state. This must be called before any goroutine calls SetRunning or SetCompleted.

func (*InitTracker) SetCompleted

func (t *InitTracker) SetCompleted(name string, hasError bool)

SetCompleted marks the named script as completed and records its finish time.

func (*InitTracker) SetRunning

func (t *InitTracker) SetRunning(name string)

SetRunning marks the named script as running and records its start time.

type K8shellFileValidationResponse

type K8shellFileValidationResponse struct {
	Status   string   `json:"status"`
	Filename string   `json:"filename"`
	Errors   []string `json:"errors,omitempty"`
}

K8shellFileValidationResponse represents the response for k8shell file validation

type ShellUser

type ShellUser struct {
	Username string
	UID      uint32
	GID      uint32
	HomeDir  string
	Shell    string
	Sudo     bool
	Groups   []Group
}

ShellUser is an immutable snapshot of the identity fields needed to launch a shell process. Obtain it via NewShellUser before starting a session; the snapshot is safe to use without further locking for the session's lifetime.

func NewShellUser

func NewShellUser(u *User) ShellUser

NewShellUser takes a snapshot of User for use in a shell session.

type User

type User struct {
	// contains filtered or unexported fields
}

User holds the workspace identity. It is populated once from the user's profile in NewUser. UID, GID, home directory and groups are fixed for the lifetime of the process — they're baked into the OS user created at startup. The rest of the profile can be refreshed from the API server via UpdateProfile (see RESTService.GetProfile), so all profile reads go through a mutex.

func NewUser

func NewUser(profile *models.UserProfile) *User

NewUser creates a User from a resolved profile.

func (*User) GetGID

func (u *User) GetGID() uint32

GetGID returns the user's primary GID.

func (*User) GetGroups

func (u *User) GetGroups() []Group

GetGroups returns the supplementary groups for the user. TODO: derive from the profile or a policy source once that is implemented.

func (*User) GetHomeDir

func (u *User) GetHomeDir() string

GetHomeDir returns the home directory, defaulting to /home/<username> when unset.

func (*User) GetShell

func (u *User) GetShell() string

GetShell returns the login shell, defaulting to /bin/sh when unset.

func (*User) GetUID

func (u *User) GetUID() uint32

GetUID returns the user's UID.

func (*User) GetUsername

func (u *User) GetUsername() string

GetUsername returns the username.

func (*User) HasRole

func (u *User) HasRole(role models.Role) bool

HasRole checks if the user has a specific role.

func (*User) ProfileSnapshot added in v0.16.0

func (u *User) ProfileSnapshot() models.UserProfile

ProfileSnapshot returns a copy of the user's profile.

func (*User) String

func (u *User) String() string

String returns a human-readable representation for logging.

func (*User) SudoEnabled

func (u *User) SudoEnabled() bool

SudoEnabled returns whether passwordless sudo is enabled for the user.

func (*User) UpdateProfile added in v0.16.0

func (u *User) UpdateProfile(profile models.UserProfile)

UpdateProfile replaces the user's profile with a freshly fetched copy, typically after a live re-fetch from the API server (see RESTService.GetProfile). UID and GID are preserved from the current profile rather than taken from the argument: they're baked into the OS user created at startup, and every UID/GID-based operation (chown, process credentials) assumes they never change underneath it.

Jump to

Keyboard shortcuts

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