update config.json on device registration

This commit is contained in:
Aleksis Brezas 2015-01-15 01:59:26 +00:00 committed by Pablo Carranza Vélez
parent 3f94b353f5
commit 7161c04123

View File

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