Added a --device-api-key option to the device register command.

Change-Type: minor
This commit is contained in:
Pagan Gazzard 2017-04-18 20:19:04 -07:00 committed by Tim Perry
parent 93818b1a98
commit 2ef56a9a3f
4 changed files with 47 additions and 20 deletions

View File

@ -84,7 +84,7 @@ exports.supported = {
exports.register = {
signature: 'device register <application>',
description: 'register a device',
help: 'Use this command to register a device to an application.\n\nExamples:\n\n $ resin device register MyApp',
help: 'Use this command to register a device to an application.\n\nExamples:\n\n $ resin device register MyApp\n $ resin device register MyApp --uuid <uuid>\n $ resin device register MyApp --uuid <uuid> --device-api-key <existingDeviceKey>',
permission: 'user',
options: [
{
@ -92,19 +92,25 @@ exports.register = {
description: 'custom uuid',
parameter: 'uuid',
alias: 'u'
}, {
signature: 'deviceApiKey',
description: 'custom device key',
parameter: 'device-api-key',
alias: 'k'
}
],
action: function(params, options, done) {
var Promise, resin;
var Promise, ref, ref1, resin;
Promise = require('bluebird');
resin = require('resin-sdk-preconfigured');
return resin.models.application.get(params.application).then(function(application) {
return Promise["try"](function() {
return options.uuid || resin.models.device.generateUniqueKey();
}).then(function(uuid) {
console.info("Registering to " + application.app_name + ": " + uuid);
return resin.models.device.register(application.app_name, uuid);
});
return Promise.join(resin.models.application.get(params.application), (ref = options.uuid) != null ? ref : resin.models.device.generateUniqueKey(), (ref1 = options.deviceApiKey) != null ? ref1 : resin.models.device.generateUniqueKey(), function(application, uuid, deviceApiKey) {
console.info("Registering to " + application.app_name + ": " + uuid);
if (options.deviceApiKey == null) {
console.info("Using generated device api key: " + deviceApiKey);
} else {
console.info('Using provided device api key');
}
return resin.models.device.register(application.app_name, uuid, deviceApiKey);
}).get('uuid').nodeify(done);
}
};

View File

@ -334,6 +334,8 @@ Use this command to register a device to an application.
Examples:
$ resin device register MyApp
$ resin device register MyApp --uuid <uuid>
$ resin device register MyApp --uuid <uuid> --device-api-key <existingDeviceKey>
### Options
@ -341,6 +343,10 @@ Examples:
custom uuid
#### --deviceApiKey, -k &#60;device-api-key&#62;
custom device key
## device rm &#60;uuid&#62;
Use this command to remove a device from resin.io.

View File

@ -134,25 +134,40 @@ exports.register =
Examples:
$ resin device register MyApp
$ resin device register MyApp --uuid <uuid>
$ resin device register MyApp --uuid <uuid> --device-api-key <existingDeviceKey>
'''
permission: 'user'
options: [
signature: 'uuid'
description: 'custom uuid'
parameter: 'uuid'
alias: 'u'
{
signature: 'uuid'
description: 'custom uuid'
parameter: 'uuid'
alias: 'u'
}
{
signature: 'deviceApiKey'
description: 'custom device key'
parameter: 'device-api-key'
alias: 'k'
}
]
action: (params, options, done) ->
Promise = require('bluebird')
resin = require('resin-sdk-preconfigured')
resin.models.application.get(params.application).then (application) ->
Promise.try ->
return options.uuid or resin.models.device.generateUniqueKey()
.then (uuid) ->
Promise.join(
resin.models.application.get(params.application)
options.uuid ? resin.models.device.generateUniqueKey()
options.deviceApiKey ? resin.models.device.generateUniqueKey()
(application, uuid, deviceApiKey) ->
console.info("Registering to #{application.app_name}: #{uuid}")
return resin.models.device.register(application.app_name, uuid)
if not options.deviceApiKey?
console.info("Using generated device api key: #{deviceApiKey}")
else
console.info('Using provided device api key')
return resin.models.device.register(application.app_name, uuid, deviceApiKey)
)
.get('uuid')
.nodeify(done)

View File

@ -105,4 +105,4 @@
"optionalDependencies": {
"removedrive": "^1.0.0"
}
}
}