From d5584a5b61ab321a3f9646490a5cc2d67536fc3b Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Thu, 19 Nov 2015 16:02:56 -0500 Subject: [PATCH] Rename Tessel.(RUN|PUSH)_PATH => REMOTE_(RUN|PUSH)_PATH; Rename Tessel.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 --- bin/tessel-2.js | 2 +- lib/controller.js | 2 +- lib/lan_connection.js | 2 +- lib/tessel/deploy.js | 6 ++--- lib/tessel/erase.js | 2 +- lib/tessel/provision.js | 6 ++--- lib/tessel/tessel.js | 4 +-- test/unit/bin-tessel-2.js | 4 +-- test/unit/erase.js | 2 +- test/unit/key.js | 12 ++++----- test/unit/provision.js | 54 +++++++++++++++++++-------------------- 11 files changed, 48 insertions(+), 48 deletions(-) diff --git a/bin/tessel-2.js b/bin/tessel-2.js index e3ef5644..4ca442f7 100755 --- a/bin/tessel-2.js +++ b/bin/tessel-2.js @@ -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', { diff --git a/lib/controller.js b/lib/controller.js index 12e2315d..3f8a4331 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -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 { diff --git a/lib/lan_connection.js b/lib/lan_connection.js index cb4a760b..8b596db2 100644 --- a/lib/lan_connection.js +++ b/lib/lan_connection.js @@ -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)); } }; diff --git a/lib/tessel/deploy.js b/lib/tessel/deploy.js index 1f047007..fb181557 100644 --- a/lib/tessel/deploy.js +++ b/lib/tessel/deploy.js @@ -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) @@ -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)) @@ -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 diff --git a/lib/tessel/erase.js b/lib/tessel/erase.js index a91ccd2a..30564e8a 100644 --- a/lib/tessel/erase.js +++ b/lib/tessel/erase.js @@ -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.'); }); diff --git a/lib/tessel/provision.js b/lib/tessel/provision.js index 25cd5717..6c6bbd3e 100644 --- a/lib/tessel/provision.js +++ b/lib/tessel/provision.js @@ -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; }, @@ -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; }, @@ -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(); }); diff --git a/lib/tessel/tessel.js b/lib/tessel/tessel.js index 2ef53ba0..0b5463e5 100644 --- a/lib/tessel/tessel.js +++ b/lib/tessel/tessel.js @@ -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; diff --git a/test/unit/bin-tessel-2.js b/test/unit/bin-tessel-2.js index 8236a5dc..b5e34eb2 100644 --- a/test/unit/bin-tessel-2.js +++ b/test/unit/bin-tessel-2.js @@ -30,7 +30,7 @@ var defaults = { name: 'usb', string: '--usb', }, - key: Tessel.TESSEL_AUTH_KEY + key: Tessel.LOCAL_AUTH_KEY }; exports['Tessel (cli: makeCommand)'] = { @@ -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', ' ']); diff --git a/test/unit/erase.js b/test/unit/erase.js index d020b0ff..16c83543 100644 --- a/test/unit/erase.js +++ b/test/unit/erase.js @@ -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 diff --git a/test/unit/key.js b/test/unit/key.js index 764675d1..4f949325 100644 --- a/test/unit/key.js +++ b/test/unit/key.js @@ -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(); }); }, @@ -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(); }); }, diff --git a/test/unit/provision.js b/test/unit/provision.js index adcfe468..13e27adc 100644 --- a/test/unit/provision.js +++ b/test/unit/provision.js @@ -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(); }, @@ -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(); }, }; @@ -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); @@ -124,13 +124,13 @@ 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)); @@ -138,9 +138,9 @@ exports['controller.provisionTessel'] = { 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); @@ -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); @@ -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)); }, @@ -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) { @@ -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(); }) @@ -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) { @@ -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(); @@ -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();