···13)
1415type OpenBaoManager struct {
16- client *vault.Client
17- mountPath string
18- logger *slog.Logger
019}
2021type OpenBaoManagerOpt func(*OpenBaoManager)
···26 }
27}
2800000029// NewOpenBaoManager creates a new OpenBao manager that connects to a Bao Proxy
30// The proxyAddress should point to the local Bao Proxy (e.g., "http://127.0.0.1:8200")
31// The proxy handles all authentication automatically via Auto-Auth
···43 }
4445 manager := &OpenBaoManager{
46- client: client,
47- mountPath: "spindle", // default KV v2 mount path
48- logger: logger,
049 }
5051 for _, opt := range opts {
···6263// testConnection verifies that we can connect to the proxy
64func (v *OpenBaoManager) testConnection() error {
65- ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
66 defer cancel()
6768 // try token self-lookup as a quick way to verify proxy works
···13)
1415type OpenBaoManager struct {
16+ client *vault.Client
17+ mountPath string
18+ logger *slog.Logger
19+ connectionTimeout time.Duration
20}
2122type OpenBaoManagerOpt func(*OpenBaoManager)
···27 }
28}
2930+func WithConnectionTimeout(timeout time.Duration) OpenBaoManagerOpt {
31+ return func(v *OpenBaoManager) {
32+ v.connectionTimeout = timeout
33+ }
34+}
35+36// NewOpenBaoManager creates a new OpenBao manager that connects to a Bao Proxy
37// The proxyAddress should point to the local Bao Proxy (e.g., "http://127.0.0.1:8200")
38// The proxy handles all authentication automatically via Auto-Auth
···50 }
5152 manager := &OpenBaoManager{
53+ client: client,
54+ mountPath: "spindle", // default KV v2 mount path
55+ logger: logger,
56+ connectionTimeout: 10 * time.Second, // default connection timeout
57 }
5859 for _, opt := range opts {
···7071// testConnection verifies that we can connect to the proxy
72func (v *OpenBaoManager) testConnection() error {
73+ ctx, cancel := context.WithTimeout(context.Background(), v.connectionTimeout)
74 defer cancel()
7576 // try token self-lookup as a quick way to verify proxy works
+5-2
spindle/secrets/openbao_test.go
···152 for _, tt := range tests {
153 t.Run(tt.name, func(t *testing.T) {
154 logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
155- manager, err := NewOpenBaoManager(tt.proxyAddr, logger, tt.opts...)
00156157 if tt.expectError {
158 assert.Error(t, err)
···596597 // All these will fail because no real proxy is running
598 // but we can test that the configuration is properly accepted
599- manager, err := NewOpenBaoManager(tt.proxyAddr, logger)
0600 assert.Error(t, err) // Expected because no real proxy
601 assert.Nil(t, manager)
602 assert.Contains(t, err.Error(), "failed to connect to bao proxy")
···152 for _, tt := range tests {
153 t.Run(tt.name, func(t *testing.T) {
154 logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
155+ // Use shorter timeout for tests to avoid long waits
156+ opts := append(tt.opts, WithConnectionTimeout(1*time.Second))
157+ manager, err := NewOpenBaoManager(tt.proxyAddr, logger, opts...)
158159 if tt.expectError {
160 assert.Error(t, err)
···598599 // All these will fail because no real proxy is running
600 // but we can test that the configuration is properly accepted
601+ // Use shorter timeout for tests to avoid long waits
602+ manager, err := NewOpenBaoManager(tt.proxyAddr, logger, WithConnectionTimeout(1*time.Second))
603 assert.Error(t, err) // Expected because no real proxy
604 assert.Nil(t, manager)
605 assert.Contains(t, err.Error(), "failed to connect to bao proxy")