Merge pull request #1238 from balena-io/1237-device-id-on-fetch

Pass in deviceId when fetching device tags
This commit is contained in:
CameronDiver 2020-03-31 14:46:29 +01:00 committed by GitHub
commit abe1b59ebe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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) => {