38 Commits

Author SHA1 Message Date
f0b52c8da7 1.2.4 2019-07-17 11:48:31 +02:00
4cb6aa03e6 fix(core): update 2019-07-17 11:48:31 +02:00
8b85b6c8bc 1.2.3 2018-09-17 22:32:31 +02:00
c032ff69d0 fix(core): update 2018-09-17 22:32:31 +02:00
0454eef45f update structure 2017-06-15 19:25:12 +02:00
def368f8ab 1.2.2 2017-06-15 17:53:24 +02:00
6853fa28b6 update to latest standards 2017-06-15 17:52:22 +02:00
56318f28cf 1.2.1 2016-11-23 12:44:37 +01:00
32b26f21cd improve README 2016-11-23 12:44:31 +01:00
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
44 changed files with 2859 additions and 709 deletions

27
.gitignore vendored
View File

@ -1,7 +1,22 @@
.idea/
node_modules/
.nogit/
# artifacts
coverage/
docs/
ts/typings/
ts/*.js
ts/*.js.map
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
# custom

View File

@ -1,46 +1,117 @@
image: hosttoday/ht-docker-node:latest
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
stages:
- security
- test
- release
- page
- metadata
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
tags:
- docker
- notpriv
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
tags:
- docker
- notpriv
# ====================
# test stage
# ====================
testLTS:
stage: test
script:
- npmci test lts
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
testSTABLE:
stage: test
script:
- npmci test stable
tags:
- docker
- docker
- notpriv
testLEGACY:
testBuild:
stage: test
script:
- npmci test 0
allow_failure: true
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
release:
stage: release
script:
- npmci publish
- npmci node install lts
- npmci npm publish
only:
- tags
- tags
tags:
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
script:
- npmci command npm install -g tslint typescript
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- docker
pages:
stage: page
script:
- mkdir public
- npmci npmpage
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
only:
- tags
allow_failure: true

View File

@ -1,12 +0,0 @@
language: node_js
node_js:
- '4'
- stable
deploy:
provider: npm
email: npm@lossless.digital
api_key:
secure: xApCMlDyZcTOgq+iomxR2A/2aMBhhPpgEBxdFYqXDNC/AGkr+NQJhGt67W4840FMrSUFEDZNQhOS+t6gYMqxUHv+vJFc0cHskFSuLDnAH2MS45TqtFYNcP+GARs1suuM9Il5hXNEvjVJ6XF0lYlNlK8mJstKQscdEKWyBHj42oSsgWRcuzBgqps8Vnbp+Ey2Bpfaw1yV+P1fyv8dNnkwG5dSt3EIxAcbGiMOhCz0u6oMroKfAYfNTxMJjja2uJJOqoTTShzeMyIYx+YwxorcZGfchI+TOPHHeVc+fByCHfzTZJYCy9qTSSTvWcKD/H7q3RGciEXHzhwMj0d8dlY3WPHC6BBliD6bLwVgDmToD3cdHm8OLsxW7hjFLO51vOIbhJZrWBVztlusuLwuyVAlIgeAsV8Yb5FxetxZmBU42qr5itykPl45rNd7talI0ZcoFPRTAWxxmCD8hp0d3ZLdjcEdbCzc5GYmEFN0NwKLTZF3Q1G4UbsHMgN8Pe4ohjdaYYhJ7RKgbmLR0J4NBrWIAUOhDaUTkZhgsHFyEmtbKI6JkxQtwCEBBBursemZWFQSIdtj2+O/RBaBCgoUNIpxUDBFq+D3Pir7BZP7DK2m3Otl0F9aCdqJmhCc7rOn3MueLpmndjtO1RFteXAdAkDxKp2RehIB6yohxbRmQ1O9PsA=
on:
tags: true
repo: pushrocks/smartssh

View File

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2016 Push.Rocks
Copyright (c) 2016 Lossless GmbH
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,34 +1,56 @@
# smartssh
# @pushrocks/smartssh
setups SSH quickly and in a painless manner
> Attention: This is still alpha, so some things won't work, not all things are inplemented.
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartssh)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartssh)
* [github.com (source mirror)](https://github.com/pushrocks/smartssh)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartssh/)
## Status for master
[![build status](https://gitlab.com/pushrocks/smartssh/badges/master/build.svg)](https://gitlab.com/pushrocks/smartssh/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartssh/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartssh/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartssh.svg)](https://www.npmjs.com/package/@pushrocks/smartssh)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartssh/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartssh)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
## Usage
```javascript
var smartssh = require("smartssh");
var smartssh = require('smartssh');
var sshInstance = new smartssh.sshInstance({
sshDir: "/some/path/.ssh", // the standard ssh directory, optional, defaults to "~./.ssh"
sshSync: true // sync ssh this instance will represent the status of an ssh dir if set to true;
sshDir: '/some/path/.ssh', // the standard ssh directory, optional, defaults to "~./.ssh"
sshSync: true // sync ssh this instance will represent the status of an ssh dir if set to true;
});
sshInstance.addKey(new smartssh.sshKey({
private: "somestring",
public: "somestring", // optional
host:"github.com",
encoding: "base64" // optional, defaults to "utf8", can be "utf8" or "base64", useful for reading ssh keys from environment variables
}));
sshInstance.addKey(
new smartssh.sshKey({
private: 'somestring',
public: 'somestring', // optional
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.removeKey(sshInstance.getKey('github.com')); // removes key for host "github.com" is present
sshInstance.createKey({
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
host:"github.com"
host: 'gitlab.com' // returns new key in the form sshKey, read more about the sshKey class below
});
sshInstance.getKeys() // returns array of all available getKeys. Each key is in form of class sshKey
sshInstance.getKey({
// returns ssh key in the form sshKey, read more about the sshKey class below
host: 'github.com'
});
sshInstance.getKeys(); // returns array of all available getKeys. Each key is in form of class sshKey
```
For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com)

5
dist/index.d.ts vendored
View File

@ -1,5 +0,0 @@
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,12 +0,0 @@
"use strict";
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;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUNQLENBQUMsQ0FEc0I7QUFHdkIsNkNBQTBCLGdDQUFnQyxDQUFDO0FBQW5ELGlFQUFtRDtBQUMzRCx3Q0FBcUIsMkJBQTJCLENBQUM7QUFBekMsa0RBQXlDO0FBQ2pELHdDQUFxQiwyQkFBMkIsQ0FBQztBQUF6QyxrREFBeUM7QUFDakQsMkNBQXdCLDhCQUE4QixDQUFDO0FBQS9DLDJEQUErQyIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCJcclxuaW1wb3J0ICogYXMgcGx1Z2lucyBmcm9tIFwiLi9zbWFydHNzaC5wbHVnaW5zXCI7XHJcblxyXG5leHBvcnQge1NzaEluc3RhbmNlfSBmcm9tIFwiLi9zbWFydHNzaC5jbGFzc2VzLnNzaGluc3RhbmNlXCI7XHJcbmV4cG9ydCB7U3NoS2V5fSBmcm9tIFwiLi9zbWFydHNzaC5jbGFzc2VzLnNzaGtleVwiO1xyXG5leHBvcnQge1NzaERpcn0gZnJvbSBcIi4vc21hcnRzc2guY2xhc3Nlcy5zc2hkaXJcIjtcclxuZXhwb3J0IHtTc2hDb25maWd9IGZyb20gXCIuL3NtYXJ0c3NoLmNsYXNzZXMuc3NoY29uZmlnXCI7Il19

View File

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

View File

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

View File

@ -1,4 +0,0 @@
import "typings-global";
export declare class SshConfig {
constructor();
}

View File

@ -1,10 +0,0 @@
"use strict";
require("typings-global");
var SshConfig = (function () {
function SshConfig() {
}
return SshConfig;
}());
exports.SshConfig = SshConfig;
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuc3NoY29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFHeEI7SUFDSTtJQUVBLENBQUM7SUFDTCxnQkFBQztBQUFELENBSkEsQUFJQyxJQUFBO0FBSlksaUJBQVMsWUFJckIsQ0FBQSIsImZpbGUiOiJzbWFydHNzaC5jbGFzc2VzLnNzaGNvbmZpZy5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XHJcbmltcG9ydCAqIGFzIHBsdWdpbnMgZnJvbSBcIi4vc21hcnRzc2gucGx1Z2luc1wiO1xyXG5pbXBvcnQgKiBhcyBoZWxwZXJzIGZyb20gXCIuL3NtYXJ0c3NoLmNsYXNzZXMuaGVscGVyc1wiO1xyXG5leHBvcnQgY2xhc3MgU3NoQ29uZmlnIHtcclxuICAgIGNvbnN0cnVjdG9yKCl7XHJcbiAgICAgICAgXHJcbiAgICB9XHJcbn0iXX0=

View File

@ -1,11 +0,0 @@
import "typings-global";
import { SshInstance } from "./smartssh.classes.sshinstance";
import { SshKey } from "./smartssh.classes.sshkey";
export declare class SshDir {
path: string;
sshInstance: SshInstance;
constructor(sshInstanceArg: SshInstance, sshDirPathArg?: string);
syncToDir(): void;
syncFromDir(): void;
getKeys(): SshKey[];
}

View File

@ -1,28 +0,0 @@
"use strict";
require("typings-global");
var plugins = require("./smartssh.plugins");
var helpers = require("./smartssh.classes.helpers");
var SshDir = (function () {
function SshDir(sshInstanceArg, sshDirPathArg) {
var sshDirPath;
if (sshDirPathArg) {
sshDirPath = sshDirPathArg;
}
else {
sshDirPath = plugins.smartpath.get.home();
}
this.path = sshDirPath;
}
SshDir.prototype.syncToDir = function () {
};
;
SshDir.prototype.syncFromDir = function () {
};
SshDir.prototype.getKeys = function () {
return helpers.sshKeyArrayFromDir(this.path);
};
return SshDir;
}());
exports.SshDir = SshDir;
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuc3NoZGlyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDeEIsSUFBWSxPQUFPLFdBQU0sb0JBQW9CLENBQUMsQ0FBQTtBQUM5QyxJQUFZLE9BQU8sV0FBTSw0QkFBNEIsQ0FBQyxDQUFBO0FBSXREO0lBR0ksZ0JBQVksY0FBMEIsRUFBQyxhQUFxQjtRQUN4RCxJQUFJLFVBQWlCLENBQUM7UUFDdEIsRUFBRSxDQUFBLENBQUMsYUFBYSxDQUFDLENBQUEsQ0FBQztZQUNkLFVBQVUsR0FBRyxhQUFhLENBQUM7UUFDL0IsQ0FBQztRQUFDLElBQUksQ0FBQyxDQUFDO1lBQ0osVUFBVSxHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUMsR0FBRyxDQUFDLElBQUksRUFBRSxDQUFDO1FBQzlDLENBQUM7UUFDRCxJQUFJLENBQUMsSUFBSSxHQUFHLFVBQVUsQ0FBQztJQUMzQixDQUFDO0lBQ0QsMEJBQVMsR0FBVDtJQUVBLENBQUM7O0lBQ0QsNEJBQVcsR0FBWDtJQUVBLENBQUM7SUFDRCx3QkFBTyxHQUFQO1FBQ0ksTUFBTSxDQUFDLE9BQU8sQ0FBQyxrQkFBa0IsQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUM7SUFDakQsQ0FBQztJQUNMLGFBQUM7QUFBRCxDQXJCQSxBQXFCQyxJQUFBO0FBckJZLGNBQU0sU0FxQmxCLENBQUEiLCJmaWxlIjoic21hcnRzc2guY2xhc3Nlcy5zc2hkaXIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgXCJ0eXBpbmdzLWdsb2JhbFwiO1xyXG5pbXBvcnQgKiBhcyBwbHVnaW5zIGZyb20gXCIuL3NtYXJ0c3NoLnBsdWdpbnNcIjtcclxuaW1wb3J0ICogYXMgaGVscGVycyBmcm9tIFwiLi9zbWFydHNzaC5jbGFzc2VzLmhlbHBlcnNcIjtcclxuaW1wb3J0IHtTc2hJbnN0YW5jZX0gZnJvbSBcIi4vc21hcnRzc2guY2xhc3Nlcy5zc2hpbnN0YW5jZVwiO1xyXG5pbXBvcnQge1NzaEtleX0gZnJvbSBcIi4vc21hcnRzc2guY2xhc3Nlcy5zc2hrZXlcIjtcclxuaW1wb3J0IHtTc2hDb25maWd9IGZyb20gXCIuL3NtYXJ0c3NoLmNsYXNzZXMuc3NoY29uZmlnXCI7XHJcbmV4cG9ydCBjbGFzcyBTc2hEaXIgeyAvLyBzc2hEaXIgY2xhc3MgLT4gTk9UIEVYUE9SVEVELCBPTkxZIEZPUiBJTlRFUk5BTCBVU0VcclxuICAgIHBhdGg6c3RyaW5nOyAvLyB0aGUgcGF0aCBvZiB0aGUgc3NoIGRpcmVjdG9yeVxyXG4gICAgc3NoSW5zdGFuY2U6U3NoSW5zdGFuY2U7XHJcbiAgICBjb25zdHJ1Y3Rvcihzc2hJbnN0YW5jZUFyZzpTc2hJbnN0YW5jZSxzc2hEaXJQYXRoQXJnPzpzdHJpbmcpe1xyXG4gICAgICAgIGxldCBzc2hEaXJQYXRoOnN0cmluZztcclxuICAgICAgICBpZihzc2hEaXJQYXRoQXJnKXtcclxuICAgICAgICAgICAgc3NoRGlyUGF0aCA9IHNzaERpclBhdGhBcmc7XHJcbiAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgc3NoRGlyUGF0aCA9IHBsdWdpbnMuc21hcnRwYXRoLmdldC5ob21lKCk7XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHRoaXMucGF0aCA9IHNzaERpclBhdGg7XHJcbiAgICB9XHJcbiAgICBzeW5jVG9EaXIoKXsgLy9zeW5jcyBcclxuICAgICAgICBcclxuICAgIH07XHJcbiAgICBzeW5jRnJvbURpcigpe1xyXG4gICAgICAgIFxyXG4gICAgfVxyXG4gICAgZ2V0S2V5cygpe1xyXG4gICAgICAgIHJldHVybiBoZWxwZXJzLnNzaEtleUFycmF5RnJvbURpcih0aGlzLnBhdGgpO1xyXG4gICAgfVxyXG59Il19

View File

@ -1,18 +0,0 @@
import "typings-global";
import { SshKey } from "./smartssh.classes.sshkey";
export declare class SshInstance {
private sshConfig;
private sshDir;
private sshKeyArray;
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;
sshKeys: SshKey[];
sync(directionArg: string): void;
}

File diff suppressed because one or more lines are too long

View File

@ -1,18 +0,0 @@
import "typings-global";
export declare class SshKey {
private privKey;
private pubKey;
private hostVar;
constructor(optionsArg?: {
private?: string;
public?: string;
host?: string;
});
host: string;
privateKey: string;
privateKeyBase64: any;
publicKey: string;
publicKeyBase64: any;
type: string;
store(filePathArg?: string): void;
}

File diff suppressed because one or more lines are too long

View File

@ -1,7 +0,0 @@
import "typings-global";
export declare let beautylog: any;
export declare let base64: any;
export declare let fs: any;
export declare let path: any;
export declare let smartfile: any;
export import smartpath = require("smartpath");

View File

@ -1,10 +0,0 @@
"use strict";
require("typings-global");
exports.beautylog = require("beautylog");
exports.base64 = require("js-base64").Base64;
exports.fs = require("fs-extra");
exports.path = require("path");
exports.smartfile = require("smartfile");
exports.smartpath = require("smartpath");
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQ1AsQ0FBQyxDQURzQjtBQUNaLGlCQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLGNBQU0sR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUMsTUFBTSxDQUFDO0FBQ3JDLFVBQUUsR0FBRyxPQUFPLENBQUMsVUFBVSxDQUFDLENBQUM7QUFDekIsWUFBSSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FBQztBQUN2QixpQkFBUyxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQztBQUM5QixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDIiwiZmlsZSI6InNtYXJ0c3NoLnBsdWdpbnMuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgXCJ0eXBpbmdzLWdsb2JhbFwiXHJcbmV4cG9ydCBsZXQgYmVhdXR5bG9nID0gcmVxdWlyZShcImJlYXV0eWxvZ1wiKTtcclxuZXhwb3J0IGxldCBiYXNlNjQgPSByZXF1aXJlKFwianMtYmFzZTY0XCIpLkJhc2U2NDtcclxuZXhwb3J0IGxldCBmcyA9IHJlcXVpcmUoXCJmcy1leHRyYVwiKTtcclxuZXhwb3J0IGxldCBwYXRoID0gcmVxdWlyZShcInBhdGhcIik7XHJcbmV4cG9ydCBsZXQgc21hcnRmaWxlID0gcmVxdWlyZShcInNtYXJ0ZmlsZVwiKTtcclxuZXhwb3J0IGltcG9ydCBzbWFydHBhdGggPSByZXF1aXJlKFwic21hcnRwYXRoXCIpOyJdfQ==

16
npmextra.json Normal file
View File

@ -0,0 +1,16 @@
{
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"gitzone": {
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartssh",
"shortDescription": "setups SSH quickly and in a painless manner",
"npmPackagename": "@pushrocks/smartssh",
"license": "MIT"
}
}
}

View File

@ -1,3 +0,0 @@
{
"mode":"default"
}

2204
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +1,18 @@
{
"name": "smartssh",
"version": "1.0.5",
"name": "@pushrocks/smartssh",
"version": "1.2.4",
"private": false,
"description": "setups SSH quickly and in a painless manner",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"test": "(npmts)"
"test": "(tstest test/)",
"testDocker": "tsdocker",
"build": "(tsbuild)"
},
"repository": {
"type": "git",
"url": "git+https://github.com/pushrocks/smartssh.git"
"url": "git+https://gitlab.com/pushrocks/smartssh.git"
},
"keywords": [
"SSH",
@ -19,20 +22,36 @@
"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": "^5.0.8",
"fs-extra": "^0.30.0",
"js-base64": "^2.1.9",
"smartfile": "^3.0.10",
"smartpath": "^3.2.2",
"typings-global": "^1.0.3",
"typings-test": "^1.0.1"
"@pushrocks/smartfile": "^7.0.4",
"@pushrocks/smartpath": "^4.0.1",
"@pushrocks/smartpromise": "^3.0.2",
"@pushrocks/smartshell": "^2.0.23",
"@pushrocks/smartstring": "^3.0.10",
"@types/fs-extra": "^8.0.0",
"@types/minimatch": "^3.0.3",
"fs-extra": "^8.1.0",
"minimatch": "^3.0.4"
},
"devDependencies": {
"npmts": "^5.1.19",
"should": "^9.0.0"
}
"@gitzone/tsbuild": "^2.1.11",
"@gitzone/tsdocker": "^1.2.39",
"@gitzone/tsrun": "^1.2.6",
"@gitzone/tstest": "^1.0.24",
"@pushrocks/tapbundle": "^3.0.11",
"@types/node": "^12.6.6"
},
"files": [
"ts/*",
"ts_web/*",
"dist/*",
"dist_web/*",
"assets/*",
"cli.js",
"npmextra.json",
"readme.md"
]
}

1
test/temp/bitbucket.org Normal file
View File

@ -0,0 +1 @@
somePrivateKey

View File

@ -0,0 +1 @@
somePublicKey

15
test/temp/config Normal file
View File

@ -0,0 +1,15 @@
Host gitlab.com
HostName gitlab.com
IdentityFile ~/.ssh/gitlab.com
StrictHostKeyChecking no
Host bitbucket.org
HostName bitbucket.org
IdentityFile ~/.ssh/bitbucket.org
StrictHostKeyChecking no
Host github.com
HostName github.com
IdentityFile ~/.ssh/github.com
StrictHostKeyChecking no

1
test/temp/example.com Normal file
View File

@ -0,0 +1 @@
someExamplePrivateKey

View File

@ -0,0 +1 @@
someExamplePublicKey

1
test/temp/github.com Normal file
View File

@ -0,0 +1 @@
someGitHubPrivateKey

1
test/temp/github.com.pub Normal file
View File

@ -0,0 +1 @@
someGitHubPublicKey

1
test/temp/gitlab.com Normal file
View File

@ -0,0 +1 @@
somePrivateKey

1
test/temp/gitlab.com.pub Normal file
View File

@ -0,0 +1 @@
somePublicKey

2
test/test.d.ts vendored
View File

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

File diff suppressed because one or more lines are too long

View File

@ -1,66 +1,84 @@
import "typings-test"
import "should";
import smartssh = require("../dist/index");
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"
});
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;
})
});
describe(".SshInstance",function(){
it("'new' keyword should create a new SshInstance object from class",function(){
testSshInstance = new smartssh.SshInstance();
testSshInstance.should.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;
sshKeyArray.should.be.Array();
sshKeyArray[0].host.should.equal("gitlab.com");
sshKeyArray[1].host.should.equal("bitbucket.org");
sshKeyArray[2].host.should.equal("github.com");
});
it(".getKey() should get a specific key selected by host",function(){
testSshInstance.getKey("github.com").publicKey.should.equal("someGitHubPublicKey");
})
it(".removeKey() should remove a key",function(){
testSshInstance.removeKey(testSshInstance.getKey("bitbucket.org"));
testSshInstance.sshKeys[1].host.should.equal("github.com");
})
});
})
import { expect, tap } from '@pushrocks/tapbundle';
import smartssh = require('../ts/index');
import path = require('path');
let testSshInstance: smartssh.SshInstance;
let testSshKey: smartssh.SshKey;
tap.test('should create a valid SshKey object', async () => {
testSshKey = new smartssh.SshKey({
host: 'example.com',
private: 'someExamplePrivateKey',
public: 'someExamplePublicKey'
});
expect(testSshKey).to.be.instanceof(smartssh.SshKey);
});
tap.test('.type should be a valid type', async () => {
expect(testSshKey.type).equal('duplex');
});
tap.test('.publicKey should be public key', async () => {
expect(testSshKey.pubKey).equal('someExamplePublicKey');
});
tap.test('.privateKey should be private key', async () => {
expect(testSshKey.privKey).equal('someExamplePrivateKey');
});
tap.test('.publicKeyBase64 should be public key base 64 encoded', async () => {
// tslint:disable-next-line:no-unused-expression
testSshKey.pubKeyBase64;
});
tap.test('.store() should store the file to disk', async () => {
testSshKey.store(path.join(process.cwd(), 'test/temp'));
});
// SSH INstance
tap.test("'new' keyword should create a new SshInstance object from class", async () => {
testSshInstance = new smartssh.SshInstance({
sshDirPath: path.join(process.cwd(), 'test/temp/')
});
expect(testSshInstance).be.instanceof(smartssh.SshInstance);
});
tap.test('.addKey() should accept a new SshKey object', async () => {
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'
})
);
});
tap.test('.sshKeys should point to an array of sshKeys', async () => {
let sshKeyArray = testSshInstance.sshKeys;
expect(sshKeyArray).be.instanceOf(Array);
expect(sshKeyArray[0].host).equal('gitlab.com');
expect(sshKeyArray[1].host).equal('bitbucket.org');
expect(sshKeyArray[2].host).equal('github.com');
});
tap.test('.getKey() should get a specific key selected by host', async () => {
expect(testSshInstance.getKey('github.com').pubKey).equal('someGitHubPublicKey');
});
tap.test('.removeKey() should remove a key', async () => {
testSshInstance.removeKey(testSshInstance.getKey('bitbucket.org'));
expect(testSshInstance.sshKeys[1].host).equal('github.com');
});
tap.test('it should store to disk', async () => {
testSshInstance.writeToDisk();
});
tap.start();

View File

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

View File

@ -1,8 +1,60 @@
import "typings-global";
import * as plugins from "./smartssh.plugins";
import * as helpers from "./smartssh.classes.helpers";
import * as plugins from './smartssh.plugins';
import * as helpers from './smartssh.classes.helpers';
import { SshKey } from './smartssh.classes.sshkey';
export class SshConfig {
constructor(){
private _sshKeyArray: SshKey[];
constructor(sshKeyArrayArg: SshKey[]) {
this._sshKeyArray = sshKeyArrayArg;
}
/**
* stores a config file
*/
store(dirPathArg: string) {
let done = plugins.smartpromise.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.smartpromise.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,47 @@
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
path:string; // the path of the ssh directory
sshInstance:SshInstance;
constructor(sshInstanceArg:SshInstance,sshDirPathArg?:string){
let sshDirPath:string;
if(sshDirPathArg){
sshDirPath = sshDirPathArg;
} else {
sshDirPath = plugins.smartpath.get.home();
}
this.path = sshDirPath;
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/');
}
syncToDir(){ //syncs
};
syncFromDir(){
}
getKeys(){
return helpers.sshKeyArrayFromDir(this.path);
}
}
}
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);
}
/**
* TODO: implement reading of directories
*/
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

