52 Commits

Author SHA1 Message Date
32c2698af7 1.2.0 2016-11-23 12:38:45 +01:00
27237f14c7 update to latest standards 2016-11-23 12:38:38 +01:00
8f29f234f1 introducde more flexible pathing 2016-06-28 02:10:51 +02:00
5091625953 1.1.5 2016-06-26 16:16:28 +02:00
f74b3a51b0 now creating config as standard 2016-06-26 16:16:12 +02:00
062f3ad060 1.1.4 2016-06-26 04:23:48 +02:00
ecd0fd8fad now setting rights for stored keys 2016-06-26 04:23:45 +02:00
742bf694e4 1.1.3 2016-06-26 04:07:37 +02:00
38165f11db some updates 2016-06-26 04:07:03 +02:00
ef2b31b4b2 1.1.2 2016-06-25 15:31:03 +02:00
5b1f800067 update structure 2016-06-25 15:30:57 +02:00
6339a3ed9b update SshKey.store() 2016-06-25 14:13:26 +02:00
bf27aaf167 update structure 2016-06-25 13:07:24 +02:00
9bc3aea59c 1.1.1 2016-06-25 02:53:09 +02:00
f5ff302d4d updated structure of SshConfig 2016-06-25 02:53:05 +02:00
cac8203bf5 1.1.0 2016-06-25 02:29:51 +02:00
e4532271cc major structural update 2016-06-25 02:29:34 +02:00
faf6c91199 update 2016-06-25 02:10:53 +02:00
d0009e7a9c update stucture 2016-06-24 20:58:55 +02:00
da76df2c3e 1.0.7 2016-06-24 02:50:02 +02:00
a43976110a update structure 2016-06-24 02:49:55 +02:00
c3ee35a699 1.0.6 2016-06-14 00:34:07 +02:00
a0ce759552 update links in package.json to point to gitlab 2016-06-14 00:33:59 +02:00
201d5cc6d7 some restructuring 2016-06-14 00:27:55 +02:00
e5bdfff743 added ability to add keys as base 64 2016-06-14 00:11:20 +02:00
967c9fd9d1 now using legacy tag in gitlab-ci.yml 2016-06-13 23:31:41 +02:00
35da2f0b73 strip pages from gitlab-ci for now 2016-06-13 23:29:37 +02:00
5e991a4e4f update gitlab ci base image 2016-06-13 23:26:54 +02:00
0f75f5238c update dependencies 2016-06-13 23:26:36 +02:00
e8f3047ac0 1.0.5 2016-06-01 05:18:08 +02:00
812d28ee3d add typings to package.json 2016-06-01 05:17:49 +02:00
fa301eea71 improved tests and reached 80% coverage milestone. 2016-06-01 05:09:20 +02:00
48ccf317d6 update some cosmetics 2016-06-01 04:25:59 +02:00
9b3af8a50a 1.0.4 2016-06-01 04:18:40 +02:00
78aa36c2be added more tests 2016-06-01 04:18:31 +02:00
09d96fd94c update directory sync 2016-06-01 03:57:17 +02:00
f4f60a685d 1.0.3 2016-06-01 02:48:45 +02:00
904129706c add some tests 2016-06-01 02:48:38 +02:00
9a96bbd266 update gitlab ci yml 2016-06-01 02:35:12 +02:00
39abfd760b start tests 2016-06-01 02:31:29 +02:00
1b30aa428e update gitlab-ci yml 2016-06-01 01:00:29 +02:00
41613c0b93 update ci yml 2016-06-01 00:59:02 +02:00
2d14617b13 rename Ssh class to SshInstance 2016-06-01 00:56:24 +02:00
3106945b47 update gitlab ci yml 2016-05-31 19:50:43 +02:00
2284620387 1.0.2 2016-05-31 19:16:52 +02:00
cd6bcb974c made all classes start with capital letters 2016-05-31 19:16:45 +02:00
eb66ed0244 restructure class files 2016-05-31 19:00:52 +02:00
d12c7ab621 update typings to use typings-global and typings-test, update dependencies 2016-05-31 18:48:46 +02:00
84374299cf latest status 2016-04-28 00:09:17 +02:00
b73928109b improve sync triggering 2016-04-26 05:09:03 +02:00
1d17dd1b84 add removeKey and replaceKey methods 2016-04-26 05:04:36 +02:00
1663d9a266 add some logic 2016-04-26 04:44:50 +02:00
34 changed files with 1011 additions and 249 deletions

8
.gitignore vendored
View File

