From 11b5e0abc9b2223daf8707500965e535b92dc534 Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Thu, 21 Jan 2016 17:50:47 -0300 Subject: [PATCH] Expose resin API key to apps --- CHANGELOG.md | 1 + src/application.coffee | 7 +------ src/utils.coffee | 6 ++++++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9691858f..d04b85dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/src/application.coffee b/src/application.coffee index 43985de0..db972e66 100644 --- a/src/application.coffee +++ b/src/application.coffee @@ -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) diff --git a/src/utils.coffee b/src/utils.coffee index 460acf0a..21bb3e60 100644 --- a/src/utils.coffee +++ b/src/utils.coffee @@ -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?