component

package
v0.16.3 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReportFormatSection = "section"
	ReportFormatTable   = "table"
	ReportFormatJSON    = "json"
	ReportFormatYAML    = "yaml"
)
View Source
const DefaultDrupalRootfs = "."

Variables

View Source
var ErrActionCancelled = errors.New("component action cancelled")

Functions

func AddCreateFlags

func AddCreateFlags(cmd *cobra.Command, options ...CreateOption)

func AddDrupalRootfsFlag

func AddDrupalRootfsFlag(cmd *cobra.Command, target *string, defaultValue string)

func AddReportFlags added in v0.7.0

func AddReportFlags(cmd *cobra.Command, verboseTarget *bool, formatTarget *string)

func AddReviewFlags added in v0.7.0

func AddReviewFlags(cmd *cobra.Command, reportTarget, verboseTarget *bool, formatTarget *string)

func BuildReviewQuestion added in v0.7.0

func BuildReviewQuestion(view ReviewView) string

func DriftCheckLines added in v0.7.0

func DriftCheckLines(view ReviewView) []string

func ParseStateOverrides

func ParseStateOverrides(values map[string]string) (map[string]State, error)

func PromptChoice added in v0.6.1

func PromptChoice(name string, choices []Choice, defaultValue string, input InputFunc, sections ...string) (string, error)

func PromptCreateFollowUps added in v0.8.0

func PromptCreateFollowUps(cmd *cobra.Command, option CreateOption, decision *ReviewDecision, input InputFunc) error

func PromptDeclaredReviewFollowUps added in v0.8.0

func PromptDeclaredReviewFollowUps(view ReviewView, decision *ReviewDecision, input InputFunc, promptChoice PromptChoiceFunc) error

func PromptFollowUp added in v0.8.0

func PromptFollowUp(componentName string, spec FollowUpSpec, defaultValue string, input InputFunc, promptChoice PromptChoiceFunc) (string, error)

func RenderChecklistItem added in v0.6.0

func RenderChecklistItem(label, state, detail string) string

func RenderCommandBlock added in v0.6.0

func RenderCommandBlock(text string) string

func RenderComponentStatus added in v0.7.0

func RenderComponentStatus(view ReviewView) string

func RenderConfiguredFollowUps added in v0.8.0

func RenderConfiguredFollowUps(view ReviewView) []string

func RenderCurrentGuidance added in v0.7.0

func RenderCurrentGuidance(view ReviewView) string

func RenderDecisionFollowUps added in v0.8.0

func RenderDecisionFollowUps(def Definition, decision ReviewDecision) string

func RenderFollowUpSection added in v0.8.0

func RenderFollowUpSection(componentName string, spec FollowUpSpec) string

func RenderIntroSection added in v0.5.4

func RenderIntroSection(title, body string) string

func RenderMigrationImpact added in v0.7.0

func RenderMigrationImpact(migration DataMigrationRequirement) string

func RenderPromptLine added in v0.5.4

func RenderPromptLine(text string) string

func RenderReviewSummary added in v0.7.0

func RenderReviewSummary(views []ReviewView, decisions map[string]ReviewDecision, summaryLine SummaryLineFunc) (string, error)

func RenderSection added in v0.5.4

func RenderSection(title, body string) string

func RenderTransitionSummary added in v0.7.0

func RenderTransitionSummary(behavior TransitionBehavior) string

func ResolveCreateDecisions added in v0.8.0

func ResolveCreateDecisions(cmd *cobra.Command, input InputFunc, options ...CreateOption) (map[string]ReviewDecision, error)

func ResolveCreateStates

func ResolveCreateStates(cmd *cobra.Command, input InputFunc, options ...CreateOption) (map[string]State, error)

func RunReview added in v0.7.0

func RunReview(views []ReviewView, opts ReviewOptions) (map[string]ReviewDecision, error)

func WriteComponentStatusReport added in v0.7.0

func WriteComponentStatusReport(out io.Writer, views []ReviewView, verbose bool) error

