Add --generate-device-api-key parameter to config generate

Change-Type: minor
This commit is contained in:
Tim Perry 2018-07-10 19:45:48 +02:00
parent af9e1a122d
commit 52f93f8f12
3 changed files with 23 additions and 4 deletions

View File

@ -1136,6 +1136,7 @@ that will be asked for the relevant device type.
Examples: Examples:
$ resin config generate --device 7cf02a6 $ resin config generate --device 7cf02a6
$ resin config generate --device 7cf02a6 --generate-device-api-key
$ resin config generate --device 7cf02a6 --device-api-key <existingDeviceKey> $ resin config generate --device 7cf02a6 --device-api-key <existingDeviceKey>
$ resin config generate --device 7cf02a6 --output config.json $ resin config generate --device 7cf02a6 --output config.json
$ resin config generate --app MyApp $ resin config generate --app MyApp
@ -1156,6 +1157,10 @@ device uuid
custom device key - note that this is only supported on ResinOS 2.0.3+ custom device key - note that this is only supported on ResinOS 2.0.3+
#### --generate-device-api-key
generate a fresh device key for the device
#### --output, -o &#60;output&#62; #### --output, -o &#60;output&#62;
output output

View File

@ -230,6 +230,7 @@ exports.generate =
Examples: Examples:
$ resin config generate --device 7cf02a6 $ resin config generate --device 7cf02a6
$ resin config generate --device 7cf02a6 --generate-device-api-key
$ resin config generate --device 7cf02a6 --device-api-key <existingDeviceKey> $ resin config generate --device 7cf02a6 --device-api-key <existingDeviceKey>
$ resin config generate --device 7cf02a6 --output config.json $ resin config generate --device 7cf02a6 --output config.json
$ resin config generate --app MyApp $ resin config generate --app MyApp
@ -240,6 +241,11 @@ exports.generate =
commandOptions.optionalApplication commandOptions.optionalApplication
commandOptions.optionalDevice commandOptions.optionalDevice
commandOptions.optionalDeviceApiKey commandOptions.optionalDeviceApiKey
{
signature: 'generate-device-api-key'
description: 'generate a fresh device key for the device'
boolean: true
}
{ {
signature: 'output' signature: 'output'
description: 'output' description: 'output'
@ -303,7 +309,7 @@ exports.generate =
form.run(formOptions, override: options) form.run(formOptions, override: options)
.then (answers) -> .then (answers) ->
if resource.uuid? if resource.uuid?
generateDeviceConfig(resource, options.deviceApiKey, answers) generateDeviceConfig(resource, options.deviceApiKey || options['generate-device-api-key'], answers)
else else
generateApplicationConfig(resource, answers) generateApplicationConfig(resource, answers)
.then (config) -> .then (config) ->

View File

@ -75,7 +75,7 @@ export function generateApplicationConfig(
export function generateDeviceConfig( export function generateDeviceConfig(
device: ResinSdk.Device & { application_name: string }, device: ResinSdk.Device & { application_name: string },
deviceApiKey: string | null, deviceApiKey: string | true | null,
options: {}, options: {},
) { ) {
return resin.models.application return resin.models.application
@ -111,9 +111,17 @@ function addApplicationKey(config: any, applicationNameOrId: string | number) {
}); });
} }
function addDeviceKey(config: any, uuid: string, customDeviceApiKey: string) { function addDeviceKey(
config: any,
uuid: string,
customDeviceApiKey: string | true,
) {
return Promise.try(() => { return Promise.try(() => {
return customDeviceApiKey || resin.models.device.generateDeviceKey(uuid); if (customDeviceApiKey === true) {
return resin.models.device.generateDeviceKey(uuid);
} else {
return customDeviceApiKey;
}
}).tap(deviceApiKey => { }).tap(deviceApiKey => {
config.deviceApiKey = deviceApiKey; config.deviceApiKey = deviceApiKey;
}); });