29 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
32 changed files with 814 additions and 514 deletions

8
.gitignore vendored
View File

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

View File

@ -1,9 +1,18 @@
image: hosttoday/ht-docker-node:latest image: hosttoday/ht-docker-node:npmts
stages: stages:
- test - test
- release - release
- page - trigger
- pages
testLEGACY:
stage: test
script:
- npmci test legacy
tags:
- docker
allow_failure: true
testLTS: testLTS:
stage: test stage: test
@ -19,12 +28,6 @@ testSTABLE:
tags: tags:
- docker - docker
testLEGACY:
stage: test
script:
- npmci test 0
allow_failure: true
release: release:
stage: release stage: release
script: script:
@ -34,13 +37,23 @@ release:
tags: tags:
- docker - docker
pages: trigger:
stage: page stage: trigger
script: script:
- mkdir public - npmci trigger
- npmci npmpage
artifacts:
paths:
- public
only: only:
- tags - 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

@ -3,6 +3,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. > Attention: This is still alpha, so some things won't work, not all things are inplemented.
## Usage ## Usage
```javascript ```javascript

10
dist/index.d.ts vendored
View File

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

3
dist/index.js vendored
View File

@ -8,5 +8,4 @@ var smartssh_classes_sshdir_1 = require("./smartssh.classes.sshdir");
exports.SshDir = smartssh_classes_sshdir_1.SshDir; exports.SshDir = smartssh_classes_sshdir_1.SshDir;
var smartssh_classes_sshconfig_1 = require("./smartssh.classes.sshconfig"); var smartssh_classes_sshconfig_1 = require("./smartssh.classes.sshconfig");
exports.SshConfig = smartssh_classes_sshconfig_1.SshConfig; exports.SshConfig = smartssh_classes_sshconfig_1.SshConfig;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBR3ZCLCtFQUEwRDtBQUFsRCxxREFBQSxXQUFXLENBQUE7QUFDbkIscUVBQWdEO0FBQXhDLDJDQUFBLE1BQU0sQ0FBQTtBQUNkLHFFQUFnRDtBQUF4QywyQ0FBQSxNQUFNLENBQUE7QUFDZCwyRUFBc0Q7QUFBOUMsaURBQUEsU0FBUyxDQUFBIn0=
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUNQLENBQUMsQ0FEc0I7QUFHdkIsNkNBQTBCLGdDQUFnQyxDQUFDO0FBQW5ELGlFQUFtRDtBQUMzRCx3Q0FBcUIsMkJBQTJCLENBQUM7QUFBekMsa0RBQXlDO0FBQ2pELHdDQUFxQiwyQkFBMkIsQ0FBQztBQUF6QyxrREFBeUM7QUFDakQsMkNBQXdCLDhCQUE4QixDQUFDO0FBQS9DLDJEQUErQyIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCJcclxuaW1wb3J0ICogYXMgcGx1Z2lucyBmcm9tIFwiLi9zbWFydHNzaC5wbHVnaW5zXCI7XHJcblxyXG5leHBvcnQge1NzaEluc3RhbmNlfSBmcm9tIFwiLi9zbWFydHNzaC5jbGFzc2VzLnNzaGluc3RhbmNlXCI7XHJcbmV4cG9ydCB7U3NoS2V5fSBmcm9tIFwiLi9zbWFydHNzaC5jbGFzc2VzLnNzaGtleVwiO1xyXG5leHBvcnQge1NzaERpcn0gZnJvbSBcIi4vc21hcnRzc2guY2xhc3Nlcy5zc2hkaXJcIjtcclxuZXhwb3J0IHtTc2hDb25maWd9IGZyb20gXCIuL3NtYXJ0c3NoLmNsYXNzZXMuc3NoY29uZmlnXCI7Il19

View File

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

View File

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

View File

@ -1,4 +1,17 @@
import "typings-global"; /// <reference types="q" />
import 'typings-global';
import { SshKey } from './smartssh.classes.sshkey';
export declare class SshConfig { export declare class SshConfig {
constructor(); 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;
} }

View File

