Compare commits
45 Commits
Author | SHA1 | Date | |
---|---|---|---|
a9820a9e98 | |||
7037cee3d8 | |||
f7661e3133 | |||
cfcaa5b059 | |||
ac048b7025 | |||
dcd32e2dd2 | |||
9a10f83bb6 | |||
9fc03e8504 | |||
9a32b156fe | |||
a319e54d60 | |||
6a2577cde6 | |||
1f1bf7c21f | |||
c652d0bf07 | |||
eccc6294a8 | |||
f8a75a8d42 | |||
d5c2bc1b53 | |||
d577a82a7b | |||
f0b52c8da7 | |||
4cb6aa03e6 | |||
8b85b6c8bc | |||
c032ff69d0 | |||
0454eef45f | |||
def368f8ab | |||
6853fa28b6 | |||
56318f28cf | |||
32b26f21cd | |||
32c2698af7 | |||
27237f14c7 | |||
8f29f234f1 | |||
5091625953 | |||
f74b3a51b0 | |||
062f3ad060 | |||
ecd0fd8fad | |||
742bf694e4 | |||
38165f11db | |||
ef2b31b4b2 | |||
5b1f800067 | |||
6339a3ed9b | |||
bf27aaf167 | |||
9bc3aea59c | |||
f5ff302d4d | |||
cac8203bf5 | |||
e4532271cc | |||
faf6c91199 | |||
d0009e7a9c |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
||||
name: Default (not tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags-ignore:
|
||||
- '**'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install pnpm and npmci
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
|
||||
- name: Run npm prepare
|
||||
run: npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
||||
name: Default (tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
||||
|
||||
release:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Release
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm publish
|
||||
|
||||
metadata:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
continue-on-error: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Code quality
|
||||
run: |
|
||||
npmci command npm install -g typescript
|
||||
npmci npm install
|
||||
|
||||
- name: Trigger
|
||||
run: npmci trigger
|
||||
|
||||
- name: Build docs and upload artifacts
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
pnpm install -g @git.zone/tsdoc
|
||||
npmci command tsdoc
|
||||
continue-on-error: true
|
25
.gitignore
vendored
25
.gitignore
vendored
@ -1,7 +1,20 @@
|
||||
.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_*/
|
||||
|
||||
# custom
|
@ -1,38 +0,0 @@
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
|
||||
stages:
|
||||
- test
|
||||
- release
|
||||
- page
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
tags:
|
||||
- docker
|
||||
- lossless
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
tags:
|
||||
- docker
|
||||
- lossless
|
||||
|
||||
testLEGACY:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test legacy
|
||||
allow_failure: true
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- lossless
|
12
.travis.yml
12
.travis.yml
@ -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
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"npmci": {
|
||||
"type": "object",
|
||||
"description": "settings for npmci"
|
||||
},
|
||||
"gitzone": {
|
||||
"type": "object",
|
||||
"description": "settings for gitzone",
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Push.Rocks
|
||||
Copyright (c) 2016 Task Venture Capital 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
|
||||
|
34
README.md
34
README.md
@ -1,34 +0,0 @@
|
||||
# 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.
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
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;
|
||||
});
|
||||
|
||||
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.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"
|
||||
});
|
||||
|
||||
sshInstance.getKeys() // returns array of all available getKeys. Each key is in form of class sshKey
|
||||
|
||||
```
|
5
dist/index.d.ts
vendored
5
dist/index.d.ts
vendored
@ -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
12
dist/index.js
vendored
@ -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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUNQLENBQUMsQ0FEc0I7QUFHdkIsNkNBQTBCLGdDQUFnQyxDQUFDO0FBQW5ELGlFQUFtRDtBQUMzRCx3Q0FBcUIsMkJBQTJCLENBQUM7QUFBekMsa0RBQXlDO0FBQ2pELHdDQUFxQiwyQkFBMkIsQ0FBQztBQUF6QyxrREFBeUM7QUFDakQsMkNBQXdCLDhCQUE4QixDQUFDO0FBQS9DLDJEQUErQyIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCJcbmltcG9ydCAqIGFzIHBsdWdpbnMgZnJvbSBcIi4vc21hcnRzc2gucGx1Z2luc1wiO1xuXG5leHBvcnQge1NzaEluc3RhbmNlfSBmcm9tIFwiLi9zbWFydHNzaC5jbGFzc2VzLnNzaGluc3RhbmNlXCI7XG5leHBvcnQge1NzaEtleX0gZnJvbSBcIi4vc21hcnRzc2guY2xhc3Nlcy5zc2hrZXlcIjtcbmV4cG9ydCB7U3NoRGlyfSBmcm9tIFwiLi9zbWFydHNzaC5jbGFzc2VzLnNzaGRpclwiO1xuZXhwb3J0IHtTc2hDb25maWd9IGZyb20gXCIuL3NtYXJ0c3NoLmNsYXNzZXMuc3NoY29uZmlnXCI7Il19
|
3
dist/smartssh.classes.helpers.d.ts
vendored
3
dist/smartssh.classes.helpers.d.ts
vendored
@ -1,3 +0,0 @@
|
||||
import "typings-global";
|
||||
import { SshKey } from "./smartssh.classes.sshkey";
|
||||
export declare let sshKeyArrayFromDir: (dirArg: string) => SshKey[];
|
8
dist/smartssh.classes.helpers.js
vendored
8
dist/smartssh.classes.helpers.js
vendored
@ -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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFDUCxDQUFDLENBRHNCO0FBSVosMEJBQWtCLEdBQUcsVUFBUyxNQUFhO0lBQ2xELElBQUksV0FBVyxHQUFHLEVBQUUsQ0FBQyxDQUFDLE1BQU07SUFDNUIsTUFBTSxDQUFDLFdBQVcsQ0FBQztBQUN2QixDQUFDLENBQUEiLCJmaWxlIjoic21hcnRzc2guY2xhc3Nlcy5oZWxwZXJzLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFwidHlwaW5ncy1nbG9iYWxcIlxuaW1wb3J0ICogYXMgcGx1Z2lucyBmcm9tIFwiLi9zbWFydHNzaC5wbHVnaW5zXCI7XG5pbXBvcnQge1NzaEtleX0gZnJvbSBcIi4vc21hcnRzc2guY2xhc3Nlcy5zc2hrZXlcIjtcblxuZXhwb3J0IGxldCBzc2hLZXlBcnJheUZyb21EaXIgPSBmdW5jdGlvbihkaXJBcmc6c3RyaW5nKTpTc2hLZXlbXXtcbiAgICBsZXQgc3NoS2V5QXJyYXkgPSBbXTsgLy9UT0RPXG4gICAgcmV0dXJuIHNzaEtleUFycmF5O1xufSJdfQ==
|
4
dist/smartssh.classes.sshconfig.d.ts
vendored
4
dist/smartssh.classes.sshconfig.d.ts
vendored
@ -1,4 +0,0 @@
|
||||
import "typings-global";
|
||||
export declare class SshConfig {
|
||||
constructor();
|
||||
}
|
10
dist/smartssh.classes.sshconfig.js
vendored
10
dist/smartssh.classes.sshconfig.js
vendored
@ -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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuc3NoY29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFHeEI7SUFDSTtJQUVBLENBQUM7SUFDTCxnQkFBQztBQUFELENBSkEsQUFJQyxJQUFBO0FBSlksaUJBQVMsWUFJckIsQ0FBQSIsImZpbGUiOiJzbWFydHNzaC5jbGFzc2VzLnNzaGNvbmZpZy5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBcInR5cGluZ3MtZ2xvYmFsXCI7XG5pbXBvcnQgKiBhcyBwbHVnaW5zIGZyb20gXCIuL3NtYXJ0c3NoLnBsdWdpbnNcIjtcbmltcG9ydCAqIGFzIGhlbHBlcnMgZnJvbSBcIi4vc21hcnRzc2guY2xhc3Nlcy5oZWxwZXJzXCI7XG5leHBvcnQgY2xhc3MgU3NoQ29uZmlnIHtcbiAgICBjb25zdHJ1Y3Rvcigpe1xuICAgICAgICBcbiAgICB9XG59Il19
|
11
dist/smartssh.classes.sshdir.d.ts
vendored
11
dist/smartssh.classes.sshdir.d.ts
vendored
@ -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);
|
||||
writeToDir(): void;
|
||||
readFromDir(): void;
|
||||
getKeys(): SshKey[];
|
||||
}
|
28
dist/smartssh.classes.sshdir.js
vendored
28
dist/smartssh.classes.sshdir.js
vendored
@ -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.writeToDir = function () {
|
||||
};
|
||||
;
|
||||
SshDir.prototype.readFromDir = function () {
|
||||
};
|
||||
SshDir.prototype.getKeys = function () {
|
||||
return helpers.sshKeyArrayFromDir(this.path);
|
||||
};
|
||||
return SshDir;
|
||||
}());
|
||||
exports.SshDir = SshDir;
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuc3NoZGlyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDeEIsSUFBWSxPQUFPLFdBQU0sb0JBQW9CLENBQUMsQ0FBQTtBQUM5QyxJQUFZLE9BQU8sV0FBTSw0QkFBNEIsQ0FBQyxDQUFBO0FBSXREO0lBR0ksZ0JBQVksY0FBMEIsRUFBQyxhQUFxQjtRQUN4RCxJQUFJLFVBQWlCLENBQUM7UUFDdEIsRUFBRSxDQUFBLENBQUMsYUFBYSxDQUFDLENBQUEsQ0FBQztZQUNkLFVBQVUsR0FBRyxhQUFhLENBQUM7UUFDL0IsQ0FBQztRQUFDLElBQUksQ0FBQyxDQUFDO1lBQ0osVUFBVSxHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUMsR0FBRyxDQUFDLElBQUksRUFBRSxDQUFDO1FBQzlDLENBQUM7UUFDRCxJQUFJLENBQUMsSUFBSSxHQUFHLFVBQVUsQ0FBQztJQUMzQixDQUFDO0lBQ0QsMkJBQVUsR0FBVjtJQUVBLENBQUM7O0lBQ0QsNEJBQVcsR0FBWDtJQUVBLENBQUM7SUFDRCx3QkFBTyxHQUFQO1FBQ0ksTUFBTSxDQUFDLE9BQU8sQ0FBQyxrQkFBa0IsQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUM7SUFDakQsQ0FBQztJQUNMLGFBQUM7QUFBRCxDQXJCQSxBQXFCQyxJQUFBO0FBckJZLGNBQU0sU0FxQmxCLENBQUEiLCJmaWxlIjoic21hcnRzc2guY2xhc3Nlcy5zc2hkaXIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgXCJ0eXBpbmdzLWdsb2JhbFwiO1xuaW1wb3J0ICogYXMgcGx1Z2lucyBmcm9tIFwiLi9zbWFydHNzaC5wbHVnaW5zXCI7XG5pbXBvcnQgKiBhcyBoZWxwZXJzIGZyb20gXCIuL3NtYXJ0c3NoLmNsYXNzZXMuaGVscGVyc1wiO1xuaW1wb3J0IHtTc2hJbnN0YW5jZX0gZnJvbSBcIi4vc21hcnRzc2guY2xhc3Nlcy5zc2hpbnN0YW5jZVwiO1xuaW1wb3J0IHtTc2hLZXl9IGZyb20gXCIuL3NtYXJ0c3NoLmNsYXNzZXMuc3Noa2V5XCI7XG5pbXBvcnQge1NzaENvbmZpZ30gZnJvbSBcIi4vc21hcnRzc2guY2xhc3Nlcy5zc2hjb25maWdcIjtcbmV4cG9ydCBjbGFzcyBTc2hEaXIgeyAvLyBzc2hEaXIgY2xhc3MgLT4gTk9UIEVYUE9SVEVELCBPTkxZIEZPUiBJTlRFUk5BTCBVU0VcbiAgICBwYXRoOnN0cmluZzsgLy8gdGhlIHBhdGggb2YgdGhlIHNzaCBkaXJlY3RvcnlcbiAgICBzc2hJbnN0YW5jZTpTc2hJbnN0YW5jZTtcbiAgICBjb25zdHJ1Y3Rvcihzc2hJbnN0YW5jZUFyZzpTc2hJbnN0YW5jZSxzc2hEaXJQYXRoQXJnPzpzdHJpbmcpe1xuICAgICAgICBsZXQgc3NoRGlyUGF0aDpzdHJpbmc7XG4gICAgICAgIGlmKHNzaERpclBhdGhBcmcpe1xuICAgICAgICAgICAgc3NoRGlyUGF0aCA9IHNzaERpclBhdGhBcmc7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBzc2hEaXJQYXRoID0gcGx1Z2lucy5zbWFydHBhdGguZ2V0LmhvbWUoKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLnBhdGggPSBzc2hEaXJQYXRoO1xuICAgIH1cbiAgICB3cml0ZVRvRGlyKCl7IC8vIHN5bmNzIHNzaEluc3RhbmNlIHRvIGRpcmVjdG9yeVxuICAgICAgICBcbiAgICB9O1xuICAgIHJlYWRGcm9tRGlyKCl7IC8vIHN5bmNzIHNzaEluc3RhbmNlIGZyb20gZGlyZWN0b3J5XG4gICAgICAgIFxuICAgIH1cbiAgICBnZXRLZXlzKCl7XG4gICAgICAgIHJldHVybiBoZWxwZXJzLnNzaEtleUFycmF5RnJvbURpcih0aGlzLnBhdGgpO1xuICAgIH1cbn0iXX0=
|
34
dist/smartssh.classes.sshinstance.d.ts
vendored
34
dist/smartssh.classes.sshinstance.d.ts
vendored
@ -1,34 +0,0 @@
|
||||
import "typings-global";
|
||||
import { SshDir } from "./smartssh.classes.sshdir";
|
||||
import { SshKey } from "./smartssh.classes.sshkey";
|
||||
export declare class SshInstance {
|
||||
private _sshConfig;
|
||||
sshDir: SshDir;
|
||||
protected sshKeyArray: SshKey[];
|
||||
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[];
|
||||
/**
|
||||
* write SshInstance to disk
|
||||
*/
|
||||
writeToDisk(): void;
|
||||
/**
|
||||
* read ab SshInstance from disk
|
||||
*/
|
||||
readFromDisk(): void;
|
||||
/**
|
||||
* method to invoke SshInstance _sync automatically when sshSync is true
|
||||
*/
|
||||
private _syncAuto(directionArg);
|
||||
/**
|
||||
* private method to sync SshInstance
|
||||
*/
|
||||
private _sync(directionArg);
|
||||
}
|
98
dist/smartssh.classes.sshinstance.js
vendored
98
dist/smartssh.classes.sshinstance.js
vendored
File diff suppressed because one or more lines are too long
18
dist/smartssh.classes.sshkey.d.ts
vendored
18
dist/smartssh.classes.sshkey.d.ts
vendored
@ -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: string;
|
||||
publicKey: string;
|
||||
publicKeyBase64: string;
|
||||
type: string;
|
||||
store(filePathArg?: string): void;
|
||||
}
|
103
dist/smartssh.classes.sshkey.js
vendored
103
dist/smartssh.classes.sshkey.js
vendored
File diff suppressed because one or more lines are too long
8
dist/smartssh.plugins.d.ts
vendored
8
dist/smartssh.plugins.d.ts
vendored
@ -1,8 +0,0 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export declare let base64: any;
|
||||
export declare let fs: any;
|
||||
export declare let minimatch: any;
|
||||
export import path = require("path");
|
||||
export import smartfile = require("smartfile");
|
||||
export import smartpath = require("smartpath");
|
11
dist/smartssh.plugins.js
vendored
11
dist/smartssh.plugins.js
vendored
@ -1,11 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
exports.beautylog = require("beautylog");
|
||||
exports.base64 = require("js-base64").Base64;
|
||||
exports.fs = require("fs-extra");
|
||||
exports.minimatch = require("minimatch");
|
||||
exports.path = require("path");
|
||||
exports.smartfile = require("smartfile");
|
||||
exports.smartpath = require("smartpath");
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQ1AsQ0FBQyxDQURzQjtBQUNULGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDcEMsY0FBTSxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQyxNQUFNLENBQUM7QUFDckMsVUFBRSxHQUFHLE9BQU8sQ0FBQyxVQUFVLENBQUMsQ0FBQztBQUN6QixpQkFBUyxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQztBQUM5QixZQUFJLFdBQVcsTUFBTSxDQUFDLENBQUM7QUFDdkIsaUJBQVMsV0FBVyxXQUFXLENBQUMsQ0FBQztBQUNqQyxpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDIiwiZmlsZSI6InNtYXJ0c3NoLnBsdWdpbnMuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgXCJ0eXBpbmdzLWdsb2JhbFwiXG5leHBvcnQgaW1wb3J0IGJlYXV0eWxvZyA9IHJlcXVpcmUoXCJiZWF1dHlsb2dcIik7XG5leHBvcnQgbGV0IGJhc2U2NCA9IHJlcXVpcmUoXCJqcy1iYXNlNjRcIikuQmFzZTY0O1xuZXhwb3J0IGxldCBmcyA9IHJlcXVpcmUoXCJmcy1leHRyYVwiKTtcbmV4cG9ydCBsZXQgbWluaW1hdGNoID0gcmVxdWlyZShcIm1pbmltYXRjaFwiKTtcbmV4cG9ydCBpbXBvcnQgcGF0aCA9IHJlcXVpcmUoXCJwYXRoXCIpO1xuZXhwb3J0IGltcG9ydCBzbWFydGZpbGUgPSByZXF1aXJlKFwic21hcnRmaWxlXCIpO1xuZXhwb3J0IGltcG9ydCBzbWFydHBhdGggPSByZXF1aXJlKFwic21hcnRwYXRoXCIpOyJdfQ==
|
30
npmextra.json
Normal file
30
npmextra.json
Normal file
@ -0,0 +1,30 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartssh",
|
||||
"description": "A library for setting up SSH configuration quickly and painlessly.",
|
||||
"npmPackagename": "@push.rocks/smartssh",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"SSH",
|
||||
"SSH configuration",
|
||||
"SSH keys management",
|
||||
"automation",
|
||||
"development tools",
|
||||
"node.js",
|
||||
"security",
|
||||
"server management"
|
||||
]
|
||||
}
|
||||
},
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
{
|
||||
"mode":"default"
|
||||
}
|
73
package.json
73
package.json
@ -1,39 +1,70 @@
|
||||
{
|
||||
"name": "smartssh",
|
||||
"version": "1.0.7",
|
||||
"description": "setups SSH quickly and in a painless manner",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"name": "@push.rocks/smartssh",
|
||||
"version": "2.0.2",
|
||||
"private": false,
|
||||
"description": "A library for setting up SSH configuration quickly and painlessly.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
"test": "(tstest test/)",
|
||||
"testDocker": "tsdocker",
|
||||
"build": "(tsbuild --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://gitlab.com/pushrocks/smartssh.git"
|
||||
"url": "https://code.foss.global/push.rocks/smartssh.git"
|
||||
},
|
||||
"keywords": [
|
||||
"SSH",
|
||||
"ENV",
|
||||
"base64"
|
||||
"SSH configuration",
|
||||
"SSH keys management",
|
||||
"automation",
|
||||
"development tools",
|
||||
"node.js",
|
||||
"security",
|
||||
"server management"
|
||||
],
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/pushrocks/smartssh/issues"
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartssh#readme",
|
||||
"homepage": "https://code.foss.global/push.rocks/smartssh",
|
||||
"dependencies": {
|
||||
"beautylog": "^5.0.12",
|
||||
"fs-extra": "^0.30.0",
|
||||
"js-base64": "^2.1.9",
|
||||
"minimatch": "^3.0.2",
|
||||
"smartfile": "^4.0.4",
|
||||
"smartpath": "^3.2.2",
|
||||
"typings-global": "^1.0.3",
|
||||
"typings-test": "^1.0.1"
|
||||
"@push.rocks/smartcrypto": "^2.0.5",
|
||||
"@push.rocks/smartfile": "^11.0.4",
|
||||
"@push.rocks/smartjson": "^5.0.10",
|
||||
"@push.rocks/smartpath": "^5.0.11",
|
||||
"@push.rocks/smartpromise": "^4.0.3",
|
||||
"@push.rocks/smartshell": "^3.0.3",
|
||||
"@push.rocks/smartstring": "^4.0.13",
|
||||
"@types/fs-extra": "^11.0.4",
|
||||
"fs-extra": "^11.2.0",
|
||||
"minimatch": "^9.0.3",
|
||||
"node-ssh": "^13.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"npmts-g": "^5.2.6",
|
||||
"should": "^9.0.2"
|
||||
}
|
||||
"@git.zone/tsbuild": "^2.1.72",
|
||||
"@git.zone/tsrun": "^1.2.46",
|
||||
"@git.zone/tstest": "^1.0.86",
|
||||
"@push.rocks/tapbundle": "^5.0.15",
|
||||
"@types/node": "^20.11.17"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
5727
pnpm-lock.yaml
generated
Normal file
5727
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
||||
|
134
readme.md
Normal file
134
readme.md
Normal file
@ -0,0 +1,134 @@
|
||||
# @push.rocks/smartssh
|
||||
setup SSH quickly and in a painless manner
|
||||
|
||||
## Install
|
||||
|
||||
To begin using `@push.rocks/smartssh` in your project, you'll need to install it via npm or yarn. You can do so by running one of the following commands:
|
||||
|
||||
```bash
|
||||
npm install @push.rocks/smartssh --save
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```bash
|
||||
yarn add @push.rocks/smartssh
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
`@push.rocks/smartssh` is a powerful package designed to simplify SSH configurations, key management, and interaction in a Typescript environment, using ESM syntax. This guide will cover how to utilize the primary functionalities provided by the package.
|
||||
|
||||
#### Setting Up an SSH Instance
|
||||
|
||||
An SSH instance represents your SSH configurations, including the keys and the SSH directory. Here's how to create an instance:
|
||||
|
||||
```typescript
|
||||
import { SshInstance } from '@push.rocks/smartssh';
|
||||
|
||||
const mySshInstance = new SshInstance({
|
||||
sshDirPath: '/path/to/.ssh', // Optional: specify SSH directory path
|
||||
sshSync: true, // Optional: keep the instance in sync with the SSH directory automatically
|
||||
});
|
||||
```
|
||||
|
||||
#### Working with SSH Keys
|
||||
|
||||
SSH keys can be managed using the `SshKey` class. You can add, remove, or retrieve keys from your SSH instance.
|
||||
|
||||
```typescript
|
||||
import { SshKey } from '@push.rocks/smartssh';
|
||||
|
||||
// Creating a new SSH key
|
||||
const mySshKey = new SshKey({
|
||||
host: 'github.com', // Hostname
|
||||
private: 'privateKeyString', // Private key string
|
||||
public: 'publicKeyString', // Optional: public key string
|
||||
authorized: false // Optional: Is this key authorized? Defaults to false
|
||||
});
|
||||
|
||||
// Adding the SSH key to the instance
|
||||
mySshInstance.addKey(mySshKey);
|
||||
|
||||
// Getting an SSH key by host
|
||||
const githubKey = mySshInstance.getKey('github.com');
|
||||
|
||||
// Removing an SSH key by instance
|
||||
mySshInstance.removeKey(githubKey);
|
||||
```
|
||||
|
||||
#### Syncing Keys with the File System
|
||||
|
||||
`@push.rocks/smartssh` makes it easy to synchronize your SSH keys with the file system, keeping your actual SSH configuration and your program state in alignment.
|
||||
|
||||
```typescript
|
||||
// To write the current state to the SSH directory
|
||||
mySshInstance.writeToDisk();
|
||||
|
||||
// To read and synchronize the state from the SSH directory
|
||||
mySshInstance.readFromDisk();
|
||||
```
|
||||
|
||||
#### Advanced Key Management
|
||||
|
||||
- **Encoding and Decoding**: Keys can be encoded in `base64` for easier environment variable storage.
|
||||
- **Key Type Detection**: The package can detect and handle private, public, or both keys present scenarios (`duplex`).
|
||||
- **Custom SSH Directory**: Support for custom SSH directory locations.
|
||||
- **Automatic Syncing**: Optionally keep the SSH instance automatically synced with the SSH directory on modifications.
|
||||
|
||||
### Comprehensive Example
|
||||
|
||||
Below is a comprehensive example demonstrating SSH instance creation, adding a new SSH key, and syncing with the filesystem.
|
||||
|
||||
```typescript
|
||||
import { SshInstance, SshKey } from '@push.rocks/smartssh';
|
||||
|
||||
async function setupSsh() {
|
||||
// Initialize the SSH instance
|
||||
const sshInstance = new SshInstance({
|
||||
sshDirPath: '/custom/path/to/.ssh',
|
||||
sshSync: true,
|
||||
});
|
||||
|
||||
// Create a new SSH key
|
||||
const newSshKey = new SshKey({
|
||||
host: 'my.custom.server.com',
|
||||
private: 'myPrivateKeyInBase64',
|
||||
public: 'myPublicKeyInBase64',
|
||||
});
|
||||
|
||||
// Add the new key to the instance
|
||||
sshInstance.addKey(newSshKey);
|
||||
|
||||
// Optionally, write to disk immediately
|
||||
sshInstance.writeToDisk();
|
||||
}
|
||||
|
||||
// Running the SSH setup
|
||||
setupSsh().then(() => {
|
||||
console.log('SSH setup complete.');
|
||||
}).catch((error) => {
|
||||
console.error('SSH setup failed:', error);
|
||||
});
|
||||
```
|
||||
|
||||
This guide should provide a robust start to managing SSH configurations using `@push.rocks/smartssh`. Whether for individual projects or shared across a team, this package offers a streamlined approach to handling SSH keys, config synchronization, and more, all within a TypeScript project.
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
1
test/temp/bitbucket.org
Normal file
1
test/temp/bitbucket.org
Normal file
@ -0,0 +1 @@
|
||||
somePrivateKey
|
1
test/temp/bitbucket.org.pub
Normal file
1
test/temp/bitbucket.org.pub
Normal file
@ -0,0 +1 @@
|
||||
somePublicKey
|
15
test/temp/config
Normal file
15
test/temp/config
Normal 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
1
test/temp/example.com
Normal file
@ -0,0 +1 @@
|
||||
someExamplePrivateKey
|
1
test/temp/example.com.pub
Normal file
1
test/temp/example.com.pub
Normal file
@ -0,0 +1 @@
|
||||
someExamplePublicKey
|
1
test/temp/github.com
Normal file
1
test/temp/github.com
Normal file
@ -0,0 +1 @@
|
||||
someGitHubPrivateKey
|
1
test/temp/github.com.pub
Normal file
1
test/temp/github.com.pub
Normal file
@ -0,0 +1 @@
|
||||
someGitHubPublicKey
|
1
test/temp/gitlab.com
Normal file
1
test/temp/gitlab.com
Normal file
@ -0,0 +1 @@
|
||||
somePrivateKey
|
1
test/temp/gitlab.com.pub
Normal file
1
test/temp/gitlab.com.pub
Normal file
@ -0,0 +1 @@
|
||||
somePublicKey
|
2
test/test.d.ts
vendored
2
test/test.d.ts
vendored
@ -1,2 +0,0 @@
|
||||
import "typings-test";
|
||||
import "should";
|
69
test/test.js
69
test/test.js
File diff suppressed because one or more lines are too long
150
test/test.ts
150
test/test.ts
@ -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 '@push.rocks/tapbundle';
|
||||
import * as smartssh from '../ts/index.js';
|
||||
import * as path from '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).toBeInstanceOf(smartssh.SshKey);
|
||||
});
|
||||
tap.test('.type should be a valid type', async () => {
|
||||
expect(testSshKey.type).toEqual('duplex');
|
||||
});
|
||||
tap.test('.publicKey should be public key', async () => {
|
||||
expect(testSshKey.pubKey).toEqual('someExamplePublicKey');
|
||||
});
|
||||
tap.test('.privateKey should be private key', async () => {
|
||||
expect(testSshKey.privKey).toEqual('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).toBeInstanceOf(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).toBeInstanceOf(Array);
|
||||
expect(sshKeyArray[0].host).toEqual('gitlab.com');
|
||||
expect(sshKeyArray[1].host).toEqual('bitbucket.org');
|
||||
expect(sshKeyArray[2].host).toEqual('github.com');
|
||||
});
|
||||
|
||||
tap.test('.getKey() should get a specific key selected by host', async () => {
|
||||
expect(testSshInstance.getKey('github.com').pubKey).toEqual('someGitHubPublicKey');
|
||||
});
|
||||
|
||||
tap.test('.removeKey() should remove a key', async () => {
|
||||
testSshInstance.removeKey(testSshInstance.getKey('bitbucket.org'));
|
||||
expect(testSshInstance.sshKeys[1].host).toEqual('github.com');
|
||||
});
|
||||
|
||||
tap.test('it should store to disk', async () => {
|
||||
testSshInstance.writeToDisk();
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartssh',
|
||||
version: '2.0.2',
|
||||
description: 'setups SSH quickly and in a painless manner'
|
||||
}
|
11
ts/index.ts
11
ts/index.ts
@ -1,7 +1,6 @@
|
||||
import "typings-global"
|
||||
import * as plugins from "./smartssh.plugins";
|
||||
import * as plugins from './smartssh.plugins.js';
|
||||
|
||||
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.js';
|
||||
export { SshKey } from './smartssh.classes.sshkey.js';
|
||||
export { SshDir } from './smartssh.classes.sshdir.js';
|
||||
export { SshConfig } from './smartssh.classes.sshconfig.js';
|
||||
|
@ -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.js';
|
||||
import { SshKey } from './smartssh.classes.sshkey.js';
|
||||
|
||||
export let sshKeyArrayFromDir = function(dirArg:string):SshKey[]{
|
||||
let sshKeyArray = []; //TODO
|
||||
return sshKeyArray;
|
||||
}
|
||||
export let sshKeyArrayFromDir = function (dirArg: string): SshKey[] {
|
||||
let sshKeyArray = []; // TODO
|
||||
return sshKeyArray;
|
||||
};
|
||||
|
@ -1,8 +1,60 @@
|
||||
import "typings-global";
|
||||
import * as plugins from "./smartssh.plugins";
|
||||
import * as helpers from "./smartssh.classes.helpers";
|
||||
export class SshConfig {
|
||||
constructor(){
|
||||
import * as plugins from './smartssh.plugins.js';
|
||||
import * as helpers from './smartssh.classes.helpers.js';
|
||||
import { SshKey } from './smartssh.classes.sshkey.js';
|
||||
|
||||
export class SshConfig {
|
||||
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;
|
||||
}
|
@ -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;
|
||||
}
|
||||
writeToDir(){ // syncs sshInstance to directory
|
||||
import * as plugins from './smartssh.plugins.js';
|
||||
import * as helpers from './smartssh.classes.helpers.js';
|
||||
import { SshInstance } from './smartssh.classes.sshinstance.js';
|
||||
import { SshKey } from './smartssh.classes.sshkey.js';
|
||||
import { SshConfig } from './smartssh.classes.sshconfig.js';
|
||||
|
||||
};
|
||||
readFromDir(){ // syncs sshInstance from directory
|
||||
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/');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,96 +1,102 @@
|
||||
import "typings-global"
|
||||
import * as plugins from "./smartssh.plugins";
|
||||
import * as helpers from "./smartssh.classes.helpers";
|
||||
import * as plugins from './smartssh.plugins.js';
|
||||
import * as helpers from './smartssh.classes.helpers.js';
|
||||
|
||||
import {SshDir} from "./smartssh.classes.sshdir";
|
||||
import {SshConfig} from "./smartssh.classes.sshconfig";
|
||||
import {SshKey} from "./smartssh.classes.sshkey";
|
||||
import { SshDir } from './smartssh.classes.sshdir.js';
|
||||
import { SshConfig } from './smartssh.classes.sshconfig.js';
|
||||
import { SshKey } from './smartssh.classes.sshkey.js';
|
||||
|
||||
/**
|
||||
* SshInstance is the main class dealing with ssh management
|
||||
*/
|
||||
export class SshInstance {
|
||||
private _sshConfig:SshConfig; // sshConfig (e.g. represents ~/.ssh/config)
|
||||
sshDir:SshDir; // points to sshDir class instance.
|
||||
protected 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.sshKeyArray = [];
|
||||
this._sshSync = optionsArg.sshSync;
|
||||
this.sshDir = new SshDir(this,optionsArg.sshDirPath);
|
||||
};
|
||||
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");
|
||||
};
|
||||
// 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(){
|
||||
this._sync("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;
|
||||
}
|
||||
}
|
||||
get sshKeys(): SshKey[] {
|
||||
this._syncAuto('from');
|
||||
return this._sshKeyArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* read ab SshInstance from disk
|
||||
*/
|
||||
readFromDisk(){
|
||||
this._sync("from");
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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: '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);
|
||||
}
|
||||
|
||||
/**
|
||||
* private method to sync SshInstance
|
||||
*/
|
||||
private _sync(directionArg:string){
|
||||
if(directionArg == "from"){
|
||||
this.sshDir.readFromDir(); // call sync method of sshDir class;
|
||||
} else if(directionArg == "to") {
|
||||
this.sshDir.writeToDir();
|
||||
} else {
|
||||
throw new Error("directionArg not recognised. Must be 'to' or 'from'");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,73 +1,106 @@
|
||||
import "typings-global";
|
||||
import * as plugins from "./smartssh.plugins";
|
||||
import * as helpers from "./smartssh.classes.helpers";
|
||||
import * as plugins from './smartssh.plugins.js';
|
||||
import * as helpers from './smartssh.classes.helpers.js';
|
||||
|
||||
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;
|
||||
};
|
||||
private _privKey: string;
|
||||
private _pubKey: string;
|
||||
private _hostVar: string;
|
||||
private _authorized: boolean;
|
||||
|
||||
// getters
|
||||
get host(){
|
||||
return this.hostVar;
|
||||
};
|
||||
get privateKey(){
|
||||
return this.privKey;
|
||||
};
|
||||
get privateKeyBase64(){
|
||||
return plugins.base64.encode(this.privKey);
|
||||
}
|
||||
get publicKey(){
|
||||
return this.pubKey;
|
||||
}
|
||||
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";
|
||||
}
|
||||
};
|
||||
private _smarthshellInstance = new plugins.smartshell.Smartshell({
|
||||
executor: 'bash',
|
||||
});
|
||||
|
||||
// setters
|
||||
set host(hostArg:string){
|
||||
this.hostVar = hostArg;
|
||||
};
|
||||
set privateKey(privateKeyArg:string){
|
||||
this.privKey = privateKeyArg;
|
||||
};
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
set privateKeyBase64(privateKeyArg:string) {
|
||||
this.privKey = plugins.base64.decode(privateKeyArg);
|
||||
// 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';
|
||||
}
|
||||
}
|
||||
set type(someVlueArg: any) {
|
||||
console.log('the type of an SshKey connot be set. This value is autocomputed.');
|
||||
}
|
||||
|
||||
set publicKey(publicKeyArg:string){
|
||||
this.pubKey = publicKeyArg;
|
||||
};
|
||||
// methods
|
||||
read(filePathArg) {}
|
||||
|
||||
set publicKeyBase64(publicKeyArg:string) {
|
||||
this.pubKey = plugins.base64.decode(publicKeyArg);
|
||||
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}`);
|
||||
}
|
||||
|
||||
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.pub")); // call this function recursivly
|
||||
}
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,30 @@
|
||||
import "typings-global"
|
||||
export import beautylog = require("beautylog");
|
||||
export let base64 = require("js-base64").Base64;
|
||||
export let fs = require("fs-extra");
|
||||
export let minimatch = require("minimatch");
|
||||
export import path = require("path");
|
||||
export import smartfile = require("smartfile");
|
||||
export import smartpath = require("smartpath");
|
||||
// node native
|
||||
import * as fs from 'fs-extra';
|
||||
import * as path from 'path';
|
||||
|
||||
export { fs, path };
|
||||
|
||||
// @push.rocks scope
|
||||
import * as smartjson from '@push.rocks/smartjson';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartcrypto from '@push.rocks/smartcrypto';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as smartshell from '@push.rocks/smartshell';
|
||||
import * as smartstring from '@push.rocks/smartstring';
|
||||
|
||||
export {
|
||||
smartjson,
|
||||
smartfile,
|
||||
smartcrypto,
|
||||
smartpath,
|
||||
smartpromise,
|
||||
smartshell,
|
||||
smartstring,
|
||||
};
|
||||
|
||||
// third party scope
|
||||
import * as minimatch from 'minimatch';
|
||||
import * as nodeSsh from 'node-ssh';
|
||||
|
||||
export { minimatch, nodeSsh };
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user