func WriteComponentStatusReportWithFormat added in v0.7.0

func WriteComponentStatusReportWithFormat(out io.Writer, views []ReviewView, verbose bool, format string) error

func WriteDriftDetails added in v0.7.0

func WriteDriftDetails(out io.Writer, status ComponentStatus)

Types

type ApplyOptions

type ApplyOptions struct {
	Yolo bool

	// AutoApprove is kept for compatibility with earlier callers.
	AutoApprove bool
	Confirm     func(prompt string) (bool, error)
}

type Behavior

type Behavior struct {
	Idempotent bool
	Enable     TransitionBehavior
	Disable    TransitionBehavior
}

type Choice added in v0.6.1

type Choice struct {
	Value            string
	Label            string
	Help             string
	Aliases          []string
	AllowCustomInput bool
}

type Component

type Component interface {
	Name() string
	DefaultState() State
	SpecFor(state State) ComponentSpec
}

type ComponentSpec

type ComponentSpec struct {
	Name          string
	Gates         GateSpec
	Compose       ComposeSpec
	Drupal        DrupalSpec
	BeforeDisable []Hook
	AfterDisable  []Hook
	BeforeEnable  []Hook
	AfterEnable   []Hook
}

type ComponentStatus

type ComponentStatus struct {
	Name  string
	State DetectedState
	On    StateCheck
	Off   StateCheck
}

func DetectComponentStatus

func DetectComponentStatus(ctx *config.Context, projectRoot string, def Definition, opts DetectOptions) (ComponentStatus, error)

func DetectComponentStatuses

func DetectComponentStatuses(ctx *config.Context, projectRoot string, opts DetectOptions, defs ...Definition) ([]ComponentStatus, error)

type ComposeDefinitions

type ComposeDefinitions struct {
	Services map[string]any
	Networks map[string]any
	Volumes  map[string]any
	Secrets  map[string]any
	Configs  map[string]any
}

func ParseComposeDefinitions

func ParseComposeDefinitions(data []byte) (*ComposeDefinitions, error)

func (*ComposeDefinitions) Definition added in v0.10.0

func (d *ComposeDefinitions) Definition(section, name string) (any, bool)

type ComposeFile

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

func LoadComposeFile

func LoadComposeFile(path string) (*ComposeFile, error)

func LoadComposeFileOptional added in v0.9.2

func LoadComposeFileOptional(path string) (*ComposeFile, error)

func (*ComposeFile) AddSectionEntryBlock added in v0.10.0

func (c *ComposeFile) AddSectionEntryBlock(section, key, block string) error

func (*ComposeFile) AddServiceBlock added in v0.9.2

func (c *ComposeFile) AddServiceBlock(name, block string) error

func (*ComposeFile) AddVolumeBlock added in v0.9.3

func (c *ComposeFile) AddVolumeBlock(name, block string) error

func (*ComposeFile) DeleteSectionEntry added in v0.5.1

func (c *ComposeFile) DeleteSectionEntry(section, key string) error

func (*ComposeFile) DeleteService added in v0.5.1

func (c *ComposeFile) DeleteService(name string) error

func (*ComposeFile) DeleteServiceEnv added in v0.5.1

func (c *ComposeFile) DeleteServiceEnv(service, key string) error

func (*ComposeFile) DeleteServiceKey added in v0.9.2

func (c *ComposeFile) DeleteServiceKey(service, key string) error

func (*ComposeFile) DeleteVolume added in v0.5.1

func (c *ComposeFile) DeleteVolume(name string) error

func (*ComposeFile) HasService added in v0.9.2

func (c *ComposeFile) HasService(name string) bool

func (*ComposeFile) HasVolume added in v0.9.3

func (c *ComposeFile) HasVolume(name string) bool

func (*ComposeFile) Save added in v0.5.1

func (c *ComposeFile) Save() error

func (*ComposeFile) SectionEntryBlock added in v0.10.0

func (c *ComposeFile) SectionEntryBlock(section, key string) (string, bool)

