UNPKG

n8n-nodes-netdevices

Version:

n8n node to interact with network devices (Cisco, Juniper, Palo Alto PAN-OS, Ciena SAOS, Linux, etc.)

81 lines 3.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeviceSpecificJumpHostConnection = void 0; const jump_host_connection_1 = require("./jump-host-connection"); let Logger; try { Logger = require('n8n-workflow').LoggerProxy; } catch (error) { Logger = { debug: (...args) => console.log('[DEBUG]', ...args), info: (...args) => console.log('[INFO]', ...args), warn: (...args) => console.warn('[WARN]', ...args), error: (...args) => console.error('[ERROR]', ...args), }; } class DeviceSpecificJumpHostConnection extends jump_host_connection_1.JumpHostConnection { constructor(credentials, deviceConnection) { super(credentials); this.deviceConnection = deviceConnection; this.deviceConnection.client = this.client; this.deviceConnection.currentChannel = this.currentChannel; } async connect() { await super.connect(); if (this.isConnected) { await this.sessionPreparation(); } else { throw new Error('Target connection was not established through jump host.'); } } async sessionPreparation() { Logger.debug('Delegating session preparation to device-specific connection', { deviceType: this.credentials.deviceType, hasClient: !!this.client, isConnected: this.isConnected, jumpHostConnected: this.jumpHostConnected }); if (!this.client || !this.isConnected) { Logger.error('SSH client not ready for session preparation', { hasClient: !!this.client, isConnected: this.isConnected, jumpHostConnected: this.jumpHostConnected, deviceType: this.credentials.deviceType }); throw new Error('SSH connection not established before session preparation'); } this.deviceConnection.client = this.client; this.deviceConnection.currentChannel = this.currentChannel; this.deviceConnection.isConnected = this.isConnected; try { await this.deviceConnection.sessionPreparation(); this.currentChannel = this.deviceConnection.currentChannel; if (!this.currentChannel) { Logger.error('Session preparation failed to create a channel', { deviceType: this.credentials.deviceType, hasClient: !!this.client, isConnected: this.isConnected }); throw new Error('Failed to create a valid shell channel during session preparation.'); } Logger.debug('Session preparation delegated successfully', { hasChannel: !!this.currentChannel, channelType: this.currentChannel.constructor.name, deviceType: this.credentials.deviceType }); } catch (sessionError) { Logger.error('Device-specific session preparation failed', { deviceType: this.credentials.deviceType, error: sessionError instanceof Error ? sessionError.message : String(sessionError), hasClient: !!this.client, isConnected: this.isConnected }); throw sessionError; } } } exports.DeviceSpecificJumpHostConnection = DeviceSpecificJumpHostConnection; //# sourceMappingURL=device-specific-jump-host-connection.js.map