@ -1,70 +1,102 @@
import "typings-global"
import * as plugins from "./smartssh.plugins";
import * as helpers from "./smartssh.classes.helpers";
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";
import { SshDir } from './smartssh.classes.sshdir';
import { SshConfig } from './smartssh.classes.sshconfig';
import { SshKey } from './smartssh.classes.sshkey';
/**
* SshInstance is the main class dealing with ssh management
*/
export class SshInstance {
private sshConfig:SshConfig; // sshConfig (e.g. represents ~/.ssh/config)
private sshDir:SshDir; // points to sshDir class instance.
private sshKeyArray:SshKey[]; //holds all ssh keys
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.sshDir = new SshDir(this,optionsArg.sshDirPath);
this.sshKeyArray = this.sshDir.getKeys();
this.sshSync = optionsArg.sshSync;
};
//altering methods
addKey(sshKeyArg:SshKey){
this.sync("from");
this.sshKeyArray.push(sshKeyArg);
this.sync("to");
};
removeKey(sshKeyArg:SshKey){
this.sync("from");
let filteredArray = this.sshKeyArray.filter((sshKeyArg2:SshKey) => {
return (sshKeyArg != sshKeyArg2);
});
this.sshKeyArray = filteredArray;
this.sync("to");
};
replaceKey(sshKeyOldArg:SshKey,sshKeyNewArg:SshKey){
this.sync("from");
this.removeKey(sshKeyOldArg);
this.addKey(sshKeyNewArg);
this.sync("to");
};
//
getKey(hostArg:string):SshKey{
this.sync("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.sync("from");
return this.sshKeyArray;
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');
}
// non altering methods
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;
}
sync(directionArg:string){
if(this.sshSync && directionArg == "from"){
this.sshDir.syncFromDir(); // call sync method of sshDir class;
} else if(this.sshSync && directionArg == "to") {
this.sshDir.syncToDir();
} else if(this.sshSync) {
throw new Error("directionArg not recognised. Must be 'to' or 'from'");
}
};
}
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 ========================
================================================================*/
/**
* method to invoke SshInstance _sync automatically when sshSync is true
*/
private _syncAuto(directionArg: 'from' | 'to') {
if (this._sshSync) {
// if auto sync is not enabled, do nothing
this._sync(directionArg);
}
}
/**
* private method to sync SshInstance
*/
private _sync(directionArg: 'from' | 'to', dirPathArg?: string) {
if (directionArg === 'from') {
this._sshDir.readFromDir(dirPathArg); // call sync method of sshDir class;
} else if (directionArg === 'to') {
this._sshDir.writeToDir(dirPathArg);
}
}
}

