service

package
v1.29.4 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRevisionNotFound = errors.New("config revision not found")
)

Errors surfaced to handlers.

Functions

func ErrParseYAML

func ErrParseYAML(err error) error

ErrParseYAML is returned when a save/restore cannot parse the incoming YAML into a FileConfig.

func ParseConfig

func ParseConfig(raw []byte) (*config.FileConfig, error)

ParseConfig is a helper for handler-side validation that mirrors config.parseDocument but is exported via the service layer.

func ShortContainerID

func ShortContainerID(id string) string

func UnifiedDiff

func UnifiedDiff(oldText, newText string) string

UnifiedDiff returns a small line-based unified diff between two byte slices. We avoid external deps by implementing a tiny LCS-based diff sufficient for human-readable config change review. The output is intentionally simple (no hunk headers, no line counts) — adequate for the admin UI which colors +/- lines.

Types

type Audit

type Audit struct{}

Audit records admin actions in SQLite.

func NewAudit

func NewAudit() *Audit

func (*Audit) List

func (a *Audit) List(limit int) ([]*model.AuditLog, error)

func (*Audit) Record

func (a *Audit) Record(action, summary, actor, clientIP, diff string) (*model.AuditLog, error)

Record records an action. If diff is non-empty, it is stored in AuditLog.Diff. The caller chooses what to put there: a unified diff (for config.save) or a JSON envelope with structured metadata (e.g. {"fromId":N,"toId":M} for config.restore).

type ConfigRevisionView

type ConfigRevisionView struct {
	ID        uint   `json:"id"`
	CreatedAt string `json:"createdAt"`
	Actor     string `json:"actor"`
	ClientIP  string `json:"clientIp"`
	Summary   string `json:"summary"`
	BytesSize int    `json:"bytesSize"`
}

ConfigRevisionView is the list-time projection of a ConfigRevision row.

func ToViews

func ToViews(rows []*model.ConfigRevision) []*ConfigRevisionView

type ConfigSchema

type ConfigSchema struct {
	SchemaVersion int         `json:"schemaVersion"`
	Groups        []*GroupDef `json:"groups"`
}

ConfigSchema is the UI-facing description of the config document.

func NewConfigSchema

func NewConfigSchema() *ConfigSchema

NewConfigSchema returns a static, pure description of the FileConfig shape. It does not load the file and has no side effects.

func (*ConfigSchema) FieldByPath

func (s *ConfigSchema) FieldByPath(p string) *FieldDef

FieldByPath returns the FieldDef for a given dotted path, or nil if not found.

type ConfigService

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

ConfigService reads/writes the server YAML file.

func NewConfigService

func NewConfigService(path string, reload *config.Manager) *ConfigService

func (*ConfigService) Document

func (s *ConfigService) Document(maskSecrets bool) (*config.FileConfig, error)

func (*ConfigService) Path

func (s *ConfigService) Path() string

func (*ConfigService) Raw

func (s *ConfigService) Raw() ([]byte, error)

func (*ConfigService) Restore

func (s *ConfigService) Restore(revID uint, in SaveRawInput) (*SaveRawResult, error)

Restore writes a historical revision's YAML back to disk, persisting a new revision row that records the lineage.

func (*ConfigService) Revisions

func (s *ConfigService) Revisions() *RevisionService

Revisions returns the revision service.

func (*ConfigService) SaveRaw

func (s *ConfigService) SaveRaw(in SaveRawInput) (*SaveRawResult, error)

SaveRaw atomically writes the YAML, persists a revision row, computes a unified diff (using the on-disk file BEFORE the save), and triggers the reload manager if present. The caller is responsible for writing the audit row.

type DomainView

type DomainView struct {
	SubDomain string `json:"subDomain"`
	ClientID  string `json:"clientId"`
}

type FieldDef

type FieldDef struct {
	Path        string          `json:"path"`
	Label       string          `json:"label"`
	Kind        SchemaFieldKind `json:"kind"`
	Required    bool            `json:"required,omitempty"`
	HelpText    string          `json:"helpText,omitempty"`
	Placeholder string          `json:"placeholder,omitempty"`
	Min         *int            `json:"min,omitempty"`
	Max         *int            `json:"max,omitempty"`
	EnumValues  []string        `json:"enumValues,omitempty"`
	Default     any             `json:"default,omitempty"`
	Item        *FieldDef       `json:"item,omitempty"`        // list<kind>
	ValueFields []*FieldDef     `json:"valueFields,omitempty"` // kvMap value fields
}

