hosts

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 16 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 NameMatches

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

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

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.

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 only backends whose BackendName() matches one of want (case-insensitive). 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

	GCPProject string
	GCPZone    string

	AWSProfile string
	AWSRegion  string

	KubeContext   string
	K8sMode       string
	K8sDebugImage string

	ConsulAddr       string
	ConsulDatacenter string
	ConsulToken      string

	ProxmoxURL         string
	ProxmoxUser        string
	ProxmoxPassword    string
	ProxmoxTokenID     string
	ProxmoxTokenSecret string
	ProxmoxInsecure    bool
}

Query carries global and per-provider 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 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