Merge pull request #86 from resin-io/18-expose-apikey-to-app

Expose resin API key to apps
This commit is contained in:
Pablo Carranza Vélez 2016-01-22 12:38:57 -03:00
commit 3e18a350f1
3 changed files with 8 additions and 6 deletions

View File

@ -1,3 +1,4 @@
* Expose resin API key to apps [Pablo]
* On download start, set download_progress to 0. On finish, set state to Idle [Pablo]
* Set GOARM separately for each architecture [Pablo]
* Add armv5 (armel) build [Trong]

View File

@ -489,11 +489,6 @@ compareForUpdate = (localApps, remoteApps, localAppEnvs, remoteAppEnvs) ->
allAppIds = _.union(localAppIds, remoteAppIds)
return { toBeRemoved, toBeDownloaded, toBeInstalled, toBeUpdated, appsWithChangedEnvs, allAppIds }
getConfig = (key) ->
knex('config').select('value').where({ key })
.then ([ conf ]) ->
return conf?.value
application.update = update = (force) ->
if updateStatus.state isnt UPDATE_IDLE
# Mark an update required after the current.
@ -502,7 +497,7 @@ application.update = update = (force) ->
return
updateStatus.state = UPDATE_UPDATING
bootstrap.done.then ->
Promise.join getConfig('apiKey'), getConfig('uuid'), knex('app').select(), (apiKey, uuid, apps) ->
Promise.join utils.getConfig('apiKey'), utils.getConfig('uuid'), knex('app').select(), (apiKey, uuid, apps) ->
deviceId = device.getID()
remoteApps = getRemoteApps(uuid, apiKey)

View File

@ -125,6 +125,11 @@ exports.getOrGenerateSecret = (name) ->
generateSecret(name)
return secretPromises[name]
exports.getConfig = getConfig = (key) ->
knex('config').select('value').where({ key })
.then ([ conf ]) ->
return conf?.value
exports.extendEnvVars = (env, uuid) ->
host = '127.0.0.1'
newEnv =
@ -134,6 +139,7 @@ exports.extendEnvVars = (env, uuid) ->
RESIN_SUPERVISOR_PORT: config.listenPort
RESIN_SUPERVISOR_API_KEY: exports.getOrGenerateSecret('api')
RESIN_SUPERVISOR_VERSION: exports.supervisorVersion
RESIN_API_KEY: getConfig('apiKey')
RESIN: '1'
USER: 'root'
if env?