update structure

This commit is contained in:
Philipp Kunz 2016-06-24 02:49:55 +02:00
parent c3ee35a699
commit a43976110a
7 changed files with 117 additions and 50 deletions

View File

@ -5,7 +5,7 @@ export declare class SshDir {
path: string; path: string;
sshInstance: SshInstance; sshInstance: SshInstance;
constructor(sshInstanceArg: SshInstance, sshDirPathArg?: string); constructor(sshInstanceArg: SshInstance, sshDirPathArg?: string);
syncToDir(): void; writeToDir(): void;
syncFromDir(): void; readFromDir(): void;
getKeys(): SshKey[]; getKeys(): SshKey[];
} }

View File

@ -13,10 +13,10 @@ var SshDir = (function () {
} }
this.path = sshDirPath; this.path = sshDirPath;
} }
SshDir.prototype.syncToDir = function () { SshDir.prototype.writeToDir = function () {
}; };
; ;
SshDir.prototype.syncFromDir = function () { SshDir.prototype.readFromDir = function () {
}; };
SshDir.prototype.getKeys = function () { SshDir.prototype.getKeys = function () {
return helpers.sshKeyArrayFromDir(this.path); return helpers.sshKeyArrayFromDir(this.path);
@ -25,4 +25,4 @@ var SshDir = (function () {
}()); }());
exports.SshDir = SshDir; exports.SshDir = SshDir;
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuc3NoZGlyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDeEIsSUFBWSxPQUFPLFdBQU0sb0JBQW9CLENBQUMsQ0FBQTtBQUM5QyxJQUFZLE9BQU8sV0FBTSw0QkFBNEIsQ0FBQyxDQUFBO0FBSXREO0lBR0ksZ0JBQVksY0FBMEIsRUFBQyxhQUFxQjtRQUN4RCxJQUFJLFVBQWlCLENBQUM7UUFDdEIsRUFBRSxDQUFBLENBQUMsYUFBYSxDQUFDLENBQUEsQ0FBQztZQUNkLFVBQVUsR0FBRyxhQUFhLENBQUM7UUFDL0IsQ0FBQztRQUFDLElBQUksQ0FBQyxDQUFDO1lBQ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lcy5zc2hjb25maWdcIjtcbmV4cG9ydCBjbGFzcyBTc2hEaXIgeyAvLyBzc2hEaXIgY2xhc3MgLT4gTk9UIEVYUE9SVEVELCBPTkxZIEZPUiBJTlRFUk5BTCBVU0VcbiAgICBwYXRoOnN0cmluZzsgLy8gdGhlIHBhdGggb2YgdGhlIHNzaCBkaXJlY3RvcnlcbiAgICBzc2hJbnN0YW5jZTpTc2hJbnN0YW5jZTtcbiAgICBjb25zdHJ1Y3Rvcihzc2hJbnN0YW5jZUFyZzpTc2hJbnN0YW5jZSxzc2hEaXJQYXRoQXJnPzpzdHJpbmcpe1xuICAgICAgICBsZXQgc3NoRGlyUGF0aDpzdHJpbmc7XG4gICAgICAgIGlmKHNzaERpclBhdGhBcmcpe1xuICAgICAgICAgICAgc3NoRGlyUGF0aCA9IHNzaERpclBhdGhBcmc7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBzc2hEaXJQYXRoID0gcGx1Z2lucy5zbWFydHBhdGguZ2V0LmhvbWUoKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLnBhdGggPSBzc2hEaXJQYXRoO1xuICAgIH1cbiAgICB3cml0ZVRvRGlyKCl7IC8vIHN5bmNzIHNzaEluc3RhbmNlIHRvIGRpcmVjdG9yeVxuICAgICAgICBcbiAgICB9O1xuICAgIHJlYWRGcm9tRGlyKCl7IC8vIHN5bmNzIHNzaEluc3RhbmNlIGZyb20gZGlyZWN0b3J5XG4gICAgICAgIFxuICAgIH1cbiAgICBnZXRLZXlzKCl7XG4gICAgICAgIHJldHVybiBoZWxwZXJzLnNzaEtleUFycmF5RnJvbURpcih0aGlzLnBhdGgpO1xuICAgIH1cbn0iXX0=

View File

