Merge pull request #784 from balena-io/api-v5

api-binder: Use API v5
This commit is contained in:
dfunckt 2018-11-01 15:25:44 +02:00 committed by GitHub
commit 40a08ee4e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 8 deletions

View File

@ -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

View File

@ -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')

View File

@ -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) ->