@deinossrl/dgp-agent 1.4.25 → 1.4.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +62 -29
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -254,7 +254,7 @@ function hasLocalSshKey() {
|
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
// Versión del agente
|
|
257
|
-
const AGENT_VERSION = '1.4.
|
|
257
|
+
const AGENT_VERSION = '1.4.27';
|
|
258
258
|
let AGENT_MODE = 'smart'; // Siempre inteligente
|
|
259
259
|
|
|
260
260
|
// Configuración (prioridad: env vars > archivo config > platform config > defaults)
|
|
@@ -1312,28 +1312,38 @@ Analiza este error y sugiere soluciones.`;
|
|
|
1312
1312
|
async function executeTestConnection(command) {
|
|
1313
1313
|
const { server_host, ssh_user, params } = command;
|
|
1314
1314
|
|
|
1315
|
-
//
|
|
1315
|
+
// Extraer credenciales y método de autenticación
|
|
1316
1316
|
let sshPrivateKey = params?.ssh_private_key || null;
|
|
1317
1317
|
let sshPassword = params?.ssh_password || null;
|
|
1318
|
+
const authMethodPreference = params?.auth_method || 'ssh_key'; // default ssh_key
|
|
1318
1319
|
let authMethod = 'ninguno';
|
|
1319
1320
|
|
|
1320
|
-
//
|
|
1321
|
-
if (
|
|
1322
|
-
|
|
1323
|
-
if (savedPath) {
|
|
1324
|
-
logSuccess(`SSH Key guardada en ${savedPath}`);
|
|
1325
|
-
authMethod = 'key (guardada localmente)';
|
|
1326
|
-
} else {
|
|
1327
|
-
authMethod = 'key (plataforma)';
|
|
1328
|
-
}
|
|
1329
|
-
} else if (hasLocalSshKey()) {
|
|
1330
|
-
// Si no viene en params pero hay una guardada, usarla
|
|
1331
|
-
sshPrivateKey = loadLocalSshKey();
|
|
1332
|
-
authMethod = `key (${getDgpSshKeyPath()})`;
|
|
1333
|
-
logInfo(`Usando SSH Key guardada: ${getDgpSshKeyPath()}`);
|
|
1334
|
-
} else if (sshPassword) {
|
|
1321
|
+
// Respetar la preferencia del usuario
|
|
1322
|
+
if (authMethodPreference === 'password' && sshPassword) {
|
|
1323
|
+
// Usuario eligió password
|
|
1335
1324
|
authMethod = 'password';
|
|
1336
|
-
logInfo('
|
|
1325
|
+
logInfo('Método elegido: Password');
|
|
1326
|
+
} else {
|
|
1327
|
+
// Usuario eligió SSH Key (o default)
|
|
1328
|
+
// Si viene SSH key en params, guardarla localmente para futuro uso
|
|
1329
|
+
if (sshPrivateKey) {
|
|
1330
|
+
const savedPath = saveSshKeyLocally(sshPrivateKey);
|
|
1331
|
+
if (savedPath) {
|
|
1332
|
+
logSuccess(`SSH Key guardada en ${savedPath}`);
|
|
1333
|
+
authMethod = 'key (guardada localmente)';
|
|
1334
|
+
} else {
|
|
1335
|
+
authMethod = 'key (plataforma)';
|
|
1336
|
+
}
|
|
1337
|
+
} else if (hasLocalSshKey()) {
|
|
1338
|
+
// Si no viene en params pero hay una guardada, usarla
|
|
1339
|
+
sshPrivateKey = loadLocalSshKey();
|
|
1340
|
+
authMethod = `key (${getDgpSshKeyPath()})`;
|
|
1341
|
+
logInfo(`Usando SSH Key guardada: ${getDgpSshKeyPath()}`);
|
|
1342
|
+
} else if (sshPassword) {
|
|
1343
|
+
// Fallback: si no hay key pero hay password, usarlo
|
|
1344
|
+
authMethod = 'password (fallback)';
|
|
1345
|
+
logInfo('No hay SSH key, usando password como alternativa');
|
|
1346
|
+
}
|
|
1337
1347
|
}
|
|
1338
1348
|
|
|
1339
1349
|
logCommand(`=== Testing SSH Connection ===`);
|
|
@@ -1384,29 +1394,52 @@ async function executeTestConnection(command) {
|
|
|
1384
1394
|
const user = ssh_user || 'root';
|
|
1385
1395
|
let sshCmd = '';
|
|
1386
1396
|
|
|
1387
|
-
//
|
|
1397
|
+
// Construir comando SSH según el método de autenticación elegido
|
|
1388
1398
|
let sshKeyPath = null;
|
|
1389
|
-
if (
|
|
1399
|
+
if (authMethodPreference === 'password' && sshPassword) {
|
|
1400
|
+
// Usuario eligió password: usar sshpass o plink
|
|
1401
|
+
await addCommandLog('info', 'Usando autenticación por password');
|
|
1402
|
+
const isWindows = process.platform === 'win32';
|
|
1403
|
+
if (isWindows) {
|
|
1404
|
+
// En Windows verificar si plink está disponible
|
|
1405
|
+
try {
|
|
1406
|
+
shellSync('where plink');
|
|
1407
|
+
await addCommandLog('info', 'Usando plink (PuTTY)');
|
|
1408
|
+
sshCmd = `echo y | plink -ssh -pw "${sshPassword}" ${user}@${server_host} "echo SSH_OK && hostname && whoami"`;
|
|
1409
|
+
} catch (e) {
|
|
1410
|
+
await addCommandLog('error', 'plink no encontrado. Instalá PuTTY desde https://www.putty.org/');
|
|
1411
|
+
await addCommandLog('info', 'Alternativa: usá SSH Key en lugar de password en Windows');
|
|
1412
|
+
throw new Error('Password auth en Windows requiere PuTTY/plink. Instalalo o usá SSH Key.');
|
|
1413
|
+
}
|
|
1414
|
+
} else {
|
|
1415
|
+
// En Linux/Mac usar sshpass
|
|
1416
|
+
await addCommandLog('info', 'Usando sshpass (Linux/Mac)');
|
|
1417
|
+
sshCmd = `sshpass -p "${sshPassword}" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 ${user}@${server_host} "echo 'SSH_OK' && hostname && whoami"`;
|
|
1418
|
+
}
|
|
1419
|
+
} else if (hasLocalSshKey()) {
|
|
1420
|
+
// Usuario eligió SSH key: usar la guardada en ~/.ssh/dgp_key
|
|
1390
1421
|
sshKeyPath = getDgpSshKeyPath();
|
|
1391
1422
|
await addCommandLog('info', `Usando SSH key: ${sshKeyPath}`);
|
|
1392
1423
|
const sshOpts = `-i ${sshKeyPath} -o StrictHostKeyChecking=no -o ConnectTimeout=10 -o BatchMode=yes`;
|
|
1393
1424
|
sshCmd = `ssh ${sshOpts} ${user}@${server_host} "echo 'SSH_OK' && hostname && whoami"`;
|
|
1394
1425
|
} else if (sshPassword) {
|
|
1395
|
-
//
|
|
1396
|
-
await addCommandLog('info', 'Usando
|
|
1426
|
+
// Fallback: no hay key local pero hay password
|
|
1427
|
+
await addCommandLog('info', 'Usando password como alternativa (no hay SSH key guardada)');
|
|
1397
1428
|
const isWindows = process.platform === 'win32';
|
|
1398
1429
|
if (isWindows) {
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1430
|
+
try {
|
|
1431
|
+
shellSync('where plink');
|
|
1432
|
+
sshCmd = `echo y | plink -ssh -pw "${sshPassword}" ${user}@${server_host} "echo SSH_OK && hostname && whoami"`;
|
|
1433
|
+
} catch (e) {
|
|
1434
|
+
await addCommandLog('error', 'plink no encontrado. Instalá PuTTY desde https://www.putty.org/');
|
|
1435
|
+
throw new Error('Password auth en Windows requiere PuTTY/plink. Instalalo o usá SSH Key.');
|
|
1436
|
+
}
|
|
1403
1437
|
} else {
|
|
1404
|
-
// En Linux/Mac usar sshpass
|
|
1405
1438
|
sshCmd = `sshpass -p "${sshPassword}" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 ${user}@${server_host} "echo 'SSH_OK' && hostname && whoami"`;
|
|
1406
1439
|
}
|
|
1407
1440
|
} else {
|
|
1408
|
-
// Sin key ni password, intentar con
|
|
1409
|
-
await addCommandLog('
|
|
1441
|
+
// Sin key ni password, intentar con keys del sistema
|
|
1442
|
+
await addCommandLog('warning', 'No hay SSH key ni password configurados. Intentando con keys del sistema (~/.ssh/)');
|
|
1410
1443
|
const sshOpts = `-o StrictHostKeyChecking=no -o ConnectTimeout=10 -o BatchMode=yes`;
|
|
1411
1444
|
sshCmd = `ssh ${sshOpts} ${user}@${server_host} "echo 'SSH_OK' && hostname && whoami"`;
|
|
1412
1445
|
}
|