config

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package config loads optional YAML settings and backend definitions for honey.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildJSONSchema added in v0.2.8

func BuildJSONSchema() map[string]any

BuildJSONSchema returns a JSON Schema payload generated from the UI schema.

func DefaultPluginsDir added in v0.2.9

func DefaultPluginsDir() string

DefaultPluginsDir returns ~/.config/honey/plugins (or XDG_CONFIG_HOME/honey/plugins).

func DefaultRecipesDirs added in v0.2.6

func DefaultRecipesDirs() []string

DefaultRecipesDirs returns the list of directories to check for default CUE recipes.

func DefaultRecordDir added in v0.2.8

func DefaultRecordDir(configPath string) string

DefaultRecordDir returns the directory used for session recordings when --record-dir is not set: <directory of config.yaml>/records (e.g. ~/.config/honey/records). If configPath is empty, returns the conventional honey config directory (.../honey/records) matching default config.yaml search paths.

func ListDefaultRecipes added in v0.2.6

func ListDefaultRecipes() []string

ListDefaultRecipes returns a list of absolute paths to all .cue files found in the default recipe directories.

func ParseBytes added in v0.2.8

func ParseBytes(s string) (int64, error)

ParseBytes converts a size string ("5GiB", "64MiB", "1024") into bytes. Accepted suffixes (case-insensitive): KiB, MiB, GiB, TiB. Bare integers are taken as bytes. Fractional values and SI suffixes (KB, MB, …) are rejected.

func ParseRetentionDuration added in v0.3.0

func ParseRetentionDuration(s string) (time.Duration, error)

ParseRetentionDuration parses a retention duration (supports Go durations and day suffix, e.g. 30d).

func ResolvePath

func ResolvePath(explicit string) (string, error)

ResolvePath returns an explicit path from --config or HONEY_CONFIG then the first existing default file, or "" if none exist.

func ResolveRecordDir added in v0.2.8

func ResolveRecordDir(cfg *File, configPath string, recordDirFlag string, recordDirFlagChanged bool) string

ResolveRecordDir returns the session recordings directory (CLI TUI, web server, cue-exec). Precedence when recordDirFlagChanged is true: non-empty global --record-dir value, otherwise DefaultRecordDir(configPath) (explicit empty flag keeps the default path). When recordDirFlagChanged is false: defaults.record_dir from cfg if set, otherwise DefaultRecordDir(configPath).

Types

type AWSBackend

type AWSBackend struct {
	Name           string         `yaml:"name" json:"name" honey:"label=Name" validate:"required"`
	Profile        string         `yaml:"profile" json:"profile" honey:"label=Profile" validate:"required"`
	Region         string         `yaml:"region" json:"region" honey:"label=Region"`
	DockerDiscover DockerDiscover `yaml:"docker_discover,omitempty" json:"docker_discover,omitempty" honey:"label=Docker Auto-Discover"`
}

AWSBackend configures one Amazon EC2 listing.

type BackendRow

type BackendRow struct {
	Kind string `json:"kind"`
	Name string `json:"name,omitempty"`
	Hint string `json:"hint,omitempty"`
}

BackendRow describes one YAML backends.* entry (for CLI / MCP listing).

type BackendSchema added in v0.2.8

type BackendSchema struct {
	Label  string        `json:"label"`
	Fields []SchemaField `json:"fields"`
}

BackendSchema describes one backend kind and its field layout.

type Backends

type Backends struct {
	GCP        []GCPBackend        `yaml:"gcp" json:"gcp" honey:"label=Google Cloud;order=10" validate:"dive"`
	AWS        []AWSBackend        `yaml:"aws" json:"aws" honey:"label=AWS;order=20" validate:"dive"`
	Kubernetes []KubernetesBackend `yaml:"kubernetes" json:"kubernetes" honey:"label=Kubernetes;order=30" validate:"dive"`
	Consul     []ConsulBackend     `yaml:"consul" json:"consul" honey:"label=Consul;order=40" validate:"dive"`
	Proxmox    []ProxmoxBackend    `yaml:"proxmox" json:"proxmox" honey:"label=Proxmox;order=50" validate:"dive"`
	TrueNAS    []TrueNASBackend    `yaml:"truenas" json:"truenas" honey:"label=TrueNAS;order=55" validate:"dive"`
	Local      []LocalBackend      `yaml:"local" json:"local" honey:"label=Local;order=60" validate:"dive"`
	Docker     []DockerBackend     `yaml:"docker" json:"docker" honey:"label=Docker;order=35" validate:"dive"`
}

