From d1c773360f8013d5c3d886d12689679b79c802d2 Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Thu, 1 Feb 2018 17:48:01 +0200 Subject: [PATCH 1/2] Fix uuid params being parsed a numbers Connects-To: #489 Change-Type: patch --- lib/actions/config.coffee | 2 ++ lib/actions/device.coffee | 12 +++++++++++ lib/actions/environment-variables.coffee | 3 +++ lib/actions/logs.coffee | 3 +++ lib/actions/notes.coffee | 3 +++ lib/actions/os.coffee | 3 +++ lib/actions/ssh.coffee | 2 ++ lib/utils/normalization.ts | 26 ++++++++++++++++++++++++ 8 files changed, 54 insertions(+) create mode 100644 lib/utils/normalization.ts diff --git a/lib/actions/config.coffee b/lib/actions/config.coffee index 178991670d..a7a821a77c 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 2e6fdca69e..9e6c175e36 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 76feb3a565..4c2a0337dd 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 0a294acfb8..fa3bd520cb 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 cdee6d0b71..aceaf315fc 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 7bd6ca2ed6..42ffe11a53 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 6d2d04feb4..561be99021 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 0000000000..1efdf76574 --- /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]); + } +} From 0e9b8e41401b171b92954e2464cfffd75f023a49 Mon Sep 17 00:00:00 2001 From: "resin-io-versionbot[bot]" Date: Sat, 3 Feb 2018 15:50:09 +0000 Subject: [PATCH 2/2] v6.12.8 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aeaf0e37ab..f1d90aacb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY! This project adheres to [Semantic Versioning](http://semver.org/). +## v6.12.8 - 2018-02-03 + +* Fix uuid params being parsed a numbers #774 [Thodoris Greasidis] + ## v6.12.7 - 2018-01-30 * Add 'or mounted resinOS image' #767 [MoranF] diff --git a/package.json b/package.json index 35718c0da9..603fb09e5f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "resin-cli", - "version": "6.12.7", + "version": "6.12.8", "description": "The official resin.io CLI tool", "main": "./build/actions/index.js", "homepage": "https://github.com/resin-io/resin-cli",