Auto-merge for PR #510 via VersionBot

Ensure preloaded apps get the deviceApiKey in the env vars, and apps …
This commit is contained in:
resin-io-versionbot[bot] 2017-10-24 05:44:25 +00:00 committed by GitHub
commit b0d6ced304
5 changed files with 21 additions and 9 deletions

View File

@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
This project adheres to [Semantic Versioning](http://semver.org/).
## v6.3.6 - 2017-10-24
* Ensure preloaded apps are properly loaded by setting their internal markedForDeletion to false, and run apps that have it set to null #510 [Pablo Carranza Velez]
* Improve the check for when the device has been provisioned but the supervisor doesn't have knowledge of it in its local state #510 [Pablo Carranza Velez]
* Ensure preloaded apps get the deviceApiKey in the env vars, and apps never get the provisioning key, and improve detection of cases when the device has been pre-provisioned #510 [Pablo Carranza Velez]
## v6.3.5 - 2017-10-19
* Update docker-toolbelt to fix applying deltas on overlay2 with huge images #509 [Akis Kesoglou]

View File

@ -1,7 +1,7 @@
{
"name": "resin-supervisor",
"description": "This is resin.io's Supervisor, a program that runs on IoT devices and has the task of running user Apps (which are Docker containers), and updating them as Resin's API informs it to.",
"version": "6.3.5",
"version": "6.3.6",
"license": "Apache-2.0",
"repository": {
"type": "git",

View File

@ -633,9 +633,9 @@ getRemoteState = (uuid, apiKey) ->
throw err
# TODO: Actually store and use app.environment and app.config separately
parseEnvAndFormatRemoteApps = (remoteApps, uuid, apiKey) ->
parseEnvAndFormatRemoteApps = (remoteApps, uuid, deviceApiKey) ->
appsWithEnv = _.mapValues remoteApps, (app, appId) ->
utils.extendEnvVars(app.environment, uuid, appId, app.name, app.commit)
utils.extendEnvVars(app.environment, uuid, deviceApiKey, appId, app.name, app.commit)
.then (env) ->
app.config ?= {}
return {
@ -716,7 +716,9 @@ application.update = update = (force, scheduled = false) ->
.then ->
utils.setConfig('name', local.name) if local.name != deviceName
.then ->
parseEnvAndFormatRemoteApps(local.apps, uuid, apiKey)
utils.getConfig('deviceApiKey')
.then (deviceApiKey) ->
parseEnvAndFormatRemoteApps(local.apps, uuid, deviceApiKey)
.then (remoteApps) ->
localApps = formatLocalApps(apps)
resourcesForUpdate = compareForUpdate(localApps, remoteApps)
@ -880,7 +882,7 @@ application.initialize = ->
listenToEvents()
getAndApplyDeviceConfig()
.then ->
knex('app').whereNot(markedForDeletion: true).select()
knex('app').whereNot(markedForDeletion: true).orWhereNull('markedForDeletion').select()
.map (app) ->
unlockAndStart(app) if !application.localMode and !device.shuttingDown
.catch (error) ->

View File

@ -16,7 +16,7 @@ semverRegex = require('semver-regex')
userConfig = {}
DuplicateUuidError = message: '"uuid" must be unique.'
DuplicateUuidError = (err) -> _.startsWith(err.message, '"uuid" must be unique')
exports.ExchangeKeyError = class ExchangeKeyError extends TypedError
bootstrapper = {}
@ -40,9 +40,10 @@ loadPreloadedApps = ->
fs.readFileAsync(appsPath, 'utf8')
.then(JSON.parse)
.map (app) ->
utils.extendEnvVars(app.env, userConfig.uuid, app.appId, app.name, app.commit)
utils.extendEnvVars(app.env, userConfig.uuid, userConfig.deviceApiKey, app.appId, app.name, app.commit)
.then (extendedEnv) ->
app.env = JSON.stringify(extendedEnv)
app.markedForDeletion = false
_.merge(devConfig, app.config)
app.config = JSON.stringify(app.config)
knex('app').insert(app)
@ -135,6 +136,7 @@ bootstrap = ->
# We use the provisioning/user `apiKey` if it still exists because if it does it means we were already registered
# using that key and have to rely on the exchange key mechanism to swap the keys as appropriate later
{ key: 'apiKey', value: userConfig.apiKey ? userConfig.deviceApiKey }
{ key: 'deviceApiKey', value: userConfig.deviceApiKey }
{ key: 'username', value: userConfig.username }
{ key: 'userId', value: userConfig.userId }
{ key: 'version', value: utils.supervisorVersion }
@ -202,6 +204,8 @@ bootstrapper.done = new Promise (resolve) ->
delete userConfig.apiKey
else
userConfig.apiKey = userConfig.deviceApiKey
utils.setConfig('deviceApiKey', userConfig.deviceApiKey)
.then ->
utils.setConfig('apiKey', userConfig.deviceApiKey)
.then ->
writeAndSyncFile(configPath, JSON.stringify(userConfig))

View File

@ -155,7 +155,7 @@ exports.setConfig = (key, value = null) ->
.then (n) ->
knex('config').insert({ key, value }) if n == 0
exports.extendEnvVars = (env, uuid, appId, appName, commit) ->
exports.extendEnvVars = (env, uuid, apiKey, appId, appName, commit) ->
host = '127.0.0.1'
newEnv =
RESIN_APP_ID: appId.toString()
@ -170,7 +170,7 @@ exports.extendEnvVars = (env, uuid, appId, appName, commit) ->
RESIN_SUPERVISOR_PORT: config.listenPort
RESIN_SUPERVISOR_API_KEY: exports.getOrGenerateSecret('api')
RESIN_SUPERVISOR_VERSION: exports.supervisorVersion
RESIN_API_KEY: getConfig('apiKey')
RESIN_API_KEY: apiKey
RESIN: '1'
USER: 'root'
if env?