Allow os configure to configure for an app, not just a specific device

This moves to --app and --uuid options, and deprecates the previous
format, but doesn't immediately remove it so this is not a breaking
change.

Connects-To: #691
Change-Type: minor
This commit is contained in:
Tim Perry 2017-11-16 19:13:20 +01:00
parent eef0d9cdbe
commit e38a0c0047
3 changed files with 88 additions and 27 deletions

View File

@ -188,36 +188,43 @@ exports.buildConfig = {
};
exports.configure = {
signature: 'os configure <image> <uuid> [deviceApiKey]',
signature: 'os configure <image> [uuid] [deviceApiKey]',
description: 'configure an os image',
help: 'Use this command to configure a previously downloaded operating system image for the specific device.\n\nNote that device api keys are only supported on ResinOS 2.0.3+\n\nExamples:\n\n $ resin os configure ../path/rpi.img 7cf02a6\n $ resin os configure ../path/rpi.img 7cf02a6 <existingDeviceKey>',
help: 'Use this command to configure a previously downloaded operating system image for\nthe specific device or for an application generally.\n\nNote that device api keys are only supported on ResinOS 2.0.3+.\n\nThis comand still supports the *deprecated* format where the UUID and optionally device key\nare passed directly on the command line, but the recommended way is to pass either an --app or\n--device argument. The deprecated format will be remove in a future release.\n\nExamples:\n\n $ resin os configure ../path/rpi.img --device 7cf02a6\n $ resin os configure ../path/rpi.img --device 7cf02a6 --deviceApiKey <existingDeviceKey>\n $ resin os configure ../path/rpi.img --app MyApp',
permission: 'user',
options: [
commandOptions.advancedConfig, {
commandOptions.advancedConfig, commandOptions.optionalApplication, commandOptions.optionalDevice, commandOptions.optionalDeviceApiKey, {
signature: 'config',
description: 'path to the config JSON file, see `resin os build-config`',
parameter: 'config'
}
],
action: function(params, options, done) {
var Promise, fs, generateDeviceConfig, helpers, init, readFileAsync, resin;
var Promise, configurationResourceType, deviceApiKey, fs, generateApplicationConfig, generateDeviceConfig, helpers, init, patterns, readFileAsync, ref, resin, uuid;
fs = require('fs');
Promise = require('bluebird');
readFileAsync = Promise.promisify(fs.readFile);
resin = require('resin-sdk-preconfigured');
init = require('resin-device-init');
helpers = require('../utils/helpers');
generateDeviceConfig = require('../utils/config').generateDeviceConfig;
patterns = require('../utils/patterns');
ref = require('../utils/config'), generateDeviceConfig = ref.generateDeviceConfig, generateApplicationConfig = ref.generateApplicationConfig;
if (_.filter([options.device, options.application, params.uuid]).length !== 1) {
patterns.expectedError('To configure an image, you must provide exactly one of:\n\n* A device, with --device <uuid>\n* An application, with --app <appname>\n* [Deprecated] A device, passing its uuid directly on the command line\n\nSee the help page for examples:\n\n $ resin help os configure');
}
uuid = options.device || params.uuid;
deviceApiKey = options.deviceApiKey || params.deviceApiKey;
console.info('Configuring operating system image');
return resin.models.device.get(params.uuid).then(function(device) {
configurationResourceType = uuid ? 'device' : 'application';
return resin.models[configurationResourceType].get(uuid || options.application).then(function(appOrDevice) {
return Promise["try"](function() {
if (options.config) {
return readFileAsync(options.config, 'utf8').then(JSON.parse);
}
return buildConfig(params.image, device.device_type, options.advanced);
return buildConfig(params.image, appOrDevice.device_type, options.advanced);
}).then(function(answers) {
return generateDeviceConfig(device, params.deviceApiKey, answers).then(function(config) {
return init.configure(params.image, device.device_type, config, answers);
return (configurationResourceType === 'device' ? generateDeviceConfig(appOrDevice, deviceApiKey, answers) : generateApplicationConfig(appOrDevice, answers)).then(function(config) {
return init.configure(params.image, appOrDevice.device_type, config, answers);
});
});
}).then(helpers.osProgressHandler).nodeify(done);

View File

@ -106,7 +106,7 @@ environment variable (in the same standard URL format).
- [os versions &#60;type&#62;](#os-versions-60-type-62-)
- [os download &#60;type&#62;](#os-download-60-type-62-)
- [os build-config &#60;image&#62; &#60;device-type&#62;](#os-build-config-60-image-62-60-device-type-62-)
- [os configure &#60;image&#62; &#60;uuid&#62; [deviceApiKey]](#os-configure-60-image-62-60-uuid-62-deviceapikey-)
- [os configure &#60;image&#62; [uuid] [deviceApiKey]](#os-configure-60-image-62-uuid-deviceapikey-)
- [os initialize &#60;image&#62;](#os-initialize-60-image-62-)
- Config
@ -909,16 +909,22 @@ show advanced configuration options
the path to the output JSON file
## os configure &#60;image&#62; &#60;uuid&#62; [deviceApiKey]
## os configure &#60;image&#62; [uuid] [deviceApiKey]
Use this command to configure a previously downloaded operating system image for the specific device.
Use this command to configure a previously downloaded operating system image for
the specific device or for an application generally.
Note that device api keys are only supported on ResinOS 2.0.3+
Note that device api keys are only supported on ResinOS 2.0.3+.
This comand still supports the *deprecated* format where the UUID and optionally device key
are passed directly on the command line, but the recommended way is to pass either an --app or
--device argument. The deprecated format will be remove in a future release.
Examples:
$ resin os configure ../path/rpi.img 7cf02a6
$ resin os configure ../path/rpi.img 7cf02a6 <existingDeviceKey>
$ resin os configure ../path/rpi.img --device 7cf02a6
$ resin os configure ../path/rpi.img --device 7cf02a6 --deviceApiKey <existingDeviceKey>
$ resin os configure ../path/rpi.img --app MyApp
### Options
@ -926,6 +932,18 @@ Examples:
show advanced configuration options
#### --application, --a,app, --a,app &#60;application&#62;
application name
#### --device, -d &#60;device&#62;
device uuid
#### --deviceApiKey, -k &#60;device-api-key&#62;
custom device key - note that this is only supported on ResinOS 2.0.3+
#### --config &#60;config&#62;
path to the config JSON file, see `resin os build-config`

View File

@ -196,21 +196,30 @@ exports.buildConfig =
.nodeify(done)
exports.configure =
signature: 'os configure <image> <uuid> [deviceApiKey]'
signature: 'os configure <image> [uuid] [deviceApiKey]'
description: 'configure an os image'
help: '''
Use this command to configure a previously downloaded operating system image for the specific device.
Use this command to configure a previously downloaded operating system image for
the specific device or for an application generally.
Note that device api keys are only supported on ResinOS 2.0.3+
Note that device api keys are only supported on ResinOS 2.0.3+.
This comand still supports the *deprecated* format where the UUID and optionally device key
are passed directly on the command line, but the recommended way is to pass either an --app or
--device argument. The deprecated format will be remove in a future release.
Examples:
$ resin os configure ../path/rpi.img 7cf02a6
$ resin os configure ../path/rpi.img 7cf02a6 <existingDeviceKey>
$ resin os configure ../path/rpi.img --device 7cf02a6
$ resin os configure ../path/rpi.img --device 7cf02a6 --deviceApiKey <existingDeviceKey>
$ resin os configure ../path/rpi.img --app MyApp
'''
permission: 'user'
options: [
commandOptions.advancedConfig
commandOptions.optionalApplication
commandOptions.optionalDevice
commandOptions.optionalDeviceApiKey
{
signature: 'config'
description: 'path to the config JSON file, see `resin os build-config`'
@ -224,20 +233,47 @@ exports.configure =
resin = require('resin-sdk-preconfigured')
init = require('resin-device-init')
helpers = require('../utils/helpers')
{ generateDeviceConfig } = require('../utils/config')
patterns = require('../utils/patterns')
{ generateDeviceConfig, generateApplicationConfig } = require('../utils/config')
if _.filter([
options.device
options.application
params.uuid
]).length != 1
patterns.expectedError '''
To configure an image, you must provide exactly one of:
* A device, with --device <uuid>
* An application, with --app <appname>
* [Deprecated] A device, passing its uuid directly on the command line
See the help page for examples:
$ resin help os configure
'''
uuid = options.device || params.uuid
deviceApiKey = options.deviceApiKey || params.deviceApiKey
console.info('Configuring operating system image')
resin.models.device.get(params.uuid)
.then (device) ->
configurationResourceType = if uuid then 'device' else 'application'
resin.models[configurationResourceType].get(uuid || options.application)
.then (appOrDevice) ->
Promise.try ->
if options.config
return readFileAsync(options.config, 'utf8')
.then(JSON.parse)
return buildConfig(params.image, device.device_type, options.advanced)
return buildConfig(params.image, appOrDevice.device_type, options.advanced)
.then (answers) ->
generateDeviceConfig(device, params.deviceApiKey, answers)
.then (config) ->
init.configure(params.image, device.device_type, config, answers)
(if configurationResourceType == 'device'
generateDeviceConfig(appOrDevice, deviceApiKey, answers)
else
generateApplicationConfig(appOrDevice, answers)
).then (config) ->
init.configure(params.image, appOrDevice.device_type, config, answers)
.then(helpers.osProgressHandler)
.nodeify(done)