searchrun

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package searchrun wires CLI flags and YAML config to host search and caching.

Index

Constants

View Source
const DefaultCacheTTL = 10 * time.Minute

DefaultCacheTTL is the product default time-to-live for host-discovery disk cache when neither CLI flags, API fields, nor config defaults.cache_ttl override it.

Variables

This section is empty.

Functions

func BuildProviders

func BuildProviders(cfg *config.File, overrides ProviderOverrides) []hosts.Backend

BuildProviders returns backends from the config file when it defines at least one backend entry; otherwise it requests the default backend from each registered provider.

func FirstNonEmpty added in v0.3.3

func FirstNonEmpty(vals ...string) string

FirstNonEmpty returns the first non-blank string from vals.

func GetBackendSliceByKind added in v0.2.8

func GetBackendSliceByKind(cfg *config.File, kind string) (reflect.Value, error)

GetBackendSliceByKind resolves cfg.Backends.<kind> as a reflect.Value slice.

func ListBackendRows added in v0.2.3

func ListBackendRows(cfg *config.File) []config.BackendRow

ListBackendRows queries all registered providers to build a list of configured backends.

func ListSearchProviderIDs added in v0.2.7

func ListSearchProviderIDs(overrides ProviderOverrides) []string

ListSearchProviderIDs returns hosts.Backend.ID() for each registered factory's default backend, in registration order (matches implicit providers when config has no backend entries).

func MergeDockerDiscover added in v0.3.0

func MergeDockerDiscover(defaults, override config.DockerDiscover) config.DockerDiscover

MergeDockerDiscover merges a backend-specific discover config over defaults.

func Register added in v0.2.3

func Register(f ProviderFactory)

Register adds a new provider factory to the registry. This is typically called from an init() function within each provider package.

func RegisterAllProviderFlags added in v0.3.3

func RegisterAllProviderFlags(cmd *cobra.Command)

RegisterAllProviderFlags calls RegisterFlags on each factory that implements FlagRegistrar.

func RegisterCRUD added in v0.2.6

func RegisterCRUD(c ProviderCRUD)

RegisterCRUD registers a ProviderCRUD implementation.

func RegisterDockerDiscover added in v0.3.0

func RegisterDockerDiscover(fn DockerDiscoverFunc)

RegisterDockerDiscover registers the docker auto-discover hook (from dockerprovider init).

func RegisteredBackendKinds added in v0.2.8

func RegisteredBackendKinds() []string

RegisteredBackendKinds returns registered backend YAML kind names, sorted.

func RunSearch

func RunSearch(
	ctx context.Context,
	q hosts.Query,
	provs []hosts.Backend,
	cacheDir string,
	cacheTTL time.Duration,
	noCache bool,
	refresh bool,
) ([]hosts.Record, error)

RunSearch executes hosts.RunParallel with an on-disk cache under cacheDir. If cacheDir is empty, hosts.DefaultCacheDir is used.

func WithDockerDiscover added in v0.3.0

func WithDockerDiscover(b hosts.Backend, d config.DockerDiscover) hosts.Backend

WithDockerDiscover wraps a backend to inject Docker auto-discover metadata into its records.

Types

type BackendConfigRegistry added in v0.2.8

type BackendConfigRegistry interface {
	BackendKind() string
	BackendSlicePtr(cfg *config.File) any
}

BackendConfigRegistry can be implemented by a ProviderFactory so backend CRUD handlers can locate the matching cfg.Backends.<kind> slice dynamically.

type ConfigReloader added in v0.3.3

type ConfigReloader interface {
	ReconfigureFromConfig(cfg *config.File)
}

ConfigReloader is optionally implemented by factories that hold provider-specific runtime state. ReconfigureFromConfig is called whenever the honey config is (re)loaded.

type DockerDiscoverFunc added in v0.3.0

type DockerDiscoverFunc func(ctx context.Context, q hosts.Query, vms []hosts.Record) ([]hosts.Record, error)

DockerDiscoverFunc lists containers on cloud VM records from a completed search pass.

type ExecutorProvider added in v0.3.3

type ExecutorProvider interface {
	// ProviderName returns the r.Provider value this factory owns.
	ProviderName() string
	// ExecutorFor returns the executor for r, or nil to fall through to SSH.
	ExecutorFor(r hosts.Record) hostexec.Executor
}

ExecutorProvider is optionally implemented by factories that provide a custom exec transport. The resolver routes records by ProviderName() before calling ExecutorFor, so ExecutorFor never needs to re-check the provider — only record-specific metadata (kind, etc.).

type FlagRegistrar added in v0.3.3

type FlagRegistrar interface {
	RegisterFlags(cmd *cobra.Command)
}

FlagRegistrar is optionally implemented by provider factories that expose CLI flags.

type ProviderCRUD added in v0.2.6

type ProviderCRUD interface {
	// ID returns the provider identifier (e.g. "gcp", "aws")
	ID() string
	// Name returns the human readable name (e.g. "GCP", "AWS")
	Name() string

	// ListOptions returns a list of huh options for the edit/delete menus
	ListOptions(cfg *config.File) []huh.Option[string]

	// Add runs the interactive prompt to add a new backend to the config
	Add(cfg *config.File) error
	// Edit runs the interactive prompt to edit an existing backend at the given index
	Edit(cfg *config.File, idx int) error
	// Delete removes the backend at the given index
	Delete(cfg *config.File, idx int) error
}

ProviderCRUD defines the interface for creating, editing, and deleting backends interactively.

func GetCRUDHandler added in v0.2.6

func GetCRUDHandler(id string) ProviderCRUD

GetCRUDHandler returns a specific ProviderCRUD implementation by ID.

func GetCRUDHandlers added in v0.2.6

func GetCRUDHandlers() []ProviderCRUD

GetCRUDHandlers returns all registered ProviderCRUD implementations.

type ProviderFactory added in v0.2.3

type ProviderFactory interface {
	// FromConfig returns a list of configured backends based on the user's YAML config.
	// overrides is an opaque map; each factory extracts its own key and deserializes its section.
	FromConfig(cfg *config.File, overrides ProviderOverrides) []hosts.Backend
	// Default returns a single backend instance using CLI flags / defaults when no config is provided.
	Default(overrides ProviderOverrides) hosts.Backend
	// BackendRows returns a summary of configured backends for listing purposes (e.g. `honey backends`).
	BackendRows(cfg *config.File) []config.BackendRow
}

ProviderFactory defines the interface that each backend provider must implement to register itself with the search engine.

type ProviderOverrides added in v0.3.3

type ProviderOverrides map[string]json.RawMessage

ProviderOverrides is an opaque map of provider key → raw JSON config override. Each factory knows its own key and unmarshals its own section — callers need not know what fields any provider accepts.

Jump to

Keyboard shortcuts

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