Skip to content

Commit

Permalink
Fixed by discussion
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
Student007 authored and rwaldron committed Oct 8, 2015
1 parent 0023cce commit 95772f7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
16 changes: 14 additions & 2 deletions lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -499,20 +502,23 @@ 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);
});
};

controller.restartScript = function(opts) {
opts.authorized = true;
return controller.standardTesselCommand(opts, function(tessel) {
// Tell Tessel to restart an existing script
return tessel.restartScript(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);
Expand All @@ -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) {
Expand All @@ -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()
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
});
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 6 additions & 2 deletions lib/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lib/tessel/tessel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit 95772f7

Please sign in to comment.