Skip to content

Commit

Permalink
Rename Tessel.(RUN|PUSH)_PATH => REMOTE_(RUN|PUSH)_PATH; Rename Tesse…
Browse files Browse the repository at this point in the history
…l.TESSEL_AUTH_(PATH|KEY) => Tessel.LOCAL_AUTH_(PATH|KEY)

Previous there were 4 file/path-centric "const-ish" properties defined on the Tessel class, two of which were specific to some local operations and two of which were specific to some remote operations. None of the 4 values clearly indicated which of those operations they were relevant to. With this renaming, it becomes very clear:

- Tessel.RUN_PATH => Tessel.REMOTE_RUN_PATH
- Tessel.PUSH_PATH => Tessel.REMOTE_PUSH_PATH
- Tessel.TESSEL_AUTH_PATH => Tessel.LOCAL_AUTH_PATH
- Tessel.TESSEL_AUTH_KEY => Tessel.LOCAL_AUTH_KEY
  • Loading branch information
rwaldron committed Nov 19, 2015
1 parent 17765e2 commit d5584a5
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion bin/tessel-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function makeCommand(commandName) {
required: false,
metavar: 'PRIVATEKEY',
abbr: 'i',
default: Tessel.TESSEL_AUTH_KEY,
default: Tessel.LOCAL_AUTH_KEY,
help: 'SSH key for authorization with your Tessel'
})
.option('name', {
Expand Down
2 changes: 1 addition & 1 deletion lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ controller.provisionTessel = function(opts) {
return new Promise(function(resolve, reject) {
if (Tessel.isProvisioned()) {
if (opts.force) {
cp.exec('rm -r ' + Tessel.TESSEL_AUTH_PATH, function(error) {
cp.exec('rm -r ' + Tessel.LOCAL_AUTH_PATH, function(error) {
if (error) {
reject(error);
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/lan_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ LAN.Connection = function(opts) {
this.ssh = undefined;

if (Tessel.isProvisioned()) {
this.auth.privateKey = opts.privateKey || fs.readFileSync(path.join(Tessel.TESSEL_AUTH_KEY));
this.auth.privateKey = opts.privateKey || fs.readFileSync(path.join(Tessel.LOCAL_AUTH_KEY));
}
};

Expand Down
6 changes: 3 additions & 3 deletions lib/tessel/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Tessel.prototype.deployScript = function(opts) {
var isPush = opts.push === true;

return new Promise(function(resolve, reject) {
var filepath = isPush ? Tessel.PUSH_PATH : Tessel.RUN_PATH;
var filepath = isPush ? Tessel.REMOTE_PUSH_PATH : Tessel.REMOTE_RUN_PATH;

// Stop running any existing scripts
return actions.execRemoteCommand(self, 'stopRunningScript', filepath)
Expand Down Expand Up @@ -157,7 +157,7 @@ Tessel.prototype.deployScript = function(opts) {
Tessel.prototype.restartScript = function(opts) {
var self = this;
var isPush = opts.type === 'flash';
var filepath = isPush ? Tessel.PUSH_PATH : Tessel.RUN_PATH;
var filepath = isPush ? Tessel.REMOTE_PUSH_PATH : Tessel.REMOTE_RUN_PATH;

return new Promise(function(resolve, reject) {
return self.simpleExec(commands.readFile(filepath + opts.entryPoint))
Expand Down Expand Up @@ -583,7 +583,7 @@ actions.pushScript = function(t, entryPoint, opts) {
actions.writeToFile = function(t) {
return new Promise(function(resolve, reject) {
// Path of the script to run a Node project
var executablePath = path.join(Tessel.PUSH_PATH, PUSH_START_SCRIPT_NAME);
var executablePath = path.join(Tessel.REMOTE_PUSH_PATH, PUSH_START_SCRIPT_NAME);
// Open a stdin pipe tp the file
return t.connection.exec(commands.openStdinToFile(executablePath))
// If it was opened successfully
Expand Down
2 changes: 1 addition & 1 deletion lib/tessel/erase.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Tessel.prototype.eraseScript = function() {
return self.simpleExec(commands.disablePushedScript());
})
.then(function disabled() {
return self.simpleExec(commands.deleteFolder(Tessel.PUSH_PATH))
return self.simpleExec(commands.deleteFolder(Tessel.REMOTE_PUSH_PATH))
.then(function erased() {
logs.info('Files erased.');
});
Expand Down
6 changes: 3 additions & 3 deletions lib/tessel/provision.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var idrsa = 'id_rsa';
var authKey = path.join(authPath, idrsa);
var remoteAuthFile = '/etc/dropbear/authorized_keys';

Object.defineProperty(Tessel, 'TESSEL_AUTH_KEY', {
Object.defineProperty(Tessel, 'LOCAL_AUTH_KEY', {
get: function() {
return authKey;
},
Expand All @@ -33,7 +33,7 @@ Object.defineProperty(Tessel, 'TESSEL_AUTH_KEY', {
}
});

Object.defineProperty(Tessel, 'TESSEL_AUTH_PATH', {
Object.defineProperty(Tessel, 'LOCAL_AUTH_PATH', {
get: function() {
return authPath;
},
Expand Down Expand Up @@ -179,7 +179,7 @@ actions.setDefaultKey = function(keyPath) {
}

// All checks pass... set the new key path
Tessel.TESSEL_AUTH_KEY = keyPath;
Tessel.LOCAL_AUTH_KEY = keyPath;

return resolve();
});
Expand Down
4 changes: 2 additions & 2 deletions lib/tessel/tessel.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ Tessel.prototype.simpleExec = function(command) {
});
};

Tessel.PUSH_PATH = '/app/';
Tessel.RUN_PATH = '/tmp/remote-script/';
Tessel.REMOTE_PUSH_PATH = '/app/';
Tessel.REMOTE_RUN_PATH = '/tmp/remote-script/';

module.exports = Tessel;

Expand Down
4 changes: 2 additions & 2 deletions test/unit/bin-tessel-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var defaults = {
name: 'usb',
string: '--usb',
},
key: Tessel.TESSEL_AUTH_KEY
key: Tessel.LOCAL_AUTH_KEY
};

exports['Tessel (cli: makeCommand)'] = {
Expand Down Expand Up @@ -146,7 +146,7 @@ exports['Tessel (cli: update)'] = {
version: 42,
_: ['update'],
timeout: 5,
key: Tessel.TESSEL_AUTH_KEY
key: Tessel.LOCAL_AUTH_KEY
});

cli(['update', '--list', ' ']);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/erase.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports['Tessel.prototype.erase'] = {

test.expect(10);

var expected = [commands.stopRunningScript(), commands.disablePushedScript(), commands.deleteFolder(Tessel.PUSH_PATH)];
var expected = [commands.stopRunningScript(), commands.disablePushedScript(), commands.deleteFolder(Tessel.REMOTE_PUSH_PATH)];
var commandNumber = 0;

// Test that we received the proper command
Expand Down
12 changes: 6 additions & 6 deletions test/unit/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ exports['provision.setDefaultKey'] = {

}).catch(function() {
test.equal(self.setDefaultKeySpy.callCount, 1);
// ensure the Tessel.TESSEL_AUTH_PATH has a default when using options without presetting key s
test.equal(Tessel.TESSEL_AUTH_PATH, authPath);
test.equal(Tessel.TESSEL_AUTH_KEY, authKey);
// ensure the Tessel.LOCAL_AUTH_PATH has a default when using options without presetting key s
test.equal(Tessel.LOCAL_AUTH_PATH, authPath);
test.equal(Tessel.LOCAL_AUTH_KEY, authKey);
test.done();
});
},
Expand All @@ -51,9 +51,9 @@ exports['provision.setDefaultKey'] = {
test.fail('...');
}).catch(function() {
test.equal(self.setDefaultKeySpy.callCount, 1);
// ensure the Tessel.TESSEL_AUTH_PATH has a default when using options without presetting key s
test.equal(Tessel.TESSEL_AUTH_PATH, authPath);
test.equal(Tessel.TESSEL_AUTH_KEY, authKey);
// ensure the Tessel.LOCAL_AUTH_PATH has a default when using options without presetting key s
test.equal(Tessel.LOCAL_AUTH_PATH, authPath);
test.equal(Tessel.LOCAL_AUTH_KEY, authKey);
test.done();
});
},
Expand Down
54 changes: 27 additions & 27 deletions test/unit/provision.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ exports['Tessel.isProvisioned()'] = {
isProvisionedTrue: function(test) {
test.expect(3);

var tesselAuthPath = Tessel.TESSEL_AUTH_PATH;
var tesselAuthPath = Tessel.LOCAL_AUTH_PATH;

Tessel.TESSEL_AUTH_PATH = testPath;
Tessel.LOCAL_AUTH_PATH = testPath;
Tessel.isProvisioned();

test.equal(this.existsSync.callCount, 2);
test.equal(this.existsSync.firstCall.args[0], path.join(Tessel.TESSEL_AUTH_PATH, 'id_rsa'));
test.equal(this.existsSync.lastCall.args[0], path.join(Tessel.TESSEL_AUTH_PATH, 'id_rsa.pub'));
test.equal(this.existsSync.firstCall.args[0], path.join(Tessel.LOCAL_AUTH_PATH, 'id_rsa'));
test.equal(this.existsSync.lastCall.args[0], path.join(Tessel.LOCAL_AUTH_PATH, 'id_rsa.pub'));

Tessel.TESSEL_AUTH_PATH = tesselAuthPath;
Tessel.LOCAL_AUTH_PATH = tesselAuthPath;
test.done();
},

Expand All @@ -37,15 +37,15 @@ exports['Tessel.isProvisioned()'] = {

this.existsSync.returns(false);

var tesselAuthPath = Tessel.TESSEL_AUTH_PATH;
var tesselAuthPath = Tessel.LOCAL_AUTH_PATH;

Tessel.TESSEL_AUTH_PATH = testPath;
Tessel.LOCAL_AUTH_PATH = testPath;
Tessel.isProvisioned();

test.equal(this.existsSync.callCount, 1);
test.equal(this.existsSync.firstCall.args[0], path.join(Tessel.TESSEL_AUTH_PATH, 'id_rsa'));
test.equal(this.existsSync.firstCall.args[0], path.join(Tessel.LOCAL_AUTH_PATH, 'id_rsa'));

Tessel.TESSEL_AUTH_PATH = tesselAuthPath;
Tessel.LOCAL_AUTH_PATH = tesselAuthPath;
test.done();
},
};
Expand Down Expand Up @@ -110,9 +110,9 @@ exports['controller.provisionTessel'] = {

completeForced: function(test) {
test.expect(6);
var tesselAuthPath = Tessel.TESSEL_AUTH_PATH;
var tesselAuthPath = Tessel.LOCAL_AUTH_PATH;

Tessel.TESSEL_AUTH_PATH = testPath;
Tessel.LOCAL_AUTH_PATH = testPath;

// Say it's provisioned to make sure old folder gets deleted
this.isProvisioned.onFirstCall().returns(true);
Expand All @@ -124,23 +124,23 @@ exports['controller.provisionTessel'] = {
})
.then(function() {
test.equal(this.exec.callCount, 1);
test.equal(this.exec.lastCall.args[0], 'rm -r ' + Tessel.TESSEL_AUTH_PATH);
test.equal(this.exec.lastCall.args[0], 'rm -r ' + Tessel.LOCAL_AUTH_PATH);
test.equal(this.provisionSpy.callCount, 1);
test.equal(this.closeTesselConnections.callCount, 1);
test.equal(Array.isArray(this.closeTesselConnections.args[0]), true);
fs.remove(path.join(process.cwd(), Tessel.TESSEL_AUTH_PATH), function(err) {
fs.remove(path.join(process.cwd(), Tessel.LOCAL_AUTH_PATH), function(err) {
test.ifError(err);
Tessel.TESSEL_AUTH_PATH = tesselAuthPath;
Tessel.LOCAL_AUTH_PATH = tesselAuthPath;
test.done();
});
}.bind(this));
},

completeUnprovisioned: function(test) {
test.expect(4);
var tesselAuthPath = Tessel.TESSEL_AUTH_PATH;
var tesselAuthPath = Tessel.LOCAL_AUTH_PATH;

Tessel.TESSEL_AUTH_PATH = testPath;
Tessel.LOCAL_AUTH_PATH = testPath;

this.isProvisioned.returns(false);

Expand All @@ -149,16 +149,16 @@ exports['controller.provisionTessel'] = {
test.equal(this.provisionSpy.callCount, 1);
test.equal(this.closeTesselConnections.callCount, 1);
test.equal(Array.isArray(this.closeTesselConnections.args[0]), true);
Tessel.TESSEL_AUTH_PATH = tesselAuthPath;
Tessel.LOCAL_AUTH_PATH = tesselAuthPath;
test.done();
}.bind(this));
},

completeUnprovisionedForced: function(test) {
test.expect(4);
var tesselAuthPath = Tessel.TESSEL_AUTH_PATH;
var tesselAuthPath = Tessel.LOCAL_AUTH_PATH;

Tessel.TESSEL_AUTH_PATH = testPath;
Tessel.LOCAL_AUTH_PATH = testPath;

this.isProvisioned.returns(false);

Expand All @@ -169,7 +169,7 @@ exports['controller.provisionTessel'] = {
test.equal(this.provisionSpy.callCount, 1);
test.equal(this.closeTesselConnections.callCount, 1);
test.equal(Array.isArray(this.closeTesselConnections.args[0]), true);
Tessel.TESSEL_AUTH_PATH = tesselAuthPath;
Tessel.LOCAL_AUTH_PATH = tesselAuthPath;
test.done();
}.bind(this));
},
Expand Down Expand Up @@ -273,8 +273,8 @@ exports['Tessel.prototype.provisionTessel'] = {

test.expect(3);

var tesselAuthPath = Tessel.TESSEL_AUTH_PATH;
Tessel.TESSEL_AUTH_PATH = testPath;
var tesselAuthPath = Tessel.LOCAL_AUTH_PATH;
Tessel.LOCAL_AUTH_PATH = testPath;

// Create folders for the folder that we'd like to
createKeyTestFolder(function(err) {
Expand All @@ -292,7 +292,7 @@ exports['Tessel.prototype.provisionTessel'] = {
test.equal(self.writeFileSpy.firstCall.args[2].mode, 384);
test.equal(self.writeFileSpy.lastCall.args[2].mode, 384);

Tessel.TESSEL_AUTH_PATH = tesselAuthPath;
Tessel.LOCAL_AUTH_PATH = tesselAuthPath;
// End the test
test.done();
})
Expand Down Expand Up @@ -341,8 +341,8 @@ exports['Tessel.prototype.provisionTessel'] = {
return false;
});

var tesselAuthPath = Tessel.TESSEL_AUTH_PATH;
Tessel.TESSEL_AUTH_PATH = testPath;
var tesselAuthPath = Tessel.LOCAL_AUTH_PATH;
Tessel.LOCAL_AUTH_PATH = testPath;

// Create folders for the folder that we'd like to
createKeyTestFolder(function(err) {
Expand All @@ -361,7 +361,7 @@ exports['Tessel.prototype.provisionTessel'] = {
var publicKey = self.writeFileSpy.firstCall.args[1];
test.equal(publicKey[publicKey.length - 1], '\n');

Tessel.TESSEL_AUTH_PATH = tesselAuthPath;
Tessel.LOCAL_AUTH_PATH = tesselAuthPath;
self.isProvisioned.restore();
// End the test
test.done();
Expand Down Expand Up @@ -529,7 +529,7 @@ exports['provision.setDefaultKey'] = {
fs.writeFileSync(publicKeyPath, 'test_contents');
provision.setDefaultKey(key)
.then(function doCall() {
test.equal(Tessel.TESSEL_AUTH_KEY, key);
test.equal(Tessel.LOCAL_AUTH_KEY, key);
fs.unlinkSync(privateKeyPath);
fs.unlinkSync(publicKeyPath);
test.done();
Expand Down

0 comments on commit d5584a5

Please sign in to comment.