2016-05-31 17:00:52 +00:00
|
|
|
import "typings-global";
|
|
|
|
import * as plugins from "./smartssh.plugins";
|
|
|
|
import * as helpers from "./smartssh.classes.helpers";
|
2016-06-01 00:31:29 +00:00
|
|
|
import {SshInstance} from "./smartssh.classes.sshinstance";
|
2016-05-31 17:16:45 +00:00
|
|
|
import {SshKey} from "./smartssh.classes.sshkey";
|
|
|
|
import {SshConfig} from "./smartssh.classes.sshconfig";
|
|
|
|
export class SshDir { // sshDir class -> NOT EXPORTED, ONLY FOR INTERNAL USE
|
2016-06-26 14:16:12 +00:00
|
|
|
private _path:string; // the path of the ssh directory
|
|
|
|
private _sshKeyArray:SshKey[];
|
|
|
|
private _sshConfig:SshConfig;
|
2016-06-25 13:30:57 +00:00
|
|
|
constructor(sshKeyArray:SshKey[],sshConfig:SshConfig,sshDirPathArg?:string){
|
2016-06-26 14:16:12 +00:00
|
|
|
this._sshKeyArray = sshKeyArray;
|
|
|
|
this._sshConfig = sshConfig;
|
2016-05-31 22:56:24 +00:00
|
|
|
if(sshDirPathArg){
|
2016-06-26 14:16:12 +00:00
|
|
|
this._path = sshDirPathArg;
|
2016-05-31 22:56:24 +00:00
|
|
|
} else {
|
2016-06-26 14:16:12 +00:00
|
|
|
this._path = plugins.path.join(plugins.smartpath.get.home(),".ssh/");
|
2016-06-24 18:58:55 +00:00
|
|
|
};
|
2016-05-31 17:00:52 +00:00
|
|
|
}
|
2016-06-28 00:10:51 +00:00
|
|
|
writeToDir(dirPathArg?:string){ // syncs sshInstance to directory
|
|
|
|
let path = this._path;
|
|
|
|
if(dirPathArg) path = dirPathArg;
|
2016-06-26 14:16:12 +00:00
|
|
|
this._sshKeyArray.forEach((sshKeyArg) => {
|
2016-06-28 00:10:51 +00:00
|
|
|
sshKeyArg.store(path);
|
2016-06-24 18:58:55 +00:00
|
|
|
});
|
2016-06-28 00:10:51 +00:00
|
|
|
this._sshConfig.store(path);
|
2016-05-31 17:00:52 +00:00
|
|
|
};
|
2016-06-28 00:10:51 +00:00
|
|
|
readFromDir(dirPathArg?:string){ // syncs sshInstance from directory
|
|
|
|
let path = this._path;
|
|
|
|
if(dirPathArg) path = dirPathArg;
|
2016-06-01 00:31:29 +00:00
|
|
|
}
|
2016-06-26 14:16:12 +00:00
|
|
|
updateDirPath(dirPathArg:string){
|
|
|
|
this._path = dirPathArg;
|
|
|
|
};
|
2016-05-31 17:00:52 +00:00
|
|
|
getKeys(){
|
2016-06-26 14:16:12 +00:00
|
|
|
return helpers.sshKeyArrayFromDir(this._path);
|
2016-05-31 17:00:52 +00:00
|
|
|
}
|
|
|
|
}
|