feat: wire bitwarden cache options

This commit is contained in:
thibaud-lclr 2026-05-02 14:59:04 +02:00
parent 9675490cd3
commit 1a44a2ea35
4 changed files with 104 additions and 58 deletions

View file

@ -15,15 +15,16 @@ type ManifestLoader func(startDir string) (manifest.File, string, error)
type ExecutableResolver func() (string, error) type ExecutableResolver func() (string, error)
type OpenFromManifestOptions struct { type OpenFromManifestOptions struct {
ServiceName string ServiceName string
LookupEnv func(string) (string, bool) LookupEnv func(string) (string, bool)
KWalletAppID string KWalletAppID string
KWalletFolder string KWalletFolder string
BitwardenCommand string BitwardenCommand string
BitwardenDebug bool BitwardenDebug bool
Shell string DisableBitwardenCache bool
ManifestLoader ManifestLoader Shell string
ExecutableResolver ExecutableResolver ManifestLoader ManifestLoader
ExecutableResolver ExecutableResolver
} }
func OpenFromManifest(options OpenFromManifestOptions) (Store, error) { func OpenFromManifest(options OpenFromManifestOptions) (Store, error) {
@ -33,14 +34,15 @@ func OpenFromManifest(options OpenFromManifestOptions) (Store, error) {
} }
return Open(Options{ return Open(Options{
ServiceName: options.ServiceName, ServiceName: options.ServiceName,
BackendPolicy: manifestPolicy.Policy, BackendPolicy: manifestPolicy.Policy,
LookupEnv: options.LookupEnv, LookupEnv: options.LookupEnv,
KWalletAppID: options.KWalletAppID, KWalletAppID: options.KWalletAppID,
KWalletFolder: options.KWalletFolder, KWalletFolder: options.KWalletFolder,
BitwardenCommand: strings.TrimSpace(options.BitwardenCommand), BitwardenCommand: strings.TrimSpace(options.BitwardenCommand),
BitwardenDebug: options.BitwardenDebug, BitwardenDebug: options.BitwardenDebug,
Shell: strings.TrimSpace(options.Shell), DisableBitwardenCache: disableBitwardenCacheOption(options.DisableBitwardenCache, manifestPolicy.BitwardenCache),
Shell: strings.TrimSpace(options.Shell),
}) })
} }
@ -53,8 +55,9 @@ func resolveManifestBackendPolicy(options OpenFromManifestOptions) (BackendPolic
} }
type manifestPolicyResolution struct { type manifestPolicyResolution struct {
Policy BackendPolicy Policy BackendPolicy
Source string Source string
BitwardenCache bool
} }
func resolveManifestPolicy(options OpenFromManifestOptions) (manifestPolicyResolution, error) { func resolveManifestPolicy(options OpenFromManifestOptions) (manifestPolicyResolution, error) {
@ -82,17 +85,24 @@ func resolveManifestPolicy(options OpenFromManifestOptions) (manifestPolicyResol
if err != nil { if err != nil {
if errors.Is(err, os.ErrNotExist) { if errors.Is(err, os.ErrNotExist) {
return manifestPolicyResolution{ return manifestPolicyResolution{
Policy: BackendAuto, Policy: BackendAuto,
Source: "", Source: "",
BitwardenCache: true,
}, nil }, nil
} }
return manifestPolicyResolution{}, fmt.Errorf("load runtime manifest from %q: %w", startDir, err) return manifestPolicyResolution{}, fmt.Errorf("load runtime manifest from %q: %w", startDir, err)
} }
bitwardenCache := true
if file.SecretStore.BitwardenCache != nil {
bitwardenCache = *file.SecretStore.BitwardenCache
}
if strings.TrimSpace(file.SecretStore.BackendPolicy) == "" { if strings.TrimSpace(file.SecretStore.BackendPolicy) == "" {
return manifestPolicyResolution{ return manifestPolicyResolution{
Policy: BackendAuto, Policy: BackendAuto,
Source: strings.TrimSpace(manifestPath), Source: strings.TrimSpace(manifestPath),
BitwardenCache: bitwardenCache,
}, nil }, nil
} }
@ -106,7 +116,12 @@ func resolveManifestPolicy(options OpenFromManifestOptions) (manifestPolicyResol
} }
return manifestPolicyResolution{ return manifestPolicyResolution{
Policy: policy, Policy: policy,
Source: strings.TrimSpace(manifestPath), Source: strings.TrimSpace(manifestPath),
BitwardenCache: bitwardenCache,
}, nil }, nil
} }
func disableBitwardenCacheOption(runtimeDisabled bool, manifestEnabled bool) bool {
return runtimeDisabled || !manifestEnabled
}

View file

