smartssh/ts/smartssh.classes.sshdir.ts

48 lines
1.4 KiB
TypeScript
Raw Normal View History

2018-09-17 20:32:31 +00:00
import * as plugins from './smartssh.plugins';
import * as helpers from './smartssh.classes.helpers';
import { SshInstance } from './smartssh.classes.sshinstance';
import { SshKey } from './smartssh.classes.sshkey';
import { SshConfig } from './smartssh.classes.sshconfig';
2017-06-15 17:25:12 +00:00
2018-09-17 20:32:31 +00:00
export class SshDir {
// sshDir class -> NOT EXPORTED, ONLY FOR INTERNAL USE
private _path: string; // the path of the ssh directory
private _sshKeyArray: SshKey[];
private _sshConfig: SshConfig;
constructor(sshKeyArray: SshKey[], sshConfig: SshConfig, sshDirPathArg?: string) {
this._sshKeyArray = sshKeyArray;
this._sshConfig = sshConfig;
2017-06-15 17:25:12 +00:00
if (sshDirPathArg) {
2018-09-17 20:32:31 +00:00
this._path = sshDirPathArg;
2017-06-15 17:25:12 +00:00
} else {
2018-09-17 20:32:31 +00:00
this._path = plugins.path.join(plugins.smartpath.get.home(), '.ssh/');
2016-05-31 17:00:52 +00:00
}
2017-06-15 17:25:12 +00:00
}
2018-09-17 20:32:31 +00:00
writeToDir(dirPathArg?: string) {
// syncs sshInstance to directory
let path = this._path;
if (dirPathArg) path = dirPathArg;
this._sshKeyArray.forEach(sshKeyArg => {
sshKeyArg.store(path);
});
this._sshConfig.store(path);
2017-06-15 17:25:12 +00:00
}
2018-09-17 20:32:31 +00:00
/**
* TODO: implement reading of directories
*/
readFromDir(dirPathArg?: string) {
// syncs sshInstance from directory
let path = this._path;
if (dirPathArg) path = dirPathArg;
2017-06-15 17:25:12 +00:00
}
2018-09-17 20:32:31 +00:00
updateDirPath(dirPathArg: string) {
this._path = dirPathArg;
2017-06-15 17:25:12 +00:00
}
2018-09-17 20:32:31 +00:00
getKeys() {
return helpers.sshKeyArrayFromDir(this._path);
2017-06-15 17:25:12 +00:00
}
2016-11-23 11:38:38 +00:00
}