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-24 18:58:55 +00:00
|
|
|
import {SshKey} from "./smartssh.classes.sshkey"
|
|
|
|
|
2016-05-31 17:16:45 +00:00
|
|
|
export class SshConfig {
|
2016-06-24 18:58:55 +00:00
|
|
|
sshKeyArray:SshKey[];
|
|
|
|
constructor(sshKeyArrayArg:SshKey[]){
|
|
|
|
this.sshKeyArray = sshKeyArrayArg;
|
|
|
|
}
|
2016-06-25 00:29:34 +00:00
|
|
|
|
|
|
|
/**
|
2016-06-25 00:53:05 +00:00
|
|
|
* stores a config file
|
2016-06-25 00:29:34 +00:00
|
|
|
*/
|
2016-06-25 13:30:57 +00:00
|
|
|
store(dirPathArg:string){
|
|
|
|
let done = plugins.q.defer();
|
2016-06-26 14:16:12 +00:00
|
|
|
let configArray:configObject[] = [];
|
2016-06-25 13:30:57 +00:00
|
|
|
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" +
|
2016-06-26 14:16:12 +00:00
|
|
|
" IdentityFile ~/.ssh/" + sshKey.host + "\n" +
|
|
|
|
" StrictHostKeyChecking no" + "\n"
|
2016-06-25 13:30:57 +00: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 14:16:12 +00:00
|
|
|
plugins.smartfile.memory.toFsSync(configFile,plugins.path.join(dirPathArg,"config"));
|
2016-06-25 13:30:57 +00:00
|
|
|
return done.promise;
|
|
|
|
}
|
|
|
|
read(dirPathArg){
|
2016-06-25 00:53:05 +00:00
|
|
|
let done = plugins.q.defer();
|
2016-06-25 00:29:34 +00:00
|
|
|
let configArray:configObject[];
|
2016-06-25 11:07:24 +00:00
|
|
|
|
2016-06-25 00:53:05 +00:00
|
|
|
return done.promise;
|
2016-05-31 17:00:52 +00:00
|
|
|
}
|
2016-06-25 00:10:53 +00:00
|
|
|
};
|
|
|
|
|
2016-06-25 00:29:34 +00:00
|
|
|
export interface configObject {
|
2016-06-25 13:30:57 +00:00
|
|
|
configString:string;
|
2016-06-25 00:10:53 +00:00
|
|
|
authorized:boolean;
|
|
|
|
sshKey:SshKey;
|
|
|
|
};
|
|
|
|
|