Pass in deviceId when fetching device tags

Change-type: patch
Closes: #1237
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2020-03-31 12:44:31 +01:00
parent 921a74f04f
commit 3c59944ce1
2 changed files with 18 additions and 5 deletions

View File

@ -383,8 +383,14 @@ export class APIBinder {
'Attempt to communicate with API, without initialized client',
);
}
const deviceId = await this.config.get('deviceId');
if (deviceId == null) {
throw new Error('Attempt to retrieve device tags before provision');
}
const tags = (await this.balenaApi.get({
resource: 'device_tag',
id: deviceId,
options: {
$select: ['id', 'tag_key', 'value'],
},

View File

@ -445,11 +445,18 @@ export function createV2Api(router: Router, applications: ApplicationManager) {
});
router.get('/v2/device/tags', async (_req, res) => {
const tags = await applications.apiBinder.fetchDeviceTags();
return res.json({
status: 'success',
tags,
});
try {
const tags = await applications.apiBinder.fetchDeviceTags();
return res.json({
status: 'success',
tags,
});
} catch (e) {
res.status(500).json({
status: 'failed',
message: e.message,
});
}
});
router.get('/v2/cleanup-volumes', async (_req, res) => {