Backends lists optional multiple instances per provider type. If a slice is nil or omitted, that provider is not defined by the file (use CLI defaults). If a slice is non-empty, one backend is created per element.

type ConsulBackend

type ConsulBackend struct {
	Name           string         `yaml:"name" json:"name" honey:"label=Name" validate:"required"`
	Addr           string         `yaml:"addr" json:"addr" honey:"label=Address" validate:"required,url"`
	Datacenter     string         `yaml:"datacenter" json:"datacenter" honey:"label=Datacenter"`
	Token          string         `yaml:"token" json:"token" honey:"label=Token;secret"`
	DockerDiscover DockerDiscover `yaml:"docker_discover,omitempty" json:"docker_discover,omitempty" honey:"label=Docker Auto-Discover"`
}

ConsulBackend configures one HashiCorp Consul catalog listing.

type Defaults

type Defaults struct {
	SSHUser         string         `yaml:"ssh_user" json:"ssh_user" honey:"label=SSH user"`
	CacheTTL        string         `yaml:"cache_ttl" json:"cache_ttl" honey:"label=Cache TTL"` // e.g. "5m", "1h"
	K8sMode         string         `yaml:"k8s_mode" json:"k8s_mode" honey:"label=Kubernetes mode;enum=nodes|pods;enum_as_warning"`
	K8sDebugImage   string         `yaml:"k8s_debug_image" json:"k8s_debug_image" honey:"label=Kubernetes debug image"`
	CacheDir        string         `yaml:"cache_dir" json:"cache_dir" honey:"label=Cache directory"`
	RecordDir       string         `yaml:"record_dir" json:"record_dir" honey:"label=Session recordings directory"`
	RecordRetention string         ``                                                                                     /* 133-byte string literal not displayed */
	Output          string         `yaml:"output" json:"output" honey:"label=Output;enum=table|json|tui;enum_as_warning"` // e.g. "table", "json", "tui" (default)
	Name            string         `yaml:"name" json:"name" honey:"label=Name filter"`
	NameRegex       string         `yaml:"name_regex" json:"name_regex" honey:"label=Name regex"`
	AISystemPrompt  string         `yaml:"ai_system_prompt" json:"ai_system_prompt" honey:"label=Default system prompt for CUE recipe ai step"`
	DockerDiscover  DockerDiscover `yaml:"docker_discover,omitempty" json:"docker_discover,omitempty" honey:"label=Docker Auto-Discover Defaults"`

	// secretsprovider unwraps the stack AES data key (see internal/cuetry/secrets/doc.go).
	// Examples: gcpkms://projects/…/cryptoKeys/…, awskms://, vault-transit://mount/key,
	// k8s://namespace/secret, keyring://service/user, age://, age-file://path.
	SecretsProvider string `` /* 135-byte string literal not displayed */
	// encryptedkey is provider-specific ciphertext or field name (see secrets package doc).
	EncryptedKey string `yaml:"encryptedkey,omitempty" json:"encryptedkey,omitempty" honey:"label=Stack encrypted data key blob;secret;reserved"`
}

Defaults apply when CLI flags are unset.

func (Defaults) DefaultsCacheTTL

func (d Defaults) DefaultsCacheTTL() (time.Duration, bool, error)

DefaultsCacheTTL parses Defaults.CacheTTL or returns empty and ok=false.

func (Defaults) DefaultsRecordRetention added in v0.3.0

func (d Defaults) DefaultsRecordRetention() (time.Duration, bool, error)

DefaultsRecordRetention parses Defaults.RecordRetention or returns empty and ok=false.

type DockerBackend added in v0.3.0