@ -1,7 +1,5 @@
.idea/
node_modules/
coverage/
docs/
ts/typings/
ts/*.js
ts/*.js.map
pages/
public/
test/temp/

59
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,59 @@
image: hosttoday/ht-docker-node:npmts
stages:
- test
- release
- trigger
- pages
testLEGACY:
stage: test
script:
- npmci test legacy
tags:
- docker
allow_failure: true
testLTS:
stage: test
script:
- npmci test lts
tags:
- docker
testSTABLE:
stage: test
script:
- npmci test stable
tags:
- docker
release:
stage: release
script:
- npmci publish
only:
- tags
tags:
- docker
trigger:
stage: trigger
script:
- npmci trigger
only:
- tags
tags:
- docker
pages:
image: hosttoday/ht-docker-node:npmpage
stage: pages
script:
- npmci command npmpage --host gitlab
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public

5
Dockerfile Normal file
View File

@ -0,0 +1,5 @@
FROM hosttoday/ht-docker-node:npmts
COPY ./ /node-app
WORKDIR /node-app
RUN npm install
RUN npmts

View File

@ -2,7 +2,8 @@
setups SSH quickly and in a painless manner
> Attention: This is still alpha, so some things won't work, not all things are inplemented.
I (Phil from Lossless) expect this to be ready 2016/05/01.
## Usage
@ -16,18 +17,20 @@ 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
```
```

5
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
import 'typings-global';
export { SshInstance } from './smartssh.classes.sshinstance';
export { SshKey } from './smartssh.classes.sshkey';
export { SshDir } from './smartssh.classes.sshdir';
export { SshConfig } from './smartssh.classes.sshconfig';

12
dist/index.js vendored
View File

@ -1,3 +1,11 @@
"use strict";
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
require("typings-global");
var smartssh_classes_sshinstance_1 = require("./smartssh.classes.sshinstance");
exports.SshInstance = smartssh_classes_sshinstance_1.SshInstance;
var smartssh_classes_sshkey_1 = require("./smartssh.classes.sshkey");
exports.SshKey = smartssh_classes_sshkey_1.SshKey;
var smartssh_classes_sshdir_1 = require("./smartssh.classes.sshdir");
exports.SshDir = smartssh_classes_sshdir_1.SshDir;
var smartssh_classes_sshconfig_1 = require("./smartssh.classes.sshconfig");
exports.SshConfig = smartssh_classes_sshconfig_1.SshConfig;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBR3ZCLCtFQUEwRDtBQUFsRCxxREFBQSxXQUFXLENBQUE7QUFDbkIscUVBQWdEO0FBQXhDLDJDQUFBLE1BQU0sQ0FBQTtBQUNkLHFFQUFnRDtBQUF4QywyQ0FBQSxNQUFNLENBQUE7QUFDZCwyRUFBc0Q7QUFBOUMsaURBQUEsU0FBUyxDQUFBIn0=

3
dist/smartssh.classes.helpers.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
import 'typings-global';
import { SshKey } from './smartssh.classes.sshkey';
export declare let sshKeyArrayFromDir: (dirArg: string) => SshKey[];

View File

@ -1,7 +1,7 @@
"use strict";
require("typings-global");
exports.sshKeyArrayFromDir = function (dirArg) {
var sshKeyArray = [];
let sshKeyArray = []; // TODO
return sshKeyArray;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBSVcsMEJBQWtCLEdBQUcsVUFBUyxNQUFhO0lBQ2xELElBQUksV0FBVyxHQUFHLEVBQUUsQ0FBQztJQUNyQixNQUFNLENBQUMsV0FBVyxDQUFDO0FBQ3ZCLENBQUMsQ0FBQSIsImZpbGUiOiJzbWFydHNzaC5jbGFzc2VzLmhlbHBlcnMuanMiLCJzb3VyY2VzQ29udGVudCI6WyIvLy8gPHJlZmVyZW5jZSBwYXRoPVwiLi90eXBpbmdzL21haW4uZC50c1wiIC8+XG5pbXBvcnQgcGx1Z2lucyA9IHJlcXVpcmUoXCIuL3NtYXJ0c3NoLnBsdWdpbnNcIik7XG5pbXBvcnQgY2xhc3NlcyA9IHJlcXVpcmUoXCIuL3NtYXJ0c3NoLmNsYXNzZXNcIik7XG5cbmV4cG9ydCBsZXQgc3NoS2V5QXJyYXlGcm9tRGlyID0gZnVuY3Rpb24oZGlyQXJnOnN0cmluZyk6Y2xhc3Nlcy5zc2hLZXlbXXtcbiAgICBsZXQgc3NoS2V5QXJyYXkgPSBbXTtcbiAgICByZXR1cm4gc3NoS2V5QXJyYXk7XG59Il0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzc2guY2xhc3Nlcy5oZWxwZXJzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzc2guY2xhc3Nlcy5oZWxwZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwQkFBdUI7QUFJWixRQUFBLGtCQUFrQixHQUFHLFVBQVMsTUFBYztJQUNuRCxJQUFJLFdBQVcsR0FBRyxFQUFFLENBQUEsQ0FBQyxPQUFPO0lBQzVCLE1BQU0sQ0FBQyxXQUFXLENBQUE7QUFDdEIsQ0FBQyxDQUFBIn0=

File diff suppressed because one or more lines are too long

17
dist/smartssh.classes.sshconfig.d.ts vendored Normal file
View File

@ -0,0 +1,17 @@
/// <reference types="q" />
import 'typings-global';
import { SshKey } from './smartssh.classes.sshkey';
export declare class SshConfig {
private _sshKeyArray;
constructor(sshKeyArrayArg: SshKey[]);
/**
* stores a config file
*/
store(dirPathArg: string): Q.Promise<{}>;
read(dirPathArg: any): Q.Promise<{}>;
}
export interface configObject {
configString: string;
authorized: boolean;
sshKey: SshKey;
}

47
dist/smartssh.classes.sshconfig.js vendored Normal file
View File

@ -0,0 +1,47 @@
"use strict";
require("typings-global");
const plugins = require("./smartssh.plugins");
class SshConfig {
constructor(sshKeyArrayArg) {
this._sshKeyArray = sshKeyArrayArg;
}
/**
* stores a config file
*/
store(dirPathArg) {
let done = plugins.q.defer();
let configArray = [];
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' +
' IdentityFile ~/.ssh/' + sshKey.host + '\n' +
' StrictHostKeyChecking no' + '\n';
}
configArray.push({
configString: configString,
authorized: sshKey.authorized,
sshKey: sshKey
});
}
let configFile = '';
for (let key in configArray) {
configFile = configFile + configArray[key].configString + '\n';
}
;
plugins.smartfile.memory.toFsSync(configFile, plugins.path.join(dirPathArg, 'config'));
return done.promise;
}
read(dirPathArg) {
let done = plugins.q.defer();
let configArray;
plugins.smartfile.fs.toStringSync(plugins.path.join(dirPathArg, 'config'));
return done.promise;
}
}
exports.SshConfig = SshConfig;
;
;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzc2guY2xhc3Nlcy5zc2hjb25maWcuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNzaC5jbGFzc2VzLnNzaGNvbmZpZy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLDhDQUE2QztBQUk3QztJQUVJLFlBQVksY0FBd0I7UUFDaEMsSUFBSSxDQUFDLFlBQVksR0FBRyxjQUFjLENBQUE7SUFDdEMsQ0FBQztJQUVEOztPQUVHO0lBQ0gsS0F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8sQ0FBQyxTQUFTLENBQUMsTUFBTSxDQUFDLFFBQVEsQ0FBQyxVQUFVLEVBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsVUFBVSxFQUFDLFFBQVEsQ0FBQyxDQUFDLENBQUE7UUFDcEYsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztJQUNELElBQUksQ0FBQyxVQUFVO1FBQ1gsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtRQUM1QixJQUFJLFdBQTJCLENBQUE7UUFDL0IsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFFLENBQUMsWUFBWSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLFVBQVUsRUFBQyxRQUFRLENBQUMsQ0FBQyxDQUFBO1FBRXpFLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7Q0FDSjtBQXpDRCw4QkF5Q0M7QUFBQSxDQUFDO0FBTUQsQ0FBQyJ9

13
dist/smartssh.classes.sshdir.d.ts vendored Normal file
View File

@ -0,0 +1,13 @@
import 'typings-global';
import { SshKey } from './smartssh.classes.sshkey';
import { SshConfig } from './smartssh.classes.sshconfig';
export declare class SshDir {
private _path;
private _sshKeyArray;
private _sshConfig;
constructor(sshKeyArray: SshKey[], sshConfig: SshConfig, sshDirPathArg?: string);
writeToDir(dirPathArg?: string): void;
readFromDir(dirPathArg?: string): void;
updateDirPath(dirPathArg: string): void;
getKeys(): SshKey[];
}

41
dist/smartssh.classes.sshdir.js vendored Normal file
View File

