49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import "typings-global"
|
|
import * as plugins from "./smartssh.plugins";
|
|
import * as helpers from "./smartssh.classes.helpers";
|
|
|
|
import {sshDir} from "./smartssh.classes.sshdir";
|
|
|
|
export class ssh {
|
|
private sshConfig:sshConfig; // points to sshConfig class instance
|
|
private sshDir:sshDir; // points to sshDir class instance.
|
|
private sshKeys:sshKey[]; //holds all ssh keys
|
|
private sshSync:boolean; // if set to true, the ssh dir will be kept in sync automatically
|
|
constructor(optionsArg:{sshDir?:string,sshSync?:boolean}={}){
|
|
this.sshDir = new sshDir(optionsArg.sshDir);
|
|
this.sshKeys = this.sshDir.getKeys();
|
|
this.sshSync = optionsArg.sshSync;
|
|
};
|
|
addKey(sshKeyArg:sshKey){
|
|
this.sshKeys.push(sshKeyArg);
|
|
this.sync();
|
|
};
|
|
getKey(hostArg:string){
|
|
let filteredArray = this.sshKeys.filter(function(keyArg){
|
|
return (keyArg.host == hostArg);
|
|
});
|
|
if(filteredArray.length > 0){
|
|
return filteredArray[0];
|
|
} else {
|
|
return undefined;
|
|
}
|
|
};
|
|
removeKey(sshKeyArg:sshKey){
|
|
let keyIndex = helpers.getKeyIndex(sshKeyArg.host);
|
|
this.sshKeys.splice(keyIndex,1);
|
|
this.sync();
|
|
};
|
|
replaceKey(sshKeyOldArg:sshKey,sshKeyNewArg:sshKey){
|
|
let keyIndex = helpers.getKeyIndex(sshKeyOldArg.host);
|
|
this.sshKeys.splice(keyIndex,1,sshKeyNewArg);
|
|
this.sync();
|
|
};
|
|
sync(){
|
|
if(this.sshSync){
|
|
this.sshDir.sync(this.sshConfig,this.sshKeys); // call sync method of sshDir class;
|
|
}
|
|
};
|
|
}
|
|
|
|
|