hosts

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package hosts defines the host search record model and pluggable cloud backends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheKeySHA256

func CacheKeySHA256(providerID string, payload []byte) string

CacheKeySHA256 builds a stable cache key from provider id and payload.

func DedupeKey

func DedupeKey(h Record) string

DedupeKey returns a stable key for deduplication.

func DefaultCacheDir

func DefaultCacheDir() (string, error)

DefaultCacheDir returns XDG-style cache directory for honey.

func DefaultCacheKey

func DefaultCacheKey(p Backend, q Query) ([]byte, error)

DefaultCacheKey serializes query fields for caching per provider instance.

func ExternalIP added in v0.3.0

func ExternalIP(r Record) string

ExternalIP returns the VM's public/out-of-VPC address when present. GCP and AWS store it in ExtraIPs while PrimaryIP is the private address used for SSH.

func IsConnectableRecord added in v0.3.0

func IsConnectableRecord(r Record) bool

IsConnectableRecord reports whether honey can exec, upload, or open a terminal on r.

func IsDockerRecord added in v0.3.0

func IsDockerRecord(r Record) bool

IsDockerRecord reports whether r is a connectable Docker container or swarm task row.

func IsTrueNASAPIShellRecord added in v0.3.0

func IsTrueNASAPIShellRecord(r Record) bool

IsTrueNASAPIShellRecord reports whether r is a TrueNAS row that can use /websocket/shell (shape only; backend config is checked at runtime).

func MetaSSHIdentityFile added in v0.2.9

func MetaSSHIdentityFile(r *Record) (path string, ok bool)

MetaSSHIdentityFile returns the private key path from r.Meta["ssh_identity_file"] when set (recipe-level ssh_private_key applied by cue-exec; not inventory search meta).

func MetaSSHPort added in v0.2.9

func MetaSSHPort(r *Record) (port int, ok bool)

MetaSSHPort returns the TCP port from r.Meta["ssh_port"] when it is a valid decimal integer in 1..65535.

func NameMatches

func NameMatches(name string, q Query) (bool, error)

NameMatches applies NameSubstring, NameRegex, or accepts all if both empty.

func NodeDisplayIP added in v0.3.0

func NodeDisplayIP(r Record) string

NodeDisplayIP prefers ExternalIP for UI tables; falls back to PrimaryIP.

func ParseBackendNames

func ParseBackendNames(s string) []string

ParseBackendNames splits a comma-separated list of backend names (trimmed, lowercased). Empty input returns nil.

func ParseProviders

func ParseProviders(s string) []string

ParseProviders splits comma list; empty means all.

func PrimaryIPTrimmed added in v0.3.0

func PrimaryIPTrimmed(r Record) string

PrimaryIPTrimmed returns r.PrimaryIP with surrounding whitespace removed.

Types

type Backend

type Backend interface {
	ID() string
	// BackendName is an optional config label (YAML backends.*.name) used with --backends.
	// Empty for unnamed backends (e.g. default flag-only quartet).
	BackendName() string
	// CacheIdentity distinguishes multiple instances with the same ID() (e.g. two GCP projects).
	// May be empty when a single implicit backend is used.
	CacheIdentity() string
	Search(ctx context.Context, q Query) ([]Record, error)
}

Backend is implemented by each cloud integration.

func FilterBackendsByNames

func FilterBackendsByNames(provs []Backend, want []string) []Backend

FilterBackendsByNames keeps backends matching any token in want (case-insensitive). Tokens without ":" match BackendName() across all kinds (legacy --backends / URL behavior). Tokens with "kind:name" match a single YAML backend kind and name (e.g. truenas:prod, kubernetes:prod). Unnamed backends (BackendName() empty) are excluded when want is non-empty. When want is empty, provs is returned unchanged.

type CacheEntry

type CacheEntry struct {
	StoredAt time.Time `json:"stored_at"`
	Records  []Record  `json:"records"`
}

CacheEntry is a single cached provider result.

type FileCache

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

FileCache is a simple JSON file cache with TTL.

func NewFileCache

func NewFileCache(path string, ttl time.Duration) *FileCache

NewFileCache creates a JSON-backed cache at path with ttl.

func (*FileCache) Get

func (c *FileCache) Get(cacheKey string) ([]Record, bool, error)

Get returns records and true if fresh.

func (*FileCache) Set

func (c *FileCache) Set(cacheKey string, records []Record) error

Set stores records for key.

type Query

type Query struct {
	NameSubstring string
	NameRegex     string
	Providers     []string // e.g. gcp, aws, k8s, consul — empty means all
}

Query carries global search filters for a search run.

type Record

type Record struct {
	Provider  string            `json:"provider"`
	Name      string            `json:"name"`
	PrimaryIP string            `json:"primary_ip"`
	ExtraIPs  []string          `json:"extra_ips,omitempty"`
	Zone      string            `json:"zone,omitempty"`
	Region    string            `json:"region,omitempty"`
	Meta      map[string]string `json:"meta,omitempty"`
}

Record is a normalized host across cloud providers.

func CloneWithMetaSSHIdentityFile added in v0.2.9

func CloneWithMetaSSHIdentityFile(r Record, path string) Record

CloneWithMetaSSHIdentityFile returns a shallow copy of r with meta["ssh_identity_file"] set.

func CloneWithMetaSSHPort added in v0.2.9

func CloneWithMetaSSHPort(r Record, port int) Record

CloneWithMetaSSHPort returns a shallow copy of r with meta["ssh_port"] set to the decimal string for port (used by cue-exec to apply recipe-level ports).

func MergeDedupe

func MergeDedupe(slices ...[]Record) []Record

MergeDedupe merges slices and removes exact duplicates by DedupeKey.

func RunParallel

func RunParallel(
	ctx context.Context,
	q Query,
	provs []Backend,
	fc *FileCache,
	noCache bool,
	refresh bool,
	cacheKeyFn func(p Backend, q Query) ([]byte, error),
) ([]Record, error)

RunParallel executes enabled providers in parallel with optional disk cache.

Jump to

Keyboard shortcuts

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