mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-20 17:52:51 +00:00
Add endpoint to get device state
This commit is contained in:
parent
38fb0c6257
commit
670f318c39
@ -1,3 +1,4 @@
|
||||
* Add endpoint to get device state [Pablo]
|
||||
* Check for valid strings or ints in all config values [Pablo]
|
||||
* Remove quotes in OS version [Pablo]
|
||||
|
||||
|
35
docs/API.md
35
docs/API.md
@ -405,3 +405,38 @@ $ curl -X POST --header "Content-Type:application/json" \
|
||||
--data '{"deviceId": <deviceId>, "appId": <appId>}' \
|
||||
"https://api.resin.io/supervisor/v1/regenerate-api-key"
|
||||
```
|
||||
|
||||
<hr>
|
||||
|
||||
### GET /v1/device
|
||||
|
||||
Introduced in supervisor v1.6.
|
||||
Returns the current device state, as reported to the Resin API.
|
||||
The state is a JSON object that contains some or all of the following:
|
||||
* `api_port`: Port on which the supervisor is listening.
|
||||
* `ip_address`: Space-separated list of IP addresses of the device.
|
||||
* `status`: Status of the device regarding the app, as a string, i.e. "Stopping", "Starting", "Downloading", "Installing", "Idle".
|
||||
* `download_progress`: Amount of the application image that has been downloaded, expressed as a percentage.
|
||||
* `os_version`: Version of the host OS running on the device.
|
||||
* `supervisor_version`: Version of the supervisor running on the device.
|
||||
|
||||
Other attributes may be added in the future, and some may be missing or null if they haven't been set yet.
|
||||
|
||||
#### Examples:
|
||||
From the app on the device:
|
||||
```bash
|
||||
$ curl -X GET --header "Content-Type:application/json" \
|
||||
"$RESIN_SUPERVISOR_ADDRESS/v1/device?apikey=$RESIN_SUPERVISOR_API_KEY"
|
||||
```
|
||||
Response:
|
||||
```json
|
||||
{"api_port":48484,"ip_address":"192.168.0.114 10.42.0.3","status":"Downloading","download_progress":84,"os_version":"Resin OS 1.0.4 (fido)","supervisor_version":"1.6.0"}
|
||||
```
|
||||
|
||||
Remotely via the API proxy:
|
||||
```bash
|
||||
$ curl -X POST --header "Content-Type:application/json" \
|
||||
--header "Authorization: Bearer <auth token>" \
|
||||
--data '{"deviceId": <deviceId>, "appId": <appId>, "method": "GET"}' \
|
||||
"https://api.resin.io/supervisor/v1/device"
|
||||
```
|
||||
|
@ -136,4 +136,7 @@ module.exports = (application) ->
|
||||
.catch (err) ->
|
||||
res.status(503).send(err?.message or err or 'Unknown error')
|
||||
|
||||
api.get '/v1/device', (req, res) ->
|
||||
res.json(device.getState())
|
||||
|
||||
return api
|
||||
|
@ -128,12 +128,16 @@ exports.getDeviceType = do ->
|
||||
throw new Error('Device type not specified in config file')
|
||||
return configFromFile.deviceType
|
||||
|
||||
targetState = {}
|
||||
exports.getState = ->
|
||||
fieldsToOmit = ['api_secret', 'logs_channel', 'provisioning_progress', 'provisioning_state']
|
||||
return _.omit(targetState, fieldsToOmit)
|
||||
|
||||
# Calling this function updates the local device state, which is then used to synchronise
|
||||
# the remote device state, repeating any failed updates until successfully synchronised.
|
||||
# This function will also optimise updates by merging multiple updates and only sending the latest state.
|
||||
exports.updateState = do ->
|
||||
applyPromise = Promise.resolve()
|
||||
targetState = {}
|
||||
actualState = {}
|
||||
|
||||
getStateDiff = ->
|
||||
|
Loading…
x
Reference in New Issue
Block a user