Add a containerId request function to the device api module

Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2019-05-27 13:18:19 +01:00
parent 5de7a50fc0
commit 39cf86ed85

View File

@ -67,6 +67,7 @@ const deviceEndpoints = {
ping: 'ping',
version: 'v2/version',
status: 'v2/state/status',
containerId: 'v2/containerId',
};
export class DeviceAPI {
@ -124,6 +125,29 @@ export class DeviceAPI {
});
}
public async getContainerId(serviceName: string): Promise<string> {
const url = this.getUrlForAction('containerId');
const body = await DeviceAPI.promisifiedRequest(
request.get,
{
url,
json: true,
qs: {
serviceName,
},
},
this.logger,
);
if (body.status !== 'success') {
throw new ApiErrors.DeviceAPIError(
'Non-successful response from supervisor containerId endpoint',
);
}
return body.containerId;
}
public async ping(): Promise<void> {
const url = this.getUrlForAction('ping');