mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-24 07:46:39 +00:00
WIP: Allow tunneling to remote unix sockets.
Change-type: minor Signed-off-by: Carlo Miguel F. Cruz <carloc@balena.io>
This commit is contained in:
parent
907a235b09
commit
3e1bf76a7c
@ -153,7 +153,7 @@ export default class LogsCmd extends Command {
|
||||
const uuid = await getOnlineTargetDeviceUuid(balena, deviceAddress);
|
||||
const device = await balena.models.device.get(uuid);
|
||||
logger.logInfo(`Opening tunnels to ${deviceAddress}`);
|
||||
await openTunnel(logger, device, balena, 48484, 'localhost', 48484);
|
||||
await openTunnel(logger, device, balena, 48484, 'localhost', '48484');
|
||||
// await openTunnel(logger, device, balena, 2375, 'localhost', 2375);
|
||||
logger.logInfo(`Opened tunnels to ${deviceAddress}...`);
|
||||
deviceAddress = '127.0.0.1';
|
||||
|
@ -157,8 +157,8 @@ export default class TunnelCmd extends Command {
|
||||
let localAddress = 'localhost';
|
||||
|
||||
// First element is always remotePort
|
||||
const remotePort = parseInt(mappingElements[0], undefined);
|
||||
let localPort = remotePort;
|
||||
const remotePort = mappingElements[0];
|
||||
let localPort = parseInt(remotePort, undefined);
|
||||
|
||||
if (mappingElements.length === 2) {
|
||||
// [1] could be localAddress or localPort
|
||||
@ -176,7 +176,7 @@ export default class TunnelCmd extends Command {
|
||||
}
|
||||
|
||||
// Validate results
|
||||
if (!this.isValidPort(remotePort) || !this.isValidPort(localPort)) {
|
||||
if (!this.isValidPort(localPort)) {
|
||||
throw new InvalidPortMappingError(portMapping);
|
||||
}
|
||||
|
||||
|
@ -135,8 +135,8 @@ export async function deployToDevice(opts: DeviceDeployOptions): Promise<void> {
|
||||
const device = await sdk.models.device.get(uuid);
|
||||
logger.logInfo(`Opening tunnels to ${device.uuid}...`);
|
||||
|
||||
await openTunnel(logger, device, sdk, 48484, 'localhost', 48484);
|
||||
await openTunnel(logger, device, sdk, 2375, 'localhost', 2375);
|
||||
await openTunnel(logger, device, sdk, 48484, 'localhost', '48484');
|
||||
await openTunnel(logger, device, sdk, 2375, 'localhost', '2375');
|
||||
logger.logInfo(`Opened tunnels to ${device.uuid}...`);
|
||||
|
||||
opts.deviceHost = 'localhost';
|
||||
|
@ -35,8 +35,8 @@ class UnableToConnectError extends TypedError {
|
||||
}
|
||||
|
||||
class RemoteSocketNotListening extends TypedError {
|
||||
public port: number;
|
||||
constructor(port: number) {
|
||||
public port: string;
|
||||
constructor(port: string) {
|
||||
super(`Device is not listening on port ${port}`);
|
||||
}
|
||||
}
|
||||
@ -48,7 +48,7 @@ export const logConnection = (
|
||||
localAddress: string,
|
||||
localPort: number,
|
||||
deviceAddress: string,
|
||||
devicePort: number,
|
||||
devicePort: string,
|
||||
err?: Error,
|
||||
) => {
|
||||
const logMessage = `${fromHost}:${fromPort} => ${localAddress}:${localPort} ===> ${deviceAddress}:${devicePort}`;
|
||||
@ -66,7 +66,7 @@ export const openTunnel = async (
|
||||
sdk: BalenaSDK,
|
||||
localPort: number,
|
||||
localAddress: string,
|
||||
remotePort: number,
|
||||
remotePort: string,
|
||||
) => {
|
||||
try {
|
||||
const handler = await tunnelConnectionToDevice(
|
||||
@ -127,7 +127,7 @@ export const openTunnel = async (
|
||||
|
||||
export const tunnelConnectionToDevice = (
|
||||
uuid: string,
|
||||
port: number,
|
||||
port: string,
|
||||
sdk: BalenaSDK,
|
||||
) => {
|
||||
return Promise.all([
|
||||
@ -172,7 +172,7 @@ const openPortThroughProxy = (
|
||||
proxyPort: number,
|
||||
proxyAuth: { user: string; password: string } | null,
|
||||
deviceUuid: string,
|
||||
devicePort: number,
|
||||
devicePort: string,
|
||||
) => {
|
||||
const httpHeaders = [`CONNECT ${deviceUuid}.balena:${devicePort} HTTP/1.0`];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user