add some logic
This commit is contained in:
parent
69a8411202
commit
1663d9a266
10
README.md
10
README.md
@ -16,18 +16,20 @@ var sshInstance = new smartssh.sshInstance({
|
|||||||
sshInstance.addKey(new smartssh.sshKey({
|
sshInstance.addKey(new smartssh.sshKey({
|
||||||
private: "somestring",
|
private: "somestring",
|
||||||
public: "somestring", // optional
|
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
|
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({
|
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
|
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
|
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");
|
import helpers = require("./smartssh.classes.helpers");
|
||||||
|
|
||||||
export class ssh {
|
export class ssh {
|
||||||
private sshDir:string;
|
private sshConfig:sshConfig;
|
||||||
private sshKeys:sshKey[];
|
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
|
private sshSync:boolean; // if set to true, the ssh dir will be kept in sync automatically
|
||||||
constructor(optionsArg:{sshDir?:string,sshSync?:boolean}={}){
|
constructor(optionsArg:{sshDir?:string,sshSync?:boolean}={}){
|
||||||
this.sshDir = optionsArg.sshDir
|
this.sshDir = new sshDir(optionsArg.sshDir);
|
||||||
this.sshDir ?
|
this.sshKeys = this.sshDir.getKeys();
|
||||||
this.sshKeys = helpers.sshKeyArrayFromDir(this.sshDir)
|
|
||||||
: void(0);
|
|
||||||
this.sshSync = optionsArg.sshSync;
|
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 {
|
export class sshConfig {
|
||||||
@ -25,13 +53,17 @@ export class sshConfig {
|
|||||||
export class sshKey {
|
export class sshKey {
|
||||||
private privKey:string;
|
private privKey:string;
|
||||||
private pubKey:string;
|
private pubKey:string;
|
||||||
constructor(optionsArg:{private:string,public:string}){
|
private hostVar:string;
|
||||||
if(!optionsArg) optionsArg = {private:undefined,public:undefined};
|
constructor(optionsArg:{private?:string,public?:string,host?:string}={}){
|
||||||
this.privKey = optionsArg.private;
|
this.privKey = optionsArg.private;
|
||||||
this.pubKey = optionsArg.public;
|
this.pubKey = optionsArg.public;
|
||||||
|
this.hostVar = optionsArg.host;
|
||||||
};
|
};
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
|
get host(){
|
||||||
|
return this.hostVar;
|
||||||
|
};
|
||||||
get privateKey(){
|
get privateKey(){
|
||||||
return this.privKey;
|
return this.privKey;
|
||||||
};
|
};
|
||||||
@ -55,6 +87,9 @@ export class sshKey {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// setters
|
// setters
|
||||||
|
set host(hostArg:string){
|
||||||
|
this.hostVar = hostArg;
|
||||||
|
};
|
||||||
set privateKey(privateKeyArg:string){
|
set privateKey(privateKeyArg:string){
|
||||||
this.privKey = privateKeyArg;
|
this.privKey = privateKeyArg;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user