mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-03-22 12:05:53 +00:00
Make use of resin-register-device
This commit is contained in:
parent
6c2467cca8
commit
aead4c7531
@ -23,6 +23,7 @@
|
||||
"pubnub": "~3.6.4",
|
||||
"randomstring": "~1.0.3",
|
||||
"request": "^2.51.0",
|
||||
"resin-register-device": "^1.0.1",
|
||||
"server-destroy": "^1.0.0",
|
||||
"sqlite3": "~3.0.4",
|
||||
"tty.js": "0.2.14-1",
|
||||
|
@ -2,30 +2,10 @@ Promise = require 'bluebird'
|
||||
_ = require 'lodash'
|
||||
knex = require './db'
|
||||
utils = require './utils'
|
||||
crypto = require 'crypto'
|
||||
deviceRegister = require 'resin-register-device'
|
||||
{ resinApi } = require './request'
|
||||
fs = Promise.promisifyAll(require('fs'))
|
||||
|
||||
registerDevice = (apiKey, userId, applicationId, deviceType, uuid) ->
|
||||
# I'd be nice if the UUID matched the output of a SHA-256 function, but although the length limit of the CN
|
||||
# attribute in a X.509 certificate is 64 chars, a 32 byte UUID (64 chars in hex) doesn't pass the certificate
|
||||
# validation in OpenVPN This either means that the RFC counts a final NULL byte as part of the CN or that the
|
||||
# OpenVPN/OpenSSL implementation has a bug.
|
||||
if not uuid?
|
||||
uuid = crypto.pseudoRandomBytes(31).toString('hex')
|
||||
|
||||
resinApi.post(
|
||||
resource: 'device'
|
||||
body:
|
||||
user: userId
|
||||
application: applicationId
|
||||
uuid: uuid
|
||||
device_type: deviceType
|
||||
customOptions:
|
||||
apikey: apiKey
|
||||
).then (data) ->
|
||||
_.pick(data, 'id', 'uuid')
|
||||
|
||||
module.exports = ->
|
||||
# Load config file
|
||||
fs.readFileAsync('/boot/config.json', 'utf8')
|
||||
@ -34,7 +14,7 @@ module.exports = ->
|
||||
userConfig.deviceType ?= 'raspberry-pi'
|
||||
if userConfig.uuid? and userConfig.registered_at?
|
||||
return userConfig
|
||||
registerDevice(userConfig.apiKey, userConfig.userId, userConfig.applicationId, userConfig.deviceType, userConfig.uuid)
|
||||
deviceRegister.register(resinApi, userConfig)
|
||||
.then (device) ->
|
||||
userConfig.uuid = device.uuid
|
||||
userConfig.registered_at = Date.now()
|
||||
|
Loading…
x
Reference in New Issue
Block a user