Fix: Support camelCase keyPassword in JSON host import #384

Merged
thorved merged 1 commits from fix/keypassword-import-camelcase into dev-1.7.3 2025-10-09 04:23:33 +00:00

View File

@@ -1412,7 +1412,7 @@ router.post(
hostData.authType === "credential" ? hostData.credentialId : null,
key: hostData.authType === "key" ? hostData.key : null,
key_password:
hostData.authType === "key" ? hostData.key_password : null,
hostData.authType === "key" ? hostData.keyPassword : null,
keyType:
gemini-code-assist[bot] commented 2025-10-08 10:36:07 +00:00 (Migrated from github.com)
Review

high

While this change correctly adds support for keyPassword, it removes the existing support for key_password. This could be a breaking change for any clients that might be using the snake_case version.

To ensure backward compatibility and make the API more robust, it would be better to support both formats. You can achieve this by checking for keyPassword first and then falling back to key_password if the former is not present. This approach is also used elsewhere in the codebase (e.g., in resolveHostCredentials).

            hostData.authType === "key" ? (hostData.keyPassword || hostData.key_password || null) : null,
![high](https://www.gstatic.com/codereviewagent/high-priority.svg) While this change correctly adds support for `keyPassword`, it removes the existing support for `key_password`. This could be a breaking change for any clients that might be using the snake_case version. To ensure backward compatibility and make the API more robust, it would be better to support both formats. You can achieve this by checking for `keyPassword` first and then falling back to `key_password` if the former is not present. This approach is also used elsewhere in the codebase (e.g., in `resolveHostCredentials`). ```suggestion hostData.authType === "key" ? (hostData.keyPassword || hostData.key_password || null) : null, ```
thorved commented 2025-10-08 10:38:47 +00:00 (Migrated from github.com)
Review

Before:

key_password:
  hostData.authType === "key" ? hostData.key_password : null,

After:

key_password:
  hostData.authType === "key" ? hostData.keyPassword : null,

The fix ensures that JSON imports with the following structure work correctly:

{
  "hosts": [
    {
      "name": "pve-m920q",
      "ip": "10.10.0.253",
      "port": 22,
      "username": "root",
      "authType": "key",
      "key": "-----BEGIN OPENSSH PRIVATE KEY-----...",
      "keyPassword": "12345678",
      "keyType": "ssh-ed25519",
      "folder": "Proxmox Hosts",
      "tags": ["home", "proxmox", "pve"],
      "pin": true,
      "enableTerminal": true,
      "enableTunnel": false,
      "enableFileManager": true,
      "defaultPath": "~"
    }
  ]
}
**Before**: ```typescript key_password: hostData.authType === "key" ? hostData.key_password : null, ``` **After**: ```typescript key_password: hostData.authType === "key" ? hostData.keyPassword : null, ``` The fix ensures that JSON imports with the following structure work correctly: ```json { "hosts": [ { "name": "pve-m920q", "ip": "10.10.0.253", "port": 22, "username": "root", "authType": "key", "key": "-----BEGIN OPENSSH PRIVATE KEY-----...", "keyPassword": "12345678", "keyType": "ssh-ed25519", "folder": "Proxmox Hosts", "tags": ["home", "proxmox", "pve"], "pin": true, "enableTerminal": true, "enableTunnel": false, "enableFileManager": true, "defaultPath": "~" } ] } ```
hostData.authType === "key" ? hostData.keyType || "auto" : null,
pin: hostData.pin || false,