type DockerBackend struct {
	Name          string       `yaml:"name" json:"name" honey:"label=Name" validate:"required"`
	Host          string       `yaml:"host" json:"host" honey:"label=Host (unix://, tcp://, ssh://; empty = DOCKER_HOST / local socket)"`
	ViaLocal      string       `yaml:"via_local,omitempty" json:"via_local,omitempty" honey:"label=Local backend name (SSH hop via backends.local)"`
	ViaSSH        DockerViaSSH `yaml:"via_ssh,omitempty" json:"via_ssh,omitempty" honey:"label=SSH hop (overrides via_local when host set)"`
	Socket        string       `yaml:"socket,omitempty" json:"socket,omitempty" honey:"label=Remote Engine socket (default /var/run/docker.sock on linux)"`
	Platform      string       `yaml:"platform,omitempty" json:"platform,omitempty" honey:"label=Remote OS;enum=linux|windows;enum_as_warning;default=linux"`
	RunAs         string       `yaml:"run_as,omitempty" json:"run_as,omitempty" honey:"label=Remote user for docker.sock via sudo (honey-ssh only)"`
	Mode          string       `yaml:"mode" json:"mode" honey:"label=Mode;enum=containers|swarm|both;enum_as_warning;default=containers"`
	AllContainers bool         `yaml:"all_containers" json:"all_containers" honey:"label=Include stopped containers;default=false"`
	TLSVerify     bool         `yaml:"tls_verify" json:"tls_verify" honey:"label=Verify TLS (tcp hosts);default=true"`
	CACert        string       `yaml:"ca_cert" json:"ca_cert" honey:"label=CA certificate path"`
	Cert          string       `yaml:"cert" json:"cert" honey:"label=Client certificate path"`
	Key           string       `yaml:"key" json:"key" honey:"label=Client key path;secret"`
}

