Auto-merge for PR #513 via VersionBot

If a device is already provisioned but the key exchange fails, retry …
This commit is contained in:
resin-io-versionbot[bot] 2017-10-30 22:22:23 +00:00 committed by GitHub
commit 15b9943f6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 26 deletions

View File

@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY! automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
This project adheres to [Semantic Versioning](http://semver.org/). This project adheres to [Semantic Versioning](http://semver.org/).
## v6.3.8 - 2017-10-30
* If a device is already provisioned but the key exchange fails, retry it until it succeeds #513 [Pablo Carranza Velez]
## v6.3.7 - 2017-10-25 ## v6.3.7 - 2017-10-25
* Change the update retry to back off to the standard update check interval #515 [Pagan Gazzard] * Change the update retry to back off to the standard update check interval #515 [Pagan Gazzard]

View File

@ -1,7 +1,7 @@
{ {
"name": "resin-supervisor", "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.", "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.7", "version": "6.3.8",
"license": "Apache-2.0", "license": "Apache-2.0",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -179,13 +179,7 @@ hasDeviceApiKeySupport = (osVersion) ->
console.error('Unable to determine if device has deviceApiKey support', err, err.stack) console.error('Unable to determine if device has deviceApiKey support', err, err.stack)
false false
bootstrapper.done = new Promise (resolve) -> exchangeKeyAndUpdateConfig = ->
bootstrapper.doneBootstrapping = ->
bootstrapper.bootstrapped = true
resolve(userConfig)
# If we're still using an old api key we can try to exchange it for a valid device key
# This will only be the case when the supervisor/OS has been updated.
if userConfig.apiKey?
# Only do a key exchange and delete the provisioning key if we're on a Resin OS version # Only do a key exchange and delete the provisioning key if we're on a Resin OS version
# that supports using the deviceApiKey (2.0.2 and above) # that supports using the deviceApiKey (2.0.2 and above)
# or if we're in a non-Resin OS (which is assumed to be updated enough). # or if we're in a non-Resin OS (which is assumed to be updated enough).
@ -209,7 +203,26 @@ bootstrapper.done = new Promise (resolve) ->
utils.setConfig('apiKey', userConfig.deviceApiKey) utils.setConfig('apiKey', userConfig.deviceApiKey)
.then -> .then ->
writeAndSyncFile(configPath, JSON.stringify(userConfig)) writeAndSyncFile(configPath, JSON.stringify(userConfig))
# We return immediately, and eventually the API key will be exchanged and replaced.
exchangeKeyOrRetry = do ->
_failedExchanges = 0
return ->
exchangeKeyAndUpdateConfig()
.catch (err) ->
console.error('Error exchanging API key, will retry', err, err.stack)
delay = Math.min((2 ** _failedExchanges) * config.bootstrapRetryDelay, 24 * 60 * 60 * 1000)
_failedExchanges += 1
setTimeout(exchangeKeyOrRetry, delay)
return
bootstrapper.done = new Promise (resolve) ->
bootstrapper.doneBootstrapping = ->
bootstrapper.bootstrapped = true
resolve(userConfig)
# If we're still using an old api key we can try to exchange it for a valid device key
# This will only be the case when the supervisor/OS has been updated.
if userConfig.apiKey?
exchangeKeyOrRetry()
return return
bootstrapper.bootstrapped = false bootstrapper.bootstrapped = false