add some logic
This commit is contained in:
parent
69a8411202
commit
1663d9a266
@ -16,16 +16,18 @@ var sshInstance = new smartssh.sshInstance({
|
||||
sshInstance.addKey(new smartssh.sshKey({
|
||||
private: "somestring",
|
||||
public: "somestring", // optional
|
||||
for:"github.com",
|
||||
host:"github.com",
|
||||
encoding: "base64" // optional, defaults to "utf8", can be "utf8" or "base64", useful for reading ssh keys from environment variables
|
||||
}));
|
||||
|
||||
sshInstance.removeKey(sshInstance.getKey("github.com")); // removes key for host "github.com" is present
|
||||
|
||||
sshInstance.createKey({
|
||||
for:"gitlab.com" // returns new key in the form sshKey, read more about the sshKey class below
|
||||
host:"gitlab.com" // returns new key in the form sshKey, read more about the sshKey class below
|
||||
})
|
||||
|
||||
sshInstance.getKey({ // returns ssh key in the form sshKey, read more about the sshKey class below
|
||||
for:"github.com"
|
||||
host:"github.com"
|
||||
});
|
||||
|
||||
sshInstance.getKeys() // returns array of all available getKeys. Each key is in form of class sshKey
|
||||
|
63
dist/smartssh.classes.js
vendored
63
dist/smartssh.classes.js
vendored
File diff suppressed because one or more lines are too long
@ -3,17 +3,45 @@ import plugins = require("./smartssh.plugins");
|
||||
import helpers = require("./smartssh.classes.helpers");
|
||||
|
||||
export class ssh {
|
||||
private sshDir:string;
|
||||
private sshKeys:sshKey[];
|
||||
private sshConfig:sshConfig;
|
||||
private sshDir:sshDir;
|
||||
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 = optionsArg.sshDir
|
||||
this.sshDir ?
|
||||
this.sshKeys = helpers.sshKeyArrayFromDir(this.sshDir)
|
||||
: void(0);
|
||||
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;
|
||||
}
|
||||
};
|
||||
sync(){
|
||||
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 {
|
||||
@ -25,13 +53,17 @@ export class sshConfig {
|
||||
export class sshKey {
|
||||
private privKey:string;
|
||||
private pubKey:string;
|
||||
constructor(optionsArg:{private:string,public:string}){
|
||||
if(!optionsArg) optionsArg = {private:undefined,public:undefined};
|
||||
private hostVar:string;
|
||||
constructor(optionsArg:{private?:string,public?:string,host?:string}={}){
|
||||
this.privKey = optionsArg.private;
|
||||
this.pubKey = optionsArg.public;
|
||||
this.hostVar = optionsArg.host;
|
||||
};
|
||||
|
||||
// getters
|
||||
get host(){
|
||||
return this.hostVar;
|
||||
};
|
||||
get privateKey(){
|
||||
return this.privKey;
|
||||
};
|
||||
@ -55,6 +87,9 @@ export class sshKey {
|
||||
};
|
||||
|
||||
// setters
|
||||
set host(hostArg:string){
|
||||
this.hostVar = hostArg;
|
||||
};
|
||||
set privateKey(privateKeyArg:string){
|
||||
this.privKey = privateKeyArg;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user