fixed CLI issue

This commit is contained in:
Turbootzz committed 2025-10-24 14:10:01 +02:00
1 parent 349ebd7562
commit 1daa409a73
1 file changed
+8 -10
+8 -10
View File
@@ -138,20 +138,18 @@ func (c *Client) GetSecret(name string) (string, error) {
// fetchSecret queries the Vaultwarden API for a secret // fetchSecret queries the Vaultwarden API for a secret
func (c *Client) fetchSecret(name string) (string, error) { func (c *Client) fetchSecret(name string) (string, error) {
// First, try using the Bitwarden CLI if available // Only try CLI if using session token (not client credentials)
// This is more reliable for Vaultwarden instances if c.authManager == nil {
if value, err := c.FetchSecretViaCLI(name); err == nil { if value, err := c.FetchSecretViaCLI(name); err == nil {
return value, nil return value, nil
} else { } else {
logger.Warn.Printf("CLI method failed, trying API: %v", err) logger.Warn.Printf("CLI method failed, trying API: %v", err)
}
} }
// Fallback to API method // Use API method
// Build the API request with context for timeout
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel() defer cancel()
// Using the Bitwarden public API endpoint for list items
url := fmt.Sprintf("%s/api/ciphers", c.baseURL) url := fmt.Sprintf("%s/api/ciphers", c.baseURL)
req, err := http.NewRequestWithContext(ctx, "GET", url, nil) req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
if err != nil { if err != nil {