envs, env add: Fix "Application is ambiguous" when using device UUID

Change-type: patch
This commit is contained in:
Paulo Castro 2021-08-11 01:19:49 +01:00
parent 485a9e944f
commit 58704b08d3
3 changed files with 13 additions and 10 deletions

View File

@ -227,7 +227,7 @@ async function setServiceVars(
sdk,
uuid,
['id'],
['app_name'],
['slug'],
);
} catch (err) {
console.error(`${err.message}, device: ${uuid}`);
@ -236,11 +236,7 @@ async function setServiceVars(
}
for (const service of options.service!.split(',')) {
try {
const serviceId = await getServiceIdForApp(
sdk,
app.app_name,
service,
);
const serviceId = await getServiceIdForApp(sdk, app.slug, service);
await sdk.models.device.serviceVar.set(
device.id,
serviceId,

View File

@ -174,11 +174,11 @@ export default class EnvsCmd extends Command {
balena,
options.device,
['uuid'],
['app_name'],
['slug'],
);
fullUUID = device.uuid;
if (app) {
appNameOrSlug = app.app_name;
appNameOrSlug = app.slug;
}
}
if (appNameOrSlug && options.service) {
@ -210,7 +210,14 @@ export default class EnvsCmd extends Command {
// Replace undefined app names with 'N/A' or null
varArray = varArray.map((i: EnvironmentVariableInfo) => {
i.appName = i.appName || (options.json ? null : 'N/A');
if (i.appName) {
// use slug in v13, app name in v12 for compatibility
i.appName = isV13()
? i.appName
: i.appName.substring(i.appName.indexOf('/') + 1);
} else {
i.appName = options.json ? null : 'N/A';
}
return i;
});

View File

@ -198,7 +198,7 @@ export class BalenaAPIMock extends NockMock {
is_online: opts.isOnline,
belongs_to__application: opts.inaccessibleApp
? []
: [{ app_name: 'test' }],
: [{ app_name: 'test', slug: 'org/test' }],
},
],
});