clientstate

package
v0.1.0-rc.40 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Overview

Package clientstate stores local client data and tunnel snapshots.

Index

Constants

This section is empty.

Variables

View Source
var ErrCertificateExpired = errors.New("clientstate: application certificate is expired")
View Source
var ErrLocked = errors.New("clientstate: state is locked by another process")

Functions

func CanonicalServer

func CanonicalServer(value string) (string, error)

CanonicalServer validates and normalizes a tnl server origin.

func DatabasePath

func DatabasePath(root string) string

DatabasePath returns the shared client database path within root.

func DefaultDir

func DefaultDir() (string, error)

func TelemetryEnabledAt

func TelemetryEnabledAt(ctx context.Context, root string) (bool, error)

TelemetryEnabledAt checks an existing database without creating client state or migrating it. an absent database defaults to enabled.

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) Current

func (r *CertificateCache) Current(ctx context.Context, hostname string) (Material, bool, error)

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 (r *CertificateCache) NewPending(ctx context.Context, hostname string) (Pending, error)

func (*CertificateCache) Pending

func (r *CertificateCache) Pending(ctx context.Context, hostname string) (Pending, error)

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.

func (*CertificateCache) Staged

func (r *CertificateCache) Staged(ctx context.Context, hostname string) (Material, bool, error)

type ControlSession

type ControlSession struct {
	AuthorityEndpoint string
	SessionID         string
	AccessToken       string
	AccessExpiresAt   time.Time
	RefreshToken      string
	RefreshExpiresAt  time.Time
}

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database owns the shared local client database.

func Open

func Open(ctx context.Context, root string) (*Database, error)

Open creates and migrates the shared local client database.

func (*Database) BeginTunnel

func (d *Database) BeginTunnel(ctx context.Context, options BeginTunnelOptions) (*Tunnel, error)

BeginTunnel registers a local tunnel and maintains its liveness lease until Finish joins the heartbeat worker.

func (*Database) Close

func (d *Database) Close() error

func (*Database) InstallationID

func (d *Database) InstallationID(ctx context.Context) (string, error)

InstallationID returns the stable pseudonymous identifier for this client database.

func (*Database) SaveServer

func (d *Database) SaveServer(ctx context.Context, serverOrigin string) error

SaveServer records the server selected by a successful login.

func (*Database) SavedServer

func (d *Database) SavedServer(ctx context.Context) (string, bool, error)

SavedServer returns the server selected by the last successful login.

func (*Database) Server

func (d *Database) Server(ctx context.Context, serverOrigin string) (*Store, error)

Server returns state scoped to a canonical server origin.

func (*Database) SetTelemetryEnabled

func (d *Database) SetTelemetryEnabled(ctx context.Context, enabled bool) error

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

func (d *Database) SnapshotProject(ctx context.Context, projectRoot string) (TunnelSnapshot, error)

SnapshotProject returns one consistent view of a project's nonterminal tunnels.

func (*Database) TelemetryEnabled

func (d *Database) TelemetryEnabled(ctx context.Context) (bool, error)

TelemetryEnabled returns the saved preference for this client state.

func (*Database) WorktreeHashSalt

func (d *Database) WorktreeHashSalt(ctx context.Context) ([worktreeHashSaltLength]byte, error)

WorktreeHashSalt returns private key material shared by worktrees using this client database.

type Lock

type Lock = filelock.Lock

Lock owns a local state lock. Store methods choose its scope and path.

func LockControlSessionContext

func LockControlSessionContext(ctx context.Context, store *Store) (*Lock, error)

func LockHostnameContext

func LockHostnameContext(ctx context.Context, store *Store, hostname string) (*Lock, error)

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 (s *Store) ControlSession(ctx context.Context) (ControlSession, bool, error)

func (*Store) LockControlSession

func (s *Store) LockControlSession() (*Lock, error)

func (*Store) LockHostname

func (s *Store) LockHostname(hostname string) (*Lock, error)

func (*Store) RemoveControlSession

func (s *Store) RemoveControlSession(ctx context.Context) error

func (*Store) SaveControlSession

func (s *Store) SaveControlSession(ctx context.Context, session ControlSession) error

func (*Store) SaveSelectedTeam

func (s *Store) SaveSelectedTeam(ctx context.Context, teamID string) error

SaveSelectedTeam records the selected team for this server origin.

func (*Store) SelectedTeam

func (s *Store) SelectedTeam(ctx context.Context) (string, bool, error)

SelectedTeam returns the stable team selection 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

func (t *Tunnel) Context() context.Context

Context is canceled if the parent ends or a failed heartbeat leaves the tunnel's local lease unmaintained.

func (*Tunnel) Finish

func (t *Tunnel) Finish(ctx context.Context, runErr error) error

Finish cancels and joins lease maintenance before recording the terminal state so a late heartbeat cannot overwrite it.

func (*Tunnel) ID

func (t *Tunnel) ID() string

func (*Tunnel) SetDevTarget

func (t *Tunnel) SetDevTarget(ctx context.Context, framework, target string) error

func (*Tunnel) SetDraining

func (t *Tunnel) SetDraining(ctx context.Context) error

func (*Tunnel) SetProvisioning

func (t *Tunnel) SetProvisioning(ctx context.Context, publishRunNumber uint64) error

func (*Tunnel) SetPublicURL

func (t *Tunnel) SetPublicURL(ctx context.Context, publicURLID, hostname string) error

func (*Tunnel) SetReady

func (t *Tunnel) SetReady(ctx context.Context, publicURL string, publishRunNumber uint64) error

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"
)

type TunnelSummary

type TunnelSummary struct {
	Total        int `json:"total"`
	Starting     int `json:"starting"`
	Provisioning int `json:"provisioning"`
	Ready        int `json:"ready"`
	Draining     int `json:"draining"`
	Stale        int `json:"stale"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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