@ -0,0 +1,41 @@
"use strict";
require("typings-global");
const plugins = require("./smartssh.plugins");
const helpers = require("./smartssh.classes.helpers");
class SshDir {
constructor(sshKeyArray, sshConfig, sshDirPathArg) {
this._sshKeyArray = sshKeyArray;
this._sshConfig = sshConfig;
if (sshDirPathArg) {
this._path = sshDirPathArg;
}
else {
this._path = plugins.path.join(plugins.smartpath.get.home(), '.ssh/');
}
;
}
writeToDir(dirPathArg) {
let path = this._path;
if (dirPathArg)
path = dirPathArg;
this._sshKeyArray.forEach((sshKeyArg) => {
sshKeyArg.store(path);
});
this._sshConfig.store(path);
}
;
readFromDir(dirPathArg) {
let path = this._path;
if (dirPathArg)
path = dirPathArg;
}
updateDirPath(dirPathArg) {
this._path = dirPathArg;
}
;
getKeys() {
return helpers.sshKeyArrayFromDir(this._path);
}
}
exports.SshDir = SshDir;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzc2guY2xhc3Nlcy5zc2hkaXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNzaC5jbGFzc2VzLnNzaGRpci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLDhDQUE2QztBQUM3QyxzREFBcUQ7QUFJckQ7SUFJSSxZQUFZLFdBQXFCLEVBQUMsU0FBb0IsRUFBQyxhQUFzQjtRQUN6RSxJQUFJLENBQUMsWUFBWSxHQUFHLFdBQVcsQ0FBQTtRQUMvQixJQUFJLENBQUMsVUFBVSxHQUFHLFNBQVMsQ0FBQTtRQUMzQixFQUFFLENBQUMsQ0FBQyxhQUFhLENBQUMsQ0FBQyxDQUFDO1lBQ2hCLElBQUksQ0FBQyxLQUFLLEdBQUcsYUFBYSxDQUFBO1FBQzlCLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNKLElBQUksQ0FBQyxLQUFLLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLFNBQVMsQ0FBQyxHQUFHLENBQUMsSUFBSSxFQUFFLEVBQUMsT0FBTyxDQUFDLENBQUE7UUFDeEUsQ0FBQztRQUFBLENBQUM7SUFDTixDQUFDO0lBQ0QsVUFBVSxDQUFDLFVBQW1CO1FBQzFCLElBQUksSUFBSSxHQUFHLElBQUksQ0FBQyxLQUFLLENBQUE7UUFDckIsRUFBRSxDQUFDLENBQUMsVUFBVSxDQUFDO1lBQUMsSUFBSSxHQUFHLFVBQVUsQ0FBQTtRQUNqQyxJQUFJLENBQUMsWUFBWSxDQUFDLE9BQU8sQ0FBQyxDQUFDLFNBQVM7WUFDaEMsU0FBUyxDQUFDLEtBQUssQ0FBQyxJQUFJLENBQUMsQ0FBQTtRQUN6QixDQUFDLENBQUMsQ0FBQTtRQUNGLElBQUksQ0FBQyxVQUFVLENBQUMsS0FBSyxDQUFDLElBQUksQ0FBQyxDQUFBO0lBQy9CLENBQUM7SUFBQSxDQUFDO0lBQ0YsV0FBVyxDQUFDLFVBQW1CO1FBQzNCLElBQUksSUFBSSxHQUFHLElBQUksQ0FBQyxLQUFLLENBQUE7UUFDckIsRUFBRSxDQUFDLENBQUMsVUFBVSxDQUFDO1lBQUMsSUFBSSxHQUFHLFVBQVUsQ0FBQTtJQUNyQyxDQUFDO0lBQ0QsYUFBYSxDQUFDLFVBQWtCO1FBQzVCLElBQUksQ0FBQyxLQUFLLEdBQUcsVUFBVSxDQUFBO0lBQzNCLENBQUM7SUFBQSxDQUFDO0lBQ0YsT0FBTztRQUNILE1BQU0sQ0FBQyxPQUFPLENBQUMsa0JBQWtCLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxDQUFBO0lBQ2pELENBQUM7Q0FDSjtBQS9CRCx3QkErQkMifQ==

34
dist/smartssh.classes.sshinstance.d.ts vendored Normal file
View File

@ -0,0 +1,34 @@
import 'typings-global';
import { SshKey } from './smartssh.classes.sshkey';
export declare class SshInstance {
private _sshKeyArray;
private _sshConfig;
private _sshDir;
private _sshSync;
constructor(optionsArg?: {
sshDirPath?: string;
sshSync?: boolean;
});
addKey(sshKeyArg: SshKey): void;
removeKey(sshKeyArg: SshKey): void;
replaceKey(sshKeyOldArg: SshKey, sshKeyNewArg: SshKey): void;
getKey(hostArg: string): SshKey;
readonly sshKeys: SshKey[];
/**
* write SshInstance to disk
*/
writeToDisk(dirPathArg?: string): void;
/**
* read ab SshInstance from disk
*/
readFromDisk(dirPathArg?: string): void;
private _makeConfig();
/**
* method to invoke SshInstance _sync automatically when sshSync is true
*/
private _syncAuto(directionArg);
/**
* private method to sync SshInstance
*/
private _sync(directionArg, dirPathArg?);
}

98
dist/smartssh.classes.sshinstance.js vendored Normal file
View File

