diff --git a/lib/actions/config.coffee b/lib/actions/config.coffee index 17899167..a7a821a7 100644 --- a/lib/actions/config.coffee +++ b/lib/actions/config.coffee @@ -15,6 +15,7 @@ limitations under the License. ### commandOptions = require('./command-options') +{ normalizeUuidProp } = require('../utils/normalization') exports.read = signature: 'config read' @@ -269,6 +270,7 @@ exports.generate = ] permission: 'user' action: (params, options, done) -> + normalizeUuidProp(options, 'device') Promise = require('bluebird') writeFileAsync = Promise.promisify(require('fs').writeFile) resin = require('resin-sdk-preconfigured') diff --git a/lib/actions/device.coffee b/lib/actions/device.coffee index 2e6fdca6..9e6c175e 100644 --- a/lib/actions/device.coffee +++ b/lib/actions/device.coffee @@ -16,6 +16,7 @@ limitations under the License. commandOptions = require('./command-options') _ = require('lodash') +{ normalizeUuidProp } = require('../utils/normalization') exports.list = signature: 'devices' @@ -77,6 +78,7 @@ exports.info = permission: 'user' primary: true action: (params, options, done) -> + normalizeUuidProp(params) resin = require('resin-sdk-preconfigured') visuals = require('resin-cli-visuals') @@ -185,6 +187,7 @@ exports.remove = options: [ commandOptions.yes ] permission: 'user' action: (params, options, done) -> + normalizeUuidProp(params) resin = require('resin-sdk-preconfigured') patterns = require('../utils/patterns') @@ -206,6 +209,7 @@ exports.identify = ''' permission: 'user' action: (params, options, done) -> + normalizeUuidProp(params) resin = require('resin-sdk-preconfigured') resin.models.device.identify(params.uuid).nodeify(done) @@ -222,6 +226,7 @@ exports.reboot = options: [ commandOptions.forceUpdateLock ] permission: 'user' action: (params, options, done) -> + normalizeUuidProp(params) resin = require('resin-sdk-preconfigured') resin.models.device.reboot(params.uuid, options).nodeify(done) @@ -238,6 +243,7 @@ exports.shutdown = options: [ commandOptions.forceUpdateLock ] permission: 'user' action: (params, options, done) -> + normalizeUuidProp(params) resin = require('resin-sdk-preconfigured') resin.models.device.shutdown(params.uuid, options).nodeify(done) @@ -253,6 +259,7 @@ exports.enableDeviceUrl = ''' permission: 'user' action: (params, options, done) -> + normalizeUuidProp(params) resin = require('resin-sdk-preconfigured') resin.models.device.enableDeviceUrl(params.uuid).nodeify(done) @@ -268,6 +275,7 @@ exports.disableDeviceUrl = ''' permission: 'user' action: (params, options, done) -> + normalizeUuidProp(params) resin = require('resin-sdk-preconfigured') resin.models.device.disableDeviceUrl(params.uuid).nodeify(done) @@ -283,6 +291,7 @@ exports.getDeviceUrl = ''' permission: 'user' action: (params, options, done) -> + normalizeUuidProp(params) resin = require('resin-sdk-preconfigured') resin.models.device.getDeviceUrl(params.uuid).then (url) -> console.log(url) @@ -300,6 +309,7 @@ exports.hasDeviceUrl = ''' permission: 'user' action: (params, options, done) -> + normalizeUuidProp(params) resin = require('resin-sdk-preconfigured') resin.models.device.hasDeviceUrl(params.uuid).then (hasDeviceUrl) -> console.log(hasDeviceUrl) @@ -320,6 +330,7 @@ exports.rename = ''' permission: 'user' action: (params, options, done) -> + normalizeUuidProp(params) Promise = require('bluebird') resin = require('resin-sdk-preconfigured') form = require('resin-cli-form') @@ -350,6 +361,7 @@ exports.move = permission: 'user' options: [ commandOptions.optionalApplication ] action: (params, options, done) -> + normalizeUuidProp(params) resin = require('resin-sdk-preconfigured') patterns = require('../utils/patterns') diff --git a/lib/actions/environment-variables.coffee b/lib/actions/environment-variables.coffee index 76feb3a5..4c2a0337 100644 --- a/lib/actions/environment-variables.coffee +++ b/lib/actions/environment-variables.coffee @@ -15,6 +15,7 @@ limitations under the License. ### commandOptions = require('./command-options') +{ normalizeUuidProp } = require('../utils/normalization') exports.list = signature: 'envs' @@ -46,6 +47,7 @@ exports.list = ] permission: 'user' action: (params, options, done) -> + normalizeUuidProp(options, 'device') Promise = require('bluebird') _ = require('lodash') resin = require('resin-sdk-preconfigured') @@ -135,6 +137,7 @@ exports.add = ] permission: 'user' action: (params, options, done) -> + normalizeUuidProp(options, 'device') Promise = require('bluebird') resin = require('resin-sdk-preconfigured') diff --git a/lib/actions/logs.coffee b/lib/actions/logs.coffee index 0a294acf..fa3bd520 100644 --- a/lib/actions/logs.coffee +++ b/lib/actions/logs.coffee @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. ### +{ normalizeUuidProp } = require('../utils/normalization') + module.exports = signature: 'logs ' description: 'show device logs' @@ -44,6 +46,7 @@ module.exports = permission: 'user' primary: true action: (params, options, done) -> + normalizeUuidProp(params) resin = require('resin-sdk-preconfigured') moment = require('moment') diff --git a/lib/actions/notes.coffee b/lib/actions/notes.coffee index cdee6d0b..aceaf315 100644 --- a/lib/actions/notes.coffee +++ b/lib/actions/notes.coffee @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. ### +{ normalizeUuidProp } = require('../utils/normalization') + exports.set = signature: 'note <|note>' description: 'set a device note' @@ -38,6 +40,7 @@ exports.set = ] permission: 'user' action: (params, options, done) -> + normalizeUuidProp(options, 'device') Promise = require('bluebird') _ = require('lodash') resin = require('resin-sdk-preconfigured') diff --git a/lib/actions/os.coffee b/lib/actions/os.coffee index 7bd6ca2e..42ffe11a 100644 --- a/lib/actions/os.coffee +++ b/lib/actions/os.coffee @@ -16,6 +16,7 @@ limitations under the License. commandOptions = require('./command-options') _ = require('lodash') +{ normalizeUuidProp } = require('../utils/normalization') formatVersion = (v, isRecommended) -> result = "v#{v}" @@ -227,6 +228,8 @@ exports.configure = } ] action: (params, options, done) -> + normalizeUuidProp(params) + normalizeUuidProp(options, 'device') fs = require('fs') Promise = require('bluebird') readFileAsync = Promise.promisify(fs.readFile) diff --git a/lib/actions/ssh.coffee b/lib/actions/ssh.coffee index 6d2d04fe..561be990 100644 --- a/lib/actions/ssh.coffee +++ b/lib/actions/ssh.coffee @@ -15,6 +15,7 @@ limitations under the License. ### commandOptions = require('./command-options') +{ normalizeUuidProp } = require('../utils/normalization') module.exports = signature: 'ssh [uuid]' @@ -54,6 +55,7 @@ module.exports = Only makes sense if you've configured proxy globally." ] action: (params, options, done) -> + normalizeUuidProp(params) child_process = require('child_process') Promise = require('bluebird') resin = require('resin-sdk-preconfigured') diff --git a/lib/utils/normalization.ts b/lib/utils/normalization.ts new file mode 100644 index 00000000..1efdf765 --- /dev/null +++ b/lib/utils/normalization.ts @@ -0,0 +1,26 @@ +/* +Copyright 2016-2018 Resin.io + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import _ = require('lodash'); + +export function normalizeUuidProp( + params: { [key: string]: any }, + propName = 'uuid', +) { + if (_.isNumber(params[propName])) { + params[propName] = _.toString(params[propName]); + } +}