diff --git a/internal/application/add/types.go b/internal/application/add/types.go index 1583312..e79dc5b 100644 --- a/internal/application/add/types.go +++ b/internal/application/add/types.go @@ -12,10 +12,9 @@ import ( "io/fs" "github.com/alyraffauf/cattery/internal/application/outcome" + applicationrepository "github.com/alyraffauf/cattery/internal/application/repository" "github.com/alyraffauf/cattery/internal/deployment" "github.com/alyraffauf/cattery/internal/filesystem" - "github.com/alyraffauf/cattery/internal/repository" - "github.com/alyraffauf/cattery/internal/selection" "github.com/alyraffauf/cattery/internal/state" ) @@ -32,21 +31,14 @@ type Dependencies struct { // RepositorySource resolves the canonical repository pair for a selection // request. The composition root satisfies it with a selection resolver bound // to the canonical home and the state default lookup. -type RepositorySource interface { - Resolve(selection.RepositoryRequest) (RepositoryIdentity, error) -} +type RepositorySource = applicationrepository.RepositorySource // RepositoryIdentity is the canonical repository pair one add compiles from. -type RepositoryIdentity struct { - Root string - Home string -} +type RepositoryIdentity = applicationrepository.RepositoryIdentity // Compiler compiles the current-platform plan from a repository so add can // prove a derived source recompiles to its target. -type Compiler interface { - Compile(repository.CompileInput) (deployment.Plan, error) -} +type Compiler = applicationrepository.Compiler // AtomicWriter durably replaces one source entry from exact validated bytes. // The filesystem adapter satisfies it structurally; request and result values @@ -65,13 +57,7 @@ type BaselineStore interface { // CATTERY_REPO value and its presence, and the initial working directory for // relative resolution. Presence is significant: an empty value with presence // blocks fallback. -type RepositoryInput struct { - RawExplicit string - ExplicitSet bool - RawEnv string - EnvSet bool - WorkingDir string -} +type RepositoryInput = applicationrepository.RepositoryInput // Request is the frozen input of one add: the raw repository fields, the raw // target arguments in command-line order, the explicit option values with diff --git a/internal/application/apply/evaluate.go b/internal/application/apply/evaluate.go index a853f4b..3c66914 100644 --- a/internal/application/apply/evaluate.go +++ b/internal/application/apply/evaluate.go @@ -57,14 +57,8 @@ func (service *Service) Evaluate(ctx context.Context, request Request) (Candidat func (service *Service) evaluate(ctx context.Context, request Request) (Candidates, error) { shared, err := service.evaluator.Evaluate(ctx, evaluation.Request{ - Repository: evaluation.RepositoryInput{ - RawExplicit: request.Repository.RawExplicit, - ExplicitSet: request.Repository.ExplicitSet, - RawEnv: request.Repository.RawEnv, - EnvSet: request.Repository.EnvSet, - WorkingDir: request.Repository.WorkingDir, - }, - Groups: request.Groups, + Repository: request.Repository, + Groups: request.Groups, }) if err != nil { return Candidates{}, err diff --git a/internal/application/apply/types.go b/internal/application/apply/types.go index d4fce00..62af512 100644 --- a/internal/application/apply/types.go +++ b/internal/application/apply/types.go @@ -11,6 +11,7 @@ import ( "github.com/alyraffauf/cattery/internal/application/evaluation" "github.com/alyraffauf/cattery/internal/application/outcome" + applicationrepository "github.com/alyraffauf/cattery/internal/application/repository" "github.com/alyraffauf/cattery/internal/deployment" "github.com/alyraffauf/cattery/internal/filesystem" "github.com/alyraffauf/cattery/internal/hooks" @@ -42,13 +43,13 @@ type Dependencies struct { // RepositorySource resolves the canonical repository pair for a selection // request. The composition root satisfies it with a selection resolver bound // to the canonical home and the state default lookup. -type RepositorySource = evaluation.RepositorySource +type RepositorySource = applicationrepository.RepositorySource // RepositoryIdentity is the canonical repository pair one apply compiles from. -type RepositoryIdentity = evaluation.RepositoryIdentity +type RepositoryIdentity = applicationrepository.RepositoryIdentity // Compiler compiles the current-platform plan from a repository. -type Compiler = evaluation.Compiler +type Compiler = applicationrepository.Compiler // StateReader is the narrow read-only port over the persisted rows and the // per-installation secret hash key of one repository pair. It never @@ -119,13 +120,7 @@ type DifferenceResolver interface { // CATTERY_REPO value and its presence, and the initial working directory for // relative resolution. Presence is significant: an empty value with presence // blocks fallback. -type RepositoryInput struct { - RawExplicit string - ExplicitSet bool - RawEnv string - EnvSet bool - WorkingDir string -} +type RepositoryInput = applicationrepository.RepositoryInput // Request is the frozen input of one apply: the raw repository fields, the // raw group arguments in command-line order, and the policy flags. diff --git a/internal/application/evaluation/types.go b/internal/application/evaluation/types.go index fcee986..4311bbf 100644 --- a/internal/application/evaluation/types.go +++ b/internal/application/evaluation/types.go @@ -4,11 +4,10 @@ package evaluation import ( + applicationrepository "github.com/alyraffauf/cattery/internal/application/repository" "github.com/alyraffauf/cattery/internal/deployment" "github.com/alyraffauf/cattery/internal/reconcile" - "github.com/alyraffauf/cattery/internal/repository" "github.com/alyraffauf/cattery/internal/secrets" - "github.com/alyraffauf/cattery/internal/selection" "github.com/alyraffauf/cattery/internal/state" ) @@ -27,21 +26,9 @@ type Dependencies struct { IncludeUnmanagedTargetDigest bool } -// RepositorySource resolves the canonical repository pair for a raw request. -type RepositorySource interface { - Resolve(selection.RepositoryRequest) (RepositoryIdentity, error) -} - -// RepositoryIdentity is the canonical repository and home pair. -type RepositoryIdentity struct { - Root string - Home string -} - -// Compiler validates and compiles one platform plan. -type Compiler interface { - Compile(repository.CompileInput) (deployment.Plan, error) -} +type RepositorySource = applicationrepository.RepositorySource +type RepositoryIdentity = applicationrepository.RepositoryIdentity +type Compiler = applicationrepository.Compiler // StateReader reads persisted rows and the installation hash key. type StateReader interface { @@ -51,13 +38,7 @@ type StateReader interface { } // RepositoryInput carries raw repository selection fields. -type RepositoryInput struct { - RawExplicit string - ExplicitSet bool - RawEnv string - EnvSet bool - WorkingDir string -} +type RepositoryInput = applicationrepository.RepositoryInput // Request is the shared input of one evaluation. type Request struct { diff --git a/internal/application/inspect/service.go b/internal/application/inspect/service.go index b9736ff..83298b7 100644 --- a/internal/application/inspect/service.go +++ b/internal/application/inspect/service.go @@ -34,14 +34,8 @@ func (service *Service) Evaluate(ctx context.Context, request Request) (Result, func (service *Service) evaluate(ctx context.Context, request Request) (Result, error) { shared, err := service.evaluator.Evaluate(ctx, evaluation.Request{ - Repository: evaluation.RepositoryInput{ - RawExplicit: request.Repository.RawExplicit, - ExplicitSet: request.Repository.ExplicitSet, - RawEnv: request.Repository.RawEnv, - EnvSet: request.Repository.EnvSet, - WorkingDir: request.Repository.WorkingDir, - }, - Groups: request.Groups, + Repository: request.Repository, + Groups: request.Groups, }) if err != nil { return Result{}, err diff --git a/internal/application/inspect/types.go b/internal/application/inspect/types.go index 682eab8..1098e75 100644 --- a/internal/application/inspect/types.go +++ b/internal/application/inspect/types.go @@ -9,6 +9,7 @@ package inspect import ( "github.com/alyraffauf/cattery/internal/application/evaluation" + applicationrepository "github.com/alyraffauf/cattery/internal/application/repository" "github.com/alyraffauf/cattery/internal/secrets" ) @@ -31,15 +32,15 @@ type Dependencies struct { // RepositorySource resolves the canonical repository pair for a selection // request. The composition root satisfies it with a selection resolver bound // to the canonical home and the state default lookup. -type RepositorySource = evaluation.RepositorySource +type RepositorySource = applicationrepository.RepositorySource // RepositoryIdentity is the canonical repository pair one inspection -// evaluates from. It is the inspect-owned projection of the lower selection -// result so no backend type leaks through the application seam. -type RepositoryIdentity = evaluation.RepositoryIdentity +// evaluates from, shared by repository-oriented application services so no +// backend type leaks through the application seam. +type RepositoryIdentity = applicationrepository.RepositoryIdentity // Compiler validates and compiles one platform plan from a repository. -type Compiler = evaluation.Compiler +type Compiler = applicationrepository.Compiler // StateReader is the narrow read-only port over the persisted rows and the // per-installation secret hash key of one repository pair. It never @@ -51,13 +52,7 @@ type StateReader = evaluation.StateReader // CATTERY_REPO value and its presence, and the initial working directory for // relative resolution. Presence is significant: an empty value with presence // blocks fallback. -type RepositoryInput struct { - RawExplicit string - ExplicitSet bool - RawEnv string - EnvSet bool - WorkingDir string -} +type RepositoryInput = applicationrepository.RepositoryInput // Request is the frozen input of one inspection: the raw repository fields // and the raw ordered group arguments. diff --git a/internal/application/repository/types.go b/internal/application/repository/types.go new file mode 100644 index 0000000..15efc63 --- /dev/null +++ b/internal/application/repository/types.go @@ -0,0 +1,34 @@ +// Package repository contains the application-layer contracts shared by +// repository-oriented services. +package repository + +import ( + "github.com/alyraffauf/cattery/internal/deployment" + backend "github.com/alyraffauf/cattery/internal/repository" + "github.com/alyraffauf/cattery/internal/selection" +) + +// RepositorySource resolves the canonical repository pair for a selection request. +type RepositorySource interface { + Resolve(selection.RepositoryRequest) (RepositoryIdentity, error) +} + +// RepositoryIdentity is the canonical repository and home pair. +type RepositoryIdentity struct { + Root string + Home string +} + +// Compiler validates and compiles one platform plan. +type Compiler interface { + Compile(backend.CompileInput) (deployment.Plan, error) +} + +// RepositoryInput carries raw repository selection fields. +type RepositoryInput struct { + RawExplicit string + ExplicitSet bool + RawEnv string + EnvSet bool + WorkingDir string +} diff --git a/internal/application/validate/types.go b/internal/application/validate/types.go index fb92805..5c5381a 100644 --- a/internal/application/validate/types.go +++ b/internal/application/validate/types.go @@ -7,9 +7,7 @@ package validate import ( - "github.com/alyraffauf/cattery/internal/deployment" - "github.com/alyraffauf/cattery/internal/repository" - "github.com/alyraffauf/cattery/internal/selection" + applicationrepository "github.com/alyraffauf/cattery/internal/application/repository" ) // Dependencies bundles the injectable seams of the validation service. @@ -17,43 +15,30 @@ import ( // Compiler compiles and validates platform plans; ProtectedTrees lists the // trees compiled plans must never target, such as the state directory. type Dependencies struct { - RepositorySource RepositorySource - Compiler Compiler + RepositorySource applicationrepository.RepositorySource + Compiler applicationrepository.Compiler ProtectedTrees []string } // RepositorySource resolves the canonical repository pair for a selection // request. The composition root satisfies it with a selection resolver bound // to the canonical home and the state default lookup. -type RepositorySource interface { - Resolve(selection.RepositoryRequest) (RepositoryIdentity, error) -} +type RepositorySource = applicationrepository.RepositorySource // RepositoryIdentity is the canonical repository pair one validation compiles -// from. It is the validate-owned projection of the lower selection result so -// no backend type leaks through the application seam. -type RepositoryIdentity struct { - Root string - Home string -} +// from, shared by repository-oriented application services so no backend type +// leaks through the application seam. +type RepositoryIdentity = applicationrepository.RepositoryIdentity // Compiler validates and compiles one platform plan from a repository. -type Compiler interface { - Compile(repository.CompileInput) (deployment.Plan, error) -} +type Compiler = applicationrepository.Compiler // RepositoryInput carries the raw repository fields the CLI adapter copies // mechanically: the explicit --repo value and its presence, the raw // CATTERY_REPO value and its presence, and the initial working directory for // relative resolution. Presence is significant: an empty value with presence // blocks fallback. -type RepositoryInput struct { - RawExplicit string - ExplicitSet bool - RawEnv string - EnvSet bool - WorkingDir string -} +type RepositoryInput = applicationrepository.RepositoryInput // Request is the frozen input of one validation: the raw repository fields // and the raw ordered group arguments. diff --git a/internal/bootstrap/applications.go b/internal/bootstrap/applications.go index c6a7648..a4bf379 100644 --- a/internal/bootstrap/applications.go +++ b/internal/bootstrap/applications.go @@ -7,6 +7,7 @@ import ( "github.com/alyraffauf/cattery/internal/application/apply" "github.com/alyraffauf/cattery/internal/application/initialize" "github.com/alyraffauf/cattery/internal/application/inspect" + applicationrepository "github.com/alyraffauf/cattery/internal/application/repository" "github.com/alyraffauf/cattery/internal/application/validate" "github.com/alyraffauf/cattery/internal/cli" "github.com/alyraffauf/cattery/internal/deployment" @@ -94,7 +95,7 @@ func buildInitialize(input ApplicationsInput, shared shared) *initialize.Service // buildValidate wires the repository validation service. func buildValidate(input ApplicationsInput, shared shared) *validate.Service { return validate.NewService(validate.Dependencies{ - RepositorySource: repositorySourceOf(shared.resolver, validateIdentity), + RepositorySource: repositorySourceOf(shared.resolver, repositoryIdentity), Compiler: shared.compiler, ProtectedTrees: input.Protected, }) @@ -103,7 +104,7 @@ func buildValidate(input ApplicationsInput, shared shared) *validate.Service { // buildInspect wires the inspection service. func buildInspect(input ApplicationsInput, shared shared) *inspect.Service { return inspect.NewService(inspect.Dependencies{ - RepositorySource: repositorySourceOf(shared.resolver, inspectIdentity), + RepositorySource: repositorySourceOf(shared.resolver, repositoryIdentity), Compiler: shared.compiler, State: shared.state, Secrets: input.Adapters.SOPS, @@ -115,7 +116,7 @@ func buildInspect(input ApplicationsInput, shared shared) *inspect.Service { // buildApply wires the apply service with the prompt resolver. func buildApply(input ApplicationsInput, shared shared) *apply.Service { return apply.NewService(apply.Dependencies{ - RepositorySource: repositorySourceOf(shared.resolver, applyIdentity), + RepositorySource: repositorySourceOf(shared.resolver, repositoryIdentity), Compiler: shared.compiler, State: shared.state, Baselines: shared.baselines, @@ -135,7 +136,7 @@ func buildApply(input ApplicationsInput, shared shared) *apply.Service { // buildAdd wires the add service with its secret execution ports. func buildAdd(input ApplicationsInput, shared shared) *add.Service { return add.NewServiceWithWrites(add.Dependencies{ - RepositorySource: repositorySourceOf(shared.resolver, addIdentity), + RepositorySource: repositorySourceOf(shared.resolver, repositoryIdentity), Compiler: shared.compiler, Writer: input.Adapters.Replacer, Baselines: shared.baselines, @@ -145,22 +146,7 @@ func buildAdd(input ApplicationsInput, shared shared) *add.Service { }) } -// applyIdentity projects one state repository into the apply identity. -func applyIdentity(repository state.Repository) apply.RepositoryIdentity { - return apply.RepositoryIdentity{Root: repository.RootPath, Home: repository.HomePath} -} - -// validateIdentity projects one state repository into the validate identity. -func validateIdentity(repository state.Repository) validate.RepositoryIdentity { - return validate.RepositoryIdentity{Root: repository.RootPath, Home: repository.HomePath} -} - -// inspectIdentity projects one state repository into the inspect identity. -func inspectIdentity(repository state.Repository) inspect.RepositoryIdentity { - return inspect.RepositoryIdentity{Root: repository.RootPath, Home: repository.HomePath} -} - -// addIdentity projects one state repository into the add identity. -func addIdentity(repository state.Repository) add.RepositoryIdentity { - return add.RepositoryIdentity{Root: repository.RootPath, Home: repository.HomePath} +// repositoryIdentity projects the backend repository into the application contract. +func repositoryIdentity(repository state.Repository) applicationrepository.RepositoryIdentity { + return applicationrepository.RepositoryIdentity{Root: repository.RootPath, Home: repository.HomePath} }