@deinossrl/dgp-agent 1.4.22 → 1.4.23
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 +33 -14
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -262,7 +262,7 @@ function hasLocalSshKey() {
|
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
// Versión del agente
|
|
265
|
-
const AGENT_VERSION = '1.4.
|
|
265
|
+
const AGENT_VERSION = '1.4.23';
|
|
266
266
|
let AGENT_MODE = 'smart'; // Siempre inteligente
|
|
267
267
|
|
|
268
268
|
// Configuración (prioridad: env vars > archivo config > platform config > defaults)
|
|
@@ -1322,29 +1322,31 @@ async function executeTestConnection(command) {
|
|
|
1322
1322
|
|
|
1323
1323
|
// SSH Key: prioridad params > guardada localmente
|
|
1324
1324
|
let sshPrivateKey = params?.ssh_private_key || null;
|
|
1325
|
-
let
|
|
1325
|
+
let sshPassword = params?.ssh_password || null;
|
|
1326
|
+
let authMethod = 'ninguno';
|
|
1326
1327
|
|
|
1327
1328
|
// Si viene SSH key en params, guardarla localmente para futuro uso
|
|
1328
1329
|
if (sshPrivateKey) {
|
|
1329
1330
|
const savedPath = saveSshKeyLocally(sshPrivateKey);
|
|
1330
1331
|
if (savedPath) {
|
|
1331
1332
|
logSuccess(`SSH Key guardada en ${savedPath}`);
|
|
1332
|
-
|
|
1333
|
+
authMethod = 'key (guardada localmente)';
|
|
1333
1334
|
} else {
|
|
1334
|
-
|
|
1335
|
+
authMethod = 'key (plataforma)';
|
|
1335
1336
|
}
|
|
1336
1337
|
} else if (hasLocalSshKey()) {
|
|
1337
1338
|
// Si no viene en params pero hay una guardada, usarla
|
|
1338
1339
|
sshPrivateKey = loadLocalSshKey();
|
|
1339
|
-
|
|
1340
|
+
authMethod = `key (${getDgpSshKeyPath()})`;
|
|
1340
1341
|
logInfo(`Usando SSH Key guardada: ${getDgpSshKeyPath()}`);
|
|
1342
|
+
} else if (sshPassword) {
|
|
1343
|
+
authMethod = 'password';
|
|
1344
|
+
logInfo('Usando autenticación por password');
|
|
1341
1345
|
}
|
|
1342
1346
|
|
|
1343
1347
|
logCommand(`=== Testing SSH Connection ===`);
|
|
1344
1348
|
logInfo(`Target: ${ssh_user || 'root'}@${server_host}`);
|
|
1345
|
-
|
|
1346
|
-
logInfo(`SSH Key: ${sshKeySource}`);
|
|
1347
|
-
}
|
|
1349
|
+
logInfo(`Auth: ${authMethod}`);
|
|
1348
1350
|
|
|
1349
1351
|
// Iniciar tracking de logs
|
|
1350
1352
|
currentCommandId = command.id;
|
|
@@ -1387,19 +1389,36 @@ async function executeTestConnection(command) {
|
|
|
1387
1389
|
// Step 2: SSH test
|
|
1388
1390
|
logInfo('Step 2: Testing SSH connection...');
|
|
1389
1391
|
|
|
1392
|
+
const user = ssh_user || 'root';
|
|
1393
|
+
let sshCmd = '';
|
|
1394
|
+
|
|
1390
1395
|
// Usar la SSH key guardada en ~/.ssh/dgp_key (ya se guardó arriba si vino de params)
|
|
1391
1396
|
let sshKeyPath = null;
|
|
1392
1397
|
if (sshPrivateKey && hasLocalSshKey()) {
|
|
1393
1398
|
sshKeyPath = getDgpSshKeyPath();
|
|
1394
1399
|
await addCommandLog('info', `Usando SSH key: ${sshKeyPath}`);
|
|
1400
|
+
const sshOpts = `-i ${sshKeyPath} -o StrictHostKeyChecking=no -o ConnectTimeout=10 -o BatchMode=yes`;
|
|
1401
|
+
sshCmd = `ssh ${sshOpts} ${user}@${server_host} "echo 'SSH_OK' && hostname && whoami"`;
|
|
1402
|
+
} else if (sshPassword) {
|
|
1403
|
+
// Usar sshpass para autenticación por password
|
|
1404
|
+
await addCommandLog('info', 'Usando autenticación por password (sshpass)');
|
|
1405
|
+
const isWindows = process.platform === 'win32';
|
|
1406
|
+
if (isWindows) {
|
|
1407
|
+
// En Windows usar plink (PuTTY) o mostrar advertencia
|
|
1408
|
+
await addCommandLog('warning', 'SSH con password en Windows requiere plink (PuTTY)');
|
|
1409
|
+
// Intentar con plink si está disponible
|
|
1410
|
+
sshCmd = `echo y | plink -ssh -pw "${sshPassword}" ${user}@${server_host} "echo SSH_OK && hostname && whoami"`;
|
|
1411
|
+
} else {
|
|
1412
|
+
// En Linux/Mac usar sshpass
|
|
1413
|
+
sshCmd = `sshpass -p "${sshPassword}" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 ${user}@${server_host} "echo 'SSH_OK' && hostname && whoami"`;
|
|
1414
|
+
}
|
|
1415
|
+
} else {
|
|
1416
|
+
// Sin key ni password, intentar con key del sistema
|
|
1417
|
+
await addCommandLog('info', 'Intentando conexión con keys del sistema (~/.ssh/)');
|
|
1418
|
+
const sshOpts = `-o StrictHostKeyChecking=no -o ConnectTimeout=10 -o BatchMode=yes`;
|
|
1419
|
+
sshCmd = `ssh ${sshOpts} ${user}@${server_host} "echo 'SSH_OK' && hostname && whoami"`;
|
|
1395
1420
|
}
|
|
1396
1421
|
|
|
1397
|
-
const user = ssh_user || 'root';
|
|
1398
|
-
const sshOpts = sshKeyPath
|
|
1399
|
-
? `-i ${sshKeyPath} -o StrictHostKeyChecking=no -o ConnectTimeout=10 -o BatchMode=yes`
|
|
1400
|
-
: `-o StrictHostKeyChecking=no -o ConnectTimeout=10 -o BatchMode=yes`;
|
|
1401
|
-
|
|
1402
|
-
const sshCmd = `ssh ${sshOpts} ${user}@${server_host} "echo 'SSH_OK' && hostname && whoami"`;
|
|
1403
1422
|
await addCommandLog('command', `ssh ${user}@${server_host} "hostname && whoami"`);
|
|
1404
1423
|
|
|
1405
1424
|
try {
|