Documentation
¶
Overview ¶
Package contract defines cchp's machine output: one JSON result object on stdout per run (or NDJSON lines for streams), stable error kinds and exit codes.
Index ¶
Constants ¶
const ( ExitOK = 0 ExitInternal = 1 ExitUsage = 2 ExitAuth = 3 ExitPermission = 4 ExitNotFound = 5 ExitConflict = 6 ExitInvalid = 7 ExitBrowser = 8 ExitRateLimited = 9 ExitServer = 10 ExitNotSent = 11 ExitUnknown = 12 ExitPolicy = 13 ExitNotSignedIn = 14 )
Exit codes. A run that fails always exits nonzero.
const ( KindUsage = "usage" KindInvalidInput = "invalid_input" KindPolicy = "policy" KindNotSignedIn = "not_signed_in" KindPermission = "permission_denied" KindNotFound = "not_found" KindConflict = "conflict" KindValidation = "validation" KindHumanCheck = "human_verification_required" KindBrowserOnly = "browser_session_required" KindRateLimited = "rate_limited" KindServer = "server_error" KindHTTP = "http_error" KindNotSent = "not_sent" KindUnknownOutcome = "unknown_outcome" KindInternal = "internal" )
Error kinds.
const ( OutcomeApplied = "applied" OutcomeNotApplied = "not_applied" OutcomeUnknown = "unknown" )
Outcomes of a mutation.
const SchemaVersion = 1
SchemaVersion changes only when an existing field changes meaning.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DryRun ¶
type DryRun struct {
Method string `json:"method"`
URL string `json:"url"`
Headers map[string]string `json:"headers"`
Body json.RawMessage `json:"body,omitempty"`
BodyText string `json:"body_text,omitempty"`
Policy PolicyView `json:"policy"`
}
DryRun is the request cchp would have sent.
type Error ¶
type Error struct {
Kind string `json:"kind"`
Message string `json:"message"`
Hint string `json:"hint,omitempty"`
Code int64 `json:"code,omitempty"`
Detail string `json:"detail,omitempty"`
RequiredPermission string `json:"required_permission,omitempty"`
ChallengeAction string `json:"challenge_action,omitempty"`
Fields []FieldError `json:"fields,omitempty"`
Retryable bool `json:"retryable"`
Problem json.RawMessage `json:"problem,omitempty"`
}
Error is the failure description.
type Event ¶
type Event struct {
Type string `json:"type"` // event
Operation string `json:"operation"`
Seq int `json:"seq"`
Event string `json:"event,omitempty"`
ID string `json:"id,omitempty"`
Data json.RawMessage `json:"data"`
}
Event is one NDJSON stream line.
type Failure ¶
type Failure struct {
Err Error
Exit int
// Status and RequestID are set when the server answered.
Status int
RequestID string
Outcome string
}
Failure is an error that carries its contract kind and exit code.
type FieldError ¶
FieldError points at one bad input value.
type FileOutput ¶
type FileOutput struct {
Path string `json:"path"`
Bytes int64 `json:"bytes"`
SHA256 string `json:"sha256"`
ContentType string `json:"content_type,omitempty"`
}
FileOutput describes a downloaded file.
type Pagination ¶
type Pagination struct {
Pages int `json:"pages"`
Items int `json:"items"`
HasMore bool `json:"has_more"`
NextCursor string `json:"next_cursor,omitempty"`
NextPage int `json:"next_page,omitempty"`
Total *int64 `json:"total,omitempty"`
Truncated bool `json:"truncated,omitempty"`
}
Pagination describes where a list stopped and how to continue.
type PolicyView ¶
type PolicyView struct {
Risk string `json:"risk"`
NeedsWrite bool `json:"needs_allow_write"`
NeedsConfirm bool `json:"needs_confirm"`
NeedsSecret bool `json:"needs_secret_out"`
Retry bool `json:"retry"`
Classified bool `json:"classified"`
}
PolicyView explains what a real run would need.
type Result ¶
type Result struct {
SchemaVersion int `json:"schema_version"`
OK bool `json:"ok"`
Operation string `json:"operation,omitempty"`
Status int `json:"status,omitempty"`
RequestID string `json:"request_id,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
Pagination *Pagination `json:"pagination,omitempty"`
Outcome string `json:"outcome,omitempty"`
IdempotencyKey string `json:"idempotency_key,omitempty"`
Secret *SecretOutput `json:"secret,omitempty"`
File *FileOutput `json:"file,omitempty"`
Stream *StreamSummary `json:"stream,omitempty"`
DryRun *DryRun `json:"dry_run,omitempty"`
Error *Error `json:"error,omitempty"`
Warnings []string `json:"warnings,omitempty"`
}
Result is the JSON object cchp prints on stdout.
type SecretOutput ¶
SecretOutput says where one-time secrets went.
type StreamSummary ¶
type StreamSummary struct {
Events int `json:"events"`
Ended string `json:"ended"` // max_events, deadline or server_closed
}
StreamSummary closes an NDJSON stream.