+15
-7
spindle/secrets/openbao.go
+15
-7
spindle/secrets/openbao.go
···
13
)
14
15
type OpenBaoManager struct {
16
-
client *vault.Client
17
-
mountPath string
18
-
logger *slog.Logger
19
}
20
21
type OpenBaoManagerOpt func(*OpenBaoManager)
···
26
}
27
}
28
29
// 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
}
44
45
manager := &OpenBaoManager{
46
-
client: client,
47
-
mountPath: "spindle", // default KV v2 mount path
48
-
logger: logger,
49
}
50
51
for _, opt := range opts {
···
62
63
// testConnection verifies that we can connect to the proxy
64
func (v *OpenBaoManager) testConnection() error {
65
-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
66
defer cancel()
67
68
// try token self-lookup as a quick way to verify proxy works
···
13
)
14
15
type OpenBaoManager struct {
16
+
client *vault.Client
17
+
mountPath string
18
+
logger *slog.Logger
19
+
connectionTimeout time.Duration
20
}
21
22
type OpenBaoManagerOpt func(*OpenBaoManager)
···
27
}
28
}
29
30
+
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
}
51
52
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
}
58
59
for _, opt := range opts {
···
70
71
// testConnection verifies that we can connect to the proxy
72
func (v *OpenBaoManager) testConnection() error {
73
+
ctx, cancel := context.WithTimeout(context.Background(), v.connectionTimeout)
74
defer cancel()
75
76
// try token self-lookup as a quick way to verify proxy works
+5
-2
spindle/secrets/openbao_test.go
+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...)
156
157
if tt.expectError {
158
assert.Error(t, err)
···
596
597
// 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)
600
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...)
158
159
if tt.expectError {
160
assert.Error(t, err)
···
598
599
// 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")