From 7386815f44d45336b9ec52c4a690dfac633018c8 Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Mon, 10 Aug 2026 11:25:13 -0400 Subject: [PATCH] refactor: remove single implementation ports --- internal/application/add/execute.go | 3 +++ internal/application/add/service.go | 8 ++------ internal/bootstrap/adapters.go | 8 -------- internal/bootstrap/applications.go | 4 ++-- internal/selection/repository.go | 12 +++++------- 5 files changed, 12 insertions(+), 23 deletions(-) diff --git a/internal/application/add/execute.go b/internal/application/add/execute.go index e08c144..1cc308a 100644 --- a/internal/application/add/execute.go +++ b/internal/application/add/execute.go @@ -124,6 +124,9 @@ func (exec *executor) recoverKey() ([32]byte, error) { if exec.service.write.HashKey == nil { return [32]byte{}, failure.New(failure.Operational, "add: recover hash key", errors.New("hash key recovery is not configured")) } + if err := exec.service.write.HashKey.EnsureAcquired(); err != nil { + return [32]byte{}, failure.New(failure.Operational, "add: recover hash key", err) + } key, err := exec.service.write.HashKey.RecoverHashKey() if err != nil { return [32]byte{}, failure.New(failure.Operational, "add: recover hash key", err) diff --git a/internal/application/add/service.go b/internal/application/add/service.go index 5b55149..a1f1b8b 100644 --- a/internal/application/add/service.go +++ b/internal/application/add/service.go @@ -9,6 +9,7 @@ import ( "github.com/alyraffauf/cattery/internal/repository" "github.com/alyraffauf/cattery/internal/secrets" "github.com/alyraffauf/cattery/internal/selection" + "github.com/alyraffauf/cattery/internal/state" ) // WriteDependencies carries the secret-specific ports required by add's @@ -16,12 +17,7 @@ import ( // so the contract owner can finish without a shared-file change. type WriteDependencies struct { Secrets *secrets.Client - HashKey Recoverer -} - -// Recoverer loads the per-installation secret hash key for keyed baselines. -type Recoverer interface { - RecoverHashKey() ([32]byte, error) + HashKey *state.Store } // Service performs one add batch against the injectable ports. Construction diff --git a/internal/bootstrap/adapters.go b/internal/bootstrap/adapters.go index 77f7b45..6ad00a7 100644 --- a/internal/bootstrap/adapters.go +++ b/internal/bootstrap/adapters.go @@ -81,14 +81,6 @@ func (adapter stateReaderAdapter) RecoverHashKey() ([32]byte, error) { return adapter.store.RecoverHashKey() } -// DefaultRepository returns the default repository of one home. -func (adapter stateReaderAdapter) DefaultRepository(home string) (state.Repository, error) { - if err := adapter.store.EnsureAcquired(); err != nil { - return state.Repository{}, err - } - return adapter.store.DefaultRepository(home) -} - // baselineAdapter exposes the baseline port over one store. type baselineAdapter struct { store *state.Store diff --git a/internal/bootstrap/applications.go b/internal/bootstrap/applications.go index a4bf379..8d703d6 100644 --- a/internal/bootstrap/applications.go +++ b/internal/bootstrap/applications.go @@ -56,7 +56,7 @@ func newShared(input ApplicationsInput) shared { baselines: baselineAdapter{store: input.Adapters.Store}, transitions: transitionAdapter{store: input.Adapters.Store}, retirements: retirementAdapter{store: input.Adapters.Store}, - resolver: selection.NewRepositoryResolver(input.Home, stateReader), + resolver: selection.NewRepositoryResolver(input.Home, input.Adapters.Store), prompt: cli.NewDecisionPrompt(cli.PromptInput{ Stdin: input.Stdin, Stderr: input.Stderr, @@ -142,7 +142,7 @@ func buildAdd(input ApplicationsInput, shared shared) *add.Service { Baselines: shared.baselines, }, add.WriteDependencies{ Secrets: input.Adapters.SOPS, - HashKey: shared.state, + HashKey: input.Adapters.Store, }) } diff --git a/internal/selection/repository.go b/internal/selection/repository.go index a121c2b..fdf6cf7 100644 --- a/internal/selection/repository.go +++ b/internal/selection/repository.go @@ -26,24 +26,19 @@ type RepositoryRequest struct { WorkingDir string } -// Defaults is the narrow read-only port over the state default lookup. -type Defaults interface { - DefaultRepository(home string) (state.Repository, error) -} - // RepositoryResolver applies the Section 8.2 precedence and returns the // canonical repository identity. Explicit and environment paths are resolved // against the initial working directory; only the default lookup may touch // state, and it never registers a row. type RepositoryResolver struct { home string - defaults Defaults + defaults *state.Store } // NewRepositoryResolver constructs a resolver bound to the canonical home // and the read-only default lookup. Construction performs no filesystem or // state access. -func NewRepositoryResolver(home string, defaults Defaults) *RepositoryResolver { +func NewRepositoryResolver(home string, defaults *state.Store) *RepositoryResolver { return &RepositoryResolver{home: home, defaults: defaults} } @@ -62,6 +57,9 @@ func (resolver *RepositoryResolver) Resolve(request RepositoryRequest) (state.Re } return resolver.canonical(request.RawEnv, request.WorkingDir) } + if err := resolver.defaults.EnsureAcquired(); err != nil { + return state.Repository{}, err + } return resolver.defaults.DefaultRepository(resolver.home) } -- 2.51.2