Merge pull request #2307 from balena-io/2306-env-add-app-is-ambiguous

envs, env add: Fix "Application is ambiguous" when using device UUID
This commit is contained in:
bulldozer-balena[bot] 2021-08-11 14:25:21 +00:00 committed by GitHub
commit e137c2aed2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 10 deletions

View File

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

View File

@ -174,11 +174,11 @@ export default class EnvsCmd extends Command {
balena, balena,
options.device, options.device,
['uuid'], ['uuid'],
['app_name'], ['slug'],
); );
fullUUID = device.uuid; fullUUID = device.uuid;
if (app) { if (app) {
appNameOrSlug = app.app_name; appNameOrSlug = app.slug;
} }
} }
if (appNameOrSlug && options.service) { if (appNameOrSlug && options.service) {
@ -210,7 +210,14 @@ export default class EnvsCmd extends Command {
// Replace undefined app names with 'N/A' or null // Replace undefined app names with 'N/A' or null
varArray = varArray.map((i: EnvironmentVariableInfo) => { 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; return i;
}); });

View File

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