@ -1,10 +1,47 @@
"use strict"; "use strict";
require("typings-global"); require("typings-global");
var SshConfig = (function () { const plugins = require("./smartssh.plugins");
function SshConfig() { 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;
}
} }
return SshConfig;
}());
exports.SshConfig = SshConfig; exports.SshConfig = SshConfig;
;
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuc3NoY29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFHeEI7SUFDSTtJQUVBLENBQUM7SUFDTCxnQkFBQztBQUFELENBSkEsQUFJQyxJQUFBO0FBSlksaUJBQVMsWUFJckIsQ0FBQSIsImZpbGUiOiJzbWFydHNzaC5jbGFzc2VzLnNzaGNvbmZpZy5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XHJcbmltcG9ydCAqIGFzIHBsdWdpbnMgZnJvbSBcIi4vc21hcnRzc2gucGx1Z2luc1wiO1xyXG5pbXBvcnQgKiBhcyBoZWxwZXJzIGZyb20gXCIuL3NtYXJ0c3NoLmNsYXNzZXMuaGVscGVyc1wiO1xyXG5leHBvcnQgY2xhc3MgU3NoQ29uZmlnIHtcclxuICAgIGNvbnN0cnVjdG9yKCl7XHJcb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shinstance"; import { SshKey } from './smartssh.classes.sshkey';
import { SshKey } from "./smartssh.classes.sshkey"; import { SshConfig } from './smartssh.classes.sshconfig';
export declare class SshDir { export declare class SshDir {
path: string; private _path;
sshInstance: SshInstance; private _sshKeyArray;
constructor(sshInstanceArg: SshInstance, sshDirPathArg?: string); private _sshConfig;
syncToDir(): void; constructor(sshKeyArray: SshKey[], sshConfig: SshConfig, sshDirPathArg?: string);
syncFromDir(): void; writeToDir(dirPathArg?: string): void;
readFromDir(dirPathArg?: string): void;
updateDirPath(dirPathArg: string): void;
getKeys(): SshKey[]; getKeys(): SshKey[];
} }

View File

