update stucture
This commit is contained in:
		| @@ -27,7 +27,7 @@ | ||||
|     "fs-extra": "^0.30.0", | ||||
|     "js-base64": "^2.1.9", | ||||
|     "minimatch": "^3.0.2", | ||||
|     "smartfile": "^4.0.4", | ||||
|     "smartfile": "^4.0.5", | ||||
|     "smartpath": "^3.2.2", | ||||
|     "typings-global": "^1.0.3", | ||||
|     "typings-test": "^1.0.1" | ||||
|   | ||||
| @@ -1,8 +1,15 @@ | ||||
| import "typings-global"; | ||||
| import * as plugins from "./smartssh.plugins"; | ||||
| import * as helpers from "./smartssh.classes.helpers"; | ||||
| import {SshKey} from "./smartssh.classes.sshkey" | ||||
|  | ||||
| export class SshConfig { | ||||
|     constructor(){ | ||||
|          | ||||
|     sshKeyArray:SshKey[]; | ||||
|      | ||||
|     constructor(sshKeyArrayArg:SshKey[]){ | ||||
|         this.sshKeyArray = sshKeyArrayArg; | ||||
|     } | ||||
|     makeConfig(){ | ||||
|  | ||||
|     } | ||||
| } | ||||
| @@ -6,18 +6,20 @@ import {SshKey} from "./smartssh.classes.sshkey"; | ||||
| import {SshConfig} from "./smartssh.classes.sshconfig"; | ||||
| export class SshDir { // sshDir class -> NOT EXPORTED, ONLY FOR INTERNAL USE | ||||
|     path:string; // the path of the ssh directory | ||||
|     sshInstance:SshInstance; | ||||
|     constructor(sshInstanceArg:SshInstance,sshDirPathArg?:string){ | ||||
|         let sshDirPath:string; | ||||
|     private sshKeyArray:SshKey[]; | ||||
|     constructor(sshKeyArray:SshKey[],sshDirPathArg?:string){ | ||||
|         this.sshKeyArray = sshKeyArray; | ||||
|         if(sshDirPathArg){ | ||||
|             sshDirPath = sshDirPathArg; | ||||
|             this.path = sshDirPathArg; | ||||
|         } else { | ||||
|             sshDirPath = plugins.smartpath.get.home(); | ||||
|         } | ||||
|         this.path = sshDirPath; | ||||
|             this.path = plugins.path.join(plugins.smartpath.get.home(),".ssh/"); | ||||
|         }; | ||||
|     } | ||||
|     writeToDir(){ // syncs sshInstance to directory | ||||
|          | ||||
|         this.sshKeyArray.forEach((sshKeyArg) => { | ||||
|             sshKeyArg.store(this.path); | ||||
|              | ||||
|         }); | ||||
|     }; | ||||
|     readFromDir(){ // syncs sshInstance from directory | ||||
|          | ||||
|   | ||||
| @@ -7,29 +7,30 @@ import {SshConfig} from "./smartssh.classes.sshconfig"; | ||||
| import {SshKey} from "./smartssh.classes.sshkey"; | ||||
|  | ||||
| export class SshInstance { | ||||
|     private _sshKeyArray:SshKey[]; //holds all ssh keys | ||||
|     private _sshConfig:SshConfig; // sshConfig (e.g. represents ~/.ssh/config) | ||||
|     sshDir:SshDir; // points to sshDir class instance. | ||||
|     protected sshKeyArray:SshKey[]; //holds all ssh keys | ||||
|     private _sshDir:SshDir; // points to sshDir class instance. | ||||
|     private _sshSync:boolean; // if set to true, the ssh dir will be kept in sync automatically | ||||
|     constructor(optionsArg:{sshDirPath?:string,sshSync?:boolean}={}){ | ||||
|         optionsArg ? void(0) : optionsArg = {}; | ||||
|         this.sshKeyArray = []; | ||||
|         this._sshKeyArray = []; | ||||
|         this._sshConfig = new SshConfig(this._sshKeyArray); | ||||
|         this._sshDir = new SshDir(this._sshKeyArray,optionsArg.sshDirPath); | ||||
|         this._sshSync = optionsArg.sshSync; | ||||
|         this.sshDir = new SshDir(this,optionsArg.sshDirPath); | ||||
|     }; | ||||
|      | ||||
|     //altering methods | ||||
|     addKey(sshKeyArg:SshKey){ | ||||
|         this._syncAuto("from"); | ||||
|         this.sshKeyArray.push(sshKeyArg); | ||||
|         this._sshKeyArray.push(sshKeyArg); | ||||
|         this._syncAuto("to"); | ||||
|     }; | ||||
|     removeKey(sshKeyArg:SshKey){ | ||||
|         this._syncAuto("from"); | ||||
|         let filteredArray = this.sshKeyArray.filter((sshKeyArg2:SshKey) => { | ||||
|         let filteredArray = this._sshKeyArray.filter((sshKeyArg2:SshKey) => { | ||||
|             return (sshKeyArg != sshKeyArg2); | ||||
|         }); | ||||
|         this.sshKeyArray = filteredArray; | ||||
|         this._sshKeyArray = filteredArray; | ||||
|         this._syncAuto("to"); | ||||
|     }; | ||||
|     replaceKey(sshKeyOldArg:SshKey,sshKeyNewArg:SshKey){ | ||||
| @@ -42,7 +43,7 @@ export class SshInstance { | ||||
|     // | ||||
|     getKey(hostArg:string):SshKey{ | ||||
|         this._syncAuto("from"); | ||||
|         let filteredArray = this.sshKeyArray.filter(function(keyArg){ | ||||
|         let filteredArray = this._sshKeyArray.filter(function(keyArg){ | ||||
|             return (keyArg.host == hostArg); | ||||
|         }); | ||||
|         if(filteredArray.length > 0){ | ||||
| @@ -53,7 +54,7 @@ export class SshInstance { | ||||
|     }; | ||||
|     get sshKeys():SshKey[] { | ||||
|         this._syncAuto("from"); | ||||
|         return this.sshKeyArray; | ||||
|         return this._sshKeyArray; | ||||
|     }; | ||||
|  | ||||
|     //FS methods | ||||
| @@ -72,6 +73,14 @@ export class SshInstance { | ||||
|         this._sync("from"); | ||||
|     } | ||||
|  | ||||
|     /* =============================================================== | ||||
|     ========================= Private Methods ======================== | ||||
|     ================================================================*/ | ||||
|  | ||||
|     private _makeConfig (){ | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * method to invoke SshInstance _sync automatically when sshSync is true | ||||
|      */ | ||||
| @@ -84,9 +93,9 @@ export class SshInstance { | ||||
|      */ | ||||
|     private _sync(directionArg:string){ | ||||
|         if(directionArg == "from"){ | ||||
|             this.sshDir.readFromDir(); // call sync method of sshDir class; | ||||
|             this._sshDir.readFromDir(); // call sync method of sshDir class; | ||||
|         } else if(directionArg == "to") { | ||||
|             this.sshDir.writeToDir(); | ||||
|             this._sshDir.writeToDir(); | ||||
|         } else { | ||||
|             throw new Error("directionArg not recognised. Must be 'to' or 'from'"); | ||||
|         } | ||||
|   | ||||
| @@ -57,13 +57,15 @@ export class SshKey { | ||||
|     set publicKeyBase64(publicKeyArg:string) { | ||||
|         this.pubKey = plugins.base64.decode(publicKeyArg); | ||||
|     } | ||||
|      | ||||
|     read(filePathArg){ | ||||
|          | ||||
|     } | ||||
|     store(filePathArg?:string){ | ||||
|         let filePathObj = plugins.path.parse(filePathArg); | ||||
|         if(filePathObj.ext = ".priv"){ | ||||
|             plugins.smartfile.memory.toFsSync(this.privKey,{fileName:filePathObj.name + filePathObj.ext,filePath:filePathObj.dir}); | ||||
|             plugins.smartfile.memory.toFsSync(this.privKey,filePathArg); | ||||
|         } else if (filePathObj.ext = ".pub"){ | ||||
|             plugins.smartfile.memory.toFsSync(this.pubKey,{fileName:filePathObj.name + filePathObj.ext,filePath:filePathObj.dir}); | ||||
|             plugins.smartfile.memory.toFsSync(this.pubKey,filePathArg); | ||||
|         } else { //we assume we are given a directory as filePathArg, so we store the whole key | ||||
|             plugins.fs.ensureDirSync(filePathObj.dir); | ||||
|             this.store(plugins.path.join(filePathObj.dir,"key.priv")); // call this function recursivly | ||||
|   | ||||
		Reference in New Issue
	
	Block a user