Documentation
¶
Overview ¶
Package toolwire holds the messages of adapter protocol v1: newline- delimited JSON between the runtime and a tool process, over the tool's stdin and stdout, one task per process (docs/rfcs/sensor-sdk-v2.md, D.4.2). Both sides (pkg/tool/adapter, pkg/sensorkit/toolhost) use these types; the protocol's JSON Schema is in pkg/tool/schema.
Index ¶
- Constants
- Variables
- func Decode(line []byte, msg any) error
- type Artifact
- type Cancel
- type Credential
- type Envelope
- type Error
- type Hello
- type HelloReply
- type Limits
- type Log
- type ManifestMsg
- type Progress
- type Reader
- type Record
- type ReportInfoMsg
- type Result
- type Run
- type RunTask
- type RuntimeInfo
- type SDKInfo
- type Stats
- type TargetStatus
- type Validate
- type Validation
- type ValidationError
- type VerdictMsg
- type Writer
Constants ¶
const ( TypeHello = "hello" TypeDescribe = "describe" TypeValidate = "validate" TypeRun = "run" TypeCancel = "cancel" )
Message types, runtime to adapter.
const ( TypeManifest = "manifest" TypeValidation = "validation" TypeLog = "log" TypeProgress = "progress" TypeRecord = "record" TypeReportInfo = "report_info" TypeTargetStatus = "target_status" TypeArtifact = "artifact" TypeHeartbeat = "heartbeat" TypeVerdict = "verdict" TypeResult = "result" )
Message types, adapter to runtime (besides hello).
const MaxLine = 1 << 20
MaxLine bounds one message.
const Version = 1
Version is the protocol version.
Variables ¶
var ErrLineTooLong = errors.New("message larger than the protocol's line limit")
ErrLineTooLong is the error of a message larger than MaxLine.
var Features = []string{"artifacts", "progress", "credentials", "target_status", "report_info", "retest"}
Features the runtime offers in its hello.
Functions ¶
Types ¶
type Artifact ¶
type Artifact struct {
Envelope
Name string `json:"name"`
MediaType string `json:"media_type"`
// Path is relative to the task's directory.
Path string `json:"path"`
SHA256 string `json:"sha256"`
Size int64 `json:"size"`
}
Artifact announces an artifact file in the task's directory.
type Credential ¶
Credential is a credential delivered with a run: only those the manifest declares and the operator stored.
type Error ¶
type Error struct {
Class tool.ErrorClass `json:"class"`
Retryable bool `json:"retryable,omitempty"`
RetryAfterMs int64 `json:"retry_after_ms,omitempty"`
Detail string `json:"detail,omitempty"`
}
Error is a categorized error on the wire.
type Hello ¶
type Hello struct {
Envelope
Protocol []int `json:"protocol"`
Runtime RuntimeInfo `json:"runtime"`
Limits Limits `json:"limits"`
Features []string `json:"features,omitempty"`
}
Hello is the runtime's first message.
type HelloReply ¶
type HelloReply struct {
Envelope
Protocol int `json:"protocol"`
SDK SDKInfo `json:"sdk"`
Features []string `json:"features,omitempty"`
}
HelloReply is the adapter's first message: the version it chose.
type Limits ¶
type Limits struct {
MaxLine int `json:"max_line"`
MaxRecords int `json:"max_records"`
MaxOutputBytes int64 `json:"max_output_bytes"`
MaxArtifactBytes int64 `json:"max_artifact_bytes"`
}
Limits are the runtime's limits, announced in its hello.
type Log ¶
type Log struct {
Envelope
Level string `json:"level"`
Msg string `json:"msg"`
Fields map[string]any `json:"fields,omitempty"`
}
Log is a log line.
type ManifestMsg ¶
type ManifestMsg struct {
Envelope
Manifest json.RawMessage `json:"manifest"`
}
ManifestMsg answers describe.
type Progress ¶
type Progress struct {
Envelope
Done int `json:"done"`
Total int `json:"total"`
Msg string `json:"msg,omitempty"`
}
Progress reports progress.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads messages, refusing lines longer than MaxLine.
type Record ¶
type Record struct {
Envelope
// Kind is asset, finding or dependency.
Kind string `json:"kind"`
// Target is the ref of the target the record belongs to ("" none).
Target string `json:"target,omitempty"`
Data json.RawMessage `json:"data"`
}
Record is one CTIS record.
type ReportInfoMsg ¶
type ReportInfoMsg struct {
Envelope
Info json.RawMessage `json:"info"`
}
ReportInfoMsg carries a report's tool, metadata and properties.
type Result ¶
type Result struct {
Envelope
Status tool.Status `json:"status"`
Error *Error `json:"error,omitempty"`
Stats Stats `json:"stats,omitzero"`
}
Result is the adapter's last message.
type RunTask ¶
type RunTask struct {
tool.Task
// Workdir is the task's private directory.
Workdir string `json:"workdir"`
Credentials []Credential `json:"credentials,omitempty"`
}
RunTask is the task as the adapter receives it.
type RuntimeInfo ¶
type RuntimeInfo struct {
Name string `json:"name"`
Version string `json:"version,omitempty"`
OS string `json:"os,omitempty"`
Arch string `json:"arch,omitempty"`
}
RuntimeInfo names the runtime.
type Stats ¶
type Stats struct {
Records int `json:"records,omitempty"`
}
Stats are the adapter's own counters (informational).
type TargetStatus ¶
type TargetStatus struct {
Envelope
Target string `json:"target"`
Status tool.TargetState `json:"status"`
Error *Error `json:"error,omitempty"`
}
TargetStatus reports one target's outcome.
type Validation ¶
type Validation struct {
Envelope
OK bool `json:"ok"`
Errors []ValidationError `json:"errors,omitempty"`
}
Validation answers validate.
type ValidationError ¶
ValidationError is one problem of a task.
type VerdictMsg ¶
type VerdictMsg struct {
Envelope
// Item is the ref of the retest item.
Item string `json:"item"`
Verdict tool.Verdict `json:"verdict"`
Detail string `json:"detail,omitempty"`
// Evidence and TemplateDigest support the verdict
// (tool.VerdictReport); the runtime checks them again.
Evidence []ctis.EvidenceItem `json:"evidence,omitempty"`
TemplateDigest string `json:"template_digest,omitempty"`
}
VerdictMsg is a retest verdict on one item.