func (*ComposeFile) ServiceBlock added in v0.9.2

func (c *ComposeFile) ServiceBlock(name string) (string, bool)

func (*ComposeFile) SetServiceEnv added in v0.5.1

func (c *ComposeFile) SetServiceEnv(service, key, value string) error

func (*ComposeFile) SetServiceStringList added in v0.9.2

func (c *ComposeFile) SetServiceStringList(service, key string, values []string) error

func (*ComposeFile) VolumeBlock added in v0.9.3

func (c *ComposeFile) VolumeBlock(name string) (string, bool)

type ComposeProject added in v0.5.1

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

func ParseComposeProject added in v0.5.1

func ParseComposeProject(data []byte) (*ComposeProject, error)

func (*ComposeProject) AddDefinitions added in v0.5.1

func (c *ComposeProject) AddDefinitions(defs *ComposeDefinitions)

func (*ComposeProject) Bytes added in v0.5.1

func (c *ComposeProject) Bytes() ([]byte, error)

func (*ComposeProject) DeleteDefinition added in v0.10.0

func (c *ComposeProject) DeleteDefinition(section, name string) bool

func (*ComposeProject) PruneUnusedResources added in v0.5.1

func (c *ComposeProject) PruneUnusedResources()

func (*ComposeProject) RemoveService added in v0.5.1

func (c *ComposeProject) RemoveService(name string) bool

func (*ComposeProject) SetDefinition added in v0.10.0

func (c *ComposeProject) SetDefinition(section, name string, value any)

type ComposeSpec

type ComposeSpec struct {
	Definitions         *ComposeDefinitions
	RemoveServices      []string
	PruneUnusedResource bool
}

type CreateOption

type CreateOption struct {
	Name                string
	Default             State
	DefaultDisposition  Disposition
	AllowedDispositions []Disposition
	Guidance            StateGuidance
	Shorthand           string
	PromptOnCreate      bool
	FollowUps           []FollowUpSpec
}

type DataMigrationRequirement

type DataMigrationRequirement string
const (
	DataMigrationNone     DataMigrationRequirement = "none"
	DataMigrationBackfill DataMigrationRequirement = "backfill"
	DataMigrationHard     DataMigrationRequirement = "hard"
)

type Definition

type Definition struct {
	Name                string
	DefaultState        State
	DefaultDisposition  Disposition
	AllowedDispositions []Disposition
	Guidance            StateGuidance
	PromptOnCreate      bool
	FollowUps           []FollowUpSpec
	Gates               GateSpec
	Dependencies        Dependencies
	Behavior            Behavior
	On                  DomainSpec
	Off                 DomainSpec
}

func (Definition) ComposerPackagesForEnable

func (d Definition) ComposerPackagesForEnable() []string

func (Definition) CreateOption added in v0.5.2

func (d Definition) CreateOption() CreateOption

func (Definition) DrupalModulesForEnable

func (d Definition) DrupalModulesForEnable() []DrupalModuleDependency

func (Definition) FollowUpsForDisposition added in v0.9.0

func (d Definition) FollowUpsForDisposition(disposition Disposition) []FollowUpSpec

func (Definition) FollowUpsForState added in v0.8.0

func (d Definition) FollowUpsForState(state State) []FollowUpSpec

func (Definition) StrictComposerPackages

func (d Definition) StrictComposerPackages() []string

func (Definition) StrictDrupalModules

func (d Definition) StrictDrupalModules() []DrupalModuleDependency

type DeleteMapEntriesTransform

type DeleteMapEntriesTransform struct {
	Matches []MapEntryMatch
}

func (DeleteMapEntriesTransform) Apply

type Dependencies

type Dependencies struct {
	DrupalModules []DrupalModuleDependency
}

func (Dependencies) ComposerPackagesForEnable

func (d Dependencies) ComposerPackagesForEnable() []string

func (Dependencies) DrupalModulesForEnable

func (d Dependencies) DrupalModulesForEnable() []DrupalModuleDependency

func (Dependencies) StrictComposerPackages

