api

package
v0.0.0-...-b256af6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package api manages saved SSH hosts and opens terminals on them, as a JSON API with relative routes plus a WebSocket terminal.

Index

Constants

View Source
const (
	StatusConnectFailed  websocket.StatusCode = 4000 // reason: the error
	StatusHostKeyChanged websocket.StatusCode = 4001 // forget the pinned key to continue
)

Close codes of the terminal socket beyond the standard ones, so the UI can offer the right next step.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectError

type ConnectError struct{ Err error }

ConnectError wraps a failure to reach or authenticate to a host.

func (*ConnectError) Error

func (e *ConnectError) Error() string

func (*ConnectError) Unwrap

func (e *ConnectError) Unwrap() error

type Input

type Input struct {
	Name        string `json:"name"`
	Address     string `json:"address"`
	Port        int    `json:"port"`
	User        string `json:"user"`
	Auth        string `json:"auth"`
	Password    string `json:"password"`
	PrivateKey  string `json:"private_key"`
	Passphrase  string `json:"passphrase"`
	Description string `json:"description"`
}

Input creates or updates a host. On update, empty secrets keep the stored ones.

type Service

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

Service manages hosts.

func NewService

func NewService(ctx context.Context, st *store.SQLite, log *slog.Logger) (*Service, error)

NewService returns the service, generating the panel key on first use.

func (*Service) Connect

func (s *Service) Connect(ctx context.Context, id int64) (*hosts.Conn, error)

Connect opens an authenticated connection to a stored host, pinning its key on first use.

func (*Service) Create

func (s *Service) Create(ctx context.Context, in Input) (hosts.View, error)

Create saves a new host.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id int64) error

Delete removes a host.

func (*Service) ForgetHostKey

func (s *Service) ForgetHostKey(ctx context.Context, id int64) error

ForgetHostKey clears the pinned key, e.g. after a server was reinstalled.

func (*Service) Get

func (s *Service) Get(ctx context.Context, id int64) (hosts.View, error)

Get returns one host.

func (*Service) Handler

func (s *Service) Handler() http.Handler

Handler serves the API. Successful responses are {"data": ...}; failures are {"error": {"code": ..., "message": ...}} with a matching status.

func (*Service) List

func (s *Service) List(ctx context.Context) ([]hosts.View, error)

List returns every host.

func (*Service) PublicKey

func (s *Service) PublicKey() string

PublicKey returns the panel's public key in authorized_keys format: add it to ~/.ssh/authorized_keys on hosts that use the "panel" method.

func (*Service) Summary

func (s *Service) Summary(ctx context.Context) (Summary, error)

Summary counts hosts and open terminals.

func (*Service) Test

func (s *Service) Test(ctx context.Context, id int64, in Input) (TestResult, error)

Test connects with in, merged into the stored host id when id > 0 (its secrets and pinned key), without saving anything.

func (*Service) Update

func (s *Service) Update(ctx context.Context, id int64, in Input) (hosts.View, error)

Update changes a host. A new address or port forgets the pinned host key, since it belongs to the old server.

type Summary

type Summary struct {
	Hosts    int   `json:"hosts"`
	Sessions int64 `json:"sessions"`
}

Summary counts hosts and open terminals for an overview.

type TestResult

type TestResult struct {
	HostKeyType   string `json:"host_key_type"`
	HostKeySHA256 string `json:"host_key_sha256"`
	Pinned        bool   `json:"pinned"` // the key was already pinned
}

TestResult reports a successful test connection.

Jump to

Keyboard shortcuts

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