DockerBackend configures one Docker Engine API endpoint (local socket, tcp, ssh://, or Honey SSH).

type DockerDiscover added in v0.3.0

type DockerDiscover struct {
	Enabled  bool   `yaml:"enabled" json:"enabled" honey:"label=Enable auto-discover"`
	RunAs    string `yaml:"run_as,omitempty" json:"run_as,omitempty" honey:"label=Remote user for docker.sock via sudo (e.g. root)"`
	Socket   string `yaml:"socket,omitempty" json:"socket,omitempty" honey:"label=Remote Docker socket"`
	Platform string `yaml:"platform,omitempty" json:"platform,omitempty" honey:"label=Remote OS;enum=linux|windows"`
}

DockerDiscover configures auto-discovery of containers on cloud VMs.

type DockerViaSSH added in v0.3.0

type DockerViaSSH struct {
	Host         string `yaml:"host" json:"host" honey:"label=SSH host"`
	Port         int    `yaml:"port,omitempty" json:"port,omitempty" honey:"label=SSH port (0 = ssh_config default)"`
	User         string `yaml:"user,omitempty" json:"user,omitempty" honey:"label=SSH user"`
	IdentityFile string `yaml:"identity_file,omitempty" json:"identity_file,omitempty" honey:"label=SSH identity file"`
}

DockerViaSSH configures an explicit SSH hop for Honey's SSH stack (not Moby ssh://).

type File

type File struct {
	Version  int            `yaml:"version" json:"version"`
	Defaults Defaults       `yaml:"defaults" json:"defaults"`
	Backends Backends       `yaml:"backends" json:"backends"`
	Transfer TransferConfig `yaml:"transfer" json:"transfer"`
	Plugins  Plugins        `yaml:"plugins,omitempty" json:"plugins,omitempty"`
}

File is the optional honey YAML configuration.

func Load

func Load(path string) (*File, error)

Load reads and parses a YAML config file.

func ParseYAML added in v0.2.7

func ParseYAML(b []byte) (*File, error)

ParseYAML parses a honey config document from memory (used by web API PUT validation).

func (*File) HasAnyBackend

func (f *File) HasAnyBackend() bool

HasAnyBackend returns true if the file defines at least one backend entry.

func (*File) Save added in v0.2.6

func (f *File) Save(path string) error

Save serializes the config and writes it to path.

func (*File) Validate added in v0.2.9

func (f *File) Validate() error

Validate checks the configuration struct recursively according to validate tags.

type GCPBackend

type GCPBackend struct {
	Name           string         `yaml:"name" json:"name" honey:"label=Name" validate:"required"`
	Project        string         `yaml:"project" json:"project" honey:"label=Project" validate:"required"`
	Zone           string         `yaml:"zone" json:"zone" honey:"label=Zone"`
	DockerDiscover DockerDiscover `yaml:"docker_discover,omitempty" json:"docker_discover,omitempty" honey:"label=Docker Auto-Discover"`
}

GCPBackend configures one Google Cloud Compute Engine listing.

type KubernetesBackend

type KubernetesBackend struct {
	Name       string `yaml:"name" json:"name" honey:"label=Name" validate:"required"`
	Context    string `yaml:"context" json:"context" honey:"label=Context"`
	Kubeconfig string `yaml:"kubeconfig" json:"kubeconfig" honey:"label=Kubeconfig path"`
	Mode       string `yaml:"mode" json:"mode" honey:"label=Mode;enum=nodes|pods;enum_as_warning;default=nodes"`
	DebugImage string `yaml:"debug_image" json:"debug_image" honey:"label=Debug image"`
}

KubernetesBackend configures one Kubernetes nodes/pods listing.

type LocalBackend added in v0.2.9

type LocalBackend struct {
	Name           string         `yaml:"name" json:"name" honey:"label=Name" validate:"required"`
	Hosts          []LocalHost    `yaml:"hosts" json:"hosts" honey:"label=Hosts" validate:"dive"`
	DockerDiscover DockerDiscover `yaml:"docker_discover,omitempty" json:"docker_discover,omitempty" honey:"label=Docker Auto-Discover"`
}

LocalBackend configures manually defined host lists.

type LocalHost added in v0.2.9

type LocalHost struct {
	Name      string            `yaml:"name" json:"name" honey:"label=Name" validate:"required"`
	PrimaryIP string            `yaml:"primary_ip" json:"primary_ip" honey:"label=Primary IP" validate:"required,ip"`
	ExtraIPs  []string          `yaml:"extra_ips,omitempty" json:"extra_ips,omitempty" honey:"label=Extra IPs" validate:"dive,ip"`
	Zone      string            `yaml:"zone,omitempty" json:"zone,omitempty" honey:"label=Zone"`
	Region    string            `yaml:"region,omitempty" json:"region,omitempty" honey:"label=Region"`
	Meta      map[string]string `yaml:"meta,omitempty" json:"meta,omitempty" honey:"label=Metadata"`
}

LocalHost represents a manually defined static server.

type Plugins added in v0.2.9

type Plugins struct {
	Enabled           *bool    `yaml:"enabled,omitempty" json:"enabled,omitempty"`
	Directory         string   `yaml:"directory,omitempty" json:"directory,omitempty"`
	Allowlist         []string `yaml:"allowlist,omitempty" json:"allowlist,omitempty"`
	MaxMemoryMB       int      `yaml:"max_memory_mb,omitempty" json:"max_memory_mb,omitempty"`
	TimeoutMS         int      `yaml:"timeout_ms,omitempty" json:"timeout_ms,omitempty"`
	NetworkDeny       *bool    `yaml:"network_deny,omitempty" json:"network_deny,omitempty"`
	NetworkAllowHosts []string `yaml:"network_allow_hosts,omitempty" json:"network_allow_hosts,omitempty"`
}

Plugins configures WASM plugins loaded from disk (Extism).

func (Plugins) WithDefaults added in v0.2.9

func (p Plugins) WithDefaults() PluginsEffective

WithDefaults returns effective plugin settings (plugins disabled unless explicitly enabled).

type PluginsEffective added in v0.2.9

type PluginsEffective struct {
	Enabled           bool
	Directory         string
	Allowlist         []string
	MaxMemoryMB       int
	TimeoutMS         int
	NetworkDeny       bool
	NetworkAllowHosts []string
}

PluginsEffective holds resolved plugin settings for runtime.

type ProxmoxBackend added in v0.2.3

type ProxmoxBackend struct {
	Name           string         `yaml:"name" json:"name" honey:"label=Name" validate:"required"`
	URL            string         `yaml:"url" json:"url" honey:"label=URL" validate:"required,url"`
	User           string         `yaml:"user" json:"user" honey:"label=User" validate:"required_without=TokenID"`
	Password       string         `yaml:"password" json:"password" honey:"label=Password;secret" validate:"required_without=TokenSecret"`
	TokenID        string         `yaml:"token_id" json:"token_id" honey:"label=Token ID" validate:"required_without=User"`
	TokenSecret    string         `yaml:"token_secret" json:"token_secret" honey:"label=Token secret;secret" validate:"required_without=Password"`
	Insecure       bool           `yaml:"insecure" json:"insecure" honey:"label=Insecure TLS;default=false"`
	ExecMode       string         `yaml:"exec_mode" json:"exec_mode" honey:"label=Exec mode;enum=ssh|pve|hybrid;enum_as_warning"`
	DockerDiscover DockerDiscover `yaml:"docker_discover,omitempty" json:"docker_discover,omitempty" honey:"label=Docker Auto-Discover"`
}

ProxmoxBackend configures one Proxmox VE listing.

type SchemaField added in v0.2.8

type SchemaField struct {
	Key           string          `json:"key"`
	Label         string          `json:"label"`
	Type          SchemaFieldType `json:"type"`
	Format        string          `json:"format,omitempty"` // "ip", "url", etc.
	Required      bool            `json:"required,omitempty"`
	Secret        bool            `json:"secret,omitempty"`
	Enum          []string        `json:"enum,omitempty"`
	EnumAsWarning bool            `json:"enum_as_warning,omitempty"`
	Default       any             `json:"default,omitempty"`
	Items         []SchemaField   `json:"items,omitempty"` // For nested array of objects
}

SchemaField describes one editable key in defaults/backends schema.

type SchemaFieldType added in v0.2.8

type SchemaFieldType string

SchemaFieldType describes supported primitive config field kinds.

const (
	SchemaFieldTypeString  SchemaFieldType = "string"
	SchemaFieldTypeBoolean SchemaFieldType = "boolean"
	SchemaFieldTypeInteger SchemaFieldType = "integer"
	SchemaFieldTypeArray   SchemaFieldType = "array"
	SchemaFieldTypeObject  SchemaFieldType = "object"
)

Primitive field kinds for defaults/backends schema and JSON Schema "type".

type TransferConfig added in v0.2.8

type TransferConfig struct {
	PresignedMaxSize        string `yaml:"presigned_max_size,omitempty" json:"presigned_max_size,omitempty"`
	MultipartThreshold      string `yaml:"multipart_threshold,omitempty" json:"multipart_threshold,omitempty"`
	PresignedURLTTL         string `yaml:"presigned_url_ttl,omitempty" json:"presigned_url_ttl,omitempty"`
	PresignedRetryWithAgent *bool  `yaml:"presigned_retry_with_agent,omitempty" json:"presigned_retry_with_agent,omitempty"`
	ForceAgentPath          bool   `yaml:"force_agent_path,omitempty" json:"force_agent_path,omitempty"`
}

TransferConfig controls the agent-transfer code path. Zero values mean "use defaults" — call WithDefaults() to materialize.

func (TransferConfig) WithDefaults added in v0.2.8

func (c TransferConfig) WithDefaults() TransferConfigEffective

WithDefaults returns an effective config, parsing strings to bytes / durations and substituting defaults for unset fields.

type TransferConfigEffective added in v0.2.8

type TransferConfigEffective struct {
	PresignedMaxSizeBytes   int64
	MultipartThresholdBytes int64
	PresignedURLTTL         time.Duration
	PresignedRetryWithAgent bool
	ForceAgentPath          bool
}

TransferConfigEffective is the post-defaults form used by callers.

type TrueNASBackend added in v0.3.0

type TrueNASBackend struct {
	Name             string `yaml:"name" json:"name" honey:"label=Name" validate:"required"`
	URL              string `yaml:"url" json:"url" honey:"label=URL" validate:"required,url"`
	Username         string `yaml:"username,omitempty" json:"username,omitempty" honey:"label=API key username (default root)"`
	APIKey           string `yaml:"api_key" json:"api_key" honey:"label=API key;secret" validate:"required"`
	Insecure         bool   `yaml:"insecure" json:"insecure" honey:"label=Insecure TLS;default=false"`
	IncludeAppliance *bool  `yaml:"include_appliance,omitempty" json:"include_appliance,omitempty" honey:"label=List appliance;default=true"`
	IncludeVMs       *bool  `yaml:"include_vms,omitempty" json:"include_vms,omitempty" honey:"label=List KVM VMs;default=true"`
	IncludeVirt      *bool  `yaml:"include_virt,omitempty" json:"include_virt,omitempty" honey:"label=List virt instances;default=true"`
	SSHUser          string `yaml:"ssh_user,omitempty" json:"ssh_user,omitempty" honey:"label=SSH user for appliance"`
}

TrueNASBackend configures one TrueNAS SCALE controller (WebSocket API 25.04+).

type UISchema added in v0.2.8

type UISchema struct {
	TopLevelKeys []string                 `json:"top_level_keys"`
	Defaults     []SchemaField            `json:"defaults"`
	Backends     map[string]BackendSchema `json:"backends"`
	BackendOrder []string                 `json:"backend_order"`
}

UISchema is the lightweight UI-focused schema payload.

func BuildUISchema added in v0.2.8

func BuildUISchema() UISchema

BuildUISchema returns the lightweight schema used by web UI rendering and linting.

type ValidationError added in v0.2.9

type ValidationError struct {
	Path    string `json:"path"`
	Message string `json:"message"`
}

ValidationError represents a single field validation error.

type ValidationErrors added in v0.2.9

type ValidationErrors []ValidationError

ValidationErrors is a slice of ValidationError that serializes to JSON.

func (ValidationErrors) Error added in v0.2.9

func (e ValidationErrors) Error() string

Jump to

Keyboard shortcuts

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