mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-20 09:26:42 +00:00
patterns: Add debug logs in the getOnlineTargetUuid resolution
Change-type: patch Signed-off-by: Thodoris Greasidis <thodoris@balena.io>
This commit is contained in:
parent
f0030a1891
commit
f095ac169a
@ -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