smartssh/dist/smartssh.classes.js
2016-04-28 00:09:17 +02:00

164 lines
15 KiB
JavaScript

"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 = {}; }
this.sshDir = new sshDir(optionsArg.sshDir);
this.sshKeys = this.sshDir.getKeys();
this.sshSync = optionsArg.sshSync;
}
;
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.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();
};
;
ssh.prototype.sync = function () {
if (this.sshSync) {
this.sshDir.sync(this.sshConfig, this.sshKeys); // call sync method of sshDir class;
}
};
;
return ssh;
}());
exports.ssh = ssh;
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;
}());
var sshConfig = (function () {
function sshConfig() {
}
return sshConfig;
}());
exports.sshConfig = sshConfig;
var sshKey = (function () {
function sshKey(optionsArg) {
if (optionsArg === void 0) { optionsArg = {}; }
this.privKey = optionsArg.private;
this.pubKey = optionsArg.public;
this.hostVar = optionsArg.host;
}
;
Object.defineProperty(sshKey.prototype, "host", {
// getters
get: function () {
return this.hostVar;
},
// setters
set: function (hostArg) {
this.hostVar = hostArg;
},
enumerable: true,
configurable: true
});
;
Object.defineProperty(sshKey.prototype, "privateKey", {
get: function () {
return this.privKey;
},
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
});
;
;
;
;
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;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDRDQUE0QztBQUM1QyxJQUFPLE9BQU8sV0FBVyxvQkFBb0IsQ0FBQyxDQUFDO0FBQy9DLElBQU8sT0FBTyxXQUFX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