worksession

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 29 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ScopeKube     = "kube"
	ScopeKubeExec = "kube_exec"
)

The scopes a cluster work session holds: kube for the Kubernetes API, and kube_exec on top of it for exec, attach and port-forward into pods.

View Source
const (
	// ApprovalPollInterval is the base gap between polls of a session waiting
	// on approval; utils.NextPollTick widens it as the wait ages.
	ApprovalPollInterval = 10 * time.Second
)
View Source
const WorkSessionEnvVar = "ALPACON_WORK_SESSION"

WorkSessionEnvVar is the environment variable consulted when no --work-session flag is given.

Variables

View Source
var ErrClusterSessionNotAttachable = errors.New("a cluster session cannot be the active work-session")

ErrClusterSessionNotAttachable refuses to set a cluster session as the active one.

Functions

func IsKubeScope added in v1.18.0

func IsKubeScope(scope string) bool

IsKubeScope reports whether scope belongs to a cluster session.

func KubeLoginAction added in v1.18.0

func KubeLoginAction(clusterName, id string) utils.NextAction

KubeLoginAction is the follow-up for a cluster session: 'kube login' opens a kube session under it and writes the kubeconfig context. It takes the session by ID for a person and an agent alike, since a cluster session is never attached as the active one.

func MarkActive

func MarkActive(rows []wsapi.WorkSessionAttributes, activeUUID string)

MarkActive puts "*" in the Active column of the row whose ID is activeUUID unless that session has ended, since one ended outside this CLI stays in config. Safe with an empty activeUUID or slice.

func NewWorkSessionCmd added in v1.20.0

func NewWorkSessionCmd(newClient clientFactory, ios *utils.IOStreams) *cobra.Command

func NormalizeClusterScopes added in v1.18.0

func NormalizeClusterScopes(scopes []string) ([]string, error)

NormalizeClusterScopes checks a scope list for a cluster session and puts it in the order the server lists it. kube_exec implies kube, which every cluster session holds, so it is added rather than refused, the way --sudo adds the sudo scope; anything but kube and kube_exec is refused.

func Pick added in v1.20.2

func Pick(sessions []wsapi.WorkSession, want Want, now time.Time) (ws *wsapi.WorkSession, wait bool)

Pick prefers the newest usable session, then the newest session still waiting on approval.

func PrintSessionAdvisories added in v1.18.0

func PrintSessionAdvisories(ios *utils.IOStreams, session *wsapi.WorkSession)

PrintSessionAdvisories shows what the approver changed or recommended, such as a scope dropped from the request. Text mode only—JSON callers return before reaching this.

func RunComplete added in v1.16.0

func RunComplete(ios *utils.IOStreams, ac *client.AlpaconClient, id string) (bool, error)

RunComplete completes the session; see endSession.

func RunCurrent

func RunCurrent(ac *client.AlpaconClient) (string, *wsapi.WorkSession, error)

RunCurrent returns the active work-session UUID and its server-side details. Returns ("", nil, nil) when nothing is set, or (uuid, nil, err) if set but unreachable.

func RunRevoke added in v1.16.0

func RunRevoke(ios *utils.IOStreams, ac *client.AlpaconClient, id string) (bool, error)

RunRevoke revokes the session; see endSession.

func RunUnset

func RunUnset() error

RunUnset clears the active work-session for the current workspace; it is a no-op when nothing is set.

func RunUse

func RunUse(ac *client.AlpaconClient, uuid string) (string, error)

RunUse validates the work-session via the server, then stores it in config. Returns the human-readable description on success.

func RunUseSession added in v1.6.0

func RunUseSession(ac *client.AlpaconClient, uuid string) (*wsapi.WorkSession, error)

RunUseSession validates the work-session via the server, then stores it in config.

func ShellWord added in v1.20.2

func ShellWord(value string) (quoted string, ok bool)

ShellWord returns value as one word POSIX shells and PowerShell 5.1 and 7 all pass on unchanged; ok is false for an empty or non-printable-ASCII value, a quote or backslash, and a leading dash (pwsh drops '--%').

func TargetErrorHint added in v1.18.0

func TargetErrorHint(err error) string

TargetErrorHint says what to do about the server's refusal of a work session's targets, scopes, lifetime or sudo patterns, or returns "" for any other error.

