diff --git a/ts/index.ts b/ts/index.ts index e2bca6e..3228763 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,3 +1,3 @@ import "typings-global" -import plugins = require("./smartssh.plugins"); -import classes = require("./smartssh.classes"); \ No newline at end of file +import * as plugins from "./smartssh.plugins"; +import {} from "./smartssh.classes.ssh"; \ No newline at end of file diff --git a/ts/smartssh.classes.ssh.ts b/ts/smartssh.classes.ssh.ts new file mode 100644 index 0000000..8a070c8 --- /dev/null +++ b/ts/smartssh.classes.ssh.ts @@ -0,0 +1,48 @@ +import "typings-global" +import * as plugins from "./smartssh.plugins"; +import * as helpers from "./smartssh.classes.helpers"; + +import {sshDir} from "./smartssh.classes.sshdir"; + +export class ssh { + private sshConfig:sshConfig; // points to sshConfig class instance + private sshDir:sshDir; // points to sshDir class instance. + private sshKeys:sshKey[]; //holds all ssh keys + private sshSync:boolean; // if set to true, the ssh dir will be kept in sync automatically + constructor(optionsArg:{sshDir?:string,sshSync?:boolean}={}){ + this.sshDir = new sshDir(optionsArg.sshDir); + this.sshKeys = this.sshDir.getKeys(); + this.sshSync = optionsArg.sshSync; + }; + addKey(sshKeyArg:sshKey){ + this.sshKeys.push(sshKeyArg); + this.sync(); + }; + getKey(hostArg:string){ + let filteredArray = this.sshKeys.filter(function(keyArg){ + return (keyArg.host == hostArg); + }); + if(filteredArray.length > 0){ + return filteredArray[0]; + } else { + return undefined; + } + }; + removeKey(sshKeyArg:sshKey){ + let keyIndex = helpers.getKeyIndex(sshKeyArg.host); + this.sshKeys.splice(keyIndex,1); + this.sync(); + }; + replaceKey(sshKeyOldArg:sshKey,sshKeyNewArg:sshKey){ + let keyIndex = helpers.getKeyIndex(sshKeyOldArg.host); + this.sshKeys.splice(keyIndex,1,sshKeyNewArg); + this.sync(); + }; + sync(){ + if(this.sshSync){ + this.sshDir.sync(this.sshConfig,this.sshKeys); // call sync method of sshDir class; + } + }; +} + + diff --git a/ts/smartssh.classes.sshconfig.ts b/ts/smartssh.classes.sshconfig.ts new file mode 100644 index 0000000..4b1ea99 --- /dev/null +++ b/ts/smartssh.classes.sshconfig.ts @@ -0,0 +1,8 @@ +import "typings-global"; +import * as plugins from "./smartssh.plugins"; +import * as helpers from "./smartssh.classes.helpers"; +export class sshConfig { + constructor(){ + + } +} \ No newline at end of file diff --git a/ts/smartssh.classes.sshdir.ts b/ts/smartssh.classes.sshdir.ts new file mode 100644 index 0000000..74d1e79 --- /dev/null +++ b/ts/smartssh.classes.sshdir.ts @@ -0,0 +1,16 @@ +import "typings-global"; +import * as plugins from "./smartssh.plugins"; +import * as helpers from "./smartssh.classes.helpers"; +import {sshKey} from "./smartssh.classes.sshkey"; +export class sshDir { // sshDir class -> NOT EXPORTED, ONLY FOR INTERNAL USE + path:string; + constructor(sshDirPathArg:string){ + this.path = sshDirPathArg; + } + sync(sshConfigArg:sshConfig,sshKeysArg:sshKey[]){ + + }; + getKeys(){ + return helpers.sshKeyArrayFromDir(this.path); + } +} \ No newline at end of file diff --git a/ts/smartssh.classes.ts b/ts/smartssh.classes.sshkey.ts similarity index 50% rename from ts/smartssh.classes.ts rename to ts/smartssh.classes.sshkey.ts index 38cad39..123b35a 100644 --- a/ts/smartssh.classes.ts +++ b/ts/smartssh.classes.sshkey.ts @@ -1,66 +1,6 @@ -import "typings-global" -import plugins = require("./smartssh.plugins"); -import helpers = require("./smartssh.classes.helpers"); - -export class ssh { - private sshConfig:sshConfig; // points to sshConfig class instance - private sshDir:sshDir; // points to sshDir class instance. - private sshKeys:sshKey[]; //holds all ssh keys - private sshSync:boolean; // if set to true, the ssh dir will be kept in sync automatically - constructor(optionsArg:{sshDir?:string,sshSync?:boolean}={}){ - this.sshDir = new sshDir(optionsArg.sshDir); - this.sshKeys = this.sshDir.getKeys(); - this.sshSync = optionsArg.sshSync; - }; - addKey(sshKeyArg:sshKey){ - this.sshKeys.push(sshKeyArg); - this.sync(); - }; - getKey(hostArg:string){ - let filteredArray = this.sshKeys.filter(function(keyArg){ - return (keyArg.host == hostArg); - }); - if(filteredArray.length > 0){ - return filteredArray[0]; - } else { - return undefined; - } - }; - removeKey(sshKeyArg:sshKey){ - let keyIndex = helpers.getKeyIndex(sshKeyArg.host); - this.sshKeys.splice(keyIndex,1); - this.sync(); - }; - replaceKey(sshKeyOldArg:sshKey,sshKeyNewArg:sshKey){ - let keyIndex = helpers.getKeyIndex(sshKeyOldArg.host); - this.sshKeys.splice(keyIndex,1,sshKeyNewArg); - this.sync(); - }; - sync(){ - if(this.sshSync){ - this.sshDir.sync(this.sshConfig,this.sshKeys); // call sync method of sshDir class; - } - }; -} - -class sshDir { // sshDir class -> NOT EXPORTED, ONLY FOR INTERNAL USE - path:string; - constructor(sshDirPathArg:string){ - this.path = sshDirPathArg; - } - sync(sshConfigArg:sshConfig,sshKeysArg:sshKey[]){ - - }; - getKeys(){ - return helpers.sshKeyArrayFromDir(this.path); - } -} - -export class sshConfig { - constructor(){ - - } -} +import "typings-global"; +import * as plugins from "./smartssh.plugins"; +import * as helpers from "./smartssh.classes.helpers"; export class sshKey { private privKey:string;