From f17cbb1205d9e0ac7138e57156319c9f4e62253e Mon Sep 17 00:00:00 2001 From: Eugene Mirotin Date: Fri, 16 Dec 2016 17:34:05 +0300 Subject: [PATCH] use the new SDK factory --- build/actions/app.js | 10 +-- build/actions/auth.js | 8 +-- build/actions/config.js | 2 +- build/actions/device.js | 30 ++++---- build/actions/enter.js | 87 ------------------------ build/actions/environment-variables.js | 8 +-- build/actions/keys.js | 8 +-- build/actions/logs.js | 2 +- build/actions/notes.js | 2 +- build/actions/os.js | 2 +- build/actions/settings.js | 2 +- build/actions/ssh.js | 2 +- build/actions/sync.js | 2 +- build/actions/wizard.js | 2 +- build/app.js | 2 +- build/events.js | 2 +- build/resin-sdk.js | 18 +++++ build/utils/helpers.js | 2 +- build/utils/patterns.js | 2 +- lib/actions/app.coffee | 10 +-- lib/actions/auth.coffee | 8 +-- lib/actions/config.coffee | 2 +- lib/actions/device.coffee | 30 ++++---- lib/actions/environment-variables.coffee | 8 +-- lib/actions/keys.coffee | 8 +-- lib/actions/logs.coffee | 2 +- lib/actions/notes.coffee | 2 +- lib/actions/os.coffee | 2 +- lib/actions/settings.coffee | 2 +- lib/actions/ssh.coffee | 2 +- lib/actions/sync.coffee | 2 +- lib/actions/wizard.coffee | 2 +- lib/app.coffee | 2 +- lib/events.coffee | 2 +- lib/resin-sdk.coffee | 13 ++++ lib/utils/helpers.coffee | 2 +- lib/utils/patterns.coffee | 2 +- 37 files changed, 119 insertions(+), 175 deletions(-) delete mode 100644 build/actions/enter.js create mode 100644 build/resin-sdk.js create mode 100644 lib/resin-sdk.coffee diff --git a/build/actions/app.js b/build/actions/app.js index 09fb0e72..6e026363 100644 --- a/build/actions/app.js +++ b/build/actions/app.js @@ -37,7 +37,7 @@ limitations under the License. primary: true, action: function(params, options, done) { var patterns, resin; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); patterns = require('../utils/patterns'); return resin.models.application.has(params.name).then(function(hasApplication) { if (hasApplication) { @@ -61,7 +61,7 @@ limitations under the License. primary: true, action: function(params, options, done) { var resin, visuals; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); visuals = require('resin-cli-visuals'); return resin.models.application.getAll().then(function(applications) { return console.log(visuals.table.horizontal(applications, ['id', 'app_name', 'device_type', 'online_devices', 'devices_length'])); @@ -77,7 +77,7 @@ limitations under the License. primary: true, action: function(params, options, done) { var resin, visuals; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); visuals = require('resin-cli-visuals'); return resin.models.application.get(params.name).then(function(application) { return console.log(visuals.table.vertical(application, ["$" + application.app_name + "$", 'id', 'device_type', 'git_repository', 'commit'])); @@ -92,7 +92,7 @@ limitations under the License. permission: 'user', action: function(params, options, done) { var resin; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); return resin.models.application.restart(params.name).nodeify(done); } }; @@ -105,7 +105,7 @@ limitations under the License. permission: 'user', action: function(params, options, done) { var patterns, resin; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); patterns = require('../utils/patterns'); return patterns.confirm(options.yes, 'Are you sure you want to delete the application?').then(function() { return resin.models.application.remove(params.name); diff --git a/build/actions/auth.js b/build/actions/auth.js index 9bb16506..c86c21f4 100644 --- a/build/actions/auth.js +++ b/build/actions/auth.js @@ -55,7 +55,7 @@ limitations under the License. _ = require('lodash'); Promise = require('bluebird'); capitano = Promise.promisifyAll(require('capitano')); - resin = require('resin-sdk'); + resin = require('../resin-sdk'); auth = require('resin-cli-auth'); form = require('resin-cli-form'); patterns = require('../utils/patterns'); @@ -104,7 +104,7 @@ limitations under the License. permission: 'user', action: function(params, options, done) { var resin; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); return resin.auth.logout().nodeify(done); } }; @@ -115,7 +115,7 @@ limitations under the License. help: 'Use this command to signup for a resin.io account.\n\nIf signup is successful, you\'ll be logged in to your new user automatically.\n\nExamples:\n\n $ resin signup\n Email: me@mycompany.com\n Username: johndoe\n Password: ***********\n\n $ resin whoami\n johndoe', action: function(params, options, done) { var form, resin, validation; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); form = require('resin-cli-form'); validation = require('../utils/validation'); return resin.settings.get('resinUrl').then(function(resinUrl) { @@ -149,7 +149,7 @@ limitations under the License. action: function(params, options, done) { var Promise, resin, visuals; Promise = require('bluebird'); - resin = require('resin-sdk'); + resin = require('../resin-sdk'); visuals = require('resin-cli-visuals'); return Promise.props({ username: resin.auth.whoami(), diff --git a/build/actions/config.js b/build/actions/config.js index 27caf439..e54619f6 100644 --- a/build/actions/config.js +++ b/build/actions/config.js @@ -210,7 +210,7 @@ limitations under the License. var Promise, _, deviceConfig, form, fs, prettyjson, resin; Promise = require('bluebird'); fs = Promise.promisifyAll(require('fs')); - resin = require('resin-sdk'); + resin = require('../resin-sdk'); _ = require('lodash'); form = require('resin-cli-form'); deviceConfig = require('resin-device-config'); diff --git a/build/actions/device.js b/build/actions/device.js index ba4768dc..81ff789b 100644 --- a/build/actions/device.js +++ b/build/actions/device.js @@ -32,7 +32,7 @@ limitations under the License. var Promise, _, resin, visuals; Promise = require('bluebird'); _ = require('lodash'); - resin = require('resin-sdk'); + resin = require('../resin-sdk'); visuals = require('resin-cli-visuals'); return Promise["try"](function() { if (options.application != null) { @@ -57,7 +57,7 @@ limitations under the License. primary: true, action: function(params, options, done) { var resin, visuals; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); visuals = require('resin-cli-visuals'); return resin.models.device.get(params.uuid).then(function(device) { return resin.models.device.getStatus(device).then(function(status) { @@ -75,7 +75,7 @@ limitations under the License. permission: 'user', action: function(params, options, done) { var resin; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); return resin.models.config.getDeviceTypes().each(function(deviceType) { return console.log(deviceType.slug); }).nodeify(done); @@ -98,7 +98,7 @@ limitations under the License. action: function(params, options, done) { var Promise, resin; Promise = require('bluebird'); - resin = require('resin-sdk'); + resin = require('../resin-sdk'); return resin.models.application.get(params.application).then(function(application) { return Promise["try"](function() { return options.uuid || resin.models.device.generateUUID(); @@ -118,7 +118,7 @@ limitations under the License. permission: 'user', action: function(params, options, done) { var patterns, resin; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); patterns = require('../utils/patterns'); return patterns.confirm(options.yes, 'Are you sure you want to delete the device?').then(function() { return resin.models.device.remove(params.uuid); @@ -133,7 +133,7 @@ limitations under the License. permission: 'user', action: function(params, options, done) { var resin; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); return resin.models.device.identify(params.uuid).nodeify(done); } }; @@ -146,7 +146,7 @@ limitations under the License. permission: 'user', action: function(params, options, done) { var resin; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); return resin.models.device.reboot(params.uuid, options).nodeify(done); } }; @@ -159,7 +159,7 @@ limitations under the License. permission: 'user', action: function(params, options, done) { var resin; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); return resin.models.device.shutdown(params.uuid, options).nodeify(done); } }; @@ -171,7 +171,7 @@ limitations under the License. permission: 'user', action: function(params, options, done) { var resin; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); return resin.models.device.enableDeviceUrl(params.uuid).nodeify(done); } }; @@ -183,7 +183,7 @@ limitations under the License. permission: 'user', action: function(params, options, done) { var resin; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); return resin.models.device.disableDeviceUrl(params.uuid).nodeify(done); } }; @@ -195,7 +195,7 @@ limitations under the License. permission: 'user', action: function(params, options, done) { var resin; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); return resin.models.device.getDeviceUrl(params.uuid).then(function(url) { return console.log(url); }).nodeify(done); @@ -209,7 +209,7 @@ limitations under the License. permission: 'user', action: function(params, options, done) { var resin; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); return resin.models.device.hasDeviceUrl(params.uuid).then(function(hasDeviceUrl) { return console.log(hasDeviceUrl); }).nodeify(done); @@ -225,7 +225,7 @@ limitations under the License. var Promise, _, form, resin; Promise = require('bluebird'); _ = require('lodash'); - resin = require('resin-sdk'); + resin = require('../resin-sdk'); form = require('resin-cli-form'); return Promise["try"](function() { if (!_.isEmpty(params.newName)) { @@ -247,7 +247,7 @@ limitations under the License. options: [commandOptions.optionalApplication], action: function(params, options, done) { var _, patterns, resin; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); _ = require('lodash'); patterns = require('../utils/patterns'); return resin.models.device.get(params.uuid).then(function(device) { @@ -282,7 +282,7 @@ limitations under the License. rimraf = Promise.promisify(require('rimraf')); tmp = Promise.promisifyAll(require('tmp')); tmp.setGracefulCleanup(); - resin = require('resin-sdk'); + resin = require('../resin-sdk'); helpers = require('../utils/helpers'); patterns = require('../utils/patterns'); return Promise["try"](function() { diff --git a/build/actions/enter.js b/build/actions/enter.js deleted file mode 100644 index faec42aa..00000000 --- a/build/actions/enter.js +++ /dev/null @@ -1,87 +0,0 @@ - -/* -Copyright 2016 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. - */ - -(function() { - var getSubShellCommand; - - getSubShellCommand = function(command) { - var os; - os = require('os'); - if (os.platform() === 'win32') { - return { - program: 'sh', - args: ['-c', command] - }; - } else { - return { - program: '/bin/sh', - args: ['-c', command] - }; - } - }; - - module.exports = { - signature: 'enter ', - description: '(beta) get a shell into the running app container of a device', - help: 'Use this command to get a shell into the running application container of\nyour device.\n\nExamples:\n\n $ resin enter 7cf02a6\n $ resin enter 7cf02a6 --port 8080', - permission: 'user', - primary: true, - options: [ - { - signature: 'port', - parameter: 'port', - description: 'ssh port', - alias: 't' - } - ], - action: function(params, options, done) { - var Promise, child_process, resin, settings; - child_process = require('child_process'); - Promise = require('bluebird'); - resin = require('resin-sdk'); - settings = require('resin-settings-client'); - if (options.port == null) { - options.port = 22; - } - console.info("Connecting with: " + params.uuid); - return Promise.props({ - isOnline: resin.models.device.isOnline(params.uuid), - username: resin.auth.whoami(), - uuid: resin.models.device.get(params.uuid).get('uuid'), - containerId: resin.models.device.getApplicationInfo(params.uuid).get('containerId') - }).then(function(arg) { - var containerId, isOnline, username, uuid; - isOnline = arg.isOnline, username = arg.username, uuid = arg.uuid, containerId = arg.containerId; - if (!isOnline) { - throw new Error('Device is not online'); - } - if (containerId == null) { - throw new Error('Did not find running application container'); - } - return Promise["try"](function() { - var command, spawn, subShellCommand; - command = "ssh -t -p " + options.port + " " + username + "@" + (settings.get('proxyUrl')) + " enter " + uuid + " " + containerId; - subShellCommand = getSubShellCommand(command); - return spawn = child_process.spawn(subShellCommand.program, subShellCommand.args, { - stdio: 'inherit' - }); - }); - }); - } - }; - -}).call(this); diff --git a/build/actions/environment-variables.js b/build/actions/environment-variables.js index 323a4d80..c2db685c 100644 --- a/build/actions/environment-variables.js +++ b/build/actions/environment-variables.js @@ -38,7 +38,7 @@ limitations under the License. var Promise, _, resin, visuals; Promise = require('bluebird'); _ = require('lodash'); - resin = require('resin-sdk'); + resin = require('../resin-sdk'); visuals = require('resin-cli-visuals'); return Promise["try"](function() { if (options.application != null) { @@ -70,7 +70,7 @@ limitations under the License. permission: 'user', action: function(params, options, done) { var patterns, resin; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); patterns = require('../utils/patterns'); return patterns.confirm(options.yes, 'Are you sure you want to delete the environment variable?').then(function() { if (options.device) { @@ -91,7 +91,7 @@ limitations under the License. action: function(params, options, done) { var Promise, resin; Promise = require('bluebird'); - resin = require('resin-sdk'); + resin = require('../resin-sdk'); return Promise["try"](function() { if (params.value == null) { params.value = process.env[params.key]; @@ -121,7 +121,7 @@ limitations under the License. action: function(params, options, done) { var Promise, resin; Promise = require('bluebird'); - resin = require('resin-sdk'); + resin = require('../resin-sdk'); return Promise["try"](function() { if (options.device) { return resin.models.environmentVariables.device.update(params.id, params.value); diff --git a/build/actions/keys.js b/build/actions/keys.js index f8054cea..3b49b1e0 100644 --- a/build/actions/keys.js +++ b/build/actions/keys.js @@ -28,7 +28,7 @@ limitations under the License. permission: 'user', action: function(params, options, done) { var resin, visuals; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); visuals = require('resin-cli-visuals'); return resin.models.key.getAll().then(function(keys) { return console.log(visuals.table.horizontal(keys, ['id', 'title'])); @@ -43,7 +43,7 @@ limitations under the License. permission: 'user', action: function(params, options, done) { var resin, visuals; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); visuals = require('resin-cli-visuals'); return resin.models.key.get(params.id).then(function(key) { console.log(visuals.table.vertical(key, ['id', 'title'])); @@ -60,7 +60,7 @@ limitations under the License. permission: 'user', action: function(params, options, done) { var patterns, resin; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); patterns = require('../utils/patterns'); return patterns.confirm(options.yes, 'Are you sure you want to delete the key?').then(function() { return resin.models.key.remove(params.id); @@ -79,7 +79,7 @@ limitations under the License. Promise = require('bluebird'); fs = Promise.promisifyAll(require('fs')); capitano = require('capitano'); - resin = require('resin-sdk'); + resin = require('../resin-sdk'); return Promise["try"](function() { if (params.path != null) { return fs.readFileAsync(params.path, { diff --git a/build/actions/logs.js b/build/actions/logs.js index cbc86acd..b73f67d5 100644 --- a/build/actions/logs.js +++ b/build/actions/logs.js @@ -34,7 +34,7 @@ limitations under the License. action: function(params, options, done) { var _, moment, printLine, promise, resin; _ = require('lodash'); - resin = require('resin-sdk'); + resin = require('../resin-sdk'); moment = require('moment'); printLine = function(line) { var timestamp; diff --git a/build/actions/notes.js b/build/actions/notes.js index 86cb687a..e83da695 100644 --- a/build/actions/notes.js +++ b/build/actions/notes.js @@ -35,7 +35,7 @@ limitations under the License. var Promise, _, resin; Promise = require('bluebird'); _ = require('lodash'); - resin = require('resin-sdk'); + resin = require('../resin-sdk'); return Promise["try"](function() { if (_.isEmpty(params.note)) { throw new Error('Missing note content'); diff --git a/build/actions/os.js b/build/actions/os.js index fced3b15..39640906 100644 --- a/build/actions/os.js +++ b/build/actions/os.js @@ -106,7 +106,7 @@ limitations under the License. action: function(params, options, done) { var _, form, helpers, init, resin; _ = require('lodash'); - resin = require('resin-sdk'); + resin = require('../resin-sdk'); form = require('resin-cli-form'); init = require('resin-device-init'); helpers = require('../utils/helpers'); diff --git a/build/actions/settings.js b/build/actions/settings.js index 2089abad..e11cad4b 100644 --- a/build/actions/settings.js +++ b/build/actions/settings.js @@ -23,7 +23,7 @@ limitations under the License. help: 'Use this command to display detected settings\n\nExamples:\n\n $ resin settings', action: function(params, options, done) { var prettyjson, resin; - resin = require('resin-sdk'); + resin = require('../resin-sdk'); prettyjson = require('prettyjson'); return resin.settings.getAll().then(prettyjson.render).then(console.log).nodeify(done); } diff --git a/build/actions/ssh.js b/build/actions/ssh.js index efc4dbfa..8daa097c 100644 --- a/build/actions/ssh.js +++ b/build/actions/ssh.js @@ -58,7 +58,7 @@ limitations under the License. var Promise, child_process, patterns, resin, settings, verbose; child_process = require('child_process'); Promise = require('bluebird'); - resin = require('resin-sdk'); + resin = require('../resin-sdk'); settings = require('resin-settings-client'); patterns = require('../utils/patterns'); if (options.port == null) { diff --git a/build/actions/sync.js b/build/actions/sync.js index 0360e484..887d3ae5 100644 --- a/build/actions/sync.js +++ b/build/actions/sync.js @@ -101,7 +101,7 @@ limitations under the License. var Promise, fs, path, patterns, resin, resinSync; fs = require('fs'); path = require('path'); - resin = require('resin-sdk'); + resin = require('../resin-sdk'); Promise = require('bluebird'); resinSync = require('resin-sync'); patterns = require('../utils/patterns'); diff --git a/build/actions/wizard.js b/build/actions/wizard.js index a9a11269..ca253cfd 100644 --- a/build/actions/wizard.js +++ b/build/actions/wizard.js @@ -26,7 +26,7 @@ limitations under the License. var Promise, capitano, patterns, resin; Promise = require('bluebird'); capitano = Promise.promisifyAll(require('capitano')); - resin = require('resin-sdk'); + resin = require('../resin-sdk'); patterns = require('../utils/patterns'); return resin.auth.isLoggedIn().then(function(isLoggedIn) { if (isLoggedIn) { diff --git a/build/app.js b/build/app.js index dc49d835..7089785b 100644 --- a/build/app.js +++ b/build/app.js @@ -25,7 +25,7 @@ limitations under the License. capitano = Promise.promisifyAll(require('capitano')); - resin = require('resin-sdk'); + resin = require('./resin-sdk'); actions = require('./actions'); diff --git a/build/events.js b/build/events.js index adb74cf4..bf6a52c3 100644 --- a/build/events.js +++ b/build/events.js @@ -8,7 +8,7 @@ Promise = require('bluebird'); - resin = require('resin-sdk'); + resin = require('./resin-sdk'); capitanoState = Promise.promisifyAll(require('capitano').state); diff --git a/build/resin-sdk.js b/build/resin-sdk.js new file mode 100644 index 00000000..1d6df46d --- /dev/null +++ b/build/resin-sdk.js @@ -0,0 +1,18 @@ +(function() { + var getSdk, opts, settings; + + getSdk = require('resin-sdk'); + + settings = require('resin-settings-client'); + + opts = { + apiUrl: settings.get('apiUrl'), + imageMakerUrl: settings.get('imageMakerUrl'), + dataDirectory: settings.get('dataDirectory'), + apiVersion: 'v2', + retries: 2 + }; + + module.exports = getSdk(opts); + +}).call(this); diff --git a/build/utils/helpers.js b/build/utils/helpers.js index a781644c..99b25924 100644 --- a/build/utils/helpers.js +++ b/build/utils/helpers.js @@ -29,7 +29,7 @@ limitations under the License. president = Promise.promisifyAll(require('president')); - resin = require('resin-sdk'); + resin = require('./resin-sdk'); imagefs = require('resin-image-fs'); diff --git a/build/utils/patterns.js b/build/utils/patterns.js index fed32876..82782994 100644 --- a/build/utils/patterns.js +++ b/build/utils/patterns.js @@ -28,7 +28,7 @@ limitations under the License. visuals = require('resin-cli-visuals'); - resin = require('resin-sdk'); + resin = require('./resin-sdk'); chalk = require('chalk'); diff --git a/lib/actions/app.coffee b/lib/actions/app.coffee index a94aa5a7..068d76bc 100644 --- a/lib/actions/app.coffee +++ b/lib/actions/app.coffee @@ -45,7 +45,7 @@ exports.create = permission: 'user' primary: true action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') patterns = require('../utils/patterns') # Validate the the application name is available @@ -79,7 +79,7 @@ exports.list = permission: 'user' primary: true action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') visuals = require('resin-cli-visuals') resin.models.application.getAll().then (applications) -> @@ -105,7 +105,7 @@ exports.info = permission: 'user' primary: true action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') visuals = require('resin-cli-visuals') resin.models.application.get(params.name).then (application) -> @@ -130,7 +130,7 @@ exports.restart = ''' permission: 'user' action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') resin.models.application.restart(params.name).nodeify(done) exports.remove = @@ -150,7 +150,7 @@ exports.remove = options: [ commandOptions.yes ] permission: 'user' action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') patterns = require('../utils/patterns') patterns.confirm(options.yes, 'Are you sure you want to delete the application?').then -> diff --git a/lib/actions/auth.coffee b/lib/actions/auth.coffee index c78790e6..e548e0b0 100644 --- a/lib/actions/auth.coffee +++ b/lib/actions/auth.coffee @@ -74,7 +74,7 @@ exports.login = _ = require('lodash') Promise = require('bluebird') capitano = Promise.promisifyAll(require('capitano')) - resin = require('resin-sdk') + resin = require('../resin-sdk') auth = require('resin-cli-auth') form = require('resin-cli-form') patterns = require('../utils/patterns') @@ -136,7 +136,7 @@ exports.logout = ''' permission: 'user' action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') resin.auth.logout().nodeify(done) exports.signup = @@ -158,7 +158,7 @@ exports.signup = johndoe ''' action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') form = require('resin-cli-form') validation = require('../utils/validation') @@ -198,7 +198,7 @@ exports.whoami = permission: 'user' action: (params, options, done) -> Promise = require('bluebird') - resin = require('resin-sdk') + resin = require('../resin-sdk') visuals = require('resin-cli-visuals') Promise.props diff --git a/lib/actions/config.coffee b/lib/actions/config.coffee index 801a43d6..d5744914 100644 --- a/lib/actions/config.coffee +++ b/lib/actions/config.coffee @@ -242,7 +242,7 @@ exports.generate = action: (params, options, done) -> Promise = require('bluebird') fs = Promise.promisifyAll(require('fs')) - resin = require('resin-sdk') + resin = require('../resin-sdk') _ = require('lodash') form = require('resin-cli-form') deviceConfig = require('resin-device-config') diff --git a/lib/actions/device.coffee b/lib/actions/device.coffee index 7d39c8f6..25af08eb 100644 --- a/lib/actions/device.coffee +++ b/lib/actions/device.coffee @@ -37,7 +37,7 @@ exports.list = action: (params, options, done) -> Promise = require('bluebird') _ = require('lodash') - resin = require('resin-sdk') + resin = require('../resin-sdk') visuals = require('resin-cli-visuals') Promise.try -> @@ -76,7 +76,7 @@ exports.info = permission: 'user' primary: true action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') visuals = require('resin-cli-visuals') resin.models.device.get(params.uuid).then (device) -> @@ -114,7 +114,7 @@ exports.supported = ''' permission: 'user' action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') resin.models.config.getDeviceTypes().each (deviceType) -> console.log(deviceType.slug) .nodeify(done) @@ -138,7 +138,7 @@ exports.register = ] action: (params, options, done) -> Promise = require('bluebird') - resin = require('resin-sdk') + resin = require('../resin-sdk') resin.models.application.get(params.application).then (application) -> @@ -167,7 +167,7 @@ exports.remove = options: [ commandOptions.yes ] permission: 'user' action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') patterns = require('../utils/patterns') patterns.confirm(options.yes, 'Are you sure you want to delete the device?').then -> @@ -188,7 +188,7 @@ exports.identify = ''' permission: 'user' action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') resin.models.device.identify(params.uuid).nodeify(done) exports.reboot = @@ -204,7 +204,7 @@ exports.reboot = options: [ commandOptions.forceUpdateLock ] permission: 'user' action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') resin.models.device.reboot(params.uuid, options).nodeify(done) exports.shutdown = @@ -220,7 +220,7 @@ exports.shutdown = options: [ commandOptions.forceUpdateLock ] permission: 'user' action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') resin.models.device.shutdown(params.uuid, options).nodeify(done) exports.enableDeviceUrl = @@ -235,7 +235,7 @@ exports.enableDeviceUrl = ''' permission: 'user' action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') resin.models.device.enableDeviceUrl(params.uuid).nodeify(done) exports.disableDeviceUrl = @@ -250,7 +250,7 @@ exports.disableDeviceUrl = ''' permission: 'user' action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') resin.models.device.disableDeviceUrl(params.uuid).nodeify(done) exports.getDeviceUrl = @@ -265,7 +265,7 @@ exports.getDeviceUrl = ''' permission: 'user' action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') resin.models.device.getDeviceUrl(params.uuid).then (url) -> console.log(url) .nodeify(done) @@ -282,7 +282,7 @@ exports.hasDeviceUrl = ''' permission: 'user' action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') resin.models.device.hasDeviceUrl(params.uuid).then (hasDeviceUrl) -> console.log(hasDeviceUrl) .nodeify(done) @@ -304,7 +304,7 @@ exports.rename = action: (params, options, done) -> Promise = require('bluebird') _ = require('lodash') - resin = require('resin-sdk') + resin = require('../resin-sdk') form = require('resin-cli-form') Promise.try -> @@ -333,7 +333,7 @@ exports.move = permission: 'user' options: [ commandOptions.optionalApplication ] action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') _ = require('lodash') patterns = require('../utils/patterns') @@ -381,7 +381,7 @@ exports.init = tmp = Promise.promisifyAll(require('tmp')) tmp.setGracefulCleanup() - resin = require('resin-sdk') + resin = require('../resin-sdk') helpers = require('../utils/helpers') patterns = require('../utils/patterns') diff --git a/lib/actions/environment-variables.coffee b/lib/actions/environment-variables.coffee index 3a195b4b..4d261506 100644 --- a/lib/actions/environment-variables.coffee +++ b/lib/actions/environment-variables.coffee @@ -48,7 +48,7 @@ exports.list = action: (params, options, done) -> Promise = require('bluebird') _ = require('lodash') - resin = require('resin-sdk') + resin = require('../resin-sdk') visuals = require('resin-cli-visuals') Promise.try -> @@ -98,7 +98,7 @@ exports.remove = ] permission: 'user' action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') patterns = require('../utils/patterns') patterns.confirm(options.yes, 'Are you sure you want to delete the environment variable?').then -> @@ -136,7 +136,7 @@ exports.add = permission: 'user' action: (params, options, done) -> Promise = require('bluebird') - resin = require('resin-sdk') + resin = require('../resin-sdk') Promise.try -> if not params.value? @@ -172,7 +172,7 @@ exports.rename = options: [ commandOptions.booleanDevice ] action: (params, options, done) -> Promise = require('bluebird') - resin = require('resin-sdk') + resin = require('../resin-sdk') Promise.try -> if options.device diff --git a/lib/actions/keys.coffee b/lib/actions/keys.coffee index f813e2fc..8d565c41 100644 --- a/lib/actions/keys.coffee +++ b/lib/actions/keys.coffee @@ -28,7 +28,7 @@ exports.list = ''' permission: 'user' action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') visuals = require('resin-cli-visuals') resin.models.key.getAll().then (keys) -> @@ -50,7 +50,7 @@ exports.info = ''' permission: 'user' action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') visuals = require('resin-cli-visuals') resin.models.key.get(params.id).then (key) -> @@ -82,7 +82,7 @@ exports.remove = options: [ commandOptions.yes ] permission: 'user' action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') patterns = require('../utils/patterns') patterns.confirm(options.yes, 'Are you sure you want to delete the key?').then -> @@ -109,7 +109,7 @@ exports.add = Promise = require('bluebird') fs = Promise.promisifyAll(require('fs')) capitano = require('capitano') - resin = require('resin-sdk') + resin = require('../resin-sdk') Promise.try -> return fs.readFileAsync(params.path, encoding: 'utf8') if params.path? diff --git a/lib/actions/logs.coffee b/lib/actions/logs.coffee index ba439424..11b657be 100644 --- a/lib/actions/logs.coffee +++ b/lib/actions/logs.coffee @@ -45,7 +45,7 @@ module.exports = primary: true action: (params, options, done) -> _ = require('lodash') - resin = require('resin-sdk') + resin = require('../resin-sdk') moment = require('moment') printLine = (line) -> diff --git a/lib/actions/notes.coffee b/lib/actions/notes.coffee index d28b4a7e..a448b312 100644 --- a/lib/actions/notes.coffee +++ b/lib/actions/notes.coffee @@ -40,7 +40,7 @@ exports.set = action: (params, options, done) -> Promise = require('bluebird') _ = require('lodash') - resin = require('resin-sdk') + resin = require('../resin-sdk') Promise.try -> if _.isEmpty(params.note) diff --git a/lib/actions/os.coffee b/lib/actions/os.coffee index fb7fe034..4a3d2ffb 100644 --- a/lib/actions/os.coffee +++ b/lib/actions/os.coffee @@ -107,7 +107,7 @@ exports.configure = ] action: (params, options, done) -> _ = require('lodash') - resin = require('resin-sdk') + resin = require('../resin-sdk') form = require('resin-cli-form') init = require('resin-device-init') helpers = require('../utils/helpers') diff --git a/lib/actions/settings.coffee b/lib/actions/settings.coffee index bb3fcbf8..32ad9b99 100644 --- a/lib/actions/settings.coffee +++ b/lib/actions/settings.coffee @@ -25,7 +25,7 @@ exports.list = $ resin settings ''' action: (params, options, done) -> - resin = require('resin-sdk') + resin = require('../resin-sdk') prettyjson = require('prettyjson') resin.settings.getAll() diff --git a/lib/actions/ssh.coffee b/lib/actions/ssh.coffee index c8f4b021..11c79841 100644 --- a/lib/actions/ssh.coffee +++ b/lib/actions/ssh.coffee @@ -69,7 +69,7 @@ module.exports = action: (params, options, done) -> child_process = require('child_process') Promise = require 'bluebird' - resin = require('resin-sdk') + resin = require('../resin-sdk') settings = require('resin-settings-client') patterns = require('../utils/patterns') diff --git a/lib/actions/sync.coffee b/lib/actions/sync.coffee index 50dd2d54..48ba68ee 100644 --- a/lib/actions/sync.coffee +++ b/lib/actions/sync.coffee @@ -130,7 +130,7 @@ module.exports = action: (params, options, done) -> fs = require('fs') path = require('path') - resin = require('resin-sdk') + resin = require('../resin-sdk') Promise = require('bluebird') resinSync = require('resin-sync') patterns = require('../utils/patterns') diff --git a/lib/actions/wizard.coffee b/lib/actions/wizard.coffee index 52b8b380..756abbcd 100644 --- a/lib/actions/wizard.coffee +++ b/lib/actions/wizard.coffee @@ -36,7 +36,7 @@ exports.wizard = action: (params, options, done) -> Promise = require('bluebird') capitano = Promise.promisifyAll(require('capitano')) - resin = require('resin-sdk') + resin = require('../resin-sdk') patterns = require('../utils/patterns') resin.auth.isLoggedIn().then (isLoggedIn) -> diff --git a/lib/app.coffee b/lib/app.coffee index 4bfa1f43..5dfc351a 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -17,7 +17,7 @@ limitations under the License. _ = require('lodash') Promise = require('bluebird') capitano = Promise.promisifyAll(require('capitano')) -resin = require('resin-sdk') +resin = require('./resin-sdk') actions = require('./actions') errors = require('./errors') events = require('./events') diff --git a/lib/events.coffee b/lib/events.coffee index e7104620..1cc4c100 100644 --- a/lib/events.coffee +++ b/lib/events.coffee @@ -1,7 +1,7 @@ _ = require('lodash') Mixpanel = require('mixpanel') Promise = require('bluebird') -resin = require('resin-sdk') +resin = require('./resin-sdk') capitanoState = Promise.promisifyAll(require('capitano').state) packageJSON = require('../package.json') diff --git a/lib/resin-sdk.coffee b/lib/resin-sdk.coffee new file mode 100644 index 00000000..b1bbaaac --- /dev/null +++ b/lib/resin-sdk.coffee @@ -0,0 +1,13 @@ +# This is a singleton Resin SDK instance builder + +getSdk = require('resin-sdk') +settings = require('resin-settings-client') +opts = + apiUrl: settings.get('apiUrl') + imageMakerUrl: settings.get('imageMakerUrl') + dataDirectory: settings.get('dataDirectory') + apiVersion: 'v2' + retries: 2 + +module.exports = getSdk(opts) + diff --git a/lib/utils/helpers.coffee b/lib/utils/helpers.coffee index 9c8cad4c..09afbe60 100644 --- a/lib/utils/helpers.coffee +++ b/lib/utils/helpers.coffee @@ -19,7 +19,7 @@ capitano = Promise.promisifyAll(require('capitano')) _ = require('lodash') _.str = require('underscore.string') president = Promise.promisifyAll(require('president')) -resin = require('resin-sdk') +resin = require('./resin-sdk') imagefs = require('resin-image-fs') rindle = require('rindle') os = require('os') diff --git a/lib/utils/patterns.coffee b/lib/utils/patterns.coffee index c1ab8a4c..0fa20dcd 100644 --- a/lib/utils/patterns.coffee +++ b/lib/utils/patterns.coffee @@ -18,7 +18,7 @@ _ = require('lodash') Promise = require('bluebird') form = require('resin-cli-form') visuals = require('resin-cli-visuals') -resin = require('resin-sdk') +resin = require('./resin-sdk') chalk = require('chalk') validation = require('./validation') messages = require('./messages')