func (d Dependencies) StrictComposerPackages() []string

func (Dependencies) StrictDrupalModules

func (d Dependencies) StrictDrupalModules() []DrupalModuleDependency

type DetectOptions

type DetectOptions struct {
	ComposeRoot  string
	DrupalRootfs string
	DrupalRoot   string
}

type DetectedState

type DetectedState string
const StateDrifted DetectedState = "drifted"

type Disposition added in v0.9.0

type Disposition string
const (
	DispositionDisabled    Disposition = "disabled"
	DispositionSuperseded  Disposition = "superceded"
	DispositionEnabled     Disposition = "enabled"
	DispositionDistributed Disposition = "distributed"
)

func LegacyDispositionForState added in v0.9.0

func LegacyDispositionForState(allowed []Disposition, state State) Disposition

func ParseDisposition added in v0.9.0

func ParseDisposition(value string) (Disposition, error)

func PromptDisposition added in v0.9.0

func PromptDisposition(name string, guidance StateGuidance, allowed []Disposition, defaultDisposition Disposition, input InputFunc) (Disposition, error)

func ResolveAllowedDisposition added in v0.9.0

func ResolveAllowedDisposition(allowed []Disposition, disposition Disposition) (Disposition, error)

func ReviewDefaultDisposition added in v0.9.0

func ReviewDefaultDisposition(view ReviewView) Disposition

func StateToDisposition added in v0.9.0

func StateToDisposition(state State) Disposition

type DomainSpec

type DomainSpec struct {
	Compose YAMLStateSpec
	Drupal  YAMLStateSpec
}

type DrupalConfigSet

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

func LoadDrupalConfigSet

func LoadDrupalConfigSet(ctx *config.Context, root string) (*DrupalConfigSet, error)

func NewDrupalConfigSet

func NewDrupalConfigSet(root string, files map[string][]byte) *DrupalConfigSet

func (*DrupalConfigSet) DeleteFiles

func (d *DrupalConfigSet) DeleteFiles(names ...string)

func (*DrupalConfigSet) DeleteMapEntries

func (d *DrupalConfigSet) DeleteMapEntries(match MapEntryMatch) error

func (*DrupalConfigSet) ReplaceString

func (d *DrupalConfigSet) ReplaceString(old, new string)

func (*DrupalConfigSet) Save

func (d *DrupalConfigSet) Save(ctx *config.Context) error

func (*DrupalConfigSet) UpsertFile

func (d *DrupalConfigSet) UpsertFile(name string, data []byte)

type DrupalLayout

type DrupalLayout struct {
	Root string
}

func ResolveDrupalLayout

func ResolveDrupalLayout(projectRoot, drupalRoot string) DrupalLayout

func (DrupalLayout) ComposerJSONPath

func (l DrupalLayout) ComposerJSONPath() string

func (DrupalLayout) ConfigSyncDir

func (l DrupalLayout) ConfigSyncDir() string

type DrupalModuleDependency

type DrupalModuleDependency struct {
	Module          string
	ComposerPackage string
	Mode            DrupalModuleDependencyMode
}

type DrupalModuleDependencyMode

type DrupalModuleDependencyMode string
const (
	// DrupalModuleDependencyStrict means the module is part of the component's
	// core contract and should stay aligned with the component state.
	DrupalModuleDependencyStrict DrupalModuleDependencyMode = "strict"
	// DrupalModuleDependencyEnableOnly means the module must exist when the
	// component is enabled, but disabling the component does not imply removing
	// or uninstalling the module.
	DrupalModuleDependencyEnableOnly DrupalModuleDependencyMode = "enable_only"
)

type DrupalSpec

type DrupalSpec struct {
	ConfigSyncDir     string
	Files             map[string][]byte
	DeleteFiles       []string
	DisableTransforms []DrupalTransform
	EnableTransforms  []DrupalTransform
}

type DrupalTransform

type DrupalTransform interface {
	Apply(*DrupalConfigSet) error
}

