2022-10-11 11:05:29 +00:00
|
|
|
import * as plugins from './smartssh.plugins.js';
|
|
|
|
import * as helpers from './smartssh.classes.helpers.js';
|
|
|
|
import { SshKey } from './smartssh.classes.sshkey.js';
|
2016-06-24 18:58:55 +00:00
|
|
|
|
2016-05-31 17:16:45 +00:00
|
|
|
export class SshConfig {
|
2018-09-17 20:32:31 +00:00
|
|
|
private _sshKeyArray: SshKey[];
|
|
|
|
constructor(sshKeyArrayArg: SshKey[]) {
|
|
|
|
this._sshKeyArray = sshKeyArrayArg;
|
|
|
|
}
|
2016-06-25 00:29:34 +00:00
|
|
|
|
2018-09-17 20:32:31 +00:00
|
|
|
/**
|
|
|
|
* stores a config file
|
|
|
|
*/
|
|
|
|
store(dirPathArg: string) {
|
2019-07-17 09:48:31 +00:00
|
|
|
let done = plugins.smartpromise.defer();
|
2018-09-17 20:32:31 +00:00
|
|
|
let configArray: configObject[] = [];
|
|
|
|
let configString;
|
|
|
|
for (let key in this._sshKeyArray) {
|
|
|
|
let sshKey = this._sshKeyArray[key];
|
|
|
|
if (sshKey.host) {
|
|
|
|
configString =
|
|
|
|
'Host ' +
|
|
|
|
sshKey.host +
|
|
|
|
'\n' +
|
|
|
|
' HostName ' +
|
|
|
|
sshKey.host +
|
|
|
|
'\n' +
|
|
|
|
' IdentityFile ~/.ssh/' +
|
|
|
|
sshKey.host +
|
|
|
|
'\n' +
|
|
|
|
' StrictHostKeyChecking no' +
|
|
|
|
'\n';
|
|
|
|
}
|
|
|
|
configArray.push({
|
|
|
|
configString: configString,
|
|
|
|
authorized: sshKey.authorized,
|
2022-10-11 11:05:29 +00:00
|
|
|
sshKey: sshKey,
|
2018-09-17 20:32:31 +00:00
|
|
|
});
|
2016-06-25 13:30:57 +00:00
|
|
|
}
|
2018-09-17 20:32:31 +00:00
|
|
|
let configFile: string = '';
|
|
|
|
for (let key in configArray) {
|
|
|
|
configFile = configFile + configArray[key].configString + '\n';
|
2016-05-31 17:00:52 +00:00
|
|
|
}
|
2018-09-17 20:32:31 +00:00
|
|
|
plugins.smartfile.memory.toFsSync(configFile, plugins.path.join(dirPathArg, 'config'));
|
|
|
|
return done.promise;
|
|
|
|
}
|
|
|
|
read(dirPathArg) {
|
2019-07-17 09:48:31 +00:00
|
|
|
let done = plugins.smartpromise.defer();
|
2018-09-17 20:32:31 +00:00
|
|
|
let configArray: configObject[];
|
|
|
|
plugins.smartfile.fs.toStringSync(plugins.path.join(dirPathArg, 'config'));
|
2016-06-25 00:10:53 +00:00
|
|
|
|
2018-09-17 20:32:31 +00:00
|
|
|
return done.promise;
|
|
|
|
}
|
|
|
|
}
|
2016-06-25 00:10:53 +00:00
|
|
|
|
2018-09-17 20:32:31 +00:00
|
|
|
export interface configObject {
|
|
|
|
configString: string;
|
|
|
|
authorized: boolean;
|
|
|
|
sshKey: SshKey;
|
|
|
|
}
|