From 95772f7874216eb3a3681dc24a4e01ff2144b83b Mon Sep 17 00:00:00 2001 From: Daniel Bunzendahl Date: Wed, 7 Oct 2015 11:20:16 +0200 Subject: [PATCH] Fixed by discussion Changed default value and also added a reasonable `opts.authorized` to each command what calls `Tessel.get` or `controller.standardTesselCommand`` - also the CASE of Tessel.js `connection.connectionType === USB` defaults to `connection.authorized === true` --- lib/controller.js | 16 ++++++++++++++-- lib/discover.js | 8 ++++++-- lib/tessel/tessel.js | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/controller.js b/lib/controller.js index 394d1f2a..2e66f50c 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -115,9 +115,11 @@ Tessel.get = function(opts) { timeout: (opts.timeout || 2) * 1000, usb: opts.usb, lan: opts.lan, - authorized: opts.authorized || true + authorized: true }; - + if (opts.authorized !== undefined) { + seekerOpts.authorized = opts.authorized; + } // Create a seeker object and start detecting any Tessels var seeker = new discover.TesselSeeker().start(seekerOpts); @@ -490,6 +492,7 @@ controller.provisionTessel = function(opts) { .then(function executeProvision() { // We should only be using a USB connection opts.usb = true; + opts.authorized = false; // Fetch a Tessel return controller.standardTesselCommand(opts, function(tessel) { // Provision Tessel with SSH keys @@ -499,6 +502,7 @@ controller.provisionTessel = function(opts) { }; controller.deployScript = function(opts) { + opts.authorized = true; return controller.standardTesselCommand(opts, function(tessel) { // Deploy a path to Tessel return tessel.deployScript(opts); @@ -506,6 +510,7 @@ controller.deployScript = function(opts) { }; controller.restartScript = function(opts) { + opts.authorized = true; return controller.standardTesselCommand(opts, function(tessel) { // Tell Tessel to restart an existing script return tessel.restartScript(opts); @@ -513,6 +518,7 @@ controller.restartScript = function(opts) { }; controller.eraseScript = function(opts) { + opts.authorized = true; return controller.standardTesselCommand(opts, function(tessel) { // Tell Tessel to erase any pushed script return tessel.eraseScript(opts, false); @@ -521,6 +527,7 @@ controller.eraseScript = function(opts) { controller.renameTessel = function(opts) { opts = opts || {}; + opts.authorized = true; // Grab the preferred tessel return new Promise(function(resolve, reject) { if (!opts.reset && !opts.newName) { @@ -541,6 +548,7 @@ controller.renameTessel = function(opts) { }; controller.printAvailableNetworks = function(opts) { + opts.authorized = true; return controller.standardTesselCommand(opts, function(tessel) { // Ask Tessel what networks it finds in a scan return tessel.findAvailableNetworks() @@ -556,6 +564,7 @@ controller.printAvailableNetworks = function(opts) { }; controller.getWifiInfo = function(opts) { + opts.authorized = true; return controller.standardTesselCommand(opts, function(tessel) { return tessel.getWifiInfo() .then(function(network) { @@ -594,6 +603,7 @@ controller.getWifiInfo = function(opts) { }; controller.connectToNetwork = function(opts) { + opts.authorized = true; return controller.standardTesselCommand(opts, function(tessel) { return tessel.connectToNetwork(opts); }); @@ -611,6 +621,7 @@ controller.printAvailableUpdates = function() { }; controller.update = function(opts) { + opts.authorized = true; return controller.standardTesselCommand(opts, function(tessel) { return new Promise(function updateProcess(resolve, reject) { // If it's not connected via USB, we can't update it @@ -740,6 +751,7 @@ controller.updateTesselWithVersion = function(force, tessel, currentVersion, bui }; controller.tesselFirmwareVerion = function(opts) { + opts.authorized = true; return controller.standardTesselCommand(opts, function(tessel) { // Grab the version information return tessel.fetchCurrentBuildInfo() diff --git a/lib/discover.js b/lib/discover.js index 4d1277f9..37ed9749 100644 --- a/lib/discover.js +++ b/lib/discover.js @@ -50,8 +50,8 @@ TesselSeeker.prototype.start = function(opts) { var tessel = new Tessel(conn); var opening = tessel.connection.open() .then(function() { - if (tessel.lanConnection && opts.authorized !== undefined) { - if (tessel.lanConnection.authorized !== opts.authorized) { + if (opts.authorized !== undefined) { + if (tessel.connection.authorized !== opts.authorized) { debug('Kicking ' + conn.host.slice(0, -6) + ' due to authorized filter: ' + opts.authorized); return Promise.reject(); } else { @@ -60,6 +60,10 @@ TesselSeeker.prototype.start = function(opts) { } else { return true; } + /*if (opts.authorized && !tessel.connection.authorized) { + debug('Kicking ' + conn.host.slice(0, -6) + ' due to authorized filter: ' + opts.authorized); + return; + }*/ }) .then(function() { debug('Connection opened:', tessel.connection.host); diff --git a/lib/tessel/tessel.js b/lib/tessel/tessel.js index 1c907bd5..63c99b80 100644 --- a/lib/tessel/tessel.js +++ b/lib/tessel/tessel.js @@ -32,6 +32,7 @@ function Tessel(connection) { // Set the connection var so we have an abstract interface to relay comms switch (connection.connectionType) { case 'USB': + connection.authorized = true; self.usbConnection = connection; break; case 'LAN':