Files
smartssh/ts/smartssh.classes.sshconfig.ts

55 lines
1.7 KiB
TypeScript
Raw Normal View History

2016-05-31 19:00:52 +02:00
import "typings-global";
import * as plugins from "./smartssh.plugins";
import * as helpers from "./smartssh.classes.helpers";
2016-06-24 20:58:55 +02:00
import {SshKey} from "./smartssh.classes.sshkey"
export class SshConfig {
2016-06-28 02:10:51 +02:00
private _sshKeyArray:SshKey[];
2016-06-24 20:58:55 +02:00
constructor(sshKeyArrayArg:SshKey[]){
2016-06-28 02:10:51 +02:00
this._sshKeyArray = sshKeyArrayArg;
2016-06-24 20:58:55 +02:00
}
2016-06-25 02:29:34 +02:00
/**
2016-06-25 02:53:05 +02:00
* stores a config file
2016-06-25 02:29:34 +02:00
*/
2016-06-25 15:30:57 +02:00
store(dirPathArg:string){
let done = plugins.q.defer();
2016-06-26 16:16:12 +02:00
let configArray:configObject[] = [];
2016-06-25 15:30:57 +02:00
let configString;
2016-06-28 02:10:51 +02:00
for(let key in this._sshKeyArray){
let sshKey = this._sshKeyArray[key];
2016-06-25 15:30:57 +02:00
if(sshKey.host){
configString = "Host " + sshKey.host + "\n" +
" HostName " + sshKey.host + "\n" +
2016-06-26 16:16:12 +02:00
" IdentityFile ~/.ssh/" + sshKey.host + "\n" +
" StrictHostKeyChecking no" + "\n"
2016-06-25 15:30:57 +02:00
}
configArray.push({
configString:configString,
authorized: sshKey.authorized,
sshKey: sshKey
});
}
let configFile:string = "";
for(let key in configArray){
configFile = configFile + configArray[key].configString + "\n";
};
2016-06-26 16:16:12 +02:00
plugins.smartfile.memory.toFsSync(configFile,plugins.path.join(dirPathArg,"config"));
2016-06-25 15:30:57 +02:00
return done.promise;
}
read(dirPathArg){
2016-06-25 02:53:05 +02:00
let done = plugins.q.defer();
2016-06-25 02:29:34 +02:00
let configArray:configObject[];
2016-06-28 02:10:51 +02:00
plugins.smartfile.fs.toStringSync(plugins.path.join(dirPathArg,"config"));
2016-06-25 02:53:05 +02:00
return done.promise;
2016-05-31 19:00:52 +02:00
}
2016-06-25 02:10:53 +02:00
};
2016-06-25 02:29:34 +02:00
export interface configObject {
2016-06-25 15:30:57 +02:00
configString:string;
2016-06-25 02:10:53 +02:00
authorized:boolean;
sshKey:SshKey;
};