smartssh/dist/smartssh.classes.js

150 lines
14 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;
}
};
;
ssh.prototype.sync = function () {
this.sshDir.sync(this.sshConfig, this.sshKeys); //call sync method of sshDir class;
};
;
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-26 02:44:50 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3N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