Auto-merge for PR #714 via VersionBot

Allow generating device configurating non-interactively
This commit is contained in:
resin-io-versionbot[bot] 2017-11-16 14:13:08 +00:00 committed by GitHub
commit 7e306fbce8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 101 additions and 10 deletions

View File

@ -4,6 +4,11 @@ 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.9.0 - 2017-11-16
* Allow non-interactice config generate for simple network settings #714 [Tim Perry]
* Fix issue where network settings were not used by `config generate` #714 [Tim Perry]
## v6.8.3 - 2017-11-16
* Remove resin promote command (which has never worked) to wait for larger resinOS provisioning updates #717 [Tim Perry]

View File

@ -194,7 +194,7 @@ exports.reconfigure = {
exports.generate = {
signature: 'config generate',
description: 'generate a config.json file',
help: 'Use this command to generate a config.json for a device or application\n\nExamples:\n\n $ resin config generate --device 7cf02a6\n $ resin config generate --device 7cf02a6 --device-api-key <existingDeviceKey>\n $ resin config generate --device 7cf02a6 --output config.json\n $ resin config generate --app MyApp\n $ resin config generate --app MyApp --output config.json',
help: 'Use this command to generate a config.json for a device or application.\n\nThis is interactive by default, but you can do this automatically without interactivity\nby specifying an option for each question on the command line, if you know the questions\nthat will be asked for the relevant device type.\n\nExamples:\n\n $ resin config generate --device 7cf02a6\n $ resin config generate --device 7cf02a6 --device-api-key <existingDeviceKey>\n $ resin config generate --device 7cf02a6 --output config.json\n $ resin config generate --app MyApp\n $ resin config generate --app MyApp --output config.json\n $ resin config generate --app MyApp --network wifi --wifiSsid mySsid --wifiKey abcdefgh --appUpdatePollInterval 1',
options: [
commandOptions.optionalApplication, commandOptions.optionalDevice, {
signature: 'deviceApiKey',
@ -206,6 +206,22 @@ exports.generate = {
description: 'output',
parameter: 'output',
alias: 'o'
}, {
signature: 'network',
description: 'the network type to use: ethernet or wifi',
parameter: 'network'
}, {
signature: 'wifiSsid',
description: 'the wifi ssid to use (used only if --network is set to wifi)',
parameter: 'wifiSsid'
}, {
signature: 'wifiKey',
description: 'the wifi key to use (used only if --network is set to wifi)',
parameter: 'wifiKey'
}, {
signature: 'appUpdatePollInterval',
description: 'how frequently (in minutes) to poll for application updates',
parameter: 'appUpdatePollInterval'
}
],
permission: 'user',
@ -228,7 +244,11 @@ exports.generate = {
}
return resin.models.application.get(options.application);
}).then(function(resource) {
return resin.models.device.getManifestBySlug(resource.device_type).get('options').then(form.run).then(function(answers) {
return resin.models.device.getManifestBySlug(resource.device_type).get('options').then(function(formOptions) {
return form.run(formOptions, {
override: options
});
}).then(function(answers) {
if (resource.uuid != null) {
return generateDeviceConfig(resource, options.deviceApiKey, answers);
} else {

View File

@ -18,10 +18,18 @@ limitations under the License.
var authenticateWithApplicationKey, authenticateWithDeviceKey;
exports.generateBaseConfig = function(application, options) {
var Promise, deviceConfig, resin;
var Promise, _, deviceConfig, resin;
Promise = require('bluebird');
_ = require('lodash');
deviceConfig = require('resin-device-config');
resin = require('resin-sdk-preconfigured');
options = _.mapValues(options, function(value, key) {
if (key === 'appUpdatePollInterval') {
return value * 60 * 1000;
} else {
return value;
}
});
return Promise.props({
userId: resin.auth.getUserId(),
username: resin.auth.whoami(),
@ -48,12 +56,12 @@ exports.generateBaseConfig = function(application, options) {
mixpanel: {
token: results.mixpanelToken
}
});
}, options);
});
};
exports.generateApplicationConfig = function(application, options) {
return exports.generateBaseConfig(application).tap(function(config) {
return exports.generateBaseConfig(application, options).tap(function(config) {
return authenticateWithApplicationKey(config, application.id);
});
};

View File

@ -1041,7 +1041,11 @@ show advanced commands
## config generate
Use this command to generate a config.json for a device or application
Use this command to generate a config.json for a device or application.
This is interactive by default, but you can do this automatically without interactivity
by specifying an option for each question on the command line, if you know the questions
that will be asked for the relevant device type.
Examples:
@ -1050,6 +1054,7 @@ Examples:
$ resin config generate --device 7cf02a6 --output config.json
$ resin config generate --app MyApp
$ resin config generate --app MyApp --output config.json
$ resin config generate --app MyApp --network wifi --wifiSsid mySsid --wifiKey abcdefgh --appUpdatePollInterval 1
### Options
@ -1069,6 +1074,22 @@ custom device key - note that this is only supported on ResinOS 2.0.3+
output
#### --network &#60;network&#62;
the network type to use: ethernet or wifi
#### --wifiSsid &#60;wifiSsid&#62;
the wifi ssid to use (used only if --network is set to wifi)
#### --wifiKey &#60;wifiKey&#62;
the wifi key to use (used only if --network is set to wifi)
#### --appUpdatePollInterval &#60;appUpdatePollInterval&#62;
how frequently (in minutes) to poll for application updates
# Preload
## preload &#60;image&#62;

View File

@ -219,7 +219,11 @@ exports.generate =
signature: 'config generate'
description: 'generate a config.json file'
help: '''
Use this command to generate a config.json for a device or application
Use this command to generate a config.json for a device or application.
This is interactive by default, but you can do this automatically without interactivity
by specifying an option for each question on the command line, if you know the questions
that will be asked for the relevant device type.
Examples:
@ -228,6 +232,7 @@ exports.generate =
$ resin config generate --device 7cf02a6 --output config.json
$ resin config generate --app MyApp
$ resin config generate --app MyApp --output config.json
$ resin config generate --app MyApp --network wifi --wifiSsid mySsid --wifiKey abcdefgh --appUpdatePollInterval 1
'''
options: [
commandOptions.optionalApplication
@ -244,6 +249,27 @@ exports.generate =
parameter: 'output'
alias: 'o'
}
# Options for non-interactive configuration
{
signature: 'network'
description: 'the network type to use: ethernet or wifi'
parameter: 'network'
}
{
signature: 'wifiSsid'
description: 'the wifi ssid to use (used only if --network is set to wifi)'
parameter: 'wifiSsid'
}
{
signature: 'wifiKey'
description: 'the wifi key to use (used only if --network is set to wifi)'
parameter: 'wifiKey'
}
{
signature: 'appUpdatePollInterval'
description: 'how frequently (in minutes) to poll for application updates'
parameter: 'appUpdatePollInterval'
}
]
permission: 'user'
action: (params, options, done) ->
@ -272,7 +298,10 @@ exports.generate =
.then (resource) ->
resin.models.device.getManifestBySlug(resource.device_type)
.get('options')
.then(form.run)
.then (formOptions) ->
# Pass params as an override: if there is any param with exactly the same name as a
# required option, that value is used (and the corresponding question is not asked)
form.run(formOptions, override: options)
.then (answers) ->
if resource.uuid?
generateDeviceConfig(resource, options.deviceApiKey, answers)

View File

@ -16,9 +16,16 @@ limitations under the License.
exports.generateBaseConfig = (application, options) ->
Promise = require('bluebird')
_ = require('lodash')
deviceConfig = require('resin-device-config')
resin = require('resin-sdk-preconfigured')
options = _.mapValues options, (value, key) ->
if key == 'appUpdatePollInterval'
value * 60 * 1000
else
value
Promise.props
userId: resin.auth.getUserId()
username: resin.auth.whoami()
@ -42,9 +49,10 @@ exports.generateBaseConfig = (application, options) ->
pubnub: results.pubNubKeys
mixpanel:
token: results.mixpanelToken
, options
exports.generateApplicationConfig = (application, options) ->
exports.generateBaseConfig(application)
exports.generateBaseConfig(application, options)
.tap (config) ->
authenticateWithApplicationKey(config, application.id)

View File

@ -1,6 +1,6 @@
{
"name": "resin-cli",
"version": "6.8.3",
"version": "6.9.0",
"description": "The official resin.io CLI tool",
"main": "./build/actions/index.js",
"homepage": "https://github.com/resin-io/resin-cli",