@ -1,28 +1,41 @@
"use strict"; "use strict";
require("typings-global"); require("typings-global");
var plugins = require("./smartssh.plugins"); const plugins = require("./smartssh.plugins");
var helpers = require("./smartssh.classes.helpers"); const helpers = require("./smartssh.classes.helpers");
var SshDir = (function () { class SshDir {
function SshDir(sshInstanceArg, sshDirPathArg) { constructor(sshKeyArray, sshConfig, sshDirPathArg) {
var sshDirPath; this._sshKeyArray = sshKeyArray;
this._sshConfig = sshConfig;
if (sshDirPathArg) { if (sshDirPathArg) {
sshDirPath = sshDirPathArg; this._path = sshDirPathArg;
} }
else { else {
sshDirPath = plugins.smartpath.get.home(); this._path = plugins.path.join(plugins.smartpath.get.home(), '.ssh/');
} }
this.path = sshDirPath;
}
SshDir.prototype.syncToDir = function () {
};
; ;
SshDir.prototype.syncFromDir = function () { }
}; writeToDir(dirPathArg) {
SshDir.prototype.getKeys = function () { let path = this._path;
return helpers.sshKeyArrayFromDir(this.path); if (dirPathArg)
}; path = dirPathArg;
return SshDir; 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; exports.SshDir = SshDir;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FuY2U6U3NoSW5zdGFuY2U7XHJcbiAgICBjb25zdHJ1Y3Rvcihzc2hJbnN0YW5jZUFyZzpTc2hJbnN0YW5jZSxzc2hEaXJQYXRoQXJnPzpzdHJpbmcpe1xyXG4gICAgICAgIGxldCBzc2hEaXJQYXRoOnN0cmluZztcclxuICAgICAgICBpZihzc2hEaXJQYXRoQXJnKXtcclxuICAgICAgICAgICAgc3NoRGlyUGF0aCA9IHNzaERpclBhdGhBcmc7XHJcbiAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgc3NoRGlyUGF0aCA9IHBsdWdpbnMuc21hcnRwYXRoLmdldC5ob21lKCk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHRoaXMucGF0aCA9IHNzaERpclBhdGg7XHJcbiAgICB9XHJcbiAgICBzeW5jVG9EaXIoKXsgLy9zeW5jcyBcclxuICAgICAgICBcclxuICAgIH07XHJcbiAgICBzeW5jRnJvbURpcigpe1xyXG4gICAgICAgIFxyXG4gICAgfVxyXG4gICAgZ2V0S2V5cygpe1xyXG4gICAgICAgIHJldHVybiBoZWxwZXJzLnNzaEtleUFycmF5RnJvbURpcih0aGlzLnBhdGgpO1xyXG4gICAgfVxyXG59Il19

View File

@ -1,10 +1,10 @@
import "typings-global"; import 'typings-global';
import { SshKey } from "./smartssh.classes.sshkey"; import { SshKey } from './smartssh.classes.sshkey';
export declare class SshInstance { export declare class SshInstance {
private sshConfig; private _sshKeyArray;
private sshDir; private _sshConfig;
private sshKeyArray; private _sshDir;
private sshSync; private _sshSync;
constructor(optionsArg?: { constructor(optionsArg?: {
sshDirPath?: string; sshDirPath?: string;
sshSync?: boolean; sshSync?: boolean;
@ -13,6 +13,22 @@ export declare class SshInstance {
removeKey(sshKeyArg: SshKey): void; removeKey(sshKeyArg: SshKey): void;
replaceKey(sshKeyOldArg: SshKey, sshKeyNewArg: SshKey): void; replaceKey(sshKeyOldArg: SshKey, sshKeyNewArg: SshKey): void;
getKey(hostArg: string): SshKey; getKey(hostArg: string): SshKey;
sshKeys: SshKey[]; readonly sshKeys: SshKey[];
sync(directionArg: string): void; /**
* 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?);
} }

File diff suppressed because one or more lines are too long

View File

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

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,11 @@
import "typings-global"; import 'typings-global';
export declare let beautylog: any; import * as beautylog from 'beautylog';
export declare let base64: any; import * as fs from 'fs-extra';
export declare let fs: any; import * as minimatch from 'minimatch';
export declare let path: any; import * as path from 'path';
export declare let smartfile: any; import * as q from 'q';
export import smartpath = require("smartpath"); 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,10 +1,21 @@
"use strict"; "use strict";
require("typings-global"); require("typings-global");
exports.beautylog = require("beautylog"); const beautylog = require("beautylog");
exports.base64 = require("js-base64").Base64; exports.beautylog = beautylog;
exports.fs = require("fs-extra"); const fs = require("fs-extra");
exports.path = require("path"); exports.fs = fs;
exports.smartfile = require("smartfile"); const minimatch = require("minimatch");
exports.smartpath = require("smartpath"); exports.minimatch = minimatch;
const path = require("path");
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQ1AsQ0FBQyxDQURzQjtBQUNaLGlCQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLGNBQU0sR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUMsTUFBTSxDQUFDO0FBQ3JDLFVBQUUsR0FBRyxPQUFPLENBQUMsVUFBVSxDQUFDLENBQUM7QUFDekIsWUFBSSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FBQztBQUN2QixpQkFBUyxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQztBQUM5QixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDIiwiZmlsZSI6InNtYXJ0c3NoLnBsdWdpbnMuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgXCJ0eXBpbmdzLWdsb2JhbFwiXHJcbmV4cG9ydCBsZXQgYmVhdXR5bG9nID0gcmVxdWlyZShcImJlYXV0eWxvZ1wiKTtcclxuZXhwb3J0IGxldCBiYXNlNjQgPSByZXF1aXJlKFwianMtYmFzZTY0XCIpLkJhc2U2NDtcclxuZXhwb3J0IGxldCBmcyA9IHJlcXVpcmUoXCJmcy1leHRyYVwiKTtcclxuZXhwb3J0IGxldCBwYXRoID0gcmVxdWlyZShcInBhdGhcIik7XHJcbmV4cG9ydCBsZXQgc21hcnRmaWxlID0gcmVxdWlyZShcInNtYXJ0ZmlsZVwiKTtcclxuZXhwb3J0IGltcG9ydCBzbWFydHBhdGggPSByZXF1aXJlKFwic21hcnRwYXRoXCIpOyJdfQ== 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

View File

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

View File

@ -1,6 +1,6 @@
{ {
"name": "smartssh", "name": "smartssh",
"version": "1.0.5", "version": "1.2.0",
"description": "setups SSH quickly and in a painless manner", "description": "setups SSH quickly and in a painless manner",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
@ -9,7 +9,7 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/pushrocks/smartssh.git" "url": "git+https://gitlab.com/pushrocks/smartssh.git"
}, },
"keywords": [ "keywords": [
"SSH", "SSH",
@ -19,20 +19,29 @@
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"bugs": { "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": { "dependencies": {
"beautylog": "^5.0.8", "@types/fs-extra": "0.0.35",
"fs-extra": "^0.30.0", "@types/js-base64": "^2.1.5",
"js-base64": "^2.1.9", "@types/minimatch": "^2.0.29",
"smartfile": "^3.0.10", "@types/q": "0.0.32",
"smartpath": "^3.2.2", "@types/shelljs": "^0.3.33",
"typings-global": "^1.0.3", "beautylog": "^6.0.0",
"typings-test": "^1.0.1" "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": { "devDependencies": {
"npmts": "^5.1.19", "@types/should": "^8.1.30",
"should": "^9.0.0" "npmts-g": "^5.2.8",
"should": "^11.1.1",
"typings-test": "^1.0.3"
} }
} }

3
test/test.d.ts vendored
View File

@ -1,2 +1 @@
import "typings-test"; import 'typings-test';
import "should";

File diff suppressed because one or more lines are too long

View File

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

View File

@ -1,7 +1,7 @@
import "typings-global" import 'typings-global'
import * as plugins from "./smartssh.plugins"; import * as plugins from './smartssh.plugins'
export {SshInstance} from "./smartssh.classes.sshinstance"; export {SshInstance} from './smartssh.classes.sshinstance'
export {SshKey} from "./smartssh.classes.sshkey"; export {SshKey} from './smartssh.classes.sshkey'
export {SshDir} from "./smartssh.classes.sshdir"; export {SshDir} from './smartssh.classes.sshdir'
export {SshConfig} from "./smartssh.classes.sshconfig"; export {SshConfig} from './smartssh.classes.sshconfig'

View File

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

View File

@ -1,8 +1,54 @@
import "typings-global"; import 'typings-global'
import * as plugins from "./smartssh.plugins"; import * as plugins from './smartssh.plugins'
import * as helpers from "./smartssh.classes.helpers"; import * as helpers from './smartssh.classes.helpers'
export class SshConfig { import {SshKey} from './smartssh.classes.sshkey'
constructor(){
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

@ -1,28 +1,38 @@
import "typings-global"; import 'typings-global'
import * as plugins from "./smartssh.plugins"; import * as plugins from './smartssh.plugins'
import * as helpers from "./smartssh.classes.helpers"; import * as helpers from './smartssh.classes.helpers'
import {SshInstance} from "./smartssh.classes.sshinstance"; import {SshInstance} from './smartssh.classes.sshinstance'
import {SshKey} from "./smartssh.classes.sshkey"; import {SshKey} from './smartssh.classes.sshkey'
import {SshConfig} from "./smartssh.classes.sshconfig"; import {SshConfig} from './smartssh.classes.sshconfig'
export class SshDir { // sshDir class -> NOT EXPORTED, ONLY FOR INTERNAL USE export class SshDir { // sshDir class -> NOT EXPORTED, ONLY FOR INTERNAL USE
path:string; // the path of the ssh directory private _path: string // the path of the ssh directory
sshInstance:SshInstance; private _sshKeyArray: SshKey[]
constructor(sshInstanceArg:SshInstance,sshDirPathArg?:string){ private _sshConfig: SshConfig
let sshDirPath:string; constructor(sshKeyArray: SshKey[],sshConfig: SshConfig,sshDirPathArg?: string) {
this._sshKeyArray = sshKeyArray
this._sshConfig = sshConfig
if (sshDirPathArg) { if (sshDirPathArg) {
sshDirPath = sshDirPathArg; this._path = sshDirPathArg
} else { } else {
sshDirPath = plugins.smartpath.get.home(); this._path = plugins.path.join(plugins.smartpath.get.home(),'.ssh/')
}
this.path = sshDirPath;
}
syncToDir(){ //syncs
}; };
syncFromDir(){
} }
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() { getKeys() {
return helpers.sshKeyArrayFromDir(this.path); return helpers.sshKeyArrayFromDir(this._path)
} }
} }

View File

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

@ -1,65 +1,99 @@
import "typings-global"; import 'typings-global'
import * as plugins from "./smartssh.plugins"; import * as plugins from './smartssh.plugins'
import * as helpers from "./smartssh.classes.helpers"; import * as helpers from './smartssh.classes.helpers'
export class SshKey { export class SshKey {
private privKey:string; private _privKey: string
private pubKey:string; private _pubKey: string
private hostVar:string; private _hostVar: string
constructor(optionsArg:{private?:string,public?:string,host?:string}={}){ private _authorized: boolean
this.privKey = optionsArg.private;
this.pubKey = optionsArg.public; /**
this.hostVar = optionsArg.host; * 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
}; };
// getters // this.host
get host(){ get host(){
return this.hostVar; return this._hostVar
}; };
get privateKey(){ set host(hostArg: string){
return this.privKey; this._hostVar = hostArg
}; };
get privateKeyBase64(){
return plugins.base64.encode(this.privKey); // 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)
} }
get publicKey(){ set privKeyBase64(privateKeyArg: string) {
return this.pubKey; this._privKey = plugins.smartstring.base64.decode(privateKeyArg)
} }
get publicKeyBase64(){
return plugins.base64.encode(this.pubKey); // 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(){ get type(){
if(this.privKey && this.pubKey){ if (this._privKey && this._pubKey) {
return "duplex"; return 'duplex'
} else if(this.privKey){ } else if (this._privKey) {
return "private"; return 'private'
} else if(this.pubKey){ } else if (this._pubKey) {
return "public"; return 'public'
} }
}; };
set type(someVlueArg: any){
console.log('the type of an SshKey connot be set. This value is autpcomputed.')
}
// setters // methods
set host(hostArg:string){ read(filePathArg) {
this.hostVar = hostArg;
};
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"){ store(dirPathArg: string) {
plugins.smartfile.memory.toFsSync(this.privKey,{fileName:filePathObj.name + filePathObj.ext,filePath:filePathObj.dir}); plugins.fs.ensureDirSync(dirPathArg)
} else if (filePathObj.ext = ".pub"){ let fileNameBase = this.host
plugins.smartfile.memory.toFsSync(this.pubKey,{fileName:filePathObj.name + filePathObj.ext,filePath:filePathObj.dir}); if (this._privKey) {
} else { //we assume we are given a directory as filePathArg, so we store the whole key let filePath = plugins.path.join(dirPathArg,fileNameBase)
plugins.fs.ensureDirSync(filePathObj.dir); plugins.smartfile.memory.toFsSync(this._privKey,filePath)
this.store(plugins.path.join(filePathObj.dir,"key.priv")); // call this function recursivly plugins.shelljs.chmod(600,filePath)
this.store(plugins.path.join(filePathObj.dir,"key.priv")); // call this function recursivly };
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,7 +1,22 @@
import "typings-global" import 'typings-global'
export let beautylog = require("beautylog"); import * as beautylog from 'beautylog'
export let base64 = require("js-base64").Base64; import * as fs from 'fs-extra'
export let fs = require("fs-extra"); import * as minimatch from 'minimatch'
export let path = require("path"); import * as path from 'path'
export let smartfile = require("smartfile"); import * as q from 'q'
export import smartpath = require("smartpath"); 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"
}