mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-04-14 14:36:36 +00:00
device-api: Add v2/device/name endpoint
This endpoint returns the last known device name from the API. This differs from the BALENA_DEVICE_NAME_AT_INIT env var because this will not change throughout the runtime of the container. Closes: #908 Change-type: minor Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
parent
2855295432
commit
3f231e8ff3
24
docs/API.md
24
docs/API.md
@ -1102,3 +1102,27 @@ Response:
|
||||
"serviceName": "main"
|
||||
}
|
||||
```
|
||||
|
||||
### V2 Device Information
|
||||
|
||||
#### Device name
|
||||
|
||||
Added in supervisor version v9.11.0
|
||||
|
||||
Get the last returned device name from the balena API. Note that this differs from the
|
||||
`BALENA_DEVICE_NAME_AT_INIT` environment variable provided to containers, as this will
|
||||
not change throughout the runtime of the container, but the endpoint will always return
|
||||
the latest known device name.
|
||||
|
||||
From an application container:
|
||||
```
|
||||
$ curl "$BALENA_SUPERVISOR_ADDRESS/v2/device/name?apikey=$BALENA_SUPERVISOR_API_KEY"
|
||||
```
|
||||
|
||||
Response:
|
||||
```json
|
||||
{
|
||||
"status": "success",
|
||||
"deviceName": "holy-wildflower"
|
||||
}
|
||||
```
|
||||
|
@ -436,4 +436,19 @@ export function createV2Api(router: Router, applications: ApplicationManager) {
|
||||
release: currentRelease,
|
||||
});
|
||||
});
|
||||
|
||||
router.get('/v2/device/name', async (_req, res) => {
|
||||
try {
|
||||
const deviceName = await applications.config.get('name');
|
||||
res.json({
|
||||
status: 'success',
|
||||
deviceName,
|
||||
});
|
||||
} catch (e) {
|
||||
res.status(503).json({
|
||||
status: 'failed',
|
||||
message: messageFromError(e),
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user