Documentation
¶
Index ¶
- Constants
- func AnswerPurposeDemand(ac *client.AlpaconClient, cmdID, purpose string) error
- func DescribePhase(phase string) string
- func GetCommandOutput(ac *client.AlpaconClient, cmdID string) (string, error)
- func IsAwaitingApprovalStatus(status string) bool
- func IsAwaitingPurposeStatus(status string) bool
- func IsRejectedStatus(status string) bool
- func IsRunningStatus(status string) bool
- func RunCommandStreaming(ac *client.AlpaconClient, serverName, command, username, groupname string, ...) error
- func StreamApprovedCommand(ac *client.AlpaconClient, cmdID string, out io.Writer, timeout time.Duration) error
- func SubscribeEvent(ac *client.AlpaconClient, channelID string, eventType EventType, ...) error
- type AwaitingPurposeError
- type CatchUpFunc
- type Chunk
- type ChunkEvent
- type ClientTimeoutError
- type CommandOutputListener
- func (l *CommandOutputListener) Chunks() <-chan ChunkEvent
- func (l *CommandOutputListener) Err() error
- func (l *CommandOutputListener) Finished() <-chan struct{}
- func (w CommandOutputListener) Start()
- func (w CommandOutputListener) Stop()
- func (w CommandOutputListener) WaitConnected(timeout time.Duration) bool
- type CommandPurposeRequest
- type CommandRejectedError
- type CommandRequest
- type CommandResponse
- type EventAttributes
- type EventDetails
- type EventSessionResponse
- type EventSubscriptionRequest
- type EventType
- type Outcome
- type PendingApprovalError
- type RemoteCommandError
- type SudoListener
- type WaitOptions
- type Waiter
- type Watcher
Constants ¶
const ( // Left untyped so every const stays in one block; they remain assignable and // comparable to EventType. EventTypeSudo = "sudo" EventTypeCommandOutput = "command_output" // Subscribed with a server id, not a command id: that is the channel // alpacon-server publishes it on. EventTypeCommandFin = "command_fin" )
Variables ¶
This section is empty.
Functions ¶
func AnswerPurposeDemand ¶ added in v1.12.0
func AnswerPurposeDemand(ac *client.AlpaconClient, cmdID, purpose string) error
AnswerPurposeDemand states what a parked command is for and sends it back through verification (ADR 0052). The server re-judges it once with the purpose in hand; whatever that second verdict is—run, hold for a human, or deny—is reached by exactly the path an un-parked command takes.
The server refuses a command that is not parked, and refuses an answer from anyone but the requester, with the same error either way: whether a given command is parked is not something a bystander needs to learn. So a failure here cannot be read as "the deadline passed" specifically.
func DescribePhase ¶ added in v1.4.8
DescribePhase returns the human-readable description for an error_phase, or the raw identifier when the phase is unknown.
func GetCommandOutput ¶ added in v1.8.1
func GetCommandOutput(ac *client.AlpaconClient, cmdID string) (string, error)
GetCommandOutput reconstructs the full command output from its chunks in seq order. Empty when no chunks were produced. Used by non-streaming paths (exec logs, polling fallback) where Result is empty under the chunk contract.
func IsAwaitingApprovalStatus ¶ added in v1.7.4
IsAwaitingApprovalStatus reports whether status is the server's hold state for a command parked pending out-of-band human approval (HITL). The server exposes this via Command.compute_status when verification_status is "awaiting_approval" and the command has not yet been delivered to the agent.
func IsAwaitingPurposeStatus ¶ added in v1.12.0
IsAwaitingPurposeStatus reports whether status is the server's hold state for a command parked while the gate asks the requester what it is for (ADR 0052). Unlike the approval hold this one is answerable here and expires on its own in about a minute, after which the command takes the ordinary path.
func IsRejectedStatus ¶ added in v1.11.1
IsRejectedStatus reports whether status is the server's terminal state for a command a reviewer refused. It never ran, and re-submitting it only files a second approval request.
func IsRunningStatus ¶ added in v1.5.0
IsRunningStatus reports whether status represents an in-progress (non-terminal) command.
func RunCommandStreaming ¶ added in v1.8.1
func RunCommandStreaming(ac *client.AlpaconClient, serverName, command, username, groupname string, env map[string]string, workSessionID, purpose string, out io.Writer) error
RunCommandStreaming runs a command and streams its output to out over the event WebSocket, falling back to polling (runCommandFallback) when WS setup fails.
func StreamApprovedCommand ¶ added in v1.8.1
func StreamApprovedCommand(ac *client.AlpaconClient, cmdID string, out io.Writer, timeout time.Duration) error
StreamApprovedCommand resubscribes to an already-submitted command and streams its output, waiting through the awaiting_approval hold (bounded by timeout) until a reviewer approves it out of band and it runs. Used by --wait after a PendingApprovalError; the parked job produced no output yet, so resubscribing loses nothing.
func SubscribeEvent ¶ added in v1.9.2
func SubscribeEvent(ac *client.AlpaconClient, channelID string, eventType EventType, targetID string) error
SubscribeEvent subscribes the given channel to eventType events, scoped to targetID (a websh session for sudo, a command for command_output, a work session for work_session). An empty targetID is omitted, which only some event types allow.
Types ¶
type AwaitingPurposeError ¶ added in v1.12.0
type AwaitingPurposeError struct {
CommandID string
// When the demand stops being answerable, as the server computed it. Nil
// when absent—an older server, or a command that was never asked. The
// reporter states the remaining window only when this is present:
// COMMAND_PURPOSE_DEADLINE is env-overridable and no endpoint publishes it,
// so a client deriving this itself would be guessing the window's length.
ExpiresAt *time.Time
}
AwaitingPurposeError is returned when the server parked a command at the "awaiting_purpose" status: the verification gate would have queued it for a human, so instead of opening an approval request it is asking the requester what the command is for (ADR 0052). Nobody has been notified, so this is not a wait—the answer is the caller's to give, with 'alpacon exec purpose'. CommandID identifies the parked job; re-submitting would create a second command that gets its own demand and may run twice.
func (*AwaitingPurposeError) Error ¶ added in v1.12.0
func (*AwaitingPurposeError) Error() string
type CatchUpFunc ¶ added in v1.9.2
CatchUpFunc reads the target's current state over REST and returns it in the event channel's sub_type vocabulary. It closes the window between subscribing and the server's next publish, which is otherwise unrecoverable: the channel has no history.
type Chunk ¶ added in v1.8.1
Chunk represents a single stdout/stderr chunk produced during command execution.
type ChunkEvent ¶ added in v1.8.1
ChunkEvent is a single command_output chunk emitted by the listener.
type ClientTimeoutError ¶ added in v1.4.8
type ClientTimeoutError struct{}
ClientTimeoutError is returned when the CLI gave up polling for the command result before the server reported a terminal status.
func (*ClientTimeoutError) Error ¶ added in v1.4.8
func (*ClientTimeoutError) Error() string
type CommandOutputListener ¶ added in v1.8.1
type CommandOutputListener struct {
// contains filtered or unexported fields
}
CommandOutputListener subscribes to a single command's chunk stream over the event WebSocket, exposing chunks on Chunks() and the command's fin on Finished().
Lifecycle: NewCommandOutputListener -> Start -> subscribeTo -> (consume Chunks) -> Stop. Stop is idempotent and safe to call from any goroutine. Event channel tokens are single-use, so every dial provisions its own session and re-subscribes.
func NewCommandOutputListener ¶ added in v1.8.1
func NewCommandOutputListener(ac *client.AlpaconClient) *CommandOutputListener
NewCommandOutputListener constructs a listener without connecting. ac may be nil only for a test that never calls Start, because provisioning a session dereferences it. The targets are set later via setTargets, because SubmitCommand must run once the WS is already connected.
func (*CommandOutputListener) Chunks ¶ added in v1.8.1
func (l *CommandOutputListener) Chunks() <-chan ChunkEvent
Chunks returns a receive-only channel of parsed chunk events.
func (*CommandOutputListener) Err ¶ added in v1.11.2
func (l *CommandOutputListener) Err() error
Err returns why the listener could not connect, so a caller that only sees WaitConnected time out can still report the server's own reason.
func (*CommandOutputListener) Finished ¶ added in v1.10.0
func (l *CommandOutputListener) Finished() <-chan struct{}
Finished fires when the command reaches a terminal state, which the chunks never say: they carry no end marker.
func (CommandOutputListener) Start ¶ added in v1.8.1
func (w CommandOutputListener) Start()
Start reads events in a background goroutine, reconnecting automatically until Stop is called.
func (CommandOutputListener) Stop ¶ added in v1.8.1
func (w CommandOutputListener) Stop()
Stop shuts down the listener and closes the connection to unblock a pending ReadMessage. Safe to call from any goroutine.
func (CommandOutputListener) WaitConnected ¶ added in v1.8.1
WaitConnected blocks until a dial has connected and its onConnected hook has returned, until timeout, or until shutdown; returns whether it connected. A hook with nothing to subscribe to still counts, so this promises no subscription.
type CommandPurposeRequest ¶ added in v1.12.0
type CommandPurposeRequest struct {
Purpose string `json:"purpose"`
}
CommandPurposeRequest is the body of the purpose-demand answer. Write-only on the server side: the 202 carries no echo of what was just sent.
type CommandRejectedError ¶ added in v1.11.1
CommandRejectedError is a type so the CLI can exit ExitCodeNotApproved: an agent reading a generic failure code retries, filing a fresh approval request. Expired separates the two settled-without-a-grant outcomes: both exit ExitCodeNotApproved, but only a reviewer's refusal is answered by going back to the reviewer—a window that simply lapsed is answered by requesting again.
func (*CommandRejectedError) Error ¶ added in v1.11.1
func (e *CommandRejectedError) Error() string
type CommandRequest ¶
type CommandRequest struct {
Shell string `json:"shell"`
Line string `json:"line"`
Env map[string]string `json:"env"`
Data string `json:"data"`
Username string `json:"username"`
Groupname string `json:"groupname"`
ScheduledAt *time.Time `json:"scheduled_at"`
Server string `json:"server"`
RunAfter []string `json:"run_after"`
WorkSession string `json:"work_session,omitempty"`
// What this one command is for (ADR 0052). Sent only when the caller
// supplied it; with it in hand the assessor judges on the first pass and the
// demand round trip never happens, which is the steady state the ADR intends.
Purpose string `json:"purpose,omitempty"`
// Declares that this client answers a purpose demand. The gate does not arm
// without it, so the declaration is the opt-in—and it is unconditional here
// because every exec path surfaces the demand to its caller instead of
// stalling on it.
PurposeDemandSupported bool `json:"purpose_demand_supported,omitempty"`
}
type CommandResponse ¶
type CommandResponse struct {
ID string `json:"id"`
Shell string `json:"shell"`
Line string `json:"line"`
Data string `json:"data"`
Username string `json:"username"`
Groupname string `json:"groupname"`
AddedAt time.Time `json:"added_at"`
ScheduledAt time.Time `json:"scheduled_at"`
Server types.ServerSummary `json:"server"`
RequestedBy types.UserSummary `json:"requested_by"`
RunAfter []any `json:"run_after"`
}
func SubmitCommand ¶ added in v1.5.0
func SubmitCommand(ac *client.AlpaconClient, serverName, command string, username, groupname string, env map[string]string, workSessionID, purpose string) (CommandResponse, error)
type EventAttributes ¶
type EventAttributes struct {
Server string `json:"server"`
Shell string `json:"shell"`
Command string `json:"command"`
Result string `json:"result"`
Status string `json:"status"`
Operator string `json:"operator"`
RequestedAt string `json:"requested_at" table:"Requested At"`
}
func GetEventList ¶
func GetEventList(ac *client.AlpaconClient, tail int, serverName string, userName string) ([]EventAttributes, error)
GetEventList returns the newest tail commands. The endpoint sorts -scheduled_at, so the newest ones arrive first and the walk stops as soon as tail is reached.
type EventDetails ¶
type EventDetails struct {
ID string `json:"id"`
Shell string `json:"shell"`
Line string `json:"line"`
Success *bool `json:"success"`
ExitCode *int `json:"exit_code"`
ErrorPhase *string `json:"error_phase"`
Result string `json:"result"`
Status string `json:"status"`
Cancellable bool `json:"cancellable"`
ResponseDelay float64 `json:"response_delay"`
ElapsedTime float64 `json:"elapsed_time"`
AddedAt time.Time `json:"added_at"`
Server types.ServerSummary `json:"server"`
RequestedBy types.UserSummary `json:"requested_by"`
// What the requester said this command is for, and when the ask expires
// (ADR 0052). Both are absent on a server predating the read exposure, and
// on any command nobody was asked—which is every command until the gate is
// enabled, so nil and empty are the ordinary shapes here.
//
// The expiry is server-derived and read instead of `purpose_requested_at`:
// the window's length is COMMAND_PURPOSE_DEADLINE and no endpoint publishes
// it, so a start time alone would leave this client guessing the length.
// The start time is deliberately not parsed—no surface here shows it, and a
// field read by nothing is a promise no surface keeps.
Purpose string `json:"purpose"`
PurposeExpiresAt *time.Time `json:"purpose_expires_at"`
// The server fills these only on the command detail; the list response omits
// them, and this struct decodes both. Pointers so an absent field stays
// distinguishable from a status the server deliberately left empty.
SudoApprovalRequestID *string `json:"sudo_approval_request_id"`
SudoGrantStatus *string `json:"sudo_grant_status"`
}
func GetCommandByID ¶ added in v1.5.0
func GetCommandByID(ac *client.AlpaconClient, cmdID string) (EventDetails, error)
func PollCommandExecution ¶
func PollCommandExecution(ac *client.AlpaconClient, cmdID string) (EventDetails, error)
PollCommandExecution polls with default timeout/tick; tests use pollCommandExecution directly.
type EventSessionResponse ¶ added in v1.4.0
type EventSessionResponse struct {
ID string `json:"id"`
WebsocketURL string `json:"websocket_url"`
ChannelID string `json:"channel_id"`
}
EventSessionResponse is returned when creating an event session.
func CreateEventSession ¶ added in v1.4.0
func CreateEventSession(ac *client.AlpaconClient) (*EventSessionResponse, error)
CreateEventSession creates a new event session and returns the WebSocket URL and channel ID for subscribing to events.
type EventSubscriptionRequest ¶ added in v1.4.0
type EventSubscriptionRequest struct {
Channel string `json:"channel"`
EventType EventType `json:"event_type"`
// Omitted rather than sent empty: the server validates target_id as a UUID.
TargetID string `json:"target_id,omitempty"`
}
EventSubscriptionRequest is sent to subscribe to an event type.
type EventType ¶ added in v1.9.2
type EventType string
EventType is a server event channel type, marshalled as a plain string. The server defines the full set; untyped literals convert, so types the CLI lacks a constant for stay usable.
type Outcome ¶ added in v1.9.2
type Outcome int
Outcome is how a Wait ended. OutcomeError is the zero value: it is only returned alongside a non-nil error, so a caller that forgets to check err still sees it.
type PendingApprovalError ¶ added in v1.7.4
type PendingApprovalError struct {
CommandID string
}
PendingApprovalError is returned when the server parked a command at the "awaiting_approval" status: the job was accepted but a human must approve it out of band in the Alpacon console before it runs. CommandID identifies the parked job so a --wait caller can poll it to completion—re-submitting would create a duplicate command (and a duplicate approval request).
func (*PendingApprovalError) Error ¶ added in v1.7.4
func (*PendingApprovalError) Error() string
type RemoteCommandError ¶ added in v1.4.8
type RemoteCommandError struct {
Output string
ExitCode int
ErrorPhase string
// CommandID identifies the job this failure came from, so an approval wait
// has something to poll. ApprovalRequestID is filled in by that wait, not
// by the server response this error is built from.
CommandID string
ApprovalRequestID string
}
RemoteCommandError is returned when the remote command completed but exited with a non-zero status. Callers populate ExitCode from the server response; errorFromDetails falls back to 1 when the server omits exit_code.
func (*RemoteCommandError) Error ¶ added in v1.4.8
func (e *RemoteCommandError) Error() string
type SudoListener ¶ added in v1.4.0
type SudoListener struct {
// contains filtered or unexported fields
}
SudoListener listens for sudo MFA events on the event WebSocket and handles the browser-based MFA flow.
The AlpaconClient (ac) is shared with the terminal WebSocket goroutines. http.Client is concurrency-safe. Token refresh and grant verification are serialized by mfaMu so only one MFA flow runs at a time.
Event channel tokens are single-use, so every dial provisions its own session and re-subscribes once connected.
func NewSudoListener ¶ added in v1.4.0
func NewSudoListener(ac *client.AlpaconClient, serverName, sessionID string) *SudoListener
NewSudoListener creates a SudoListener but does not connect yet. ac may be nil only for a test that never calls Start: MFA request frames are then dropped, but provisioning a session on the listen goroutine would dereference it.
func (*SudoListener) Err ¶ added in v1.11.2
func (sl *SudoListener) Err() error
Err returns the last reason the listener could not connect, so a caller that only sees WaitConnected time out can report that instead of a bare timeout.
func (SudoListener) Start ¶ added in v1.4.0
func (w SudoListener) Start()
Start reads events in a background goroutine, reconnecting automatically until Stop is called.
func (SudoListener) Stop ¶ added in v1.4.0
func (w SudoListener) Stop()
Stop shuts down the listener and closes the connection to unblock a pending ReadMessage. Safe to call from any goroutine.
func (SudoListener) WaitConnected ¶ added in v1.4.0
WaitConnected blocks until a dial has connected and its onConnected hook has returned, until timeout, or until shutdown; returns whether it connected. A hook with nothing to subscribe to still counts, so this promises no subscription.
type WaitOptions ¶ added in v1.9.2
type WaitOptions struct {
// CatchUp may be nil for a type with no REST projection.
CatchUp CatchUpFunc
OK []string
Fail []string
Timeout time.Duration
}
WaitOptions carries everything type-specific about a wait. Keeping it injected is why this package needs no knowledge of any event type.
type Waiter ¶ added in v1.9.2
type Waiter struct {
*Watcher
// contains filtered or unexported fields
}
Waiter blocks until one event decides the wait, then returns it. Reconnects and session reprovisioning are inherited from Watcher.
func NewWaiter ¶ added in v1.9.2
func NewWaiter(ac *client.AlpaconClient, eventType EventType, targetID string, opts WaitOptions) *Waiter
NewWaiter constructs a Waiter without connecting. Call Wait.
func (*Waiter) CatchUpFailed ¶ added in v1.9.2
CatchUpFailed reports a catch-up that could not be read. Buffered at one: a caller that misses a notice loses nothing a later one does not also carry.
func (Waiter) Start ¶ added in v1.9.2
func (w Waiter) Start()
Start reads events in a background goroutine, reconnecting automatically until Stop is called.
func (Waiter) Stop ¶ added in v1.9.2
func (w Waiter) Stop()
Stop shuts down the listener and closes the connection to unblock a pending ReadMessage. Safe to call from any goroutine.
func (*Waiter) Wait ¶ added in v1.9.2
Wait blocks until an event matches, the timeout elapses, or Stop is called. The returned frame is the server's bytes verbatim, except on a catch-up hit where it is synthesized. A non-nil error means the wait could not run; Outcome is meaningless then.
func (Waiter) WaitConnected ¶ added in v1.9.2
WaitConnected blocks until a dial has connected and its onConnected hook has returned, until timeout, or until shutdown; returns whether it connected. A hook with nothing to subscribe to still counts, so this promises no subscription.
type Watcher ¶ added in v1.9.2
type Watcher struct {
// contains filtered or unexported fields
}
Watcher streams raw event frames for one event type. Event channel tokens are single-use, so every dial attempt provisions its own session and re-subscribes once connected. When WaitConnected returns false, Err holds the reason if it was fatal.
func NewWatcher ¶ added in v1.9.2
func NewWatcher(ac *client.AlpaconClient, eventType EventType, targetID string) *Watcher
func (*Watcher) Err ¶ added in v1.9.2
Err returns the error that stopped the Watcher before it ever subscribed.
func (*Watcher) ReconnectFailed ¶ added in v1.9.2
ReconnectFailed reports the first failure of each outage, so a stream whose reconnects keep failing is distinguishable from a quiet one.
func (*Watcher) Reconnected ¶ added in v1.9.2
func (w *Watcher) Reconnected() <-chan struct{}
Reconnected fires on each re-subscribe. Events published while disconnected are lost for good: the event channel has no history to replay.
func (Watcher) Start ¶ added in v1.9.2
func (w Watcher) Start()
Start reads events in a background goroutine, reconnecting automatically until Stop is called.
func (Watcher) Stop ¶ added in v1.9.2
func (w Watcher) Stop()
Stop shuts down the listener and closes the connection to unblock a pending ReadMessage. Safe to call from any goroutine.
func (Watcher) WaitConnected ¶ added in v1.9.2
WaitConnected blocks until a dial has connected and its onConnected hook has returned, until timeout, or until shutdown; returns whether it connected. A hook with nothing to subscribe to still counts, so this promises no subscription.