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