func ValidateAgentScopes added in v1.18.0

func ValidateAgentScopes(requesterType string, scopes []string) error

ValidateAgentScopes returns an error when requester_type is "agent" and scopes contains one an agent session cannot hold (websh, kube_exec), which the server disallows.

func WaitExitError added in v1.20.0

func WaitExitError(ios *utils.IOStreams, operation string, session *wsapi.WorkSession, next utils.NextAction, err error, pendingNext ...utils.NextAction) error

WaitExitError is a failed wait on session, as 'alpacon event wait' exits: 6 settled, 4 still open (printed here, offering next), 1 for a polling failure, which the caller prints.

func WaitForApproval added in v1.18.0

func WaitForApproval(ios *utils.IOStreams, ac *client.AlpaconClient, id string, untilActive bool, interval, timeout time.Duration) (*wsapi.WorkSession, error)

WaitForApproval polls until the session reaches a terminal state or timeout elapses. It returns on approved or active, or only on active when untilActive is set. It is deadline-based, so a timeout under one interval still waits the full duration. A fatal 4xx ends the wait at once and other transient failures end it at MaxConsecutivePollFailures; 429s are bounded by the throttle budget and the deadline instead.

func WriteCurrentRaw added in v1.16.0

func WriteCurrentRaw(ios *utils.IOStreams, ac *client.AlpaconClient, uuid string) error

func WriteCurrentTable added in v1.16.0

func WriteCurrentTable(ios *utils.IOStreams, ac *client.AlpaconClient, uuid string) error

WriteCurrentTable projects the session through ProjectAttributes so the columns match 'work-session ls', and marks it as 'ls' does.

Types

type Need added in v1.20.2

type Need struct {
	Operation Operation
	Server    string
	Account   string
	Command   string // the alpacon command the user ran, when Operation names another
}

Need describes the server access one operation requires.

type Operation added in v1.20.2

type Operation uint8

Operation identifies the scopes one CLI operation needs.

const (
	Command Operation = iota
	FileCommand
	Websh
	Transfer
	Tunnel
)

type Selection added in v1.20.2

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

Selection holds the WorkSession an operation runs under; read ID at each request, since a settled offer replaces it.

func Fixed added in v1.20.2

func Fixed(id string) *Selection

Fixed returns a Selection that never offers to replace id.

func OfferedForTest added in v1.20.2

func OfferedForTest(ios *utils.IOStreams, ac *client.AlpaconClient, id string, need Need) *Selection

OfferedForTest returns a selection with its interactive offer enabled for command integration tests.

func Select added in v1.20.2

func Select(ios *utils.IOStreams, ac *client.AlpaconClient, flagValue string, need Need) (*Selection, error)

Select resolves flag, environment, then the client's pinned workspace configuration.

func (*Selection) ID added in v1.20.2

func (s *Selection) ID() string

ID returns the WorkSession the next request sends.

func (*Selection) Offer added in v1.20.2

Offer adds this selection's one WorkSession refusal recovery hook when eligible.

func (*Selection) ResumeWith added in v1.20.2

func (s *Selection) ResumeWith(step string)

ResumeWith replaces "re-run this command" in the resume guidance, for an operation whose earlier steps a re-run would repeat.

func (*Selection) ResumeWithCommand added in v1.20.2

func (s *Selection) ResumeWithCommand(step, command string)

ResumeWithCommand is ResumeWith for a step that runs command instead of the one the user ran.

type Source added in v1.20.2

type Source uint8

Source identifies where a selected WorkSession came from.

const (
	SourceNone Source = iota
	SourceFlag
	SourceEnv
	SourceConfig
)

type Want added in v1.20.2

type Want struct {
	ServerID      string
	ClusterID     string
	AssignedUser  string
	RequesterType string
	Scopes        []string
	Exclude       string
}

Want describes the ownership, target, and scopes a reusable WorkSession must have.

func (Want) Usable added in v1.20.2

func (w Want) Usable(ws *wsapi.WorkSession, now time.Time) bool

Usable reports whether ws can serve the wanted operation now.

func (Want) Waitable added in v1.20.2

func (w Want) Waitable(ws *wsapi.WorkSession, now time.Time) bool

Waitable reports whether ws can serve the operation after its open approval settles.

Jump to

Keyboard shortcuts

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