smartssh/dist/smartssh.classes.sshinstance.js

99 lines
6.2 KiB
JavaScript
Raw Normal View History

2016-06-01 00:31:29 +00:00
"use strict";
2017-06-15 15:52:22 +00:00
Object.defineProperty(exports, "__esModule", { value: true });
2016-06-01 00:31:29 +00:00
require("typings-global");
2016-11-23 11:38:38 +00:00
const smartssh_classes_sshdir_1 = require("./smartssh.classes.sshdir");
const smartssh_classes_sshconfig_1 = require("./smartssh.classes.sshconfig");
class SshInstance {
constructor(optionsArg = {}) {
2016-06-01 00:31:29 +00:00
optionsArg ? void (0) : optionsArg = {};
2016-06-25 00:29:34 +00:00
this._sshKeyArray = [];
this._sshConfig = new smartssh_classes_sshconfig_1.SshConfig(this._sshKeyArray);
2016-06-25 13:30:57 +00:00
this._sshDir = new smartssh_classes_sshdir_1.SshDir(this._sshKeyArray, this._sshConfig, optionsArg.sshDirPath);
2016-06-24 00:49:55 +00:00
this._sshSync = optionsArg.sshSync;
2016-06-01 00:31:29 +00:00
}
;
2016-11-23 11:38:38 +00:00
// altering methods
addKey(sshKeyArg) {
this._syncAuto('from');
2016-06-25 00:29:34 +00:00
this._sshKeyArray.push(sshKeyArg);
2016-11-23 11:38:38 +00:00
this._syncAuto('to');
}
2016-06-01 00:31:29 +00:00
;
2016-11-23 11:38:38 +00:00
removeKey(sshKeyArg) {
this._syncAuto('from');
let filteredArray = this._sshKeyArray.filter((sshKeyArg2) => {
2016-06-01 02:18:31 +00:00
return (sshKeyArg != sshKeyArg2);
});
2016-06-25 00:29:34 +00:00
this._sshKeyArray = filteredArray;
2016-11-23 11:38:38 +00:00
this._syncAuto('to');
}
2016-06-01 01:57:17 +00:00
;
2016-11-23 11:38:38 +00:00
replaceKey(sshKeyOldArg, sshKeyNewArg) {
this._syncAuto('from');
2016-06-01 02:25:59 +00:00
this.removeKey(sshKeyOldArg);
this.addKey(sshKeyNewArg);
2016-11-23 11:38:38 +00:00
this._syncAuto('to');
}
2016-06-01 01:57:17 +00:00
;
//
2016-11-23 11:38:38 +00:00
getKey(hostArg) {
this._syncAuto('from');
let filteredArray = this._sshKeyArray.filter(function (keyArg) {
return (keyArg.host === hostArg);
2016-06-01 00:31:29 +00:00
});
if (filteredArray.length > 0) {
return filteredArray[0];
}
else {
return undefined;
}
2016-11-23 11:38:38 +00:00
}
2016-06-01 00:31:29 +00:00
;
2016-11-23 11:38:38 +00:00
get sshKeys() {
this._syncAuto('from');
return this._sshKeyArray;
}
2016-06-24 00:49:55 +00:00
;
2016-11-23 11:38:38 +00:00
// FS methods
2016-06-24 00:49:55 +00:00
/**
* write SshInstance to disk
*/
2016-11-23 11:38:38 +00:00
writeToDisk(dirPathArg) {
this._sync('to', dirPathArg);
}
2016-06-24 00:49:55 +00:00
/**
* read ab SshInstance from disk
*/
2016-11-23 11:38:38 +00:00
readFromDisk(dirPathArg) {
this._sync('from', dirPathArg);
}
2016-06-25 00:29:34 +00:00
/* ===============================================================
========================= Private Methods ========================
================================================================*/
2016-11-23 11:38:38 +00:00
_makeConfig() {
}
2016-06-24 00:49:55 +00:00
/**
* method to invoke SshInstance _sync automatically when sshSync is true
*/
2016-11-23 11:38:38 +00:00
_syncAuto(directionArg) {
2016-06-24 00:49:55 +00:00
if (this._sshSync)
this._sync(directionArg);
2016-11-23 11:38:38 +00:00
}
2016-06-24 00:49:55 +00:00
/**
* private method to sync SshInstance
*/
2016-11-23 11:38:38 +00:00
_sync(directionArg, dirPathArg) {
if (directionArg === 'from') {
2016-06-28 00:10:51 +00:00
this._sshDir.readFromDir(dirPathArg); // call sync method of sshDir class;
2016-06-01 01:57:17 +00:00
}
2016-11-23 11:38:38 +00:00
else if (directionArg === 'to') {
2016-06-28 00:10:51 +00:00
this._sshDir.writeToDir(dirPathArg);
2016-06-01 01:57:17 +00:00
}
2016-06-24 00:49:55 +00:00
else {
2016-06-01 01:57:17 +00:00
throw new Error("directionArg not recognised. Must be 'to' or 'from'");
2016-06-01 00:31:29 +00:00
}
2016-11-23 11:38:38 +00:00
}
2016-06-01 00:31:29 +00:00
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