Documentation
¶
Overview ¶
Package clientstate stores local client data and tunnel snapshots.
Index ¶
- Variables
- func CanonicalServer(value string) (string, error)
- func DatabasePath(root string) string
- func DefaultDir() (string, error)
- func TelemetryEnabledAt(ctx context.Context, root string) (bool, error)
- type BeginTunnelOptions
- type CertificateCache
- func (r *CertificateCache) Current(ctx context.Context, hostname string) (Material, bool, error)
- func (r *CertificateCache) Lock(ctx context.Context) (*Lock, error)
- func (r *CertificateCache) NewPending(ctx context.Context, hostname string) (Pending, error)
- func (r *CertificateCache) Pending(ctx context.Context, hostname string) (Pending, error)
- func (r *CertificateCache) Promote(ctx context.Context, hostname, issuanceID string) error
- func (r *CertificateCache) Stage(ctx context.Context, hostname string, pending Pending, certificatePEM []byte, ...) (Material, error)
- func (r *CertificateCache) Staged(ctx context.Context, hostname string) (Material, bool, error)
- type ControlSession
- type Database
- func (d *Database) BeginTunnel(ctx context.Context, options BeginTunnelOptions) (*Tunnel, error)
- func (d *Database) Close() error
- func (d *Database) InstallationID(ctx context.Context) (string, error)
- func (d *Database) SaveServer(ctx context.Context, serverOrigin string) error
- func (d *Database) SavedServer(ctx context.Context) (string, bool, error)
- func (d *Database) Server(ctx context.Context, serverOrigin string) (*Store, error)
- func (d *Database) SetTelemetryEnabled(ctx context.Context, enabled bool) error
- func (d *Database) Snapshot(ctx context.Context) (TunnelSnapshot, error)
- func (d *Database) SnapshotProject(ctx context.Context, projectRoot string) (TunnelSnapshot, error)
- func (d *Database) TelemetryEnabled(ctx context.Context) (bool, error)
- func (d *Database) WorktreeHashSalt(ctx context.Context) ([worktreeHashSaltLength]byte, error)
- type Lock
- type Material
- type Pending
- type Store
- func (s *Store) Certificates(teamID string, plan controlv1.CertificatePlan) (*CertificateCache, error)
- func (s *Store) ControlSession(ctx context.Context) (ControlSession, bool, error)
- func (s *Store) LockControlSession() (*Lock, error)
- func (s *Store) LockHostname(hostname string) (*Lock, error)
- func (s *Store) RemoveControlSession(ctx context.Context) error
- func (s *Store) SaveControlSession(ctx context.Context, session ControlSession) error
- func (s *Store) SaveSelectedTeam(ctx context.Context, teamID string) error
- func (s *Store) SelectedTeam(ctx context.Context) (string, bool, error)
- type Tunnel
- func (t *Tunnel) Context() context.Context
- func (t *Tunnel) Finish(ctx context.Context, runErr error) error
- func (t *Tunnel) ID() string
- func (t *Tunnel) SetDevTarget(ctx context.Context, framework, target string) error
- func (t *Tunnel) SetDraining(ctx context.Context) error
- func (t *Tunnel) SetProvisioning(ctx context.Context, publishRunNumber uint64) error
- func (t *Tunnel) SetPublicURL(ctx context.Context, publicURLID, hostname string) error
- func (t *Tunnel) SetReady(ctx context.Context, publicURL string, publishRunNumber uint64) error
- type TunnelCommand
- type TunnelInfo
- type TunnelSnapshot
- type TunnelState
- type TunnelSummary
Constants ¶
This section is empty.
Variables ¶
var ErrCertificateExpired = errors.New("clientstate: application certificate is expired")
var ErrLocked = errors.New("clientstate: state is locked by another process")
Functions ¶
func CanonicalServer ¶
CanonicalServer validates and normalizes a tnl server origin.
func DatabasePath ¶
DatabasePath returns the shared client database path within root.
func DefaultDir ¶
Types ¶
type BeginTunnelOptions ¶
type BeginTunnelOptions struct {
Command TunnelCommand
Server string
Target string
Project string
Service string
}
type CertificateCache ¶
type CertificateCache struct {
// contains filtered or unexported fields
}
func (*CertificateCache) Lock ¶
func (r *CertificateCache) Lock(ctx context.Context) (*Lock, error)
Lock serializes a certificate transaction, not the tunnel using its material.
func (*CertificateCache) NewPending ¶
func (*CertificateCache) Promote ¶
func (r *CertificateCache) Promote(ctx context.Context, hostname, issuanceID string) error
func (*CertificateCache) Stage ¶
func (r *CertificateCache) Stage( ctx context.Context, hostname string, pending Pending, certificatePEM []byte, renewAt time.Time, issuanceID string, ) (Material, error)
Stage retains issued material without replacing the last acknowledged certificate. the caller holds Lock through staging, control acknowledgement, and promotion.
type ControlSession ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database owns the shared local client database.
func (*Database) BeginTunnel ¶
BeginTunnel registers a local tunnel and maintains its liveness lease until Finish joins the heartbeat worker.
func (*Database) InstallationID ¶
InstallationID returns the stable pseudonymous identifier for this client database.
func (*Database) SaveServer ¶
SaveServer records the server selected by a successful login.
func (*Database) SavedServer ¶
SavedServer returns the server selected by the last successful login.
func (*Database) SetTelemetryEnabled ¶
SetTelemetryEnabled saves the preference across commands and projects.
func (*Database) Snapshot ¶
func (d *Database) Snapshot(ctx context.Context) (TunnelSnapshot, error)
Snapshot returns one consistent view of all nonterminal local tunnels.
func (*Database) SnapshotProject ¶
SnapshotProject returns one consistent view of a project's nonterminal tunnels.
func (*Database) TelemetryEnabled ¶
TelemetryEnabled returns the saved preference for this client state.
type Lock ¶
Lock owns a local state lock. Store methods choose its scope and path.
type Material ¶
type Material struct {
Certificate tls.Certificate
RenewAt time.Time
IssuanceID string
}
type Pending ¶
type Pending struct {
Key *ecdsa.PrivateKey
CSRDER []byte
// contains filtered or unexported fields
}
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store scopes credentials, certificates, and locks to one server profile.
func (*Store) Certificates ¶
func (s *Store) Certificates(teamID string, plan controlv1.CertificatePlan) (*CertificateCache, error)
func (*Store) ControlSession ¶
func (*Store) LockControlSession ¶
func (*Store) RemoveControlSession ¶
func (*Store) SaveControlSession ¶
func (s *Store) SaveControlSession(ctx context.Context, session ControlSession) error
func (*Store) SaveSelectedTeam ¶
SaveSelectedTeam records the selected team for this server origin.
type Tunnel ¶
type Tunnel struct {
// contains filtered or unexported fields
}
Tunnel is the write handle for one local publish or dev invocation.
func (*Tunnel) Context ¶
Context is canceled if the parent ends or a failed heartbeat leaves the tunnel's local lease unmaintained.
func (*Tunnel) Finish ¶
Finish cancels and joins lease maintenance before recording the terminal state so a late heartbeat cannot overwrite it.
func (*Tunnel) SetDevTarget ¶
func (*Tunnel) SetProvisioning ¶
func (*Tunnel) SetPublicURL ¶
type TunnelCommand ¶
type TunnelCommand string
const ( TunnelCommandPublish TunnelCommand = "publish" TunnelCommandDev TunnelCommand = "dev" )
type TunnelInfo ¶
type TunnelInfo struct {
ID string `json:"tunnel_id"`
Command TunnelCommand `json:"command"`
State TunnelState `json:"state"`
ProcessID int `json:"process_id"`
Server string `json:"server"`
Project string `json:"project"`
Service string `json:"service,omitempty"`
PublicURLID string `json:"public_url_id,omitempty"`
PublishRunNumber uint64 `json:"publish_run_number,omitempty"`
Hostname string `json:"hostname,omitempty"`
PublicURL string `json:"public_url,omitempty"`
Target string `json:"target,omitempty"`
Framework string `json:"framework,omitempty"`
StartedAt time.Time `json:"started_at"`
UpdatedAt time.Time `json:"updated_at"`
HeartbeatAt time.Time `json:"heartbeat_at"`
LeaseExpiresAt time.Time `json:"lease_expires_at"`
}
type TunnelSnapshot ¶
type TunnelSnapshot struct {
SchemaVersion int `json:"schema_version"`
ObservedAt time.Time `json:"observed_at"`
Summary TunnelSummary `json:"summary"`
Tunnels []TunnelInfo `json:"tunnels"`
}
type TunnelState ¶
type TunnelState string
const ( TunnelStateStarting TunnelState = "starting" TunnelStateProvisioning TunnelState = "provisioning" TunnelStateReady TunnelState = "ready" TunnelStateDraining TunnelState = "draining" TunnelStateStopped TunnelState = "stopped" TunnelStateFailed TunnelState = "failed" TunnelStateStale TunnelState = "stale" )