buddy-tunnel
Advanced tools
Comparing version 1.7.6-dev to 1.7.7-dev
{ | ||
"name": "buddy-tunnel", | ||
"preferGlobal": false, | ||
"version": "1.7.6-dev", | ||
"version": "1.7.7-dev", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "dependencies": { |
@@ -124,2 +124,4 @@ const EventEmitter = require('events'); | ||
tunnels.forEach((data) => { | ||
let sshHostKey; | ||
if (this.manager) sshHostKey = this.manager.sshHostKey; | ||
const tunnel = this.tunnels.find((tunnel) => data.id === tunnel.id); | ||
@@ -129,3 +131,6 @@ if (!tunnel) { | ||
logger.debug(data); | ||
this.addTunnel(new Tunnel(data)); | ||
this.addTunnel(new Tunnel({ | ||
...data, | ||
sshHostKey | ||
})); | ||
} else if (tunnel.hasChanged(data)) { | ||
@@ -132,0 +137,0 @@ tunnel.recreate(data); |
@@ -27,3 +27,4 @@ const { | ||
isWindows, | ||
TUNNEL_SSH | ||
TUNNEL_SSH, | ||
createSshHostKey | ||
} = require('../utils'); | ||
@@ -46,2 +47,3 @@ const AgentOsx = require('./osx'); | ||
this.shouldStart = null; | ||
this.sshHostKey = null; | ||
this.agent = null; | ||
@@ -290,3 +292,3 @@ this.server = null; | ||
try { | ||
tunnel = await ApiBuddy.addTunnel(this.id, this.host, this.token, data); | ||
tunnel = await ApiBuddy.addTunnel(this.id, this.host, this.token, data, this.sshHostKey); | ||
} catch (err) { | ||
@@ -361,2 +363,3 @@ this.serverError(res, err.message); | ||
this.shouldStart = !!json.shouldStart; | ||
this.sshHostKey = json.sshHostKey; | ||
} catch { | ||
@@ -366,2 +369,3 @@ // save from param | ||
} | ||
if (!this.sshHostKey) this.sshHostKey = createSshHostKey(); | ||
} else { | ||
@@ -373,3 +377,3 @@ // save from param | ||
// resave config | ||
this.system.saveAgentConfig(this.shouldStart); | ||
this.system.saveAgentConfig(this.shouldStart, this.sshHostKey); | ||
return true; | ||
@@ -376,0 +380,0 @@ } catch { |
@@ -189,7 +189,8 @@ const { | ||
saveAgentConfig(shouldStart) { | ||
saveAgentConfig(shouldStart, sshHostKey) { | ||
try { | ||
logger.info(LOG_SAVING_AGENT_LOCAL_CONFIG); | ||
writeFileSync(this.getAgentConfigPath(), JSON.stringify({ | ||
shouldStart | ||
shouldStart, | ||
sshHostKey | ||
}), 'utf-8'); | ||
@@ -196,0 +197,0 @@ return true; |
@@ -125,3 +125,3 @@ const { Agent: HttpsAgent } = require('https'); | ||
async addTunnel(agentId, host, token, prepared) { | ||
async addTunnel(agentId, host, token, prepared, sshHostKey) { | ||
logger.info(LOG_REGISTERING_TUNNEL); | ||
@@ -134,3 +134,6 @@ const config = await makeRequest(host, '/tunnel/add', { | ||
logger.info(LOG_TUNNEL_REGISTERED(config.id)); | ||
return new Tunnel(config); | ||
return new Tunnel({ | ||
...config, | ||
sshHostKey | ||
}); | ||
} | ||
@@ -137,0 +140,0 @@ |
@@ -6,3 +6,2 @@ const { Command } = require('commander'); | ||
ERR_SWW_AGENT_UPDATING, | ||
TXT_DISABLING_AGENT, | ||
} = require('../../texts.js'); | ||
@@ -13,3 +12,4 @@ const Output = require('../../output.js'); | ||
const { ERR_AGENT_ADMIN_RIGHTS, | ||
TXT_AGENT_UPDATED | ||
TXT_AGENT_UPDATED, | ||
TXT_UPDATING_AGENT | ||
} = require('../../texts'); | ||
@@ -30,3 +30,3 @@ const ApiAgent = require('../../api/agent'); | ||
} | ||
Output.normal(TXT_DISABLING_AGENT); | ||
Output.normal(TXT_UPDATING_AGENT); | ||
try { | ||
@@ -33,0 +33,0 @@ await AgentManager.system.update(); |
@@ -456,2 +456,3 @@ const logger = require('../logger'); | ||
this.sftp.removeAllListeners(); | ||
this.sftp.end(); | ||
this.sftp = null; | ||
@@ -458,0 +459,0 @@ } |
@@ -8,5 +8,4 @@ const EventEmitter = require('events'); | ||
class ServerSsh extends EventEmitter { | ||
constructor(login, password) { | ||
constructor(login, password, hostKey) { | ||
super(); | ||
const keys = Ssh2.utils.generateKeyPairSync('ed25519', {}); | ||
this.login = login; | ||
@@ -16,3 +15,3 @@ this.password = password; | ||
keepAlive: true, | ||
hostKeys: [keys.private], | ||
hostKeys: [hostKey], | ||
ident: 'ssh2 server' | ||
@@ -53,2 +52,3 @@ }, (client) => this.processClient(client)); | ||
client.removeAllListeners(); | ||
client.end(); | ||
client = null; | ||
@@ -55,0 +55,0 @@ }); |
@@ -126,2 +126,3 @@ const ERR_AGENT_NOT_REGISTERED = 'Agent not registered. Exiting...'; | ||
const TXT_ENABLING_AGENT = 'Enabling agent...'; | ||
const TXT_UPDATING_AGENT = 'Updating agent...'; | ||
const TXT_OPENING_TUNNEL = 'Opening tunnel...'; | ||
@@ -398,2 +399,3 @@ | ||
TXT_ENABLING_AGENT, | ||
TXT_UPDATING_AGENT, | ||
TXT_NEW_CLI_DOCKER_VERSION, | ||
@@ -400,0 +402,0 @@ TXT_NEW_CLI_VERSION, |
@@ -78,3 +78,4 @@ const basicAuth = require('basic-auth'); | ||
TUNNEL_SSH, | ||
SSH_CLIENT_EVENT_STREAM_SSH | ||
SSH_CLIENT_EVENT_STREAM_SSH, | ||
createSshHostKey | ||
} = require('./utils'); | ||
@@ -96,5 +97,8 @@ const { LOG_TUNNEL_SSH_STREAM } = require('./texts'); | ||
sshSettings, | ||
sshHostKey | ||
}) { | ||
super(); | ||
if (!sshHostKey) sshHostKey = createSshHostKey(); | ||
this.id = id; | ||
this.sshHostKey = sshHostKey; | ||
this.create({ | ||
@@ -110,3 +114,3 @@ type, | ||
httpSettings, | ||
sshSettings | ||
sshSettings, | ||
}); | ||
@@ -237,3 +241,3 @@ } | ||
httpSettings, | ||
sshSettings | ||
sshSettings, | ||
}); | ||
@@ -244,3 +248,6 @@ if (started) this.start(); | ||
hasChanged(data) { | ||
const tunnel = new Tunnel(data); | ||
const tunnel = new Tunnel({ | ||
...data, | ||
sshHostKey: this.sshHostKey | ||
}); | ||
if (this.type !== tunnel.type) return true; | ||
@@ -622,3 +629,3 @@ if (this.target !== tunnel.target) return true; | ||
}); | ||
this.sshServer = new ServerSsh(this.sshClientUser, this.sshClientPassword); | ||
this.sshServer = new ServerSsh(this.sshClientUser, this.sshClientPassword, this.sshHostKey); | ||
} | ||
@@ -625,0 +632,0 @@ // ssh |
@@ -9,2 +9,3 @@ const { resolve } = require('path'); | ||
const { getAsset, isSea } = require('node:sea'); | ||
const Ssh2 = require('ssh2'); | ||
const { | ||
@@ -243,2 +244,7 @@ OPTION_REGION, | ||
const createSshHostKey = () => { | ||
const keys = Ssh2.utils.generateKeyPairSync('ed25519', {}); | ||
return keys.private; | ||
}; | ||
const getBasicCommandTcp = () => { | ||
@@ -346,2 +352,3 @@ const commandTcp = new Command('tcp'); | ||
isWindows, | ||
createSshHostKey, | ||
AGENT_STATUS_INITIALIZING, | ||
@@ -348,0 +355,0 @@ AGENT_STATUS_FETCH_FAILED, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
349864
8302