Resolve variable collision

This commit is contained in:
Petros Angelatos
2014-05-14 00:47:55 +01:00
committed by Pablo Carranza Vélez
parent 39261f5d6b
commit 94eeaaa510

View File

@ -11,7 +11,7 @@ request = Promise.promisify require 'request'
module.exports = -> module.exports = ->
# Load config file # Load config file
config = fs.readFileAsync('/boot/config.json', 'utf8').then(JSON.parse) userConfig = fs.readFileAsync('/boot/config.json', 'utf8').then(JSON.parse)
version = utils.getSupervisorVersion() version = utils.getSupervisorVersion()
@ -37,23 +37,23 @@ module.exports = ->
division: '' division: ''
) )
Promise.all([config, keys, version]) Promise.all([userConfig, keys, version])
.then ([config, keys, version]) -> .then ([userConfig, keys, version]) ->
console.log('UUID:', uuid) console.log('UUID:', uuid)
console.log('User ID:', config.userId) console.log('User ID:', userConfig.userId)
console.log('User:', config.username) console.log('User:', userConfig.username)
console.log('Supervisor Version:', version) console.log('Supervisor Version:', version)
console.log('API key:', config.apiKey) console.log('API key:', userConfig.apiKey)
console.log('Application ID:', config.applicationId) console.log('Application ID:', userConfig.applicationId)
console.log('CSR :', keys.csr) console.log('CSR :', keys.csr)
console.log('Posting to the API..') console.log('Posting to the API..')
config.csr = keys.csr userConfig.csr = keys.csr
config.uuid = uuid userConfig.uuid = uuid
config.version = version userConfig.version = version
return request( return request(
method: 'POST' method: 'POST'
url: url.resolve(config.apiEndpoint, 'associate') url: url.resolve(config.apiEndpoint, 'associate')
json: config json: userConfig
) )
.spread (response, body) -> .spread (response, body) ->
if response.statusCode >= 400 if response.statusCode >= 400
@ -74,13 +74,13 @@ module.exports = ->
Promise.all([ Promise.all([
knex('config').truncate() knex('config').truncate()
.then -> .then ->
config userConfig
.then (config) -> .then (userConfig) ->
knex('config').insert([ knex('config').insert([
{key: 'uuid', value: uuid} {key: 'uuid', value: uuid}
{key: 'apiKey', value: config.apiKey} {key: 'apiKey', value: userConfig.apiKey}
{key: 'username', value: config.username} {key: 'username', value: userConfig.username}
{key: 'userId', value: config.userId} {key: 'userId', value: userConfig.userId}
{key: 'version', value: version} {key: 'version', value: version}
]) ])
knex('app').truncate() knex('app').truncate()