managedstream

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SchemaVersion   = "authorization-ledger-v1"
	DefaultEndpoint = "/api/v1/authorization-ledger/batches"

	DefaultBatchLimit = 100
	MaxPayloadBytes   = 192 * 1024
	DefaultInterval   = 10 * time.Second
)

Variables

This section is empty.

Functions

func DefaultIntervalFromEnv

func DefaultIntervalFromEnv() time.Duration

func DefaultStatePath

func DefaultStatePath() string

func DefaultStatePathForDB

func DefaultStatePathForDB(dbPath string) string

func Flush

func Flush(ctx context.Context, opts Options) error

func Run

func Run(ctx context.Context, opts Options) error

func SaveState

func SaveState(path string, state State) error

Types

type Device

type Device struct {
	Label             string `json:"label,omitempty"`
	DeploymentVersion string `json:"deployment_version,omitempty"`
}

type Options

type Options struct {
	DBPath            string
	StatePath         string
	CloudURL          string
	InstallationID    string
	InstallToken      string
	DeviceLabel       string
	DeploymentVersion func() string
	Interval          time.Duration
	BatchLimit        int
	HTTPClient        *http.Client
	Diagnostic        diagnostic.Logger
	// OnAuthFailure fires (nil-safe) after several consecutive 401/403
	// rejections — the signature of a revoked or rotated install token,
	// which would otherwise spin silently under launchd. Re-fires
	// periodically so a long-running daemon keeps surfacing it without
	// spamming every flush.
	OnAuthFailure func(status int)
	// OnFlushSuccess fires (nil-safe) after every ACCEPTED hosted post, so
	// callers can clear "token rejected" breadcrumbs. It deliberately does
	// not depend on this process's failure counter (a breadcrumb can outlive
	// a daemon restart) and deliberately does NOT fire on empty flushes that
	// never contacted the server — an idle machine with a revoked token must
	// keep its breadcrumb.
	OnFlushSuccess func()
}

type Payload

type Payload struct {
	SchemaVersion      string                           `json:"schema_version"`
	InstallationID     string                           `json:"installation_id"`
	BatchID            string                           `json:"batch_id"`
	SentAt             string                           `json:"sent_at"`
	Device             *Device                          `json:"device,omitempty"`
	Sessions           []sqlite.LedgerRecord            `json:"agent_sessions"`
	Actions            []sqlite.LedgerRecord            `json:"authorization_actions"`
	Receipts           []sqlite.LedgerRecord            `json:"authorization_receipts"`
	ReceiptChainAnchor *sqlite.LedgerReceiptChainAnchor `json:"receipt_chain_anchor,omitempty"`
}

type State

type State struct {
	UpdatedAfter *time.Time
	ActionID     string
}

func LoadState

func LoadState(path string) (State, error)

Jump to

Keyboard shortcuts

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