type FollowUpSpec added in v0.8.0

type FollowUpSpec struct {
	Name                 string
	Label                string
	FlagName             string
	FlagUsage            string
	Question             string
	Choices              []Choice
	DefaultValue         string
	PromptOnCreate       bool
	AppliesTo            State
	AppliesToDisposition Disposition
	CustomPrompt         string
}

type FollowUpValue added in v0.8.0

type FollowUpValue struct {
	Value string
}

type GateSpec

type GateSpec struct {
	LocalOnly           bool
	DisableConfirmation string
	EnableConfirmation  string
}

type Hook

type Hook func(context.Context, *Runtime) error

type InputFunc

type InputFunc func(question ...string) (string, error)

type Manager

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

func NewManager

func NewManager(ctx *config.Context) *Manager

func (*Manager) DisableComponent

func (m *Manager) DisableComponent(ctx context.Context, spec ComponentSpec) error

func (*Manager) DisableComponentWithOptions

func (m *Manager) DisableComponentWithOptions(ctx context.Context, spec ComponentSpec, opts ApplyOptions) error

func (*Manager) EnableComponent

func (m *Manager) EnableComponent(ctx context.Context, spec ComponentSpec) error

func (*Manager) EnableComponentWithOptions

func (m *Manager) EnableComponentWithOptions(ctx context.Context, spec ComponentSpec, opts ApplyOptions) error

func (*Manager) ReconcileAll

func (m *Manager) ReconcileAll(ctx context.Context, states map[string]State, opts ApplyOptions, features ...Component) error

func (*Manager) ReconcileComponent

func (m *Manager) ReconcileComponent(ctx context.Context, feature Component, state State, opts ApplyOptions) error

type MapEntryMatch

type MapEntryMatch struct {
	Key   string
	Value string
}

type PromptChoiceFunc added in v0.8.0

type PromptChoiceFunc func(name string, choices []Choice, defaultValue string, input InputFunc, sections ...string) (string, error)

type PromptDispositionFunc added in v0.9.0

type PromptDispositionFunc func(name string, guidance StateGuidance, allowed []Disposition, defaultDisposition Disposition, input InputFunc) (Disposition, error)

type PromptStateFunc added in v0.7.0

type PromptStateFunc func(name string, guidance StateGuidance, input InputFunc) (State, error)

type Registry

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

func NewRegistry

func NewRegistry(features ...Component) *Registry

func (*Registry) Component

func (r *Registry) Component(name string) (Component, bool)

func (*Registry) Components

func (r *Registry) Components() []Component

func (*Registry) MustRegister

func (r *Registry) MustRegister(feature Component)

func (*Registry) Register

func (r *Registry) Register(feature Component) error

type ReplaceStringsTransform

type ReplaceStringsTransform struct {
	Replacements []StringReplacement
}

func (ReplaceStringsTransform) Apply

type RepoSource

type RepoSource struct {
	Repo string
	Ref  string
	Path string
}

type ReportRow added in v0.7.0

type ReportRow struct {
	Name            string            `json:"name" yaml:"name"`
	State           string            `json:"state" yaml:"state"`
	DetectedMode    string            `json:"detected_mode,omitempty" yaml:"detected_mode,omitempty"`
	FollowUps       map[string]string `json:"follow_ups,omitempty" yaml:"follow_ups,omitempty"`
	CurrentGuidance string            `json:"current_guidance,omitempty" yaml:"current_guidance,omitempty"`
	IfEnabled       string            `json:"if_enabled" yaml:"if_enabled"`
	IfDisabled      string            `json:"if_disabled" yaml:"if_disabled"`
	DriftDetail     string            `json:"drift_detail,omitempty" yaml:"drift_detail,omitempty"`
	DriftChecks     []string          `json:"drift_checks,omitempty" yaml:"drift_checks,omitempty"`
}

func BuildComponentStatusRows added in v0.7.0

func BuildComponentStatusRows(views []ReviewView, verbose bool) []ReportRow

type ReviewConfirmFunc added in v0.7.0

