mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-04-19 08:36:14 +00:00
api-binder: Use API v5
Change-type: major
This commit is contained in:
parent
ffd8171b48
commit
b71c59c002
@ -74,17 +74,13 @@ module.exports = class APIBinder
|
||||
if offlineMode
|
||||
console.log('Offline Mode is set, skipping API client initialization')
|
||||
return
|
||||
baseUrl = url.resolve(apiEndpoint, '/v4/')
|
||||
baseUrl = url.resolve(apiEndpoint, '/v5/')
|
||||
passthrough = _.cloneDeep(requestOpts)
|
||||
passthrough.headers ?= {}
|
||||
passthrough.headers.Authorization = "Bearer #{currentApiKey}"
|
||||
@resinApi = new PinejsClient
|
||||
apiPrefix: baseUrl
|
||||
passthrough: passthrough
|
||||
baseUrlLegacy = url.resolve(apiEndpoint, '/v2/')
|
||||
@resinApiLegacy = new PinejsClient
|
||||
apiPrefix: baseUrlLegacy
|
||||
passthrough: passthrough
|
||||
@cachedResinApi = @resinApi.clone({}, cache: {})
|
||||
|
||||
start: =>
|
||||
@ -265,7 +261,6 @@ module.exports = class APIBinder
|
||||
body: device
|
||||
.timeout(conf.apiTimeout)
|
||||
|
||||
# This uses resin API v2 for now, as the proxyvisor expects to be able to patch the device's commit
|
||||
patchDevice: (id, updatedFields) =>
|
||||
@config.getMany([
|
||||
'offlineMode'
|
||||
@ -277,7 +272,7 @@ module.exports = class APIBinder
|
||||
throw new Error('Cannot update dependent device in offline mode')
|
||||
if !conf.provisioned
|
||||
throw new Error('Device must be provisioned to update a dependent device')
|
||||
@resinApiLegacy.patch
|
||||
@resinApi.patch
|
||||
resource: 'device'
|
||||
id: id
|
||||
body: updatedFields
|
||||
|
@ -169,6 +169,9 @@ createProxyvisorRouter = (proxyvisor) ->
|
||||
|
||||
fieldsToUpdateOnDB = _.pickBy({ status, is_online, commit, releaseId, config, environment }, isDefined)
|
||||
fieldsToUpdateOnAPI = _.pick(fieldsToUpdateOnDB, 'status', 'is_online', 'commit', 'releaseId')
|
||||
if fieldsToUpdateOnAPI.commit?
|
||||
fieldsToUpdateOnAPI.is_on__commit = fieldsToUpdateOnAPI.commit
|
||||
delete fieldsToUpdateOnAPI.commit
|
||||
|
||||
if _.isEmpty(fieldsToUpdateOnDB)
|
||||
res.status(400).send('At least one device attribute must be updated')
|
||||
|
@ -26,7 +26,7 @@ api.resinBackend = {
|
||||
api.post '/device/register', (req, res) ->
|
||||
api.resinBackend.registerHandler(req, res)
|
||||
|
||||
api.get '/v4/device', (req, res) ->
|
||||
api.get '/v5/device', (req, res) ->
|
||||
api.resinBackend.getDeviceHandler(req, res)
|
||||
|
||||
api.post '/api-key/device/:deviceId/device-key', (req, res) ->
|
||||
|
Loading…
x
Reference in New Issue
Block a user