@ -0,0 +1,98 @@
"use strict";
require("typings-global");
const smartssh_classes_sshdir_1 = require("./smartssh.classes.sshdir");
const smartssh_classes_sshconfig_1 = require("./smartssh.classes.sshconfig");
class SshInstance {
constructor(optionsArg = {}) {
optionsArg ? void (0) : optionsArg = {};
this._sshKeyArray = [];
this._sshConfig = new smartssh_classes_sshconfig_1.SshConfig(this._sshKeyArray);
this._sshDir = new smartssh_classes_sshdir_1.SshDir(this._sshKeyArray, this._sshConfig, optionsArg.sshDirPath);
this._sshSync = optionsArg.sshSync;
}
;
// altering methods
addKey(sshKeyArg) {
this._syncAuto('from');
this._sshKeyArray.push(sshKeyArg);
this._syncAuto('to');
}
;
removeKey(sshKeyArg) {
this._syncAuto('from');
let filteredArray = this._sshKeyArray.filter((sshKeyArg2) => {
return (sshKeyArg != sshKeyArg2);
});
this._sshKeyArray = filteredArray;
this._syncAuto('to');
}
;
replaceKey(sshKeyOldArg, sshKeyNewArg) {
this._syncAuto('from');
this.removeKey(sshKeyOldArg);
this.addKey(sshKeyNewArg);
this._syncAuto('to');
}
;
//
getKey(hostArg) {
this._syncAuto('from');
let filteredArray = this._sshKeyArray.filter(function (keyArg) {
return (keyArg.host === hostArg);
});
if (filteredArray.length > 0) {
return filteredArray[0];
}
else {
return undefined;
}
}
;
get sshKeys() {
this._syncAuto('from');
return this._sshKeyArray;
}
;
// FS methods
/**
* write SshInstance to disk
*/
writeToDisk(dirPathArg) {
this._sync('to', dirPathArg);
}
/**
* read ab SshInstance from disk
*/
readFromDisk(dirPathArg) {
this._sync('from', dirPathArg);
}
/* ===============================================================
========================= Private Methods ========================
================================================================*/
_makeConfig() {
}
/**
* method to invoke SshInstance _sync automatically when sshSync is true
*/
_syncAuto(directionArg) {
if (this._sshSync)
this._sync(directionArg);
}
/**
* private method to sync SshInstance
*/
_sync(directionArg, dirPathArg) {
if (directionArg === 'from') {
this._sshDir.readFromDir(dirPathArg); // call sync method of sshDir class;
}
else if (directionArg === 'to') {
this._sshDir.writeToDir(dirPathArg);
}
else {
throw new Error("directionArg not recognised. Must be 'to' or 'from'");
}
}
;
}
exports.SshInstance = SshInstance;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzc2guY2xhc3Nlcy5zc2hpbnN0YW5jZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c3NoLmNsYXNzZXMuc3NoaW5zdGFuY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUl2Qix1RUFBZ0Q7QUFDaEQsNkVBQXNEO0FBR3REO0lBS0ksWUFBWSxhQUFxRCxFQUFFO1FBQy9ELFVBQVUsR0FBRyxLQUFJLENBQUMsQ0FBQyxDQUFDLEdBQUcsVUFBVSxHQUFHLEVBQUUsQ0FBQTtRQUN0QyxJQUFJLENBQUMsWUFBWSxHQUFHLEVBQUUsQ0FBQTtRQUN0QixJQUFJLENBQUMsVUFBVSxHQUFHLElBQUksc0NBQVMsQ0FBQyxJQUFJLENBQUMsWUFBWSxDQUFDLENBQUE7UUFDbEQsSUFBSSxDQUFDLE9BQU8sR0FBRyxJQUFJLGdDQUFNLENBQUMsSUFBSSxDQUFDLFlBQVksRUFBQyxJQUFJLENBQUMsVUFBVSxFQUFDLFVBQVUsQ0FBQyxVQUFVLENBQUMsQ0FBQTtRQUNsRixJQUFJLENBQUMsUUFBUSxHQUFHLFVBQVUsQ0FBQyxPQUFPLENBQUE7SUFDdEMsQ0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QUFDO0lBRUQ7O09BRUc7SUFDSyxLQUFLLENBQUMsWUFBb0IsRUFBQyxVQUFtQjtRQUNsRCxFQUFFLENBQUMsQ0FBQyxZQUFZLEtBQUssTUFBTSxDQUFDLENBQUMsQ0FBQztZQUMxQixJQUFJLENBQUMsT0FBTyxDQUFDLFdBQVcsQ0FBQyxVQUFVLENBQUMsQ0FBQSxDQUFDLG9DQUFvQztRQUM3RSxDQUFDO1FBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQyxDQUFDLFlBQVksS0FBSyxJQUFJLENBQUMsQ0FBQyxDQUFDO1lBQy9CLElBQUksQ0FBQyxPQUFPLENBQUMsVUFBVSxDQUFDLFVBQVUsQ0FBQyxDQUFBO1FBQ3ZDLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNKLE1BQU0sSUFBSSxLQUFLLENBQUMscURBQXFELENBQUMsQ0FBQTtRQUMxRSxDQUFDO0lBQ0wsQ0FBQztJQUFBLENBQUM7Q0FDTDtBQTlGRCxrQ0E4RkMifQ==

25
dist/smartssh.classes.sshkey.d.ts vendored Normal file
View File

@ -0,0 +1,25 @@
import 'typings-global';
export declare class SshKey {
private _privKey;
private _pubKey;
private _hostVar;
private _authorized;
/**
* the constructor for class SshKey
*/
constructor(optionsArg?: {
private?: string;
public?: string;
host?: string;
authorized?: boolean;
});
host: string;
privKey: string;
privKeyBase64: string;
pubKey: string;
pubKeyBase64: string;
authorized: boolean;
type: any;
read(filePathArg: any): void;
store(dirPathArg: string): void;
}

96
dist/smartssh.classes.sshkey.js vendored Normal file
View File

@ -0,0 +1,96 @@
"use strict";
require("typings-global");
const plugins = require("./smartssh.plugins");
class SshKey {
/**
* the constructor for class SshKey
*/
constructor(optionsArg = {}) {
this._privKey = optionsArg.private;
this._pubKey = optionsArg.public;
this._hostVar = optionsArg.host;
this._authorized = optionsArg.authorized;
}
;
// this.host
get host() {
return this._hostVar;
}
;
set host(hostArg) {
this._hostVar = hostArg;
}
;
// this.privKey
get privKey() {
return this._privKey;
}
;
set privKey(privateKeyArg) {
this._privKey = privateKeyArg;
}
;
// this.privKeyBase64
get privKeyBase64() {
return plugins.smartstring.base64.encode(this._privKey);
}
set privKeyBase64(privateKeyArg) {
this._privKey = plugins.smartstring.base64.decode(privateKeyArg);
}
// this.pubKey
get pubKey() {
return this._pubKey;
}
set pubKey(publicKeyArg) {
this._pubKey = publicKeyArg;
}
;
// this.pubKeyBase64
get pubKeyBase64() {
return plugins.smartstring.base64.encode(this._pubKey);
}
set pubKeyBase64(publicKeyArg) {
this._pubKey = plugins.smartstring.base64.decode(publicKeyArg);
}
get authorized() {
return this._authorized;
}
set authorized(authorizedArg) {
this._authorized = authorizedArg;
}
get type() {
if (this._privKey && this._pubKey) {
return 'duplex';
}
else if (this._privKey) {
return 'private';
}
else if (this._pubKey) {
return 'public';
}
}
;
set type(someVlueArg) {
console.log('the type of an SshKey connot be set. This value is autpcomputed.');
}
// methods
read(filePathArg) {
}
store(dirPathArg) {
plugins.fs.ensureDirSync(dirPathArg);
let fileNameBase = this.host;
if (this._privKey) {
let filePath = plugins.path.join(dirPathArg, fileNameBase);
plugins.smartfile.memory.toFsSync(this._privKey, filePath);
plugins.shelljs.chmod(600, filePath);
}
;
if (this._pubKey) {
let filePath = plugins.path.join(dirPathArg, fileNameBase + '.pub');
plugins.smartfile.memory.toFsSync(this._pubKey, filePath);
plugins.shelljs.chmod(600, filePath);
}
}
}
exports.SshKey = SshKey;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzc2guY2xhc3Nlcy5zc2hrZXkuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNzaC5jbGFzc2VzLnNzaGtleS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLDhDQUE2QztBQUc3QztJQU1JOztPQUVHO0lBQ0gsWUFBWSxhQUFtRixFQUFFO1FBQ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FDLFFBQVEsQ0FBQyxDQUFBO1lBQ3hELE9BQU8sQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLEdBQUcsRUFBQyxRQUFRLENBQUMsQ0FBQTtRQUN2QyxDQUFDO0lBQ0wsQ0FBQztDQUNKO0FBOUZELHdCQThGQyJ9

