diff --git a/doc/cli.markdown b/doc/cli.markdown index 141d4da0..1ae752f3 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -1136,6 +1136,7 @@ that will be asked for the relevant device type. Examples: $ resin config generate --device 7cf02a6 + $ resin config generate --device 7cf02a6 --generate-device-api-key $ resin config generate --device 7cf02a6 --device-api-key $ resin config generate --device 7cf02a6 --output config.json $ 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+ +#### --generate-device-api-key + +generate a fresh device key for the device + #### --output, -o <output> output diff --git a/lib/actions/config.coffee b/lib/actions/config.coffee index 1c71680f..608e4c96 100644 --- a/lib/actions/config.coffee +++ b/lib/actions/config.coffee @@ -230,6 +230,7 @@ exports.generate = Examples: $ resin config generate --device 7cf02a6 + $ resin config generate --device 7cf02a6 --generate-device-api-key $ resin config generate --device 7cf02a6 --device-api-key $ resin config generate --device 7cf02a6 --output config.json $ resin config generate --app MyApp @@ -240,6 +241,11 @@ exports.generate = commandOptions.optionalApplication commandOptions.optionalDevice commandOptions.optionalDeviceApiKey + { + signature: 'generate-device-api-key' + description: 'generate a fresh device key for the device' + boolean: true + } { signature: 'output' description: 'output' @@ -303,7 +309,7 @@ exports.generate = form.run(formOptions, override: options) .then (answers) -> if resource.uuid? - generateDeviceConfig(resource, options.deviceApiKey, answers) + generateDeviceConfig(resource, options.deviceApiKey || options['generate-device-api-key'], answers) else generateApplicationConfig(resource, answers) .then (config) -> diff --git a/lib/utils/config.ts b/lib/utils/config.ts index 9926e38a..fac78b08 100644 --- a/lib/utils/config.ts +++ b/lib/utils/config.ts @@ -75,7 +75,7 @@ export function generateApplicationConfig( export function generateDeviceConfig( device: ResinSdk.Device & { application_name: string }, - deviceApiKey: string | null, + deviceApiKey: string | true | null, options: {}, ) { 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 customDeviceApiKey || resin.models.device.generateDeviceKey(uuid); + if (customDeviceApiKey === true) { + return resin.models.device.generateDeviceKey(uuid); + } else { + return customDeviceApiKey; + } }).tap(deviceApiKey => { config.deviceApiKey = deviceApiKey; });