mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-28 01:28:51 +00:00
Merge pull request #1180 from balena-io/tunnel-short-uuid
tunnel: allow using partial device uuids
This commit is contained in:
commit
12615cd0dc
@ -20,6 +20,7 @@ import * as _ from 'lodash';
|
||||
import { createServer, Server, Socket } from 'net';
|
||||
import { isArray } from 'util';
|
||||
|
||||
import { inferOrSelectDevice } from '../utils/patterns';
|
||||
import { tunnelConnectionToDevice } from '../utils/tunnel';
|
||||
|
||||
interface Args {
|
||||
@ -128,12 +129,11 @@ export const tunnel: CommandDefinition<Args, Options> = {
|
||||
? (options.port as string[])
|
||||
: [options.port as string];
|
||||
|
||||
return Bluebird.try(() =>
|
||||
sdk.models.device
|
||||
.get(params.uuid)
|
||||
return inferOrSelectDevice(params.uuid)
|
||||
.then(sdk.models.device.get)
|
||||
.then(device => {
|
||||
if (!device.is_online) {
|
||||
throw new DeviceIsOfflineError(params.uuid);
|
||||
throw new DeviceIsOfflineError(device.uuid);
|
||||
}
|
||||
|
||||
const localListeners = _.chain(ports)
|
||||
@ -174,7 +174,7 @@ export const tunnel: CommandDefinition<Args, Options> = {
|
||||
};
|
||||
})
|
||||
.map(({ localPort, localAddress, remotePort }) => {
|
||||
return tunnelConnectionToDevice(params.uuid, remotePort, sdk)
|
||||
return tunnelConnectionToDevice(device.uuid, remotePort, sdk)
|
||||
.then(handler =>
|
||||
createServer((client: Socket) => {
|
||||
return handler(client)
|
||||
@ -212,16 +212,18 @@ export const tunnel: CommandDefinition<Args, Options> = {
|
||||
)
|
||||
.then(() => {
|
||||
logger.logInfo(
|
||||
` - tunnelling ${localAddress}:${localPort} to device:${remotePort}`,
|
||||
` - tunnelling ${localAddress}:${localPort} to ${
|
||||
device.uuid
|
||||
}:${remotePort}`,
|
||||
);
|
||||
|
||||
return true;
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
logger.logWarn(
|
||||
` - not tunnelling ${localAddress}:${localPort} to device:${remotePort}, failed ${JSON.stringify(
|
||||
err.message,
|
||||
)}`,
|
||||
` - not tunnelling ${localAddress}:${localPort} to ${
|
||||
device.uuid
|
||||
}:${remotePort}, failed ${JSON.stringify(err.message)}`,
|
||||
);
|
||||
|
||||
return false;
|
||||
@ -237,7 +239,7 @@ export const tunnel: CommandDefinition<Args, Options> = {
|
||||
}
|
||||
|
||||
logger.logInfo('Waiting for connections...');
|
||||
}),
|
||||
).nodeify(done);
|
||||
})
|
||||
.nodeify(done);
|
||||
},
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user