From 3fdca3dd16782a9ddab5cab6c16eedf442fb73e3 Mon Sep 17 00:00:00 2001 From: "courtmanr@gmail.com" Date: Fri, 30 May 2025 14:11:23 +0100 Subject: [PATCH] fix: improve test connections to use existing token secrets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Allow testing with existing saved token secrets when not provided in form - Improve error messages to indicate what fields are missing - Fall back to existing .env file for token secrets during testing - Handle both new secrets and existing configuration testing scenarios 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- server/configApi.js | 71 +++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 22 deletions(-) diff --git a/server/configApi.js b/server/configApi.js index e237b17ca..6d23e963d 100644 --- a/server/configApi.js +++ b/server/configApi.js @@ -243,36 +243,63 @@ class ConfigApi { const testPbsConfigs = []; // Test Proxmox endpoint if configured - if (proxmoxHost && proxmoxTokenId && proxmoxTokenSecret) { - testEndpoints.push({ - id: 'test-primary', - name: 'Test Primary', - host: proxmoxHost, - port: parseInt(proxmoxPort) || 8006, - tokenId: proxmoxTokenId, - tokenSecret: proxmoxTokenSecret, - enabled: true, - allowSelfSignedCerts: true - }); + if (proxmoxHost && proxmoxTokenId) { + // If no token secret provided, try to get it from existing config + let tokenSecret = proxmoxTokenSecret; + if (!tokenSecret) { + const existingConfig = await this.readEnvFile(); + tokenSecret = existingConfig.PROXMOX_TOKEN_SECRET; + } + + if (tokenSecret) { + testEndpoints.push({ + id: 'test-primary', + name: 'Test Primary', + host: proxmoxHost, + port: parseInt(proxmoxPort) || 8006, + tokenId: proxmoxTokenId, + tokenSecret: tokenSecret, + enabled: true, + allowSelfSignedCerts: true + }); + } } // Test PBS endpoint if configured - if (pbsHost && pbsTokenId && pbsTokenSecret) { - testPbsConfigs.push({ - id: 'test-pbs', - name: 'Test PBS', - host: pbsHost, - port: parseInt(pbsPort) || 8007, - tokenId: pbsTokenId, - tokenSecret: pbsTokenSecret, - allowSelfSignedCerts: true - }); + if (pbsHost && pbsTokenId) { + // If no token secret provided, try to get it from existing config + let tokenSecret = pbsTokenSecret; + if (!tokenSecret) { + const existingConfig = await this.readEnvFile(); + tokenSecret = existingConfig.PBS_TOKEN_SECRET; + } + + if (tokenSecret) { + testPbsConfigs.push({ + id: 'test-pbs', + name: 'Test PBS', + host: pbsHost, + port: parseInt(pbsPort) || 8007, + tokenId: pbsTokenId, + tokenSecret: tokenSecret, + allowSelfSignedCerts: true + }); + } } if (testEndpoints.length === 0) { + let errorMessage = 'No Proxmox server configured to test. '; + if (!proxmoxHost) { + errorMessage += 'Missing host address.'; + } else if (!proxmoxTokenId) { + errorMessage += 'Missing API token ID.'; + } else { + errorMessage += 'Missing API token secret (enter a new one or save existing configuration first).'; + } + return { success: false, - error: 'No Proxmox server configured to test' + error: errorMessage }; }