11
dist/smartssh.plugins.d.ts vendored Normal file
View File

@ -0,0 +1,11 @@
import 'typings-global';
import * as beautylog from 'beautylog';
import * as fs from 'fs-extra';
import * as minimatch from 'minimatch';
import * as path from 'path';
import * as q from 'q';
import * as shelljs from 'shelljs';
import * as smartfile from 'smartfile';
import * as smartpath from 'smartpath';
import * as smartstring from 'smartstring';
export { beautylog, fs, minimatch, path, q, shelljs, smartfile, smartpath, smartstring };

View File

@ -1,9 +1,21 @@
"use strict";
/// <reference path="./typings/main.d.ts" />
exports.beautylog = require("beautylog");
exports.base64 = require("js-base64").Base64;
exports.fs = require("fs-extra");
exports.path = require("path");
exports.smartfile = require("smartfile");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDRDQUE0QztBQUNqQyxpQkFBUyxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQztBQUNqQyxjQUFNLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDLE1BQU0sQ0FBQztBQUNyQyxVQUFFLEdBQUcsT0FBTyxDQUFDLFVBQVUsQ0FBQyxDQUFDO0FBQ3pCLFlBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUM7QUFDdkIsaUJBQVMsR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUMiLCJmaWxlIjoic21hcnRzc2gucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCIuL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz5cbmV4cG9ydCBsZXQgYmVhdXR5bG9nID0gcmVxdWlyZShcImJlYXV0eWxvZ1wiKTtcbmV4cG9ydCBsZXQgYmFzZTY0ID0gcmVxdWlyZShcImpzLWJhc2U2NFwiKS5CYXNlNjQ7XG5leHBvcnQgbGV0IGZzID0gcmVxdWlyZShcImZzLWV4dHJhXCIpO1xuZXhwb3J0IGxldCBwYXRoID0gcmVxdWlyZShcInBhdGhcIik7XG5leHBvcnQgbGV0IHNtYXJ0ZmlsZSA9IHJlcXVpcmUoXCJzbWFydGZpbGVcIik7Il0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9
require("typings-global");
const beautylog = require("beautylog");
exports.beautylog = beautylog;
const fs = require("fs-extra");
exports.fs = fs;
const minimatch = require("minimatch");
exports.minimatch = minimatch;
const path = require("path");
exports.path = path;
const q = require("q");
exports.q = q;
const shelljs = require("shelljs");
exports.shelljs = shelljs;
const smartfile = require("smartfile");
exports.smartfile = smartfile;
const smartpath = require("smartpath");
exports.smartpath = smartpath;
const smartstring = require("smartstring");
exports.smartstring = smartstring;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzc2gucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c3NoLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2Qix1Q0FBc0M7QUFXbEMsOEJBQVM7QUFWYiwrQkFBOEI7QUFXMUIsZ0JBQUU7QUFWTix1Q0FBc0M7QUFXbEMsOEJBQVM7QUFWYiw2QkFBNEI7QUFXeEIsb0JBQUk7QUFWUix1QkFBc0I7QUFXbEIsY0FBQztBQVZMLG1DQUFrQztBQVc5QiwwQkFBTztBQVZYLHVDQUFzQztBQVdsQyw4QkFBUztBQVZiLHVDQUFzQztBQVdsQyw4QkFBUztBQVZiLDJDQUEwQztBQVd0QyxrQ0FBVyJ9

4
npmts.json Normal file
View File

@ -0,0 +1,4 @@
{
"mode":"default",
"coverageTreshold":50
}

View File

@ -1,14 +1,15 @@
{
"name": "smartssh",
"version": "1.0.1",
"version": "1.2.0",
"description": "setups SSH quickly and in a painless manner",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"test": "(npmts)"
},
"repository": {
"type": "git",
"url": "git+https://github.com/pushrocks/smartssh.git"
"url": "git+https://gitlab.com/pushrocks/smartssh.git"
},
"keywords": [
"SSH",
@ -18,17 +19,29 @@
"author": "Lossless GmbH",
"license": "MIT",
"bugs": {
"url": "https://github.com/pushrocks/smartssh/issues"
"url": "https://gitlab.com/pushrocks/smartssh/issues"
},
"homepage": "https://github.com/pushrocks/smartssh#readme",
"homepage": "https://gitlab.com/pushrocks/smartssh#readme",
"dependencies": {
"beautylog": "^4.1.2",
"fs-extra": "^0.28.0",
"js-base64": "^2.1.9",
"smartfile": "^3.0.5"
"@types/fs-extra": "0.0.35",
"@types/js-base64": "^2.1.5",
"@types/minimatch": "^2.0.29",
"@types/q": "0.0.32",
"@types/shelljs": "^0.3.33",
"beautylog": "^6.0.0",
"fs-extra": "^1.0.0",
"minimatch": "^3.0.3",
"q": "^1.4.1",
"shelljs": "^0.7.5",
"smartfile": "^4.1.0",
"smartpath": "^3.2.5",
"smartstring": "^2.0.22",
"typings-global": "^1.0.14"
},
"devDependencies": {
"npmts": "^5.0.4",
"should": "^8.3.1"
"@types/should": "^8.1.30",
"npmts-g": "^5.2.8",
"should": "^11.1.1",
"typings-test": "^1.0.3"
}
}

1
test/test.d.ts vendored Normal file
View File

@ -0,0 +1 @@
import 'typings-test';

View File

