smartssh/dist/smartssh.classes.js

164 lines
15 KiB
JavaScript
Raw Normal View History

2016-04-25 02:06:20 +00:00
"use strict";
/// <reference path="./typings/main.d.ts" />
var plugins = require("./smartssh.plugins");
var helpers = require("./smartssh.classes.helpers");
var ssh = (function () {
function ssh(optionsArg) {
if (optionsArg === void 0) { optionsArg = {}; }
2016-04-26 02:44:50 +00:00
this.sshDir = new sshDir(optionsArg.sshDir);
this.sshKeys = this.sshDir.getKeys();
this.sshSync = optionsArg.sshSync;
2016-04-25 02:06:20 +00:00
}
;
2016-04-26 02:44:50 +00:00
ssh.prototype.addKey = function (sshKeyArg) {
this.sshKeys.push(sshKeyArg);
this.sync();
};
;
ssh.prototype.getKey = function (hostArg) {
var filteredArray = this.sshKeys.filter(function (keyArg) {
return (keyArg.host == hostArg);
});
if (filteredArray.length > 0) {
return filteredArray[0];
}
else {
return undefined;
}
};
;
2016-04-27 22:09:17 +00:00
ssh.prototype.removeKey = function (sshKeyArg) {
var keyIndex = helpers.getKeyIndex(sshKeyArg.host);
this.sshKeys.splice(keyIndex, 1);
this.sync();
};
;
ssh.prototype.replaceKey = function (sshKeyOldArg, sshKeyNewArg) {
var keyIndex = helpers.getKeyIndex(sshKeyOldArg.host);
this.sshKeys.splice(keyIndex, 1, sshKeyNewArg);
this.sync();
};
;
2016-04-26 02:44:50 +00:00
ssh.prototype.sync = function () {
2016-04-27 22:09:17 +00:00
if (this.sshSync) {
this.sshDir.sync(this.sshConfig, this.sshKeys); // call sync method of sshDir class;
}
2016-04-26 02:44:50 +00:00
};
;
2016-04-25 02:06:20 +00:00
return ssh;
}());
exports.ssh = ssh;
2016-04-26 02:44:50 +00:00
var sshDir = (function () {
function sshDir(sshDirPathArg) {
this.path = sshDirPathArg;
}
sshDir.prototype.sync = function (sshConfigArg, sshKeysArg) {
};
;
sshDir.prototype.getKeys = function () {
return helpers.sshKeyArrayFromDir(this.path);
};
return sshDir;
}());
2016-04-25 02:06:20 +00:00
var sshConfig = (function () {
function sshConfig() {
}
return sshConfig;
}());
exports.sshConfig = sshConfig;
var sshKey = (function () {
function sshKey(optionsArg) {
2016-04-26 02:44:50 +00:00
if (optionsArg === void 0) { optionsArg = {}; }
2016-04-25 02:06:20 +00:00
this.privKey = optionsArg.private;
this.pubKey = optionsArg.public;
2016-04-26 02:44:50 +00:00
this.hostVar = optionsArg.host;
2016-04-25 02:06:20 +00:00
}
;
2016-04-26 02:44:50 +00:00
Object.defineProperty(sshKey.prototype, "host", {
2016-04-25 02:06:20 +00:00
// getters
get: function () {
2016-04-26 02:44:50 +00:00
return this.hostVar;
2016-04-25 02:06:20 +00:00
},
// setters
2016-04-26 02:44:50 +00:00
set: function (hostArg) {
this.hostVar = hostArg;
},
enumerable: true,
configurable: true
});
;
Object.defineProperty(sshKey.prototype, "privateKey", {
get: function () {
return this.privKey;
},
2016-04-25 02:06:20 +00:00
set: function (privateKeyArg) {
this.privKey = privateKeyArg;
},
enumerable: true,
configurable: true
});
;
Object.defineProperty(sshKey.prototype, "privateKeyBase64", {
get: function () {
return plugins.base64.encode(this.privKey);
},
enumerable: true,
configurable: true
});
Object.defineProperty(sshKey.prototype, "publicKey", {
get: function () {
return this.publicKey;
},
// setters
set: function (publicKeyArg) {
this.pubKey = publicKeyArg;
},
enumerable: true,
configurable: true
});
Object.defineProperty(sshKey.prototype, "publicKeyBase64", {
get: function () {
return plugins.base64.encode(this.pubKey);
},
enumerable: true,
configurable: true
});
Object.defineProperty(sshKey.prototype, "type", {
get: function () {
if (this.privKey && this.pubKey) {
return "duplex";
}
else if (this.privKey) {
return "private";
}
else if (this.pubKey) {
return "public";
}
},
enumerable: true,
configurable: true
});
;
;
;
2016-04-26 02:44:50 +00:00
;
2016-04-25 02:06:20 +00:00
sshKey.prototype.store = function (filePathArg) {
var filePathObj = plugins.path.parse(filePathArg);
if (filePathObj.ext = ".priv") {
plugins.smartfile.memory.toFsSync(this.privKey, { fileName: filePathObj.name + filePathObj.ext, filePath: filePathObj.dir });
}
else if (filePathObj.ext = ".pub") {
plugins.smartfile.memory.toFsSync(this.pubKey, { fileName: filePathObj.name + filePathObj.ext, filePath: filePathObj.dir });
}
else {
plugins.fs.ensureDirSync(filePathObj.dir);
this.store(plugins.path.join(filePathObj.dir, "key.priv")); // call this function recursivly
this.store(plugins.path.join(filePathObj.dir, "key.priv")); // call this function recursivly
}
};
return sshKey;
}());
exports.sshKey = sshKey;
2016-04-27 22:09:17 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDRDQUE0QztBQUM1QyxJQUFPLE9BQU8sV0FBVyxvQkFBb0IsQ0FBQyxDQUFDO0FBQy9DLElBQU8sT0FBTyxXQUFXLDRCQUE0QixDQUFDLENBQUM7QUFFdkQ7SUFLSSxhQUFZLFVBQStDO1FBQS9DLDBCQUErQyxHQUEvQyxlQUErQztRQUN2RCxJQUFJLENBQUMsTUFBTSxHQUFHLElBQUksTUFBTSxDQUFDLFVBQVUsQ0FBQyxNQUFNLENBQUMsQ0FBQztRQUM1QyxJQUFJLENBQUMsT0FBTyxHQUFHLElBQUksQ0FBQyxNQUFNLENBQUMsT0FBTyxFQUFFLENBQUM7UUFDckMsSUFBSSxDQUFDLE9BQU8sR0FBRyxVQUFVLENBQUMsT0FBTyxDQUFDO0lBQ3RDLENBQUM7O0lBQ0Qsb0JBQU0sR0FBTixVQUFPLFNBQWdCO1FBQ25CLElBQUksQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLFNBQVMsQ0FBQyxDQUFDO1FBQzdCLElBQUksQ0FBQyxJQUFJLEVBQUUsQ0FBQztJQUNoQixDQUFDOztJQUNELG9CQUFNLEdBQU4sVUFBTyxPQUFjO1FBQ2pCLElBQUksYUFBYSxHQUFHLElBQUksQ0FBQyxPQUFPLENBQUMsTUFBTSxDQUFDLFVBQVMsTUFBTTtZQUNuRCxNQU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