@ -111,6 +111,33 @@ func TestOpenFromManifestReturnsExplicitErrorForInvalidManifestPolicy(t *testing
} }
} }
func TestResolveManifestPolicyPreservesBitwardenCacheDisable(t *testing.T) {
cacheDisabled := false
resolution, err := resolveManifestPolicy(OpenFromManifestOptions{
ServiceName: "email-mcp",
ExecutableResolver: func() (string, error) {
return filepath.Join(string(filepath.Separator), "opt", "email-mcp", "bin", "email-mcp"), nil
},
ManifestLoader: func(startDir string) (manifest.File, string, error) {
return manifest.File{
SecretStore: manifest.SecretStore{
BackendPolicy: string(BackendBitwardenCLI),
BitwardenCache: &cacheDisabled,
},
}, filepath.Join(startDir, manifest.DefaultFile), nil
},
})
if err != nil {
t.Fatalf("resolveManifestPolicy returned error: %v", err)
}
if resolution.BitwardenCache {
t.Fatal("resolution BitwardenCache = true, want false")
}
if resolution.Policy != BackendBitwardenCLI {
t.Fatalf("resolution policy = %q, want %q", resolution.Policy, BackendBitwardenCLI)
}
}
func TestOpenFromManifestReturnsExecutableResolutionError(t *testing.T) { func TestOpenFromManifestReturnsExecutableResolutionError(t *testing.T) {
execErr := errors.New("boom") execErr := errors.New("boom")
_, err := OpenFromManifest(OpenFromManifestOptions{ _, err := OpenFromManifest(OpenFromManifestOptions{

View file

@ -9,15 +9,16 @@ import (
const DefaultManifestSource = "default:auto (manifest not found)" const DefaultManifestSource = "default:auto (manifest not found)"
type DescribeRuntimeOptions struct { type DescribeRuntimeOptions struct {
ServiceName string ServiceName string
LookupEnv func(string) (string, bool) LookupEnv func(string) (string, bool)
KWalletAppID string KWalletAppID string
KWalletFolder string KWalletFolder string
BitwardenCommand string BitwardenCommand string
BitwardenDebug bool BitwardenDebug bool
Shell string DisableBitwardenCache bool
ManifestLoader ManifestLoader Shell string
ExecutableResolver ExecutableResolver ManifestLoader ManifestLoader
ExecutableResolver ExecutableResolver
} }
type RuntimeDescription struct { type RuntimeDescription struct {
@ -47,14 +48,15 @@ type PreflightReport struct {
func DescribeRuntime(options DescribeRuntimeOptions) (RuntimeDescription, error) { func DescribeRuntime(options DescribeRuntimeOptions) (RuntimeDescription, error) {
resolution, err := resolveManifestPolicy(OpenFromManifestOptions{ resolution, err := resolveManifestPolicy(OpenFromManifestOptions{
ServiceName: options.ServiceName, ServiceName: options.ServiceName,
LookupEnv: options.LookupEnv, LookupEnv: options.LookupEnv,
KWalletAppID: options.KWalletAppID, KWalletAppID: options.KWalletAppID,
KWalletFolder: options.KWalletFolder, KWalletFolder: options.KWalletFolder,
BitwardenCommand: options.BitwardenCommand, BitwardenCommand: options.BitwardenCommand,
Shell: options.Shell, DisableBitwardenCache: options.DisableBitwardenCache,
ManifestLoader: options.ManifestLoader, Shell: options.Shell,
ExecutableResolver: options.ExecutableResolver, ManifestLoader: options.ManifestLoader,
ExecutableResolver: options.ExecutableResolver,
}) })
if err != nil { if err != nil {
return RuntimeDescription{}, err return RuntimeDescription{}, err
@ -68,14 +70,15 @@ func DescribeRuntime(options DescribeRuntimeOptions) (RuntimeDescription, error)
} }
store, openErr := Open(Options{ store, openErr := Open(Options{
ServiceName: options.ServiceName, ServiceName: options.ServiceName,
BackendPolicy: resolution.Policy, BackendPolicy: resolution.Policy,
LookupEnv: options.LookupEnv, LookupEnv: options.LookupEnv,
KWalletAppID: options.KWalletAppID, KWalletAppID: options.KWalletAppID,
KWalletFolder: options.KWalletFolder, KWalletFolder: options.KWalletFolder,
BitwardenCommand: options.BitwardenCommand, BitwardenCommand: options.BitwardenCommand,
BitwardenDebug: options.BitwardenDebug, BitwardenDebug: options.BitwardenDebug,
Shell: options.Shell, DisableBitwardenCache: disableBitwardenCacheOption(options.DisableBitwardenCache, resolution.BitwardenCache),
Shell: options.Shell,
}) })
if openErr != nil { if openErr != nil {
desc.Ready = false desc.Ready = false

View file

@ -31,14 +31,15 @@ const (
) )
type Options struct { type Options struct {
ServiceName string ServiceName string
BackendPolicy BackendPolicy BackendPolicy BackendPolicy
LookupEnv func(string) (string, bool) LookupEnv func(string) (string, bool)
KWalletAppID string KWalletAppID string
KWalletFolder string KWalletFolder string
BitwardenCommand string BitwardenCommand string
BitwardenDebug bool BitwardenDebug bool
Shell string DisableBitwardenCache bool
Shell string
} }
type Store interface { type Store interface {