@deinossrl/dgp-agent 1.4.22 → 1.4.24
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 +41 -30
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -206,9 +206,7 @@ let platformConfig = null;
|
|
|
206
206
|
* Obtiene la ruta del archivo de SSH key del agente
|
|
207
207
|
*/
|
|
208
208
|
function getDgpSshKeyPath() {
|
|
209
|
-
|
|
210
|
-
const path = require('path');
|
|
211
|
-
return path.join(os.homedir(), '.ssh', 'dgp_key');
|
|
209
|
+
return join(homedir(), '.ssh', 'dgp_key');
|
|
212
210
|
}
|
|
213
211
|
|
|
214
212
|
/**
|
|
@@ -216,19 +214,15 @@ function getDgpSshKeyPath() {
|
|
|
216
214
|
*/
|
|
217
215
|
function saveSshKeyLocally(sshPrivateKey) {
|
|
218
216
|
try {
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const sshDir = path.join(os.homedir(), '.ssh');
|
|
224
|
-
if (!fs.existsSync(sshDir)) {
|
|
225
|
-
fs.mkdirSync(sshDir, { recursive: true, mode: 0o700 });
|
|
217
|
+
const sshDir = join(homedir(), '.ssh');
|
|
218
|
+
if (!existsSync(sshDir)) {
|
|
219
|
+
mkdirSync(sshDir, { recursive: true, mode: 0o700 });
|
|
226
220
|
}
|
|
227
221
|
|
|
228
222
|
const keyPath = getDgpSshKeyPath();
|
|
229
223
|
// Normalizar saltos de línea
|
|
230
224
|
const normalizedKey = sshPrivateKey.replace(/\\n/g, '\n').replace(/\r\n/g, '\n');
|
|
231
|
-
|
|
225
|
+
writeFileSync(keyPath, normalizedKey, { mode: 0o600 });
|
|
232
226
|
|
|
233
227
|
return keyPath;
|
|
234
228
|
} catch (e) {
|
|
@@ -242,10 +236,9 @@ function saveSshKeyLocally(sshPrivateKey) {
|
|
|
242
236
|
*/
|
|
243
237
|
function loadLocalSshKey() {
|
|
244
238
|
try {
|
|
245
|
-
const fs = require('fs');
|
|
246
239
|
const keyPath = getDgpSshKeyPath();
|
|
247
|
-
if (
|
|
248
|
-
return
|
|
240
|
+
if (existsSync(keyPath)) {
|
|
241
|
+
return readFileSync(keyPath, 'utf8');
|
|
249
242
|
}
|
|
250
243
|
return null;
|
|
251
244
|
} catch (e) {
|
|
@@ -257,12 +250,11 @@ function loadLocalSshKey() {
|
|
|
257
250
|
* Verifica si hay una SSH key guardada localmente
|
|
258
251
|
*/
|
|
259
252
|
function hasLocalSshKey() {
|
|
260
|
-
|
|
261
|
-
return fs.existsSync(getDgpSshKeyPath());
|
|
253
|
+
return existsSync(getDgpSshKeyPath());
|
|
262
254
|
}
|
|
263
255
|
|
|
264
256
|
// Versión del agente
|
|
265
|
-
const AGENT_VERSION = '1.4.
|
|
257
|
+
const AGENT_VERSION = '1.4.23';
|
|
266
258
|
let AGENT_MODE = 'smart'; // Siempre inteligente
|
|
267
259
|
|
|
268
260
|
// Configuración (prioridad: env vars > archivo config > platform config > defaults)
|
|
@@ -1322,29 +1314,31 @@ async function executeTestConnection(command) {
|
|
|
1322
1314
|
|
|
1323
1315
|
// SSH Key: prioridad params > guardada localmente
|
|
1324
1316
|
let sshPrivateKey = params?.ssh_private_key || null;
|
|
1325
|
-
let
|
|
1317
|
+
let sshPassword = params?.ssh_password || null;
|
|
1318
|
+
let authMethod = 'ninguno';
|
|
1326
1319
|
|
|
1327
1320
|
// Si viene SSH key en params, guardarla localmente para futuro uso
|
|
1328
1321
|
if (sshPrivateKey) {
|
|
1329
1322
|
const savedPath = saveSshKeyLocally(sshPrivateKey);
|
|
1330
1323
|
if (savedPath) {
|
|
1331
1324
|
logSuccess(`SSH Key guardada en ${savedPath}`);
|
|
1332
|
-
|
|
1325
|
+
authMethod = 'key (guardada localmente)';
|
|
1333
1326
|
} else {
|
|
1334
|
-
|
|
1327
|
+
authMethod = 'key (plataforma)';
|
|
1335
1328
|
}
|
|
1336
1329
|
} else if (hasLocalSshKey()) {
|
|
1337
1330
|
// Si no viene en params pero hay una guardada, usarla
|
|
1338
1331
|
sshPrivateKey = loadLocalSshKey();
|
|
1339
|
-
|
|
1332
|
+
authMethod = `key (${getDgpSshKeyPath()})`;
|
|
1340
1333
|
logInfo(`Usando SSH Key guardada: ${getDgpSshKeyPath()}`);
|
|
1334
|
+
} else if (sshPassword) {
|
|
1335
|
+
authMethod = 'password';
|
|
1336
|
+
logInfo('Usando autenticación por password');
|
|
1341
1337
|
}
|
|
1342
1338
|
|
|
1343
1339
|
logCommand(`=== Testing SSH Connection ===`);
|
|
1344
1340
|
logInfo(`Target: ${ssh_user || 'root'}@${server_host}`);
|
|
1345
|
-
|
|
1346
|
-
logInfo(`SSH Key: ${sshKeySource}`);
|
|
1347
|
-
}
|
|
1341
|
+
logInfo(`Auth: ${authMethod}`);
|
|
1348
1342
|
|
|
1349
1343
|
// Iniciar tracking de logs
|
|
1350
1344
|
currentCommandId = command.id;
|
|
@@ -1387,19 +1381,36 @@ async function executeTestConnection(command) {
|
|
|
1387
1381
|
// Step 2: SSH test
|
|
1388
1382
|
logInfo('Step 2: Testing SSH connection...');
|
|
1389
1383
|
|
|
1384
|
+
const user = ssh_user || 'root';
|
|
1385
|
+
let sshCmd = '';
|
|
1386
|
+
|
|
1390
1387
|
// Usar la SSH key guardada en ~/.ssh/dgp_key (ya se guardó arriba si vino de params)
|
|
1391
1388
|
let sshKeyPath = null;
|
|
1392
1389
|
if (sshPrivateKey && hasLocalSshKey()) {
|
|
1393
1390
|
sshKeyPath = getDgpSshKeyPath();
|
|
1394
1391
|
await addCommandLog('info', `Usando SSH key: ${sshKeyPath}`);
|
|
1392
|
+
const sshOpts = `-i ${sshKeyPath} -o StrictHostKeyChecking=no -o ConnectTimeout=10 -o BatchMode=yes`;
|
|
1393
|
+
sshCmd = `ssh ${sshOpts} ${user}@${server_host} "echo 'SSH_OK' && hostname && whoami"`;
|
|
1394
|
+
} else if (sshPassword) {
|
|
1395
|
+
// Usar sshpass para autenticación por password
|
|
1396
|
+
await addCommandLog('info', 'Usando autenticación por password (sshpass)');
|
|
1397
|
+
const isWindows = process.platform === 'win32';
|
|
1398
|
+
if (isWindows) {
|
|
1399
|
+
// En Windows usar plink (PuTTY) o mostrar advertencia
|
|
1400
|
+
await addCommandLog('warning', 'SSH con password en Windows requiere plink (PuTTY)');
|
|
1401
|
+
// Intentar con plink si está disponible
|
|
1402
|
+
sshCmd = `echo y | plink -ssh -pw "${sshPassword}" ${user}@${server_host} "echo SSH_OK && hostname && whoami"`;
|
|
1403
|
+
} else {
|
|
1404
|
+
// En Linux/Mac usar sshpass
|
|
1405
|
+
sshCmd = `sshpass -p "${sshPassword}" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 ${user}@${server_host} "echo 'SSH_OK' && hostname && whoami"`;
|
|
1406
|
+
}
|
|
1407
|
+
} else {
|
|
1408
|
+
// Sin key ni password, intentar con key del sistema
|
|
1409
|
+
await addCommandLog('info', 'Intentando conexión con keys del sistema (~/.ssh/)');
|
|
1410
|
+
const sshOpts = `-o StrictHostKeyChecking=no -o ConnectTimeout=10 -o BatchMode=yes`;
|
|
1411
|
+
sshCmd = `ssh ${sshOpts} ${user}@${server_host} "echo 'SSH_OK' && hostname && whoami"`;
|
|
1395
1412
|
}
|
|
1396
1413
|
|
|
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
1414
|
await addCommandLog('command', `ssh ${user}@${server_host} "hostname && whoami"`);
|
|
1404
1415
|
|
|
1405
1416
|
try {
|