Documentation
¶
Overview ¶
Package service defines the transport-facing Web service contract and the service-owned authentication component.
Index ¶
- Constants
- Variables
- func AccessKeyMatches(key, candidate string) bool
- func BearerToken(header string) (string, bool)
- func RequestIsHTTPS(r *http.Request) bool
- func SessionMatches(key, candidate string) bool
- func SessionValue(key string) string
- func ValidateMode(mode string) (string, error)
- func ValidateTarget(raw string) (string, error)
- type AgentPool
- func (p *AgentPool) BroadcastConfigReload(config *types.DistributeConfig) int
- func (p *AgentPool) CancelPTY(nodeID, terminalID string)
- func (p *AgentPool) CancelTask(nodeID, taskID string, sessionID ...string) error
- func (p *AgentPool) ClosePTY(nodeID, terminalID string)
- func (p *AgentPool) Count() int
- func (p *AgentPool) DispatchCloseSession(nodeID, requestID string, request *aop.CloseSessionRequest) (<-chan taskResult, error)
- func (p *AgentPool) DispatchCommand(nodeID, taskID string, command *types.CommandRequest) (<-chan taskResult, error)
- func (p *AgentPool) DispatchOpenSession(nodeID, requestID string, request *aop.OpenSessionRequest) (<-chan taskResult, error)
- func (p *AgentPool) DispatchRun(nodeID string, request *aop.RunTurnRequest) (<-chan taskResult, error)
- func (p *AgentPool) DispatchToolCall(nodeID, taskID string, call *aop.ToolCall) (<-chan taskResult, error)
- func (p *AgentPool) ForwardPTY(nodeID string, message *ptypb.ProtocolMessage) error
- func (p *AgentPool) HandleNodeWebSocket(w http.ResponseWriter, r *http.Request)
- func (p *AgentPool) List() []*types.AgentView
- func (p *AgentPool) Pick() *remoteAgent
- func (p *AgentPool) ServeNode(parent context.Context, stream aop.EnvelopeStream) error
- func (p *AgentPool) SessionOpen(nodeID, sessionID string) bool
- func (p *AgentPool) SetArtifactIngestor(ingestor ArtifactIngestor)
- func (p *AgentPool) SetSessionLookup(sl SessionLookup)
- func (p *AgentPool) SubscribePTY(nodeID, terminalID string) (<-chan *ptypb.ProtocolMessage, bool, func())
- type ArtifactIngestor
- type Auth
- type ConfigStore
- type Hub
- func (h *Hub) BroadcastAOP(sessionID string, delivery *aop.EventDelivery, reliable bool)
- func (h *Hub) BroadcastScan(event *types.ScanEvent, reliable bool)
- func (h *Hub) SubscribeAOP(sessionID string) (<-chan *aop.EventDelivery, func())
- func (h *Hub) SubscribeScan(scanID string) (<-chan *types.ScanEvent, uint64, func())
- type PreparedConfig
- type SCOStore
- type SQLiteStore
- func (s *SQLiteStore) AddAOPEvent(ctx context.Context, sessionID string, event *aop.Event) error
- func (s *SQLiteStore) AppendAOPEvent(ctx context.Context, sessionID string, event *aop.Event) (cursor int64, persisted bool, err error)
- func (s *SQLiteStore) Close() error
- func (s *SQLiteStore) Create(ctx context.Context, scan *types.Scan) error
- func (s *SQLiteStore) CreateSession(ctx context.Context, session *types.SessionRecord) error
- func (s *SQLiteStore) Delete(ctx context.Context, id string) error
- func (s *SQLiteStore) DeleteSCONodesByScan(ctx context.Context, scanID string) error
- func (s *SQLiteStore) DeleteSession(ctx context.Context, id string) error
- func (s *SQLiteStore) Get(ctx context.Context, id string) (*types.Scan, error)
- func (s *SQLiteStore) GetSCONode(ctx context.Context, cstxID string) (json.RawMessage, error)
- func (s *SQLiteStore) GetSession(ctx context.Context, id string) (*types.SessionRecord, error)
- func (s *SQLiteStore) LinkScanToSession(ctx context.Context, sessionID, scanID string) error
- func (s *SQLiteStore) List(ctx context.Context, limit int) ([]*types.Scan, error)
- func (s *SQLiteStore) ListAOPEventPage(ctx context.Context, sessionID string, before int64, limit int) ([]*aop.EventDelivery, int64, error)
- func (s *SQLiteStore) ListAOPEvents(ctx context.Context, sessionID string, limit int) ([]*aop.Event, error)
- func (s *SQLiteStore) ListAOPEventsAfter(ctx context.Context, sessionID string, after int64, limit int) ([]*aop.EventDelivery, error)
- func (s *SQLiteStore) ListSCONodes(ctx context.Context, nodeType string, limit int) ([]json.RawMessage, error)
- func (s *SQLiteStore) ListSCONodesByScanID(ctx context.Context, scanID, nodeType string, limit int) ([]json.RawMessage, error)
- func (s *SQLiteStore) ListSessionPage(ctx context.Context, offset, limit int, includeClosed bool) ([]*types.SessionRecord, bool, error)
- func (s *SQLiteStore) ListSessions(ctx context.Context, limit int) ([]*types.SessionRecord, error)
- func (s *SQLiteStore) LoadAOPRequest(ctx context.Context, requestID, method string, requestHash []byte, ...) (found, conflict bool, err error)
- func (s *SQLiteStore) MaxAOPEventSeq(ctx context.Context, sessionID string) (uint64, error)
- func (s *SQLiteStore) SCONodeStats(ctx context.Context) (map[string]int, error)
- func (s *SQLiteStore) SaveAOPRequest(ctx context.Context, requestID, method string, requestHash []byte, ...) error
- func (s *SQLiteStore) SessionScanIDs(ctx context.Context, sessionID string) ([]string, error)
- func (s *SQLiteStore) TransitionScan(ctx context.Context, scan *types.Scan, expected ...types.ScanStatus) (bool, error)
- func (s *SQLiteStore) Update(ctx context.Context, scan *types.Scan) error
- func (s *SQLiteStore) UpdateSession(ctx context.Context, session *types.SessionRecord) error
- func (s *SQLiteStore) UpsertSCONodes(ctx context.Context, operationID string, nodes []json.RawMessage) error
- type Service
- func (s *Service) API() *managementapi.API
- func (s *Service) AgentInfo(nodeID string) (string, bool)
- func (s *Service) ApplicationWebSocketHandler() http.Handler
- func (s *Service) Auth() web.Auth
- func (s *Service) BroadcastAOPEvent(sessionID string, event *aop.Event)
- func (s *Service) CancelScan(id string) error
- func (s *Service) CancelTurn(ctx context.Context, sessionID, turnID string) error
- func (s *Service) Close()
- func (s *Service) CloseAgentSession(ctx context.Context, requestID, nodeID string, ...) (bool, error)
- func (s *Service) DeleteSession(ctx context.Context, id string) error
- func (s *Service) ExecuteSessionCommand(sessionID, line string) (string, error)
- func (s *Service) GetReport(ctx context.Context, id, lang string) (string, error)
- func (s *Service) GetScan(ctx context.Context, id string) (*types.Scan, error)
- func (s *Service) HandleApplicationWebSocket(w http.ResponseWriter, r *http.Request)
- func (s *Service) Hub() *Hub
- func (s *Service) ListScans(ctx context.Context) ([]*types.Scan, error)
- func (s *Service) NodeWebSocketHandler() http.Handler
- func (s *Service) OpenAgentSession(ctx context.Context, requestID string, request *aop.OpenSessionRequest) error
- func (s *Service) PublishUserMessage(sessionID, turnID string, message *aop.Message)
- func (s *Service) ServeApplication(ctx context.Context, stream aop.EnvelopeStream) error
- func (s *Service) SessionMenu(sessionID string) []*types.CommandSpec
- func (s *Service) SetAgentPool(pool *AgentPool)
- func (s *Service) StartAgentTurn(sessionID string, request *aop.RunTurnRequest)
- func (s *Service) Status() *types.SystemStatus
- func (s *Service) SubmitScan(ctx context.Context, target, mode string, verify, sniper, deep bool) (*types.Scan, error)
- func (s *Service) SubscribeSessionEvents(sessionID string) (<-chan *aop.EventDelivery, func())
- func (s *Service) TaskSession(taskID string) (string, bool)
- func (s *Service) Upload(ctx context.Context, sessionID, filename string, data []byte) (*filepb.Result, error)
- type ServiceConfig
- type SessionLookup
Constants ¶
const ( SysNoRunningTask = "no_running_task" SysPaused = "paused" SysFileUploaded = "file_uploaded" SysNoAgentsConnected = "no_agents_connected" SysAgentsList = "agents_list" SysAgentNotConnected = "agent_not_connected" )
Stable system-message codes mirrored by the frontend i18n catalog.
const ( ApplicationWebSocketPath = web.ApplicationWebSocketPath NodeWebSocketPath = web.NodeWebSocketPath )
const ( SessionStateOpen = managementapi.SessionStateOpen SessionStateClosed = managementapi.SessionStateClosed )
const CookieName = "aiscan_session"
Variables ¶
var ( ErrScanNotFound = managementapi.ErrScanNotFound ErrScanNotCancelable = managementapi.ErrScanNotCancelable )
var ( ErrSessionNotFound = errors.New("session not found") ErrTurnNotFound = managementapi.ErrTurnNotFound )
Functions ¶
func AccessKeyMatches ¶
func BearerToken ¶
func RequestIsHTTPS ¶
func SessionMatches ¶
func SessionValue ¶
func ValidateMode ¶
func ValidateTarget ¶
Types ¶
type AgentPool ¶
type AgentPool struct {
// contains filtered or unexported fields
}
AgentPool manages connected aiscan agent nodes. Every member is a node that registered over the application WebSocket — including the hub's own embedded agent, which connects over loopback like any other node.
func NewAgentPool ¶
func (*AgentPool) BroadcastConfigReload ¶
func (p *AgentPool) BroadcastConfigReload(config *types.DistributeConfig) int
BroadcastConfigReload sends the committed protobuf config on the same FIFO as every other application message. Agents never fetch a second REST DTO.
func (*AgentPool) CancelTask ¶
func (*AgentPool) DispatchCloseSession ¶
func (p *AgentPool) DispatchCloseSession(nodeID, requestID string, request *aop.CloseSessionRequest) (<-chan taskResult, error)
func (*AgentPool) DispatchCommand ¶
func (p *AgentPool) DispatchCommand(nodeID, taskID string, command *types.CommandRequest) (<-chan taskResult, error)
func (*AgentPool) DispatchOpenSession ¶
func (p *AgentPool) DispatchOpenSession(nodeID, requestID string, request *aop.OpenSessionRequest) (<-chan taskResult, error)
func (*AgentPool) DispatchRun ¶
func (p *AgentPool) DispatchRun(nodeID string, request *aop.RunTurnRequest) (<-chan taskResult, error)
func (*AgentPool) DispatchToolCall ¶
func (p *AgentPool) DispatchToolCall(nodeID, taskID string, call *aop.ToolCall) (<-chan taskResult, error)
DispatchToolCall sends a canonical AOP tool.call to a tool-capable node. The task completes only on the matching AOP tool.result.
func (*AgentPool) ForwardPTY ¶
func (p *AgentPool) ForwardPTY(nodeID string, message *ptypb.ProtocolMessage) error
func (*AgentPool) HandleNodeWebSocket ¶
func (p *AgentPool) HandleNodeWebSocket(w http.ResponseWriter, r *http.Request)
func (*AgentPool) Pick ¶
func (p *AgentPool) Pick() *remoteAgent
Pick selects an idle agent, or any agent if none idle.
func (*AgentPool) ServeNode ¶
ServeNode owns the Node Endpoint handshake and AgentPool registration. Once initialized, node traffic uses the same Connection runtime as applications.
func (*AgentPool) SessionOpen ¶
func (*AgentPool) SetArtifactIngestor ¶
func (p *AgentPool) SetArtifactIngestor(ingestor ArtifactIngestor)
func (*AgentPool) SetSessionLookup ¶
func (p *AgentPool) SetSessionLookup(sl SessionLookup)
func (*AgentPool) SubscribePTY ¶
func (p *AgentPool) SubscribePTY(nodeID, terminalID string) (<-chan *ptypb.ProtocolMessage, bool, func())
type ArtifactIngestor ¶
type ArtifactIngestor interface {
IngestArtifact(context.Context, *toolpb.Artifact) error
NormalizeArtifact(context.Context, string, string, []byte) (uint64, uint64, error)
SupportedArtifacts() []string
Close() error
}
ArtifactIngestor is the server-side normalization boundary. Agent nodes send scanner-native records; implementations convert and persist canonical SCO.
func NewArtifactIngestor ¶
func NewArtifactIngestor(store SCOStore) (ArtifactIngestor, error)
type Auth ¶
type Auth struct {
// contains filtered or unexported fields
}
Auth owns the access-key policy shared by HTTP, ConnectRPC, WebSocket and the IOA browser bridge.
func (*Auth) Authenticate ¶
Authenticate resolves an explicit bearer credential or browser session. An invalid explicit bearer never falls back to the cookie.
func (*Auth) Middleware ¶
Middleware gates API requests while leaving health, login and static routes available to browsers.
func (*Auth) RegisterRoutes ¶
RegisterRoutes installs the browser session endpoints owned by Auth.
type ConfigStore ¶
type ConfigStore = managementapi.ConfigStore
ConfigStore and PreparedConfig are the host integration surface for config persistence; the business semantics live in web/api.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub is a typed in-process broker. Durable replay remains the responsibility of the event stores; live protobuf values never pass through JSON envelopes.
func (*Hub) BroadcastAOP ¶
func (h *Hub) BroadcastAOP(sessionID string, delivery *aop.EventDelivery, reliable bool)
func (*Hub) SubscribeAOP ¶
func (h *Hub) SubscribeAOP(sessionID string) (<-chan *aop.EventDelivery, func())
func (*Hub) SubscribeScan ¶
SubscribeScan registers a live subscriber and returns the sequence that was current at the subscription boundary. A caller can stamp its initial snapshot with this value, then safely ignore queued events at or below it.
type PreparedConfig ¶
type PreparedConfig = managementapi.PreparedConfig
type SCOStore ¶
type SCOStore interface {
UpsertSCONodes(ctx context.Context, operationID string, nodes []json.RawMessage) error
}
SCOStore persists server-normalized nodes and records which AOP operation observed them. Node identity is global; operation membership is many-to-many.
type SQLiteStore ¶
type SQLiteStore struct {
// contains filtered or unexported fields
}
func NewSQLiteStore ¶
func NewSQLiteStore(dbPath string) (*SQLiteStore, error)
func (*SQLiteStore) AddAOPEvent ¶
func (*SQLiteStore) AppendAOPEvent ¶
func (*SQLiteStore) Close ¶
func (s *SQLiteStore) Close() error
func (*SQLiteStore) CreateSession ¶
func (s *SQLiteStore) CreateSession(ctx context.Context, session *types.SessionRecord) error
func (*SQLiteStore) DeleteSCONodesByScan ¶
func (s *SQLiteStore) DeleteSCONodesByScan(ctx context.Context, scanID string) error
func (*SQLiteStore) DeleteSession ¶
func (s *SQLiteStore) DeleteSession(ctx context.Context, id string) error
func (*SQLiteStore) GetSCONode ¶
func (s *SQLiteStore) GetSCONode(ctx context.Context, cstxID string) (json.RawMessage, error)
func (*SQLiteStore) GetSession ¶
func (s *SQLiteStore) GetSession(ctx context.Context, id string) (*types.SessionRecord, error)
func (*SQLiteStore) LinkScanToSession ¶
func (s *SQLiteStore) LinkScanToSession(ctx context.Context, sessionID, scanID string) error
func (*SQLiteStore) ListAOPEventPage ¶
func (s *SQLiteStore) ListAOPEventPage(ctx context.Context, sessionID string, before int64, limit int) ([]*aop.EventDelivery, int64, error)
func (*SQLiteStore) ListAOPEvents ¶
func (*SQLiteStore) ListAOPEventsAfter ¶
func (s *SQLiteStore) ListAOPEventsAfter(ctx context.Context, sessionID string, after int64, limit int) ([]*aop.EventDelivery, error)
func (*SQLiteStore) ListSCONodes ¶
func (s *SQLiteStore) ListSCONodes(ctx context.Context, nodeType string, limit int) ([]json.RawMessage, error)
func (*SQLiteStore) ListSCONodesByScanID ¶
func (s *SQLiteStore) ListSCONodesByScanID(ctx context.Context, scanID, nodeType string, limit int) ([]json.RawMessage, error)
func (*SQLiteStore) ListSessionPage ¶
func (s *SQLiteStore) ListSessionPage(ctx context.Context, offset, limit int, includeClosed bool) ([]*types.SessionRecord, bool, error)
func (*SQLiteStore) ListSessions ¶
func (s *SQLiteStore) ListSessions(ctx context.Context, limit int) ([]*types.SessionRecord, error)
func (*SQLiteStore) LoadAOPRequest ¶
func (*SQLiteStore) MaxAOPEventSeq ¶
func (*SQLiteStore) SCONodeStats ¶
func (*SQLiteStore) SaveAOPRequest ¶
func (*SQLiteStore) SessionScanIDs ¶
func (*SQLiteStore) TransitionScan ¶
func (s *SQLiteStore) TransitionScan(ctx context.Context, scan *types.Scan, expected ...types.ScanStatus) (bool, error)
func (*SQLiteStore) UpdateSession ¶
func (s *SQLiteStore) UpdateSession(ctx context.Context, session *types.SessionRecord) error
func (*SQLiteStore) UpsertSCONodes ¶
func (s *SQLiteStore) UpsertSCONodes(ctx context.Context, operationID string, nodes []json.RawMessage) error
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(cfg ServiceConfig) *Service
func (*Service) API ¶
func (s *Service) API() *managementapi.API
API exposes the existing business service composition to transport adapters.
func (*Service) ApplicationWebSocketHandler ¶
func (*Service) Auth ¶
Auth returns the authentication mechanism shared by HTTP, ConnectRPC and WebSocket bindings.
func (*Service) BroadcastAOPEvent ¶
func (*Service) CancelScan ¶
func (*Service) CancelTurn ¶
func (*Service) CloseAgentSession ¶
func (*Service) DeleteSession ¶
func (*Service) ExecuteSessionCommand ¶
func (*Service) GetReport ¶
GetReport returns the report frozen when the scan completed. Canonical scan artifacts live in the libcstx SCO store, not inside Scan.
func (*Service) HandleApplicationWebSocket ¶
func (s *Service) HandleApplicationWebSocket(w http.ResponseWriter, r *http.Request)
func (*Service) NodeWebSocketHandler ¶
func (*Service) OpenAgentSession ¶
func (*Service) PublishUserMessage ¶
PublishUserMessage records the operator input in the durable AOP timeline. Node delivery remains the caller's RunTurn/Command request; this function does not create a second transport path.
func (*Service) ServeApplication ¶
ServeApplication performs the Application Endpoint initialization and then hands the unified Connection to the api business dispatcher.
func (*Service) SessionMenu ¶
func (s *Service) SessionMenu(sessionID string) []*types.CommandSpec
SessionMenu is the web "/" command catalog for a session: the hub-scope commands plus the bound agent's reported agent-scope commands (its skills included). It falls back to the static agent-scope menu when no agent is bound, so the menu is populated even before an agent connects. This is the single source both SessionService/ListCommands and /help render from.
func (*Service) SetAgentPool ¶
func (*Service) StartAgentTurn ¶
func (s *Service) StartAgentTurn(sessionID string, request *aop.RunTurnRequest)
func (*Service) Status ¶
func (s *Service) Status() *types.SystemStatus
func (*Service) SubmitScan ¶
func (*Service) SubscribeSessionEvents ¶
func (s *Service) SubscribeSessionEvents(sessionID string) (<-chan *aop.EventDelivery, func())
type ServiceConfig ¶
type ServiceConfig struct {
Store *SQLiteStore
App *runner.App
ConfigStore ConfigStore
AppFactory func(ctx context.Context, prepared *PreparedConfig) (*runner.App, error)
AgentPool *AgentPool
Artifacts ArtifactIngestor
MaxConcurrent int
ScanTimeout time.Duration
AccessKey string
}