FieldDef describes a single field for the UI.

type GroupDef

type GroupDef struct {
	Key    string      `json:"key"`
	Label  string      `json:"label"`
	Path   string      `json:"path"`
	Kind   string      `json:"kind"` // "object" | "list" | "kvMap"
	Fields []*FieldDef `json:"fields"`
}

GroupDef describes a top-level config group rendered as a section.

type Monitor

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

Monitor provides read-only views of runtime state.

func NewMonitor

func NewMonitor(deps RuntimeDeps) *Monitor

func (*Monitor) AdminStatus added in v1.29.4

func (m *Monitor) AdminStatus() map[string]any

AdminStatus returns resolved admin console settings for read-only display.

func (*Monitor) Domains

func (m *Monitor) Domains() []DomainView

func (*Monitor) Overview

func (m *Monitor) Overview() map[string]any

func (*Monitor) Sessions

func (m *Monitor) Sessions() []SessionView

func (*Monitor) StatsByClient

func (m *Monitor) StatsByClient() map[string]map[string]any

func (*Monitor) StatsGlobal

func (m *Monitor) StatsGlobal() map[string]any

type RevisionService

type RevisionService struct{}

RevisionService manages ConfigRevision rows. It deliberately does not transact with the file write itself: the on-disk save is atomic (SaveRawAtomic), but the SQLite write and the file rename are not. On failure between the two, the next save will overwrite the orphan revision. See plan PR-2 §2.3 for the rationale.

func NewRevisionService

func NewRevisionService() *RevisionService

func (*RevisionService) Get

Get returns one revision by ID.

func (*RevisionService) List

func (s *RevisionService) List(limit int) ([]*model.ConfigRevision, error)

List returns the most recent N revisions, newest first.

func (*RevisionService) Save

func (s *RevisionService) Save(yamlText, summary, actor, clientIP string) (*model.ConfigRevision, error)

Save persists a new revision row with the given YAML. Returns the row.

type RuntimeDeps

type RuntimeDeps struct {
	Ctx           *types.Context
	Domain        string
	HTTPPort      int
	TCPPort       int
	Secure        bool
	ServerVersion string
	Started       time.Time
	ConfigPath    string
	ReloadManager *config.Manager
	Admin         *config.ResolvedAdmin
}

RuntimeDeps holds shared admin runtime dependencies.

type SaveRawInput

type SaveRawInput struct {
	Raw      []byte
	Summary  string
	Actor    string
	ClientIP string
}

SaveRawInput carries audit metadata for SaveRaw.

type SaveRawResult

type SaveRawResult struct {
	RevisionID uint
	Diff       string
}

SaveRawResult is the outcome of a save/restore.

type SchemaFieldKind

type SchemaFieldKind string

SchemaFieldKind describes the UI control to render for a field.

const (
	KindString   SchemaFieldKind = "string"
	KindInt      SchemaFieldKind = "int"
	KindPort     SchemaFieldKind = "port"
	KindBool     SchemaFieldKind = "bool"
	KindEnum     SchemaFieldKind = "enum"
	KindDuration SchemaFieldKind = "duration"
	KindSecret   SchemaFieldKind = "secret"
)

type SessionView

type SessionView struct {
	ContainerID    string   `json:"containerId"`
	ClientID       string   `json:"clientId"`
	Type           string   `json:"type"`
	AuthType       string   `json:"authType"`
	Version        string   `json:"version"`
	PublicEntry    string   `json:"publicEntry"`
	SourcePort     *int     `json:"sourcePort,omitempty"`
	UseNewProtocol bool     `json:"useNewProtocol"`
	ConfigIndex    *int     `json:"configIndex,omitempty"`
	ConfigMatch    string   `json:"configMatch"` // "exact" | "partial" | "missing" | ""
	MatchIssues    []string `json:"matchIssues,omitempty"`
}

Jump to

Keyboard shortcuts

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