mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-20 17:33:18 +00:00
Merge pull request #1324 from balena-io/1302-fix-ssh-numeric-short-uuid
Fix incorrect parsing of numeric short UUIDs in ssh and tunnel actions
This commit is contained in:
commit
30e48b658f
@ -162,6 +162,9 @@ function generateVpnSshCommand(opts: {
|
||||
export const ssh: CommandDefinition<
|
||||
{
|
||||
applicationOrDevice: string;
|
||||
// when Capitano converts a positional parameter (but not an option)
|
||||
// to a number, the original value is preserved with the _raw suffix
|
||||
applicationOrDevice_raw: string;
|
||||
serviceName?: string;
|
||||
},
|
||||
{
|
||||
@ -221,6 +224,8 @@ export const ssh: CommandDefinition<
|
||||
},
|
||||
],
|
||||
action: async (params, options) => {
|
||||
const applicationOrDevice =
|
||||
params.applicationOrDevice_raw || params.applicationOrDevice;
|
||||
const bash = await import('bash');
|
||||
// TODO: Make this typed
|
||||
const hasbin = require('hasbin');
|
||||
@ -241,12 +246,12 @@ export const ssh: CommandDefinition<
|
||||
|
||||
// if we're doing a direct SSH connection locally...
|
||||
if (
|
||||
validateDotLocalUrl(params.applicationOrDevice) ||
|
||||
validateIPAddress(params.applicationOrDevice)
|
||||
validateDotLocalUrl(applicationOrDevice) ||
|
||||
validateIPAddress(applicationOrDevice)
|
||||
) {
|
||||
const { performLocalDeviceSSH } = await import('../utils/device/ssh');
|
||||
return await performLocalDeviceSSH({
|
||||
address: params.applicationOrDevice,
|
||||
address: applicationOrDevice,
|
||||
port,
|
||||
verbose,
|
||||
service: params.serviceName,
|
||||
@ -255,7 +260,7 @@ export const ssh: CommandDefinition<
|
||||
|
||||
// this will be a tunnelled SSH connection...
|
||||
exitIfNotLoggedIn();
|
||||
const uuid = await getOnlineTargetUuid(sdk, params.applicationOrDevice);
|
||||
const uuid = await getOnlineTargetUuid(sdk, applicationOrDevice);
|
||||
let version: string | undefined;
|
||||
let id: number | undefined;
|
||||
|
||||
|
@ -25,6 +25,9 @@ import { tunnelConnectionToDevice } from '../utils/tunnel';
|
||||
|
||||
interface Args {
|
||||
deviceOrApplication: string;
|
||||
// when Capitano converts a positional parameter (but not an option)
|
||||
// to a number, the original value is preserved with the _raw suffix
|
||||
deviceOrApplication_raw: string;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
@ -88,6 +91,8 @@ export const tunnel: CommandDefinition<Args, Options> = {
|
||||
primary: true,
|
||||
|
||||
action: async (params, options) => {
|
||||
const deviceOrApplication =
|
||||
params.deviceOrApplication_raw || params.deviceOrApplication;
|
||||
const Logger = await import('../utils/logger');
|
||||
const logger = new Logger();
|
||||
const balena = await import('balena-sdk');
|
||||
@ -120,7 +125,7 @@ export const tunnel: CommandDefinition<Args, Options> = {
|
||||
? (options.port as string[])
|
||||
: [options.port as string];
|
||||
|
||||
const uuid = await getOnlineTargetUuid(sdk, params.deviceOrApplication);
|
||||
const uuid = await getOnlineTargetUuid(sdk, deviceOrApplication);
|
||||
const device = await sdk.models.device.get(uuid);
|
||||
|
||||
logger.logInfo(`Opening a tunnel to ${device.uuid}...`);
|
||||
|
@ -332,6 +332,8 @@ export async function getOnlineTargetUuid(
|
||||
sdk: BalenaSdk.BalenaSDK,
|
||||
applicationOrDevice: string,
|
||||
) {
|
||||
const Logger = await import('../utils/logger');
|
||||
const logger = new Logger();
|
||||
const appTest = validation.validateApplicationName(applicationOrDevice);
|
||||
const uuidTest = validation.validateUuid(applicationOrDevice);
|
||||
|
||||
@ -341,6 +343,9 @@ export async function getOnlineTargetUuid(
|
||||
|
||||
// if we have a definite device UUID...
|
||||
if (uuidTest && !appTest) {
|
||||
logger.logDebug(
|
||||
`Fetching device by UUID ${applicationOrDevice} (${typeof applicationOrDevice})`,
|
||||
);
|
||||
return (await sdk.models.device.get(applicationOrDevice, {
|
||||
$select: ['uuid'],
|
||||
$filter: { is_online: true },
|
||||
@ -349,6 +354,9 @@ export async function getOnlineTargetUuid(
|
||||
|
||||
// otherwise, it may be a device OR an application...
|
||||
try {
|
||||
logger.logDebug(
|
||||
`Fetching application by name ${applicationOrDevice} (${typeof applicationOrDevice})`,
|
||||
);
|
||||
const app = await sdk.models.application.get(applicationOrDevice);
|
||||
const devices = await sdk.models.device.getAllByApplication(app.id, {
|
||||
$filter: { is_online: true },
|
||||
@ -374,9 +382,13 @@ export async function getOnlineTargetUuid(
|
||||
if (!(err instanceof BalenaApplicationNotFound)) {
|
||||
throw err;
|
||||
}
|
||||
logger.logDebug(`Application not found`);
|
||||
}
|
||||
|
||||
// it wasn't an application, maybe it's a device...
|
||||
logger.logDebug(
|
||||
`Fetching device by UUID ${applicationOrDevice} (${typeof applicationOrDevice})`,
|
||||
);
|
||||
return (await sdk.models.device.get(applicationOrDevice, {
|
||||
$select: ['uuid'],
|
||||
$filter: { is_online: true },
|
||||
|
Loading…
x
Reference in New Issue
Block a user