autoconf

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package autoconf provides environment detection for automatic workspace configuration.

Index

Constants

This section is empty.

Variables

View Source
var ErrSkipped = errors.New("skipped")

ErrSkipped may be returned by Options.SelectTarget to signal that the user chose not to add the secret to any configuration target.

Functions

This section is empty.

Types

type Autoconf

type Autoconf interface {
	Run(out io.Writer) error
}

Autoconf orchestrates secret detection and application: it scans the environment, prompts for confirmation, creates secrets, and records their references in the chosen configuration target.

func New

func New(opts Options) Autoconf

New returns an Autoconf configured by opts.

type ConfigTarget

type ConfigTarget int

ConfigTarget identifies where a detected secret's reference is recorded.

const (
	// ConfigTargetGlobal records the secret in the global entry of projects.json
	// (applies to all projects).
	ConfigTargetGlobal ConfigTarget = iota
	// ConfigTargetProject records the secret in the project-specific entry of
	// projects.json (keyed by the computed project ID for the current directory).
	ConfigTargetProject
	// ConfigTargetLocal records the secret in the local .kaiden/workspace.json.
	ConfigTargetLocal
)

type ConfigTargetOption

type ConfigTargetOption struct {
	Target ConfigTarget
	Label  string
}

ConfigTargetOption pairs a ConfigTarget with a human-readable label for display in selection prompts.

type ConfiguredSecret

type ConfiguredSecret struct {
	DetectedSecret
	// Locations lists every config source where the secret is referenced.
	Locations []ConfigTarget
}

ConfiguredSecret is a detected secret that is already fully set up — present in the store and referenced in at least one configuration source.

type DetectedSecret

type DetectedSecret struct {
	ServiceName string
	EnvVarName  string
	Value       string
}

DetectedSecret represents a secret found in the environment for a specific service.

type FilterResult

type FilterResult struct {
	// NeedsAction contains secrets that are missing from the store or from every
	// known config source and therefore require user action.
	NeedsAction []DetectedSecret
	// Configured contains secrets that are already fully set up. Each entry
	// includes the locations where the secret is referenced.
	Configured []ConfiguredSecret
}

FilterResult is the output of SecretFilter.Filter.

type Options

type Options struct {
	Detector SecretDetector
	Store    secret.Store

	// ProjectUpdater writes to ~/.kdn/config/projects.json.
	ProjectUpdater config.ProjectConfigUpdater
	// WorkspaceUpdater writes to .kaiden/workspace.json in the current directory.
	// When nil the local target is not offered to the user. When non-nil the file
	// is created automatically if the user selects the local target.
	WorkspaceUpdater config.WorkspaceConfigUpdater
	// ProjectID is the project identifier for the current working directory,
	// used when the user selects ConfigTargetProject.
	ProjectID string

	Yes bool

	// Confirm is called (once per secret) to ask whether to create it.
	// Returning false skips the secret entirely.
	Confirm func(prompt string) (bool, error)

	// SelectTarget is called after a secret is created to ask where to record
	// the reference. It may return ErrSkipped to skip adding to any config.
	// Not called when Yes is true (defaults to ConfigTargetGlobal).
	SelectTarget func(secretName string, options []ConfigTargetOption) (ConfigTarget, error)
}

Options configures an Autoconf runner.

type SecretDetector

type SecretDetector interface {
	Detect() (FilterResult, error)
}

SecretDetector scans the environment for secrets belonging to registered services. Detect takes no parameters — services are provided at construction time so that this interface stays consistent with future detectors (language, config-dir, etc.) that also own their own data sources. When the detector was created with NewFilteredSecretDetector, fully-configured secrets are returned in FilterResult.Configured so callers can display their status.

func NewFilteredSecretDetector

func NewFilteredSecretDetector(
	services []secretservice.SecretService,
	store secret.Store,
	loader config.ProjectConfigLoader,
	projectID string,
	workspaceConfig config.Config,
) SecretDetector

NewFilteredSecretDetector returns a SecretDetector that reads from the process environment and removes secrets that are already stored and referenced in any configuration source — callers receive only secrets that require action. projectID is the computed project identifier for the current directory; workspaceConfig is optional and covers the local .kaiden/workspace.json.

func NewSecretDetector

func NewSecretDetector(services []secretservice.SecretService) SecretDetector

NewSecretDetector returns a SecretDetector that reads from the process environment without any filtering of already-configured secrets.

type SecretFilter

type SecretFilter interface {
	Filter(detected []DetectedSecret) (FilterResult, error)
}

SecretFilter classifies DetectedSecrets into those needing action and those already fully configured.

func NewAlreadyConfiguredFilter

func NewAlreadyConfiguredFilter(
	store secret.Store,
	loader config.ProjectConfigLoader,
	projectID string,
	workspaceConfig config.Config,
) SecretFilter

NewAlreadyConfiguredFilter returns a SecretFilter that classifies secrets across all configuration sources. loader.Load("") covers the global config; loader.Load(projectID) covers global + project-specific merged, from which project-specific secrets are derived. workspaceConfig is optional and covers .kaiden/workspace.json.

Jump to

Keyboard shortcuts

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