@ -1,5 +1,77 @@
/// <reference path="../ts/typings/main.d.ts" />
var should = require("should");
var smartssh = require("../dist/index.js");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsZ0RBQWdEO0FBQ2hELElBQUksTUFBTSxHQUFHLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0FBQztBQUMvQixJQUFJLFFBQVEsR0FBRyxPQUFPLENBQUMsa0JBQWtCLENBQUMsQ0FBQyIsImZpbGUiOiJ0ZXN0LmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4uL3RzL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz5cbmxldCBzaG91bGQgPSByZXF1aXJlKFwic2hvdWxkXCIpO1xubGV0IHNtYXJ0c3NoID0gcmVxdWlyZShcIi4uL2Rpc3QvaW5kZXguanNcIik7XG4iXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
"use strict";
require("typings-test");
const should = require("should");
const smartssh = require("../dist/index");
const path = require("path");
describe('smartssh', function () {
let testSshInstance;
let testSshKey;
describe('.SshKey', function () {
it("'new' keyword should create a valid SshKey object", function () {
testSshKey = new smartssh.SshKey({
host: 'example.com',
private: 'someExamplePrivateKey',
public: 'someExamplePublicKey'
});
should(testSshKey).be.instanceof(smartssh.SshKey);
});
it('.type should be a valid type', function () {
should(testSshKey.type).equal('duplex');
});
it('.publicKey should be public key', function () {
should(testSshKey.pubKey).equal('someExamplePublicKey');
});
it('.privateKey should be private key', function () {
should(testSshKey.privKey).equal('someExamplePrivateKey');
});
it('.publicKeyBase64 should be public key base 64 encoded', function () {
testSshKey.pubKeyBase64;
});
it('.store() should store the file to disk', function () {
testSshKey.store(path.join(process.cwd(), 'test/temp'));
});
});
describe('.SshInstance', function () {
it("'new' keyword should create a new SshInstance object from class", function () {
testSshInstance = new smartssh.SshInstance({
sshDirPath: path.join(process.cwd(), 'test/temp/')
});
should(testSshInstance).be.instanceof(smartssh.SshInstance);
});
it('.addKey() should accept a new SshKey object', function () {
testSshInstance.addKey(new smartssh.SshKey({
public: 'somePublicKey',
private: 'somePrivateKey',
host: 'gitlab.com'
}));
testSshInstance.addKey(new smartssh.SshKey({
public: 'somePublicKey',
private: 'somePrivateKey',
host: 'bitbucket.org'
}));
testSshInstance.addKey(new smartssh.SshKey({
public: 'someGitHubPublicKey',
private: 'someGitHubPrivateKey',
host: 'github.com'
}));
});
it('.sshKeys should point to an array of sshKeys', function () {
let sshKeyArray = testSshInstance.sshKeys;
should(sshKeyArray).be.Array();
should(sshKeyArray[0].host).equal('gitlab.com');
should(sshKeyArray[1].host).equal('bitbucket.org');
should(sshKeyArray[2].host).equal('github.com');
});
it('.getKey() should get a specific key selected by host', function () {
should(testSshInstance.getKey('github.com').pubKey).equal('someGitHubPublicKey');
});
it('.removeKey() should remove a key', function () {
testSshInstance.removeKey(testSshInstance.getKey('bitbucket.org'));
should(testSshInstance.sshKeys[1].host).equal('github.com');
});
it('it should store to disk', function () {
testSshInstance.writeToDisk();
});
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFDaEMsMENBQTBDO0FBQzFDLDZCQUE2QjtBQUM3QixRQUFRLENBQUMsVUFBVSxFQUFDO0lBQ2hCLElBQUksZUFBcUMsQ0FBQTtJQUN6QyxJQUFJLFVBQTJCLENBQUE7SUFDL0IsUUFBUSxDQUFDLFNBQVMsRUFBQztRQUNmLEVBQUUsQ0FBQyxtREFBbUQsRUFBQztZQUNuRCxVQUFVLEdBQUcsSUFBSSxRQUFRLENBQUMsTUFBTSxDQUFDO2dCQUM3QixJQUFJLEVBQUUsYUFBYTtnQkFDbkIsT0FBTyxFQUFFLHVCQUF1QjtnQkFDaEMsTUFBTSxFQUFFLHNCQUFzQjthQUNqQyxDQUFDLENBQUE7WUFDRixNQUFNLENBQUMsVUFBVSxDQUFDLENBQUMsRUFBRSxDQUFDLFV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Q0FBQyxDQUFDLEtBQUssQ0FBQyxZQUFZLENBQUMsQ0FBQTtZQUMvQyxNQUFNLENBQUMsV0FBVyxDQUFDLENBQUMsQ0FBQyxDQUFDLElBQUksQ0FBQyxDQUFDLEtBQUssQ0FBQyxlQUFlLENBQUMsQ0FBQTtZQUNsRCxNQUFNLENBQUMsV0FBVyxDQUFDLENBQUMsQ0FBQyxDQUFDLElBQUksQ0FBQyxDQUFDLEtBQUssQ0FBQyxZQUFZLENBQUMsQ0FBQTtRQUNuRCxDQUFDLENBQUMsQ0FBQTtRQUNGLEVBQUUsQ0FBQyxzREFBc0QsRUFBQztZQUN0RCxNQUFNLENBQUMsZUFBZSxDQUFDLE1BQU0sQ0FBQyxZQUFZLENBQUMsQ0FBQyxNQUFNLENBQUMsQ0FBQyxLQUFLLENBQUMscUJBQXFCLENBQUMsQ0FBQTtRQUNwRixDQUFDLENBQUMsQ0FBQTtRQUNGLEVBQUUsQ0FBQyxrQ0FBa0MsRUFBQztZQUNsQyxlQUFlLENBQUMsU0FBUyxDQUFDLGVBQWUsQ0FBQyxNQUFNLENBQUMsZUFBZSxDQUFDLENBQUMsQ0FBQTtZQUNsRSxNQUFNLENBQUMsZUFBZSxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUMsQ0FBQyxLQUFLLENBQUMsWUFBWSxDQUFDLENBQUE7UUFDL0QsQ0FBQyxDQUFDLENBQUE7UUFDRixFQUFFLENBQUMseUJBQXlCLEVBQUM7WUFDekIsZUFBZSxDQUFDLFdBQVcsRUFBRSxDQUFBO1FBQ2pDLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9

View File

@ -1,3 +1,75 @@
/// <reference path="../ts/typings/main.d.ts" />
let should = require("should");
let smartssh = require("../dist/index.js");
import 'typings-test'
import * as should from 'should'
import smartssh = require('../dist/index')
import path = require('path')
describe('smartssh',function(){
let testSshInstance: smartssh.SshInstance
let testSshKey: smartssh.SshKey
describe('.SshKey',function(){
it("'new' keyword should create a valid SshKey object",function(){
testSshKey = new smartssh.SshKey({
host: 'example.com',
private: 'someExamplePrivateKey',
public: 'someExamplePublicKey'
})
should(testSshKey).be.instanceof(smartssh.SshKey)
})
it('.type should be a valid type',function(){
should(testSshKey.type).equal('duplex')
})
it('.publicKey should be public key',function(){
should(testSshKey.pubKey).equal('someExamplePublicKey')
})
it('.privateKey should be private key',function(){
should(testSshKey.privKey).equal('someExamplePrivateKey')
})
it('.publicKeyBase64 should be public key base 64 encoded',function(){
testSshKey.pubKeyBase64
})
it('.store() should store the file to disk',function(){
testSshKey.store(path.join(process.cwd(),'test/temp'))
})
})
describe('.SshInstance',function(){
it("'new' keyword should create a new SshInstance object from class",function(){
testSshInstance = new smartssh.SshInstance({
sshDirPath: path.join(process.cwd(),'test/temp/')
})
should(testSshInstance).be.instanceof(smartssh.SshInstance)
})
it('.addKey() should accept a new SshKey object',function(){
testSshInstance.addKey(new smartssh.SshKey({
public: 'somePublicKey',
private: 'somePrivateKey',
host: 'gitlab.com'
}))
testSshInstance.addKey(new smartssh.SshKey({
public: 'somePublicKey',
private: 'somePrivateKey',
host: 'bitbucket.org'
}))
testSshInstance.addKey(new smartssh.SshKey({
public: 'someGitHubPublicKey',
private: 'someGitHubPrivateKey',
host: 'github.com'
}))
})
it('.sshKeys should point to an array of sshKeys',function(){
let sshKeyArray = testSshInstance.sshKeys
should(sshKeyArray).be.Array()
should(sshKeyArray[0].host).equal('gitlab.com')
should(sshKeyArray[1].host).equal('bitbucket.org')
should(sshKeyArray[2].host).equal('github.com')
})
it('.getKey() should get a specific key selected by host',function(){
should(testSshInstance.getKey('github.com').pubKey).equal('someGitHubPublicKey')
})
it('.removeKey() should remove a key',function(){
testSshInstance.removeKey(testSshInstance.getKey('bitbucket.org'))
should(testSshInstance.sshKeys[1].host).equal('github.com')
})
it('it should store to disk',function(){
testSshInstance.writeToDisk()
})
})
})

View File

@ -1,3 +1,7 @@
/// <reference path="./typings/main.d.ts" />
import plugins = require("./smartssh.plugins");
import classes = require("./smartssh.classes");
import 'typings-global'
import * as plugins from './smartssh.plugins'
export {SshInstance} from './smartssh.classes.sshinstance'
export {SshKey} from './smartssh.classes.sshkey'
export {SshDir} from './smartssh.classes.sshdir'
export {SshConfig} from './smartssh.classes.sshconfig'

View File

@ -1,8 +1,8 @@
/// <reference path="./typings/main.d.ts" />
import plugins = require("./smartssh.plugins");
import classes = require("./smartssh.classes");
import 'typings-global'
import * as plugins from './smartssh.plugins'
import {SshKey} from './smartssh.classes.sshkey'
export let sshKeyArrayFromDir = function(dirArg:string):classes.sshKey[]{
let sshKeyArray = [];
return sshKeyArray;
}
export let sshKeyArrayFromDir = function(dirArg: string): SshKey[]{
let sshKeyArray = [] // TODO
return sshKeyArray
}

View File

@ -0,0 +1,54 @@
import 'typings-global'
import * as plugins from './smartssh.plugins'
import * as helpers from './smartssh.classes.helpers'
import {SshKey} from './smartssh.classes.sshkey'
export class SshConfig {
private _sshKeyArray: SshKey[]
constructor(sshKeyArrayArg: SshKey[]) {
this._sshKeyArray = sshKeyArrayArg
}
/**
* stores a config file
*/
store(dirPathArg: string) {
let done = plugins.q.defer()
let configArray: configObject[] = []
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' +
' IdentityFile ~/.ssh/' + sshKey.host + '\n' +
' StrictHostKeyChecking no' + '\n'
}
configArray.push({
configString: configString,
authorized: sshKey.authorized,
sshKey: sshKey
})
}
let configFile: string = ''
for (let key in configArray) {
configFile = configFile + configArray[key].configString + '\n'
};
plugins.smartfile.memory.toFsSync(configFile,plugins.path.join(dirPathArg,'config'))
return done.promise
}
read(dirPathArg) {
let done = plugins.q.defer()
let configArray: configObject[]
plugins.smartfile.fs.toStringSync(plugins.path.join(dirPathArg,'config'))
return done.promise
}
};
export interface configObject {
configString: string
authorized: boolean
sshKey: SshKey
};

View File

@ -0,0 +1,38 @@
import 'typings-global'
import * as plugins from './smartssh.plugins'
import * as helpers from './smartssh.classes.helpers'
import {SshInstance} from './smartssh.classes.sshinstance'
import {SshKey} from './smartssh.classes.sshkey'
import {SshConfig} from './smartssh.classes.sshconfig'
export class SshDir { // sshDir class -> NOT EXPORTED, ONLY FOR INTERNAL USE
private _path: string // the path of the ssh directory
private _sshKeyArray: SshKey[]
private _sshConfig: SshConfig
constructor(sshKeyArray: SshKey[],sshConfig: SshConfig,sshDirPathArg?: string) {
this._sshKeyArray = sshKeyArray
this._sshConfig = sshConfig
if (sshDirPathArg) {
this._path = sshDirPathArg
} else {
this._path = plugins.path.join(plugins.smartpath.get.home(),'.ssh/')
};
}
writeToDir(dirPathArg?: string) { // syncs sshInstance to directory
let path = this._path
if (dirPathArg) path = dirPathArg
this._sshKeyArray.forEach((sshKeyArg) => {
sshKeyArg.store(path)
})
this._sshConfig.store(path)
};
readFromDir(dirPathArg?: string) { // syncs sshInstance from directory
let path = this._path
if (dirPathArg) path = dirPathArg
}
updateDirPath(dirPathArg: string) {
this._path = dirPathArg
};
getKeys() {
return helpers.sshKeyArrayFromDir(this._path)
}
}

View File

@ -0,0 +1,103 @@
import 'typings-global'
import * as plugins from './smartssh.plugins'
import * as helpers from './smartssh.classes.helpers'
import {SshDir} from './smartssh.classes.sshdir'
import {SshConfig} from './smartssh.classes.sshconfig'
import {SshKey} from './smartssh.classes.sshkey'
export class SshInstance {
private _sshKeyArray: SshKey[] // holds all ssh keys
private _sshConfig: SshConfig // sshConfig (e.g. represents ~/.ssh/config)
private _sshDir: SshDir // points to sshDir class instance.
private _sshSync: boolean // if set to true, the ssh dir will be kept in sync automatically
constructor(optionsArg: {sshDirPath?: string,sshSync?: boolean}= {}) {
optionsArg ? void(0) : optionsArg = {}
this._sshKeyArray = []
this._sshConfig = new SshConfig(this._sshKeyArray)
this._sshDir = new SshDir(this._sshKeyArray,this._sshConfig,optionsArg.sshDirPath)
this._sshSync = optionsArg.sshSync
};
// altering methods
addKey(sshKeyArg: SshKey) {
this._syncAuto('from')
this._sshKeyArray.push(sshKeyArg)
this._syncAuto('to')
};
removeKey(sshKeyArg: SshKey) {
this._syncAuto('from')
let filteredArray = this._sshKeyArray.filter((sshKeyArg2: SshKey) => {
return (sshKeyArg != sshKeyArg2)
})
this._sshKeyArray = filteredArray
this._syncAuto('to')
};
replaceKey(sshKeyOldArg: SshKey,sshKeyNewArg: SshKey) {
this._syncAuto('from')
this.removeKey(sshKeyOldArg)
this.addKey(sshKeyNewArg)
this._syncAuto('to')
};
//
getKey(hostArg: string): SshKey {
this._syncAuto('from')
let filteredArray = this._sshKeyArray.filter(function(keyArg){
return (keyArg.host === hostArg)
})
if (filteredArray.length > 0) {
return filteredArray[0]
} else {
return undefined
}
};
get sshKeys(): SshKey[] {
this._syncAuto('from')
return this._sshKeyArray
};
// FS methods
/**
* write SshInstance to disk
*/
writeToDisk(dirPathArg?: string) {
this._sync('to',dirPathArg)
}
/**
* read ab SshInstance from disk
*/
readFromDisk(dirPathArg?: string) {
this._sync('from',dirPathArg)
}
/* ===============================================================
========================= Private Methods ========================
================================================================*/
private _makeConfig () {
}
/**
* method to invoke SshInstance _sync automatically when sshSync is true
*/
private _syncAuto(directionArg) {
if (this._sshSync) this._sync(directionArg)
}
/**
* private method to sync SshInstance
*/
private _sync(directionArg: string,dirPathArg?: string) {
if (directionArg === 'from') {
this._sshDir.readFromDir(dirPathArg) // call sync method of sshDir class;
} else if (directionArg === 'to') {
this._sshDir.writeToDir(dirPathArg)
} else {
throw new Error("directionArg not recognised. Must be 'to' or 'from'")
}
};
}

View File

@ -0,0 +1,99 @@
import 'typings-global'
import * as plugins from './smartssh.plugins'
import * as helpers from './smartssh.classes.helpers'
export class SshKey {
private _privKey: string
private _pubKey: string
private _hostVar: string
private _authorized: boolean
/**
* the constructor for class SshKey
*/
constructor(optionsArg: {private?: string,public?: string,host?: string,authorized?: boolean}= {}) {
this._privKey = optionsArg.private
this._pubKey = optionsArg.public
this._hostVar = optionsArg.host
this._authorized = optionsArg.authorized
};
// this.host
get host(){
return this._hostVar
};
set host(hostArg: string){
this._hostVar = hostArg
};
// this.privKey
get privKey(){
return this._privKey
};
set privKey(privateKeyArg: string){
this._privKey = privateKeyArg
};
// this.privKeyBase64
get privKeyBase64(){
return plugins.smartstring.base64.encode(this._privKey)
}
set privKeyBase64(privateKeyArg: string) {
this._privKey = plugins.smartstring.base64.decode(privateKeyArg)
}
// this.pubKey
get pubKey(){
return this._pubKey
}
set pubKey(publicKeyArg: string){
this._pubKey = publicKeyArg
};
// this.pubKeyBase64
get pubKeyBase64(){
return plugins.smartstring.base64.encode(this._pubKey)
}
set pubKeyBase64(publicKeyArg: string) {
this._pubKey = plugins.smartstring.base64.decode(publicKeyArg)
}
get authorized(){
return this._authorized
}
set authorized(authorizedArg: boolean){
this._authorized = authorizedArg
}
get type(){
if (this._privKey && this._pubKey) {
return 'duplex'
} else if (this._privKey) {
return 'private'
} else if (this._pubKey) {
return 'public'
}
};
set type(someVlueArg: any){
console.log('the type of an SshKey connot be set. This value is autpcomputed.')
}
// methods
read(filePathArg) {
}
store(dirPathArg: string) {
plugins.fs.ensureDirSync(dirPathArg)
let fileNameBase = this.host
if (this._privKey) {
let filePath = plugins.path.join(dirPathArg,fileNameBase)
plugins.smartfile.memory.toFsSync(this._privKey,filePath)
plugins.shelljs.chmod(600,filePath)
};
if (this._pubKey) {
let filePath = plugins.path.join(dirPathArg,fileNameBase + '.pub')
plugins.smartfile.memory.toFsSync(this._pubKey,filePath)
plugins.shelljs.chmod(600,filePath)
}
}
}

View File

@ -1,78 +0,0 @@
/// <reference path="./typings/main.d.ts" />
import plugins = require("./smartssh.plugins");
import helpers = require("./smartssh.classes.helpers");
export class ssh {
private sshDir:string;
private sshKeys:sshKey[];
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.sshSync = optionsArg.sshSync;
};
}
export class sshConfig {
constructor(){
}
}
export class sshKey {
private privKey:string;
private pubKey:string;
constructor(optionsArg:{private:string,public:string}){
if(!optionsArg) optionsArg = {private:undefined,public:undefined};
this.privKey = optionsArg.private;
this.pubKey = optionsArg.public;
};
// getters
get privateKey(){
return this.privKey;
};
get privateKeyBase64(){
return plugins.base64.encode(this.privKey);
}
get publicKey(){
return this.publicKey;
}
get publicKeyBase64(){
return plugins.base64.encode(this.pubKey);
}
get type(){
if(this.privKey && this.pubKey){
return "duplex";
} else if(this.privKey){
return "private";
} else if(this.pubKey){
return "public";
}
};
// setters
set privateKey(privateKeyArg:string){
this.privKey = privateKeyArg;
};
// setters
set publicKey(publicKeyArg:string){
this.pubKey = publicKeyArg;
};
store(filePathArg?:string){
let filePathObj = plugins.path.parse(filePathArg);
if(filePathObj.ext = ".priv"){
plugins.smartfile.memory.toFsSync(this.privKey,{fileName:filePathObj.name + filePathObj.ext,filePath:filePathObj.dir});
} else if (filePathObj.ext = ".pub"){
plugins.smartfile.memory.toFsSync(this.pubKey,{fileName:filePathObj.name + filePathObj.ext,filePath:filePathObj.dir});
} else { //we assume we are given a directory as filePathArg, so we store the whole key
plugins.fs.ensureDirSync(filePathObj.dir);
this.store(plugins.path.join(filePathObj.dir,"key.priv")); // call this function recursivly
this.store(plugins.path.join(filePathObj.dir,"key.priv")); // call this function recursivly
}
}
}

View File

@ -1,6 +1,22 @@
/// <reference path="./typings/main.d.ts" />
export let beautylog = require("beautylog");
export let base64 = require("js-base64").Base64;
export let fs = require("fs-extra");
export let path = require("path");
export let smartfile = require("smartfile");
import 'typings-global'
import * as beautylog from 'beautylog'
import * as fs from 'fs-extra'
import * as minimatch from 'minimatch'
import * as path from 'path'
import * as q from 'q'
import * as shelljs from 'shelljs'
import * as smartfile from 'smartfile'
import * as smartpath from 'smartpath'
import * as smartstring from 'smartstring'
export {
beautylog,
fs,
minimatch,
path,
q,
shelljs,
smartfile,
smartpath,
smartstring
}

View File

@ -1,8 +0,0 @@
{
"version": false,
"dependencies": {},
"ambientDependencies": {
"colors": "registry:dt/colors#0.6.0-1+20160317120654",
"node": "registry:dt/node#4.0.0+20160423143914"
}
}

3
tslint.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "tslint-config-standard"
}