registration

package
v0.1.2-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidInvite     = errors.New("invalid invite token")
	ErrInviteUsed        = errors.New("invite token has already been used")
	ErrInviteExpired     = errors.New("invite token has expired")
	ErrInvalidBootstrap  = errors.New("invalid bootstrap token")
	ErrBootstrapUsed     = errors.New("bootstrap token has already been used")
	ErrBootstrapExpired  = errors.New("bootstrap token has expired")
	ErrRepositoryMissing = errors.New("registration repository is not configured")
)

Functions

func HashToken

func HashToken(token string) string

Types

type InviteRecord

type InviteRecord struct {
	ID        string
	FleetID   string
	TokenHash string
	ExpiresAt time.Time
	CreatedAt time.Time
}

type InviteToken

type InviteToken struct {
	ID        string
	FleetID   string
	Token     string
	ExpiresAt time.Time
}

type NodeRegistration

type NodeRegistration struct {
	InviteTokenHash         string
	NodeID                  string
	KeyID                   string
	PublicKey               string
	HardwareFingerprintHash string
	BootstrapTokenID        string
	BootstrapTokenHash      string
	BootstrapTokenExpiresAt time.Time
	Now                     time.Time
}

type NodeSummary

type NodeSummary struct {
	ID              string     `json:"id"`
	State           string     `json:"state"`
	CurrentModelID  string     `json:"current_model_id,omitempty"`
	LastSeenAt      *time.Time `json:"last_seen_at,omitempty"`
	SessionStatus   string     `json:"session_status"`
	LastHeartbeatAt *time.Time `json:"last_heartbeat_at,omitempty"`
	ScheduleState   string     `json:"schedule_state,omitempty"`
	ThermalState    string     `json:"thermal_state,omitempty"`
	Paused          bool       `json:"paused"`
	Draining        bool       `json:"draining"`
}

type PGStore

type PGStore struct {
	Pool *pgxpool.Pool
}

func (PGStore) CloseSession

func (s PGStore) CloseSession(ctx context.Context, sessionID, nodeID string, now time.Time) error

func (PGStore) ConsumeBootstrap

func (s PGStore) ConsumeBootstrap(ctx context.Context, nodeID, bootstrapHash string, now time.Time) error

func (PGStore) CreateInvite

func (s PGStore) CreateInvite(ctx context.Context, invite InviteRecord) error

func (PGStore) ListNodes

func (s PGStore) ListNodes(ctx context.Context) ([]NodeSummary, error)

func (PGStore) MarkStale

func (s PGStore) MarkStale(ctx context.Context, cutoff, now time.Time) (int64, error)

func (PGStore) OpenSession

func (s PGStore) OpenSession(ctx context.Context, nodeID, protocolVersion, remoteAddr string, now time.Time) (string, error)

func (PGStore) PublicKeyForNode

func (s PGStore) PublicKeyForNode(ctx context.Context, nodeID string) (string, error)

func (PGStore) RecordHeartbeat

func (s PGStore) RecordHeartbeat(ctx context.Context, sessionID string, heartbeat protocol.NodeHeartbeatPayload, receivedAt time.Time) error

func (PGStore) RecordSafetyEvent

func (s PGStore) RecordSafetyEvent(ctx context.Context, event protocol.NodeSafetyEventPayload, receivedAt time.Time) error

func (PGStore) RecordStateChanged

func (s PGStore) RecordStateChanged(ctx context.Context, stateChanged protocol.NodeStateChangedPayload, receivedAt time.Time) error

func (PGStore) RegisterNode

func (s PGStore) RegisterNode(ctx context.Context, registration NodeRegistration) (RegistrationCreated, error)

type RegisterRequest

type RegisterRequest struct {
	InviteToken             string `json:"invite_token"`
	PublicKey               string `json:"public_key"`
	HardwareFingerprintHash string `json:"hardware_fingerprint_hash"`
}

type RegisterResult

type RegisterResult struct {
	NodeID                  string            `json:"node_id"`
	BootstrapToken          string            `json:"bootstrap_token"`
	BootstrapTokenExpiresAt time.Time         `json:"bootstrap_token_expires_at"`
	FleetSchedule           *ScheduleDefaults `json:"fleet_schedule,omitempty"`
}

type RegistrationCreated

type RegistrationCreated struct {
	NodeID                  string
	BootstrapTokenExpiresAt time.Time
	FleetSchedule           *ScheduleDefaults
}

type Repository

type Repository interface {
	CreateInvite(ctx context.Context, invite InviteRecord) error
	RegisterNode(ctx context.Context, registration NodeRegistration) (RegistrationCreated, error)
	ConsumeBootstrap(ctx context.Context, nodeID, bootstrapHash string, now time.Time) error
}

type ScheduleDefaults

type ScheduleDefaults struct {
	From     string `json:"from"`
	Until    string `json:"until"`
	Timezone string `json:"timezone"`
}

type Service

type Service struct {
	Repository   Repository
	Now          func() time.Time
	InviteTTL    time.Duration
	BootstrapTTL time.Duration
	TokenBytes   int
}

func (Service) ConsumeBootstrap

func (s Service) ConsumeBootstrap(ctx context.Context, nodeID, bootstrapToken string) error

func (Service) CreateInvite

func (s Service) CreateInvite(ctx context.Context, fleetID string) (InviteToken, error)

func (Service) RegisterNode

func (s Service) RegisterNode(ctx context.Context, req RegisterRequest) (RegisterResult, error)

Jump to

Keyboard shortcuts

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