From e7584045662590227c94b05553493210bff6a55b Mon Sep 17 00:00:00 2001 From: Steven Terwindt Date: Thu, 23 Jul 2026 07:29:05 +1000 Subject: [PATCH] fix(status): set SecretLookup so templates with secrets render correctly status and check built a template context for hash comparison but never set SecretLookup. Templates with bitwarden() calls failed to render, fell back to raw source hash, and falsely showed as modified. --- internal/cli/check.go | 10 ++++++++++ internal/cli/status.go | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/internal/cli/check.go b/internal/cli/check.go index 26f7cea..b6ceb12 100644 --- a/internal/cli/check.go +++ b/internal/cli/check.go @@ -8,6 +8,7 @@ import ( "github.com/subbeh/statemate/internal/config" "github.com/subbeh/statemate/internal/encrypt" "github.com/subbeh/statemate/internal/profile" + "github.com/subbeh/statemate/internal/secrets" "github.com/subbeh/statemate/internal/state" "github.com/subbeh/statemate/internal/target" "github.com/subbeh/statemate/internal/template" @@ -81,8 +82,10 @@ func runCheck(cmd *cobra.Command, args []string) error { defer func() { _ = db.Close() }() var enc *encrypt.AgeEncryptor + identitySource := "" if cfg.Age != nil { enc, _ = encrypt.NewAgeEncryptor(cfg.Age.Identity, cfg.Age.IdentityCommand, cfg.Age.Recipients) + identitySource = cfg.Age.Identity } var ctxOpts []template.ContextOption @@ -91,6 +94,13 @@ func runCheck(cmd *cobra.Command, args []string) error { } tmplCtx, _ := template.NewContext(cfg, profileName, ctxOpts...) + if mgr, err := secrets.NewManager(enc, identitySource, cfg.SecretsCache); err == nil { + tmplCtx.SecretLookup = func(item, typ, field string) (string, error) { + key := secrets.CacheKey{Provider: "bitwarden", Item: item, Type: typ, Field: field} + return mgr.Get(key) + } + } + changes, err := target.ComputeChanges(tree, db, target.ComputeOpts{ TmplCtx: tmplCtx, Enc: enc, diff --git a/internal/cli/status.go b/internal/cli/status.go index a215b72..df5a3d6 100644 --- a/internal/cli/status.go +++ b/internal/cli/status.go @@ -97,6 +97,13 @@ func runStatus(cmd *cobra.Command, args []string) error { } tmplCtx, _ := template.NewContext(cfg, profileName, ctxOpts...) + if mgr, err := secrets.NewManager(enc, identitySource, cfg.SecretsCache); err == nil { + tmplCtx.SecretLookup = func(item, typ, field string) (string, error) { + key := secrets.CacheKey{Provider: "bitwarden", Item: item, Type: typ, Field: field} + return mgr.Get(key) + } + } + changes, err := target.ComputeChanges(tree, db, target.ComputeOpts{ TmplCtx: tmplCtx, Enc: enc,