type ReviewConfirmFunc func(prompt string) (bool, error)

type ReviewDecision added in v0.7.0

type ReviewDecision struct {
	Disposition Disposition
	State       State
	Options     map[string]string
}

type ReviewMode added in v0.7.0

type ReviewMode struct {
	Report  bool
	Verbose bool
}

type ReviewOptions added in v0.7.0

type ReviewOptions struct {
	Input             InputFunc
	PromptState       PromptStateFunc
	PromptDisposition PromptDispositionFunc
	PromptChoice      PromptChoiceFunc
	PromptExtra       ReviewPromptExtraFunc
	SummaryLine       SummaryLineFunc
	Confirm           ReviewConfirmFunc
}

type ReviewPromptExtraFunc added in v0.7.0

type ReviewPromptExtraFunc func(view ReviewView, decision *ReviewDecision) error

type ReviewView added in v0.7.0

type ReviewView struct {
	Definition     Definition
	Name           string
	State          DetectedState
	Disposition    Disposition
	Detail         string
	DriftDetail    string
	SDKStatus      *ComponentStatus
	FollowUpValues map[string]string
	Extra          any
}

type RuleCheckResult

type RuleCheckResult struct {
	Domain string
	File   string
	Op     RuleOp
	Path   string
	Match  bool
	Detail string
}

type RuleOp

type RuleOp string
const (
	OpSet     RuleOp = "set"
	OpDelete  RuleOp = "delete"
	OpRestore RuleOp = "restore"
	OpReplace RuleOp = "replace"
)

type Runtime

type Runtime struct {
	Context *config.Context
	Docker  *docker.DockerClient
}

type State

type State string
const (
	StateOn  State = "on"
	StateOff State = "off"
)

func DispositionToState added in v0.9.0

func DispositionToState(disposition Disposition) State

func ParseState

func ParseState(value string) (State, error)

func PromptState

func PromptState(name string, guidance StateGuidance, input InputFunc) (State, error)

func ReviewDefaultState added in v0.7.0

func ReviewDefaultState(view ReviewView) State

type StateCheck

type StateCheck struct {
	State   State
	Passed  int
	Failed  int
	Results []RuleCheckResult
}

type StateGuidance

type StateGuidance struct {
	Question        string
	OnHelp          string
	OffHelp         string
	DefaultState    State
	EnabledHelp     string
	DisabledHelp    string
	SupersededHelp  string
	DistributedHelp string
}

type StaticComponent

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

func NewStaticComponent

func NewStaticComponent(name string, defaultState State, on ComponentSpec, off ComponentSpec) StaticComponent

func (StaticComponent) DefaultState

func (f StaticComponent) DefaultState() State

func (StaticComponent) Name

func (f StaticComponent) Name() string

func (StaticComponent) SpecFor

func (f StaticComponent) SpecFor(state State) ComponentSpec

type StringReplacement

type StringReplacement struct {
	Old string
	New string
}

type SummaryLineFunc added in v0.7.0

type SummaryLineFunc func(view ReviewView, decision ReviewDecision) (string, error)

type TransitionBehavior

type TransitionBehavior struct {
	DataMigration DataMigrationRequirement
	Summary       string
}

type YAMLDocument

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

func LoadYAMLDocument

func LoadYAMLDocument(data []byte) (*YAMLDocument, error)

func (*YAMLDocument) Bytes

func (d *YAMLDocument) Bytes() ([]byte, error)

func (*YAMLDocument) DeletePath

func (d *YAMLDocument) DeletePath(path string) error

func (*YAMLDocument) SetString

func (d *YAMLDocument) SetString(path, value string) error

type YAMLRule

type YAMLRule struct {
	Files       []string
	Exclude     []string
	SourceFiles []string
	Op          RuleOp
	Path        string
	Value       any
	Old         any
}

type YAMLStateSpec

type YAMLStateSpec struct {
	Canonical []RepoSource
	Rules     []YAMLRule
}

Jump to

Keyboard shortcuts

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