models

package
v0.15.7 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: AGPL-3.0 Imports: 5 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 an atomic snapshot of User for use in a shell session.

type User

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

User holds the workspace identity.

Immutable fields (username, uid, gid, homeDir, groups) are set once in NewUser and never changed — they may be read from any goroutine without acquiring mu.

Mutable fields (claims, userToken) are replaced atomically on each token renewal and must always be accessed through the accessor methods, which acquire mu internally.

func NewUser

func NewUser(claims *authz.UserClaims, token string) *User

NewUser creates a User from a verified JWT claims set and the raw token string.

func (*User) ClaimsSnapshot

func (u *User) ClaimsSnapshot() authz.UserClaims

ClaimsSnapshot returns a copy of the current JWT claims under the read lock. The returned value is safe to inspect without any further locking.

func (*User) GetGID

func (u *User) GetGID() uint32

GetGID returns the user's primary GID. Immutable — no lock needed.

func (*User) GetGroups

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

GetGroups returns the supplementary groups for the user. TODO: derive from JWT claims 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. Immutable — no lock needed.

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. Immutable — no lock needed.

func (*User) GetUserToken

func (u *User) GetUserToken() string

GetUserToken returns the current raw JWT string.

func (*User) GetUsername

func (u *User) GetUsername() string

GetUsername returns the username (JWT subject). Immutable — no lock needed.

func (*User) HasRole

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

HasRole checks if the user has a specific role.

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) TokenEqual

func (u *User) TokenEqual(token string) bool

func (*User) Update

func (u *User) Update(claims *authz.UserClaims, token string) (bool, error)

Update atomically replaces the mutable JWT claims and token string. Returns (true, nil) when the update was applied, (false, nil) when the token is unchanged (no-op), or (false, error) when an immutable field has changed.

Jump to

Keyboard shortcuts

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