mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-25 08:21:07 +00:00
update config.json on device registration
This commit is contained in:
parent
3f94b353f5
commit
7161c04123
@ -6,6 +6,7 @@ utils = require './utils'
|
|||||||
crypto = require 'crypto'
|
crypto = require 'crypto'
|
||||||
config = require './config'
|
config = require './config'
|
||||||
PlatformAPI = require 'pinejs-client-js/request'
|
PlatformAPI = require 'pinejs-client-js/request'
|
||||||
|
fs = Promise.promisifyAll(require('fs'))
|
||||||
|
|
||||||
PLATFORM_ENDPOINT = url.resolve(config.apiEndpoint, '/ewa/')
|
PLATFORM_ENDPOINT = url.resolve(config.apiEndpoint, '/ewa/')
|
||||||
resinAPI = new PlatformAPI(PLATFORM_ENDPOINT)
|
resinAPI = new PlatformAPI(PLATFORM_ENDPOINT)
|
||||||
@ -27,8 +28,8 @@ registerDevice = (apiKey, userId, applicationId, deviceType, uuid) ->
|
|||||||
device_type: deviceType
|
device_type: deviceType
|
||||||
customOptions:
|
customOptions:
|
||||||
apikey: apiKey
|
apikey: apiKey
|
||||||
).then ->
|
).then (data) ->
|
||||||
return uuid
|
_.pick(data, 'id', 'uuid')
|
||||||
|
|
||||||
module.exports = ->
|
module.exports = ->
|
||||||
# Load config file
|
# Load config file
|
||||||
@ -39,9 +40,11 @@ module.exports = ->
|
|||||||
if userConfig.uuid? and userConfig.registered_at?
|
if userConfig.uuid? and userConfig.registered_at?
|
||||||
return userConfig
|
return userConfig
|
||||||
registerDevice(userConfig.apiKey, userConfig.userId, userConfig.applicationId, userConfig.deviceType, userConfig.uuid)
|
registerDevice(userConfig.apiKey, userConfig.userId, userConfig.applicationId, userConfig.deviceType, userConfig.uuid)
|
||||||
.then (uuid) ->
|
.then (device) ->
|
||||||
userConfig.uuid = uuid
|
userConfig.uuid = device.uuid
|
||||||
return userConfig
|
userConfig.deviceId = device.id
|
||||||
|
fs.writeFileAsync('/boot/config.json', JSON.stringify(userConfig))
|
||||||
|
.return(userConfig)
|
||||||
.then ->
|
.then ->
|
||||||
console.log('Finishing bootstrapping')
|
console.log('Finishing bootstrapping')
|
||||||
Promise.all([
|
Promise.all([
|
||||||
|
Loading…
Reference in New Issue
Block a user