@ -1,10 +1,11 @@
import "typings-global"; import "typings-global";
import { SshDir } from "./smartssh.classes.sshdir";
import { SshKey } from "./smartssh.classes.sshkey"; import { SshKey } from "./smartssh.classes.sshkey";
export declare class SshInstance { export declare class SshInstance {
private sshConfig; private _sshConfig;
private sshDir; sshDir: SshDir;
protected sshKeyArray: SshKey[]; protected sshKeyArray: SshKey[];
private sshSync; private _sshSync;
constructor(optionsArg?: { constructor(optionsArg?: {
sshDirPath?: string; sshDirPath?: string;
sshSync?: boolean; sshSync?: boolean;
@ -14,5 +15,20 @@ export declare class SshInstance {
replaceKey(sshKeyOldArg: SshKey, sshKeyNewArg: SshKey): void; replaceKey(sshKeyOldArg: SshKey, sshKeyNewArg: SshKey): void;
getKey(hostArg: string): SshKey; getKey(hostArg: string): SshKey;
sshKeys: SshKey[]; sshKeys: SshKey[];
sync(directionArg: string): void; /**
* write SshInstance to disk
*/
writeToDisk(): void;
/**
* read ab SshInstance from disk
*/
readFromDisk(): void;
/**
* method to invoke SshInstance _sync automatically when sshSync is true
*/
private _syncAuto(directionArg);
/**
* private method to sync SshInstance
*/
private _sync(directionArg);
} }

File diff suppressed because one or more lines are too long

View File

@ -23,11 +23,11 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartssh#readme", "homepage": "https://gitlab.com/pushrocks/smartssh#readme",
"dependencies": { "dependencies": {
"beautylog": "^5.0.10", "beautylog": "^5.0.12",
"fs-extra": "^0.30.0", "fs-extra": "^0.30.0",
"js-base64": "^2.1.9", "js-base64": "^2.1.9",
"minimatch": "^3.0.0", "minimatch": "^3.0.2",
"smartfile": "^3.0.10", "smartfile": "^4.0.4",
"smartpath": "^3.2.2", "smartpath": "^3.2.2",
"typings-global": "^1.0.3", "typings-global": "^1.0.3",
"typings-test": "^1.0.1" "typings-test": "^1.0.1"

View File

@ -16,10 +16,10 @@ export class SshDir { // sshDir class -> NOT EXPORTED, ONLY FOR INTERNAL USE
} }
this.path = sshDirPath; this.path = sshDirPath;
} }
syncToDir(){ // syncs sshInstance to directory writeToDir(){ // syncs sshInstance to directory
}; };
syncFromDir(){ // syncs sshInstance from directory readFromDir(){ // syncs sshInstance from directory
} }
getKeys(){ getKeys(){

View File

@ -7,41 +7,41 @@ import {SshConfig} from "./smartssh.classes.sshconfig";
import {SshKey} from "./smartssh.classes.sshkey"; import {SshKey} from "./smartssh.classes.sshkey";
export class SshInstance { export class SshInstance {
private sshConfig:SshConfig; // sshConfig (e.g. represents ~/.ssh/config) private _sshConfig:SshConfig; // sshConfig (e.g. represents ~/.ssh/config)
private sshDir:SshDir; // points to sshDir class instance. sshDir:SshDir; // points to sshDir class instance.
protected sshKeyArray:SshKey[]; //holds all ssh keys protected sshKeyArray:SshKey[]; //holds all ssh keys
private sshSync:boolean; // if set to true, the ssh dir will be kept in sync automatically private _sshSync:boolean; // if set to true, the ssh dir will be kept in sync automatically
constructor(optionsArg:{sshDirPath?:string,sshSync?:boolean}={}){ constructor(optionsArg:{sshDirPath?:string,sshSync?:boolean}={}){
optionsArg ? void(0) : optionsArg = {}; optionsArg ? void(0) : optionsArg = {};
this.sshDir = new SshDir(this,optionsArg.sshDirPath);
this.sshKeyArray = []; this.sshKeyArray = [];
this.sshSync = optionsArg.sshSync; this._sshSync = optionsArg.sshSync;
this.sshDir = new SshDir(this,optionsArg.sshDirPath);
}; };
//altering methods //altering methods
addKey(sshKeyArg:SshKey){ addKey(sshKeyArg:SshKey){
this.sync("from"); this._syncAuto("from");
this.sshKeyArray.push(sshKeyArg); this.sshKeyArray.push(sshKeyArg);
this.sync("to"); this._syncAuto("to");
}; };
removeKey(sshKeyArg:SshKey){ removeKey(sshKeyArg:SshKey){
this.sync("from"); this._syncAuto("from");
let filteredArray = this.sshKeyArray.filter((sshKeyArg2:SshKey) => { let filteredArray = this.sshKeyArray.filter((sshKeyArg2:SshKey) => {
return (sshKeyArg != sshKeyArg2); return (sshKeyArg != sshKeyArg2);
}); });
this.sshKeyArray = filteredArray; this.sshKeyArray = filteredArray;
this.sync("to"); this._syncAuto("to");
}; };
replaceKey(sshKeyOldArg:SshKey,sshKeyNewArg:SshKey){ replaceKey(sshKeyOldArg:SshKey,sshKeyNewArg:SshKey){
this.sync("from"); this._syncAuto("from");
this.removeKey(sshKeyOldArg); this.removeKey(sshKeyOldArg);
this.addKey(sshKeyNewArg); this.addKey(sshKeyNewArg);
this.sync("to"); this._syncAuto("to");
}; };
// //
getKey(hostArg:string):SshKey{ getKey(hostArg:string):SshKey{
this.sync("from"); this._syncAuto("from");
let filteredArray = this.sshKeyArray.filter(function(keyArg){ let filteredArray = this.sshKeyArray.filter(function(keyArg){
return (keyArg.host == hostArg); return (keyArg.host == hostArg);
}); });
@ -52,15 +52,42 @@ export class SshInstance {
} }
}; };
get sshKeys():SshKey[] { get sshKeys():SshKey[] {
this.sync("from"); this._syncAuto("from");
return this.sshKeyArray; return this.sshKeyArray;
};
//FS methods
/**
* write SshInstance to disk
*/
writeToDisk(){
this._sync("to");
} }
sync(directionArg:string){
if(this.sshSync && directionArg == "from"){ /**
this.sshDir.syncFromDir(); // call sync method of sshDir class; * read ab SshInstance from disk
} else if(this.sshSync && directionArg == "to") { */
this.sshDir.syncToDir(); readFromDisk(){
} else if(this.sshSync) { this._sync("from");
}
/**
* method to invoke SshInstance _sync automatically when sshSync is true
*/
private _syncAuto(directionArg){
if(this._sshSync) this._sync(directionArg);
}
/**
* private method to sync SshInstance
*/
private _sync(directionArg:string){
if(directionArg == "from"){
this.sshDir.readFromDir(); // call sync method of sshDir class;
} else if(directionArg == "to") {
this.sshDir.writeToDir();
} else {
throw new Error("directionArg not recognised. Must be 'to' or 'from'"); throw new Error("directionArg not recognised. Must be 'to' or 'from'");
} }
}; };