View File

@ -1,65 +1,106 @@
import "typings-global";
import * as plugins from "./smartssh.plugins";
import * as helpers from "./smartssh.classes.helpers";
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;
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;
};
get privateKeyBase64(){
return plugins.base64.encode(this.privKey);
private _privKey: string;
private _pubKey: string;
private _hostVar: string;
private _authorized: boolean;
private _smarthshellInstance = new plugins.shelljs.Smartshell({
executor: 'bash'
});
/**
* 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;
}
/**
* returns wether there is a private, a public or both keys
*/
get type() {
if (this._privKey && this._pubKey) {
return 'duplex';
} else if (this._privKey) {
return 'private';
} else if (this._pubKey) {
return 'public';
}
get publicKey(){
return this.pubKey;
}
set type(someVlueArg: any) {
console.log('the type of an SshKey connot be set. This value is autocomputed.');
}
// methods
read(filePathArg) {}
async 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);
await this._smarthshellInstance.exec(`chmod 0600 ${filePath}`);
}
get publicKeyBase64(){
return plugins.base64.encode(this.pubKey);
if (this._pubKey) {
let filePath = plugins.path.join(dirPathArg, fileNameBase + '.pub');
plugins.smartfile.memory.toFsSync(this._pubKey, filePath);
await this._smarthshellInstance.exec(`chmod 0600 ${filePath}`);
}
get type(){
if(this.privKey && this.pubKey){
return "duplex";
} else if(this.privKey){
return "private";
} else if(this.pubKey){
return "public";
}
};
// setters
set host(hostArg:string){
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"){
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,7 +1,10 @@
import "typings-global"
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");
export import smartpath = require("smartpath");
import * as fs from 'fs-extra';
import * as minimatch from 'minimatch';
import * as path from 'path';
import * as smartpromise from '@pushrocks/smartpromise';
import * as shelljs from '@pushrocks/smartshell';
import * as smartfile from '@pushrocks/smartfile';
import * as smartpath from '@pushrocks/smartpath';
import * as smartstring from '@pushrocks/smartstring';
export { fs, minimatch, path, smartpromise, 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"
}
}

17
tslint.json Normal file
View File

@ -0,0 +1,17 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}