Compare commits

...

28 Commits

Author SHA1 Message Date
jkunz 4a97d63c04 v2.0.3 2026-05-01 18:44:22 +00:00
jkunz d8ab8a8d73 fix(ssh): modernize filesystem handling and package exports for NodeNext compatibility 2026-05-01 18:44:22 +00:00
philkunz a9820a9e98 update description 2024-05-29 14:16:27 +02:00
philkunz 7037cee3d8 update tsconfig 2024-04-14 18:22:42 +02:00
philkunz f7661e3133 update tsconfig 2024-04-01 21:41:15 +02:00
philkunz cfcaa5b059 update npmextra.json: githost 2024-04-01 19:59:45 +02:00
philkunz ac048b7025 update npmextra.json: githost 2024-03-30 21:48:46 +01:00
philkunz dcd32e2dd2 2.0.2 2024-02-09 18:21:33 +01:00
philkunz 9a10f83bb6 fix(core): update 2024-02-09 18:21:33 +01:00
philkunz 9fc03e8504 2.0.1 2023-07-27 15:52:02 +02:00
philkunz 9a32b156fe fix(core): update 2023-07-27 15:52:01 +02:00
philkunz a319e54d60 2.0.0 2022-10-11 13:18:35 +02:00
philkunz 6a2577cde6 BREAKING CHANGE(core): switch to esm 2022-10-11 13:18:35 +02:00
philkunz 1f1bf7c21f 1.2.7 2022-10-11 13:18:04 +02:00
philkunz c652d0bf07 fix(core): update 2022-10-11 13:18:04 +02:00
philkunz eccc6294a8 1.2.6 2022-10-11 13:13:14 +02:00
philkunz f8a75a8d42 fix(core): update 2022-10-11 13:13:14 +02:00
philkunz d5c2bc1b53 1.2.5 2022-10-11 13:05:30 +02:00
philkunz d577a82a7b fix(core): update 2022-10-11 13:05:29 +02:00
philkunz f0b52c8da7 1.2.4 2019-07-17 11:48:31 +02:00
philkunz 4cb6aa03e6 fix(core): update 2019-07-17 11:48:31 +02:00
philkunz 8b85b6c8bc 1.2.3 2018-09-17 22:32:31 +02:00
philkunz c032ff69d0 fix(core): update 2018-09-17 22:32:31 +02:00
philkunz 0454eef45f update structure 2017-06-15 19:25:12 +02:00
philkunz def368f8ab 1.2.2 2017-06-15 17:53:24 +02:00
philkunz 6853fa28b6 update to latest standards 2017-06-15 17:52:22 +02:00
philkunz 56318f28cf 1.2.1 2016-11-23 12:44:37 +01:00
philkunz 32b26f21cd improve README 2016-11-23 12:44:31 +01:00
55 changed files with 8781 additions and 1029 deletions
+66
View 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
View 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
+18 -3
View File
@@ -1,5 +1,20 @@
node_modules/ .nogit/
# artifacts
coverage/ coverage/
pages/
public/ public/
test/temp/ pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom
-59
View File
@@ -1,59 +0,0 @@
image: hosttoday/ht-docker-node:npmts
stages:
- test
- release
- trigger
- pages
testLEGACY:
stage: test
script:
- npmci test legacy
tags:
- docker
allow_failure: true
testLTS:
stage: test
script:
- npmci test lts
tags:
- docker
testSTABLE:
stage: test
script:
- npmci test stable
tags:
- docker
release:
stage: release
script:
- npmci publish
only:
- tags
tags:
- docker
trigger:
stage: trigger
script:
- npmci trigger
only:
- tags
tags:
- docker
pages:
image: hosttoday/ht-docker-node:npmpage
stage: pages
script:
- npmci command npmpage --host gitlab
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
+38
View File
@@ -0,0 +1,38 @@
{
"@ship.zone/szci": {
"npmGlobalTools": [],
"npmRegistryUrl": "registry.npmjs.org"
},
"@git.zone/cli": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartssh",
"shortDescription": "SSH configuration utilities",
"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"
]
},
"release": {
"registries": [
"https://verdaccio.lossless.digital",
"https://registry.npmjs.org"
],
"accessLevel": "public"
}
},
"@git.zone/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"
}
}
-12
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
+11
View File
@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"type": "node-terminal"
}
]
}
+26
View 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"]
}
}
}
}
}
}
]
}
-5
View File
@@ -1,5 +0,0 @@
FROM hosttoday/ht-docker-node:npmts
COPY ./ /node-app
WORKDIR /node-app
RUN npm install
RUN npmts
+1 -1
View File
@@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2016 Push.Rocks Copyright (c) 2026 Task Venture Capital GmbH <hello@task.vc>
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
-36
View File
@@ -1,36 +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
```
+96
View File
@@ -0,0 +1,96 @@
# Changelog
## 2026-05-01 - 2.0.3 - fix(ssh)
modernize filesystem handling and package exports for NodeNext compatibility
- replace smartfile, smartpromise, and shell-based chmod usage with direct fs operations
- add package exports and tighten TypeScript settings with noImplicitAny and Node types
- update tests to the current tstest runner and move them to a node-specific entry file
- refresh package metadata and dependency versions to match the updated toolchain
## 2024-05-29 - 2.0.2 - maintenance
Release 2.0.2 focused on repository and TypeScript configuration housekeeping.
- Updated project description
- Refined TypeScript configuration
- Updated npm metadata for git host configuration
- Summarizes trivial maintenance commits across 2024-02-09 to 2024-05-29
## 2024-02-09 - 2.0.1 - core
Delivered a core update in the 2.0.1 release line.
- Updated core implementation
## 2023-07-27 - 2.0.0 - core
Delivered a core update for the 2.0.0 release.
- Updated core implementation
## 2022-10-11 - 1.2.7 - core
Introduced a breaking core change by switching the package to ESM.
- BREAKING: switched core package output to ESM
## 2022-10-11 - 1.2.4 to 1.2.6 - core
This release range contained small core maintenance updates.
- Repeated core update fixes delivered across versions 1.2.4, 1.2.5, and 1.2.6
## 2017-06-15 - 1.2.2 - maintenance
Refined project structure in the 1.2.2 release.
- Updated project structure
## 2016-11-23 - 1.2.0 to 1.2.1 - maintenance
This release range focused on standards and documentation improvements.
- Updated project to latest standards
- Improved README documentation
## 2016-06-26 - 1.1.2 to 1.1.5 - core
This release range delivered several core configuration and path-handling improvements.
- Added more flexible path handling
- Created config generation as a standard behavior
- Set rights for stored keys
- Included general maintenance and standards updates
## 2016-06-25 - 1.1.0 to 1.1.1 - core
This release range reworked the internal structure around SSH configuration and key storage.
- Updated structure of `SshConfig`
- Updated `SshKey.store()`
- Performed related structural cleanup
## 2016-06-24 - 1.0.6 to 1.0.7 - core
This release range focused on structural changes in the core implementation.
- Major structural updates
- Additional structure refinements
## 2016-06-01 - 1.0.2 to 1.0.5 - features
This release range added testing, packaging, CI, and key-handling improvements.
- Renamed `Ssh` class to `SshInstance`
- Added support for base64-encoded keys
- Added typings to package metadata
- Expanded and improved test coverage, including an 80% coverage milestone
- Updated dependency and CI configuration
- Improved directory synchronization behavior
## 2016-04-25 - 1.0.1 - core
Expanded the initial API and improved class structure after the first stable release.
- Added `removeKey` and `replaceKey` methods
- Improved sync triggering
- Restructured class files
- Standardized class names to start with capital letters
- Added supporting logic and typing updates
## 2016-04-24 - 1.0.0 - project
Initial public release of the project.
- Started the project structure
- Created `package.json` and enabled CI
- Added `.gitignore`
- Added and improved README documentation
-5
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';
-11
View File
@@ -1,11 +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;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBR3ZCLCtFQUEwRDtBQUFsRCxxREFBQSxXQUFXLENBQUE7QUFDbkIscUVBQWdEO0FBQXhDLDJDQUFBLE1BQU0sQ0FBQTtBQUNkLHFFQUFnRDtBQUF4QywyQ0FBQSxNQUFNLENBQUE7QUFDZCwyRUFBc0Q7QUFBOUMsaURBQUEsU0FBUyxDQUFBIn0=
-3
View File
@@ -1,3 +0,0 @@
import 'typings-global';
import { SshKey } from './smartssh.classes.sshkey';
export declare let sshKeyArrayFromDir: (dirArg: string) => SshKey[];
-7
View File
@@ -1,7 +0,0 @@
"use strict";
require("typings-global");
exports.sshKeyArrayFromDir = function (dirArg) {
let sshKeyArray = []; // TODO
return sshKeyArray;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzc2guY2xhc3Nlcy5oZWxwZXJzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzc2guY2xhc3Nlcy5oZWxwZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwQkFBdUI7QUFJWixRQUFBLGtCQUFrQixHQUFHLFVBQVMsTUFBYztJQUNuRCxJQUFJLFdBQVcsR0FBRyxFQUFFLENBQUEsQ0FBQyxPQUFPO0lBQzVCLE1BQU0sQ0FBQyxXQUFXLENBQUE7QUFDdEIsQ0FBQyxDQUFBIn0=
-17
View File
@@ -1,17 +0,0 @@
/// <reference types="q" />
import 'typings-global';
import { SshKey } from './smartssh.classes.sshkey';
export declare class SshConfig {
private _sshKeyArray;
constructor(sshKeyArrayArg: SshKey[]);
/**
* stores a config file
*/
store(dirPathArg: string): Q.Promise<{}>;
read(dirPathArg: any): Q.Promise<{}>;
}
export interface configObject {
configString: string;
authorized: boolean;
sshKey: SshKey;
}
-47
View File
@@ -1,47 +0,0 @@
"use strict";
require("typings-global");
const plugins = require("./smartssh.plugins");
class SshConfig {
constructor(sshKeyArrayArg) {
this._sshKeyArray = sshKeyArrayArg;
}
/**
* stores a config file
*/
store(dirPathArg) {
let done = plugins.q.defer();
let configArray = [];
let configString;
for (let key in this._sshKeyArray) {
let sshKey = this._sshKeyArray[key];
if (sshKey.host) {
configString = 'Host ' + sshKey.host + '\n' +
' HostName ' + sshKey.host + '\n' +
' IdentityFile ~/.ssh/' + sshKey.host + '\n' +
' StrictHostKeyChecking no' + '\n';
}
configArray.push({
configString: configString,
authorized: sshKey.authorized,
sshKey: sshKey
});
}
let configFile = '';
for (let key in configArray) {
configFile = configFile + configArray[key].configString + '\n';
}
;
plugins.smartfile.memory.toFsSync(configFile, plugins.path.join(dirPathArg, 'config'));
return done.promise;
}
read(dirPathArg) {
let done = plugins.q.defer();
let configArray;
plugins.smartfile.fs.toStringSync(plugins.path.join(dirPathArg, 'config'));
return done.promise;
}
}
exports.SshConfig = SshConfig;
;
;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzc2guY2xhc3Nlcy5zc2hjb25maWcuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNzaC5jbGFzc2VzLnNzaGNvbmZpZy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLDhDQUE2QztBQUk3QztJQUVJLFlBQVksY0FBd0I7UUFDaEMsSUFBSSxDQUFDLFlBQVksR0FBRyxjQUFjLENBQUE7SUFDdEMsQ0FBQztJQUVEOztPQUVHO0lBQ0gsS0FBSyxDQUFDLFVBQWtCO1FBQ3BCLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUE7UUFDNUIsSUFBSSxXQUFXLEdBQW1CLEVBQUUsQ0FBQTtRQUNwQyxJQUFJLFlBQVksQ0FBQTtRQUNoQixHQUFHLENBQUMsQ0FBQyxJQUFJLEdBQUcsSUFBSSxJQUFJLENBQUMsWUFBWSxDQUFDLENBQUMsQ0FBQztZQUNoQyxJQUFJLE1BQU0sR0FBRyxJQUFJLENBQUMsWUFBWSxDQUFDLEdBQUcsQ0FBQyxDQUFBO1lBQ25DLEVBQUUsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDO2dCQUNkLFlBQVksR0FBRyxPQUFPLEdBQUcsTUFBTSxDQUFDLElBQUksR0FBRyx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BQUMsQ0FBQyxDQUFBO1FBRXpFLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7Q0FDSjtBQXpDRCw4QkF5Q0M7QUFBQSxDQUFDO0FBTUQsQ0FBQyJ9
-13
View File
@@ -1,13 +0,0 @@
import 'typings-global';
import { SshKey } from './smartssh.classes.sshkey';
import { SshConfig } from './smartssh.classes.sshconfig';
export declare class SshDir {
private _path;
private _sshKeyArray;
private _sshConfig;
constructor(sshKeyArray: SshKey[], sshConfig: SshConfig, sshDirPathArg?: string);
writeToDir(dirPathArg?: string): void;
readFromDir(dirPathArg?: string): void;
updateDirPath(dirPathArg: string): void;
getKeys(): SshKey[];
}
-41
View File
@@ -1,41 +0,0 @@
"use strict";
require("typings-global");
const plugins = require("./smartssh.plugins");
const helpers = require("./smartssh.classes.helpers");
class SshDir {
constructor(sshKeyArray, sshConfig, sshDirPathArg) {
this._sshKeyArray = sshKeyArray;
this._sshConfig = sshConfig;
if (sshDirPathArg) {
this._path = sshDirPathArg;
}
else {
this._path = plugins.path.join(plugins.smartpath.get.home(), '.ssh/');
}
;
}
writeToDir(dirPathArg) {
let path = this._path;
if (dirPathArg)
path = dirPathArg;
this._sshKeyArray.forEach((sshKeyArg) => {
sshKeyArg.store(path);
});
this._sshConfig.store(path);
}
;
readFromDir(dirPathArg) {
let path = this._path;
if (dirPathArg)
path = dirPathArg;
}
updateDirPath(dirPathArg) {
this._path = dirPathArg;
}
;
getKeys() {
return helpers.sshKeyArrayFromDir(this._path);
}
}
exports.SshDir = SshDir;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzc2guY2xhc3Nlcy5zc2hkaXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNzaC5jbGFzc2VzLnNzaGRpci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3Z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SUFBSSxHQUFHLFVBQVUsQ0FBQTtJQUNyQyxDQUFDO0lBQ0QsYUFBYSxDQUFDLFVBQWtCO1FBQzVCLElBQUksQ0FBQyxLQUFLLEdBQUcsVUFBVSxDQUFBO0lBQzNCLENBQUM7SUFBQSxDQUFDO0lBQ0YsT0FBTztRQUNILE1BQU0sQ0FBQyxPQUFPLENBQUMsa0JBQWtCLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxDQUFBO0lBQ2pELENBQUM7Q0FDSjtBQS9CRCx3QkErQkMifQ==
-34
View File
@@ -1,34 +0,0 @@
import 'typings-global';
import { SshKey } from './smartssh.classes.sshkey';
export declare class SshInstance {
private _sshKeyArray;
private _sshConfig;
private _sshDir;
private _sshSync;
constructor(optionsArg?: {
sshDirPath?: string;
sshSync?: boolean;
});
addKey(sshKeyArg: SshKey): void;
removeKey(sshKeyArg: SshKey): void;
replaceKey(sshKeyOldArg: SshKey, sshKeyNewArg: SshKey): void;
getKey(hostArg: string): SshKey;
readonly sshKeys: SshKey[];
/**
* write SshInstance to disk
*/
writeToDisk(dirPathArg?: string): void;
/**
* read ab SshInstance from disk
*/
readFromDisk(dirPathArg?: string): void;
private _makeConfig();
/**
* method to invoke SshInstance _sync automatically when sshSync is true
*/
private _syncAuto(directionArg);
/**
* private method to sync SshInstance
*/
private _sync(directionArg, dirPathArg?);
}
-98
View File
@@ -1,98 +0,0 @@
"use strict";
require("typings-global");
const smartssh_classes_sshdir_1 = require("./smartssh.classes.sshdir");
const smartssh_classes_sshconfig_1 = require("./smartssh.classes.sshconfig");
class SshInstance {
constructor(optionsArg = {}) {
optionsArg ? void (0) : optionsArg = {};
this._sshKeyArray = [];
this._sshConfig = new smartssh_classes_sshconfig_1.SshConfig(this._sshKeyArray);
this._sshDir = new smartssh_classes_sshdir_1.SshDir(this._sshKeyArray, this._sshConfig, optionsArg.sshDirPath);
this._sshSync = optionsArg.sshSync;
}
;
// altering methods
addKey(sshKeyArg) {
this._syncAuto('from');
this._sshKeyArray.push(sshKeyArg);
this._syncAuto('to');
}
;
removeKey(sshKeyArg) {
this._syncAuto('from');
let filteredArray = this._sshKeyArray.filter((sshKeyArg2) => {
return (sshKeyArg != sshKeyArg2);
});
this._sshKeyArray = filteredArray;
this._syncAuto('to');
}
;
replaceKey(sshKeyOldArg, sshKeyNewArg) {
this._syncAuto('from');
this.removeKey(sshKeyOldArg);
this.addKey(sshKeyNewArg);
this._syncAuto('to');
}
;
//
getKey(hostArg) {
this._syncAuto('from');
let filteredArray = this._sshKeyArray.filter(function (keyArg) {
return (keyArg.host === hostArg);
});
if (filteredArray.length > 0) {
return filteredArray[0];
}
else {
return undefined;
}
}
;
get sshKeys() {
this._syncAuto('from');
return this._sshKeyArray;
}
;
// FS methods
/**
* write SshInstance to disk
*/
writeToDisk(dirPathArg) {
this._sync('to', dirPathArg);
}
/**
* read ab SshInstance from disk
*/
readFromDisk(dirPathArg) {
this._sync('from', dirPathArg);
}
/* ===============================================================
========================= Private Methods ========================
================================================================*/
_makeConfig() {
}
/**
* method to invoke SshInstance _sync automatically when sshSync is true
*/
_syncAuto(directionArg) {
if (this._sshSync)
this._sync(directionArg);
}
/**
* private method to sync SshInstance
*/
_sync(directionArg, dirPathArg) {
if (directionArg === 'from') {
this._sshDir.readFromDir(dirPathArg); // call sync method of sshDir class;
}
else if (directionArg === 'to') {
this._sshDir.writeToDir(dirPathArg);
}
else {
throw new Error("directionArg not recognised. Must be 'to' or 'from'");
}
}
;
}
exports.SshInstance = SshInstance;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzc2guY2xhc3Nlcy5zc2hpbnN0YW5jZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c3NoLmNsYXNzZXMuc3NoaW5zdGFuY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUl2Qix1RUFBZ0Q7QUFDa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0,0 @@
import 'typings-global';
export declare class SshKey {
private _privKey;
private _pubKey;
private _hostVar;
private _authorized;
/**
* the constructor for class SshKey
*/
constructor(optionsArg?: {
private?: string;
public?: string;
host?: string;
authorized?: boolean;
});
host: string;
privKey: string;
privKeyBase64: string;
pubKey: string;
pubKeyBase64: string;
authorized: boolean;
type: any;
read(filePathArg: any): void;
store(dirPathArg: string): void;
}
-96
View File
@@ -1,96 +0,0 @@
"use strict";
require("typings-global");
const plugins = require("./smartssh.plugins");
class SshKey {
/**
* the constructor for class SshKey
*/
constructor(optionsArg = {}) {
this._privKey = optionsArg.private;
this._pubKey = optionsArg.public;
this._hostVar = optionsArg.host;
this._authorized = optionsArg.authorized;
}
;
// this.host
get host() {
return this._hostVar;
}
;
set host(hostArg) {
this._hostVar = hostArg;
}
;
// this.privKey
get privKey() {
return this._privKey;
}
;
set privKey(privateKeyArg) {
this._privKey = privateKeyArg;
}
;
// this.privKeyBase64
get privKeyBase64() {
return plugins.smartstring.base64.encode(this._privKey);
}
set privKeyBase64(privateKeyArg) {
this._privKey = plugins.smartstring.base64.decode(privateKeyArg);
}
// this.pubKey
get pubKey() {
return this._pubKey;
}
set pubKey(publicKeyArg) {
this._pubKey = publicKeyArg;
}
;
// this.pubKeyBase64
get pubKeyBase64() {
return plugins.smartstring.base64.encode(this._pubKey);
}
set pubKeyBase64(publicKeyArg) {
this._pubKey = plugins.smartstring.base64.decode(publicKeyArg);
}
get authorized() {
return this._authorized;
}
set authorized(authorizedArg) {
this._authorized = authorizedArg;
}
get type() {
if (this._privKey && this._pubKey) {
return 'duplex';
}
else if (this._privKey) {
return 'private';
}
else if (this._pubKey) {
return 'public';
}
}
;
set type(someVlueArg) {
console.log('the type of an SshKey connot be set. This value is autpcomputed.');
}
// methods
read(filePathArg) {
}
store(dirPathArg) {
plugins.fs.ensureDirSync(dirPathArg);
let fileNameBase = this.host;
if (this._privKey) {
let filePath = plugins.path.join(dirPathArg, fileNameBase);
plugins.smartfile.memory.toFsSync(this._privKey, filePath);
plugins.shelljs.chmod(600, filePath);
}
;
if (this._pubKey) {
let filePath = plugins.path.join(dirPathArg, fileNameBase + '.pub');
plugins.smartfile.memory.toFsSync(this._pubKey, filePath);
plugins.shelljs.chmod(600, filePath);
}
}
}
exports.SshKey = SshKey;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzc2guY2xhc3Nlcy5zc2hrZXkuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNzaC5jbGFzc2VzLnNzaGtleS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLDhDQUE2QztBQUc3QztJQU1JOztPQUVHO0lBQ0gsWUFBWSxhQUFtRixFQUFFO1FBQzdGLElBQUksQ0FBQyxRQUFRLEdBQUcsVUFBVSxDQUFDLE9BQU8sQ0FBQTtRQUNsQyxJQUFJLENBQUMsT0FBTyxHQUFHLFVBQVUsQ0FBQyxNQUFNLENBQUE7UUFDaEMsSUFBSSxDQUFDLFFBQVEsR0FBRyxVQUFVLENBQUMsSUFBSSxDQUFBO1FBQy9CLElBQUksQ0FBQyxXQUFXLEdBQUcsVUFBVSxDQUFDLFVBQVUsQ0FBQTtJQUM1QyxDQUFDO0lBQUEsQ0FBQztJQUVGLFlBQVk7SUFDWixJQUFJLElBQUk7UUFDSixNQUFNLENBQUMsSUFBSSxDQUFDLFFBQVEsQ0FBQTtJQUN4QixDQUFDO0lBQUEsQ0FBQztJQUNGLElBQUksSUFBSSxDQUFDLE9BQWU7UUFDcEIsSUFBSSxDQUFDLFFBQVEsR0FBRyxPQUFPLENBQUE7SUFDM0IsQ0FBQztJQUFBLENBQUM7SUFFRixlQUFlO0lBQ2YsSUFBSSxPQUFPO1FBQ1AsTUFBTSxDQUFDLElBQUksQ0FBQyxRQUFRLENBQUE7SUFDeEIsQ0FBQztJQUFBLENBQUM7SUFDRixJQUFJLE9BQU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QUFDLElBQUksQ0FBQyxRQUFRLEVBQUMsUUFBUSxDQUFDLENBQUE7WUFDekQsT0FBTyxDQUFDLE9BQU8sQ0FBQyxLQUFLLENBQUMsR0FBRyxFQUFDLFFBQVEsQ0FBQyxDQUFBO1FBQ3ZDLENBQUM7UUFBQSxDQUFDO1FBQ0YsRUFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUM7WUFDZixJQUFJLFFBQVEsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxVQUFVLEVBQUMsWUFBWSxHQUFHLE1BQU0sQ0FBQyxDQUFBO1lBQ2xFLE9BQU8sQ0FBQyxTQUFTLENBQUMsTUFBTSxDQUFDLFFBQVEsQ0FBQyxJQUFJLENBQUMsT0FBTyxFQUFDLFFBQVEsQ0FBQyxDQUFBO1lBQ3hELE9BQU8sQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLEdBQUcsRUFBQyxRQUFRLENBQUMsQ0FBQTtRQUN2QyxDQUFDO0lBQ0wsQ0FBQztDQUNKO0FBOUZELHdCQThGQyJ9
-11
View File
@@ -1,11 +0,0 @@
import 'typings-global';
import * as beautylog from 'beautylog';
import * as fs from 'fs-extra';
import * as minimatch from 'minimatch';
import * as path from 'path';
import * as q from 'q';
import * as shelljs from 'shelljs';
import * as smartfile from 'smartfile';
import * as smartpath from 'smartpath';
import * as smartstring from 'smartstring';
export { beautylog, fs, minimatch, path, q, shelljs, smartfile, smartpath, smartstring };
-21
View File
@@ -1,21 +0,0 @@
"use strict";
require("typings-global");
const beautylog = require("beautylog");
exports.beautylog = beautylog;
const fs = require("fs-extra");
exports.fs = fs;
const minimatch = require("minimatch");
exports.minimatch = minimatch;
const path = require("path");
exports.path = path;
const q = require("q");
exports.q = q;
const shelljs = require("shelljs");
exports.shelljs = shelljs;
const smartfile = require("smartfile");
exports.smartfile = smartfile;
const smartpath = require("smartpath");
exports.smartpath = smartpath;
const smartstring = require("smartstring");
exports.smartstring = smartstring;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzc2gucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c3NoLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2Qix1Q0FBc0M7QUFXbEMsOEJBQVM7QUFWYiwrQkFBOEI7QUFXMUIsZ0JBQUU7QUFWTix1Q0FBc0M7QUFXbEMsOEJBQVM7QUFWYiw2QkFBNEI7QUFXeEIsb0JBQUk7QUFWUix1QkFBc0I7QUFXbEIsY0FBQztBQVZMLG1DQUFrQztBQVc5QiwwQkFBTztBQVZYLHVDQUFzQztBQVdsQyw4QkFBUztBQVZiLHVDQUFzQztBQVdsQyw4QkFBUztBQVZiLDJDQUEwQztBQVd0QyxrQ0FBVyJ9
+38
View File
@@ -0,0 +1,38 @@
{
"@ship.zone/szci": {
"npmGlobalTools": [],
"npmRegistryUrl": "registry.npmjs.org"
},
"@git.zone/cli": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartssh",
"shortDescription": "SSH configuration utilities",
"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"
]
},
"release": {
"registries": [
"https://verdaccio.lossless.digital",
"https://registry.npmjs.org"
],
"accessLevel": "public"
}
},
"@git.zone/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"
}
}
-4
View File
@@ -1,4 +0,0 @@
{
"mode":"default",
"coverageTreshold":50
}
+55 -31
View File
@@ -1,47 +1,71 @@
{ {
"name": "smartssh", "name": "@push.rocks/smartssh",
"version": "1.2.0", "version": "2.0.3",
"description": "setups SSH quickly and in a painless manner", "private": false,
"main": "dist/index.js", "description": "A library for setting up SSH configuration quickly and painlessly.",
"typings": "dist/index.d.ts", "exports": {
".": "./dist_ts/index.js"
},
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
"scripts": { "scripts": {
"test": "(npmts)" "test": "tstest test/",
"testDocker": "tsdocker",
"build": "tsbuild",
"buildDocs": "tsdoc"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://gitlab.com/pushrocks/smartssh.git" "url": "https://code.foss.global/push.rocks/smartssh.git"
}, },
"keywords": [ "keywords": [
"SSH", "SSH",
"ENV", "SSH configuration",
"base64" "SSH keys management",
"automation",
"development tools",
"node.js",
"security",
"server management"
], ],
"author": "Lossless GmbH", "author": "Task Venture Capital GmbH <hello@task.vc>",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://gitlab.com/pushrocks/smartssh/issues" "url": "https://code.foss.global/push.rocks/smartssh/issues"
}, },
"homepage": "https://gitlab.com/pushrocks/smartssh#readme", "homepage": "https://code.foss.global/push.rocks/smartssh",
"dependencies": { "dependencies": {
"@types/fs-extra": "0.0.35", "@push.rocks/smartcrypto": "^2.0.4",
"@types/js-base64": "^2.1.5", "@push.rocks/smartjson": "^6.0.1",
"@types/minimatch": "^2.0.29", "@push.rocks/smartpath": "^6.0.0",
"@types/q": "0.0.32", "@push.rocks/smartstring": "^4.1.1",
"@types/shelljs": "^0.3.33", "@types/fs-extra": "^11.0.4",
"beautylog": "^6.0.0", "@types/ssh2": "^1.15.5",
"fs-extra": "^1.0.0", "fs-extra": "^11.3.4",
"minimatch": "^3.0.3", "minimatch": "^10.2.5",
"q": "^1.4.1", "node-ssh": "^13.2.1"
"shelljs": "^0.7.5",
"smartfile": "^4.1.0",
"smartpath": "^3.2.5",
"smartstring": "^2.0.22",
"typings-global": "^1.0.14"
}, },
"devDependencies": { "devDependencies": {
"@types/should": "^8.1.30", "@git.zone/tsbuild": "^4.4.0",
"npmts-g": "^5.2.8", "@git.zone/tstest": "^3.6.3",
"should": "^11.1.1", "@types/node": "^25.6.0"
"typings-test": "^1.0.3" },
} "files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
".smartconfig.json",
"LICENSE",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
} }
+7732
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -0,0 +1 @@
+134
View 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
View File
@@ -0,0 +1 @@
somePrivateKey
+1
View File
@@ -0,0 +1 @@
somePublicKey
+15
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
View File
@@ -0,0 +1 @@
someExamplePrivateKey
+1
View File
@@ -0,0 +1 @@
someExamplePublicKey
+1
View File
@@ -0,0 +1 @@
someGitHubPrivateKey
+1
View File
@@ -0,0 +1 @@
someGitHubPublicKey
+1
View File
@@ -0,0 +1 @@
somePrivateKey
+1
View File
@@ -0,0 +1 @@
somePublicKey
-1
View File
@@ -1 +0,0 @@
import 'typings-test';
-77
View File
@@ -1,77 +0,0 @@
"use strict";
require("typings-test");
const should = require("should");
const smartssh = require("../dist/index");
const path = require("path");
describe('smartssh', function () {
let testSshInstance;
let testSshKey;
describe('.SshKey', function () {
it("'new' keyword should create a valid SshKey object", function () {
testSshKey = new smartssh.SshKey({
host: 'example.com',
private: 'someExamplePrivateKey',
public: 'someExamplePublicKey'
});
should(testSshKey).be.instanceof(smartssh.SshKey);
});
it('.type should be a valid type', function () {
should(testSshKey.type).equal('duplex');
});
it('.publicKey should be public key', function () {
should(testSshKey.pubKey).equal('someExamplePublicKey');
});
it('.privateKey should be private key', function () {
should(testSshKey.privKey).equal('someExamplePrivateKey');
});
it('.publicKeyBase64 should be public key base 64 encoded', function () {
testSshKey.pubKeyBase64;
});
it('.store() should store the file to disk', function () {
testSshKey.store(path.join(process.cwd(), 'test/temp'));
});
});
describe('.SshInstance', function () {
it("'new' keyword should create a new SshInstance object from class", function () {
testSshInstance = new smartssh.SshInstance({
sshDirPath: path.join(process.cwd(), 'test/temp/')
});
should(testSshInstance).be.instanceof(smartssh.SshInstance);
});
it('.addKey() should accept a new SshKey object', function () {
testSshInstance.addKey(new smartssh.SshKey({
public: 'somePublicKey',
private: 'somePrivateKey',
host: 'gitlab.com'
}));
testSshInstance.addKey(new smartssh.SshKey({
public: 'somePublicKey',
private: 'somePrivateKey',
host: 'bitbucket.org'
}));
testSshInstance.addKey(new smartssh.SshKey({
public: 'someGitHubPublicKey',
private: 'someGitHubPrivateKey',
host: 'github.com'
}));
});
it('.sshKeys should point to an array of sshKeys', function () {
let sshKeyArray = testSshInstance.sshKeys;
should(sshKeyArray).be.Array();
should(sshKeyArray[0].host).equal('gitlab.com');
should(sshKeyArray[1].host).equal('bitbucket.org');
should(sshKeyArray[2].host).equal('github.com');
});
it('.getKey() should get a specific key selected by host', function () {
should(testSshInstance.getKey('github.com').pubKey).equal('someGitHubPublicKey');
});
it('.removeKey() should remove a key', function () {
testSshInstance.removeKey(testSshInstance.getKey('bitbucket.org'));
should(testSshInstance.sshKeys[1].host).equal('github.com');
});
it('it should store to disk', function () {
testSshInstance.writeToDisk();
});
});
});
//# sourceMappingURL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DQUFDLENBQUMsQ0FBQTtRQUNGLEVBQUUsQ0FBQyxrQ0FBa0MsRUFBQztZQUNsQyxlQUFlLENBQUMsU0FBUyxDQUFDLGVBQWUsQ0FBQyxNQUFNLENBQUMsZUFBZSxDQUFDLENBQUMsQ0FBQTtZQUNsRSxNQUFNLENBQUMsZUFBZSxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUMsQ0FBQyxLQUFLLENBQUMsWUFBWSxDQUFDLENBQUE7UUFDL0QsQ0FBQyxDQUFDLENBQUE7UUFDRixFQUFFLENBQUMseUJBQXlCLEVBQUM7WUFDekIsZUFBZSxDQUFDLFdBQVcsRUFBRSxDQUFBO1FBQ2pDLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9
+90
View File
@@ -0,0 +1,90 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import * as smartssh from '../ts/index.js';
import * as path from 'path';
const testDir = path.join(process.cwd(), '.nogit/test/temp');
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 () => {
await testSshKey.store(testDir);
});
// SSH INstance
tap.test("'new' keyword should create a new SshInstance object from class", async () => {
testSshInstance = new smartssh.SshInstance({
sshDirPath: testDir,
});
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 () => {
const sshKey = testSshInstance.getKey('github.com');
expect(sshKey).toBeInstanceOf(smartssh.SshKey);
expect(sshKey?.pubKey).toEqual('someGitHubPublicKey');
});
tap.test('.removeKey() should remove a key', async () => {
const sshKey = testSshInstance.getKey('bitbucket.org');
expect(sshKey).toBeInstanceOf(smartssh.SshKey);
testSshInstance.removeKey(sshKey!);
expect(testSshInstance.sshKeys[1].host).toEqual('github.com');
});
tap.test('it should store to disk', async () => {
testSshInstance.writeToDisk();
});
export default tap.start();
-75
View File
@@ -1,75 +0,0 @@
import 'typings-test'
import * as should from 'should'
import smartssh = require('../dist/index')
import path = require('path')
describe('smartssh',function(){
let testSshInstance: smartssh.SshInstance
let testSshKey: smartssh.SshKey
describe('.SshKey',function(){
it("'new' keyword should create a valid SshKey object",function(){
testSshKey = new smartssh.SshKey({
host: 'example.com',
private: 'someExamplePrivateKey',
public: 'someExamplePublicKey'
})
should(testSshKey).be.instanceof(smartssh.SshKey)
})
it('.type should be a valid type',function(){
should(testSshKey.type).equal('duplex')
})
it('.publicKey should be public key',function(){
should(testSshKey.pubKey).equal('someExamplePublicKey')
})
it('.privateKey should be private key',function(){
should(testSshKey.privKey).equal('someExamplePrivateKey')
})
it('.publicKeyBase64 should be public key base 64 encoded',function(){
testSshKey.pubKeyBase64
})
it('.store() should store the file to disk',function(){
testSshKey.store(path.join(process.cwd(),'test/temp'))
})
})
describe('.SshInstance',function(){
it("'new' keyword should create a new SshInstance object from class",function(){
testSshInstance = new smartssh.SshInstance({
sshDirPath: path.join(process.cwd(),'test/temp/')
})
should(testSshInstance).be.instanceof(smartssh.SshInstance)
})
it('.addKey() should accept a new SshKey object',function(){
testSshInstance.addKey(new smartssh.SshKey({
public: 'somePublicKey',
private: 'somePrivateKey',
host: 'gitlab.com'
}))
testSshInstance.addKey(new smartssh.SshKey({
public: 'somePublicKey',
private: 'somePrivateKey',
host: 'bitbucket.org'
}))
testSshInstance.addKey(new smartssh.SshKey({
public: 'someGitHubPublicKey',
private: 'someGitHubPrivateKey',
host: 'github.com'
}))
})
it('.sshKeys should point to an array of sshKeys',function(){
let sshKeyArray = testSshInstance.sshKeys
should(sshKeyArray).be.Array()
should(sshKeyArray[0].host).equal('gitlab.com')
should(sshKeyArray[1].host).equal('bitbucket.org')
should(sshKeyArray[2].host).equal('github.com')
})
it('.getKey() should get a specific key selected by host',function(){
should(testSshInstance.getKey('github.com').pubKey).equal('someGitHubPublicKey')
})
it('.removeKey() should remove a key',function(){
testSshInstance.removeKey(testSshInstance.getKey('bitbucket.org'))
should(testSshInstance.sshKeys[1].host).equal('github.com')
})
it('it should store to disk',function(){
testSshInstance.writeToDisk()
})
})
})
+8
View File
@@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartssh',
version: '2.0.3',
description: 'A library for setting up SSH configuration quickly and painlessly.'
}
+5 -6
View File
@@ -1,7 +1,6 @@
import 'typings-global' import * as plugins from './smartssh.plugins.js';
import * as plugins from './smartssh.plugins'
export {SshInstance} from './smartssh.classes.sshinstance' export { SshInstance } from './smartssh.classes.sshinstance.js';
export {SshKey} from './smartssh.classes.sshkey' export { SshKey } from './smartssh.classes.sshkey.js';
export {SshDir} from './smartssh.classes.sshdir' export { SshDir } from './smartssh.classes.sshdir.js';
export {SshConfig} from './smartssh.classes.sshconfig' export { SshConfig } from './smartssh.classes.sshconfig.js';
+6 -7
View File
@@ -1,8 +1,7 @@
import 'typings-global' import * as plugins from './smartssh.plugins.js';
import * as plugins from './smartssh.plugins' import { SshKey } from './smartssh.classes.sshkey.js';
import {SshKey} from './smartssh.classes.sshkey'
export let sshKeyArrayFromDir = function(dirArg: string): SshKey[]{ export let sshKeyArrayFromDir = function (dirArg: string): SshKey[] {
let sshKeyArray = [] // TODO let sshKeyArray: SshKey[] = []; // TODO
return sshKeyArray return sshKeyArray;
} };
+35 -35
View File
@@ -1,54 +1,54 @@
import 'typings-global' import * as plugins from './smartssh.plugins.js';
import * as plugins from './smartssh.plugins' import * as helpers from './smartssh.classes.helpers.js';
import * as helpers from './smartssh.classes.helpers' import { SshKey } from './smartssh.classes.sshkey.js';
import {SshKey} from './smartssh.classes.sshkey'
export class SshConfig { export class SshConfig {
private _sshKeyArray: SshKey[] private _sshKeyArray: SshKey[];
constructor(sshKeyArrayArg: SshKey[]) { constructor(sshKeyArrayArg: SshKey[]) {
this._sshKeyArray = sshKeyArrayArg this._sshKeyArray = sshKeyArrayArg;
} }
/** /**
* stores a config file * stores a config file
*/ */
store(dirPathArg: string) { store(dirPathArg: string) {
let done = plugins.q.defer() plugins.fs.ensureDirSync(dirPathArg);
let configArray: configObject[] = [] let configArray: configObject[] = [];
let configString for (const sshKey of this._sshKeyArray) {
for (let key in this._sshKeyArray) { let configString = '';
let sshKey = this._sshKeyArray[key]
if (sshKey.host) { if (sshKey.host) {
configString = 'Host ' + sshKey.host + '\n' + configString =
' HostName ' + sshKey.host + '\n' + 'Host ' +
' IdentityFile ~/.ssh/' + sshKey.host + '\n' + sshKey.host +
' StrictHostKeyChecking no' + '\n' '\n' +
' HostName ' +
sshKey.host +
'\n' +
' IdentityFile ~/.ssh/' +
sshKey.host +
'\n' +
' StrictHostKeyChecking no' +
'\n';
} }
configArray.push({ configArray.push({
configString: configString, configString: configString,
authorized: sshKey.authorized, authorized: sshKey.authorized,
sshKey: sshKey sshKey: sshKey,
}) });
} }
let configFile: string = '' let configFile: string = '';
for (let key in configArray) { for (const config of configArray) {
configFile = configFile + configArray[key].configString + '\n' configFile = configFile + config.configString + '\n';
};
plugins.smartfile.memory.toFsSync(configFile,plugins.path.join(dirPathArg,'config'))
return done.promise
} }
read(dirPathArg) { plugins.fs.writeFileSync(plugins.path.join(dirPathArg, 'config'), configFile);
let done = plugins.q.defer()
let configArray: configObject[]
plugins.smartfile.fs.toStringSync(plugins.path.join(dirPathArg,'config'))
return done.promise
} }
}; read(dirPathArg: string) {
return plugins.fs.readFileSync(plugins.path.join(dirPathArg, 'config'), 'utf8');
}
}
export interface configObject { export interface configObject {
configString: string configString: string;
authorized: boolean authorized: boolean;
sshKey: SshKey sshKey: SshKey;
}; }
+38 -29
View File
@@ -1,38 +1,47 @@
import 'typings-global' import * as plugins from './smartssh.plugins.js';
import * as plugins from './smartssh.plugins' import * as helpers from './smartssh.classes.helpers.js';
import * as helpers from './smartssh.classes.helpers' import { SshInstance } from './smartssh.classes.sshinstance.js';
import {SshInstance} from './smartssh.classes.sshinstance' import { SshKey } from './smartssh.classes.sshkey.js';
import {SshKey} from './smartssh.classes.sshkey' import { SshConfig } from './smartssh.classes.sshconfig.js';
import {SshConfig} from './smartssh.classes.sshconfig'
export class SshDir { // sshDir class -> NOT EXPORTED, ONLY FOR INTERNAL USE export class SshDir {
private _path: string // the path of the ssh directory // sshDir class -> NOT EXPORTED, ONLY FOR INTERNAL USE
private _sshKeyArray: SshKey[] private _path: string; // the path of the ssh directory
private _sshConfig: SshConfig private _sshKeyArray: SshKey[];
constructor(sshKeyArray: SshKey[],sshConfig: SshConfig,sshDirPathArg?: string) { private _sshConfig: SshConfig;
this._sshKeyArray = sshKeyArray constructor(sshKeyArray: SshKey[], sshConfig: SshConfig, sshDirPathArg?: string) {
this._sshConfig = sshConfig this._sshKeyArray = sshKeyArray;
this._sshConfig = sshConfig;
if (sshDirPathArg) { if (sshDirPathArg) {
this._path = sshDirPathArg this._path = sshDirPathArg;
} else { } else {
this._path = plugins.path.join(plugins.smartpath.get.home(),'.ssh/') this._path = plugins.path.join(plugins.smartpath.get.home(), '.ssh/');
};
} }
writeToDir(dirPathArg?: string) { // syncs sshInstance to directory }
let path = this._path
if (dirPathArg) path = dirPathArg writeToDir(dirPathArg?: string) {
// syncs sshInstance to directory
let path = this._path;
if (dirPathArg) path = dirPathArg;
this._sshKeyArray.forEach((sshKeyArg) => { this._sshKeyArray.forEach((sshKeyArg) => {
sshKeyArg.store(path) sshKeyArg.store(path);
}) });
this._sshConfig.store(path) this._sshConfig.store(path);
}; }
readFromDir(dirPathArg?: string) { // syncs sshInstance from directory
let path = this._path /**
if (dirPathArg) path = dirPathArg * TODO: implement reading of directories
*/
readFromDir(dirPathArg?: string) {
// syncs sshInstance from directory
let path = this._path;
if (dirPathArg) path = dirPathArg;
} }
updateDirPath(dirPathArg: string) { updateDirPath(dirPathArg: string) {
this._path = dirPathArg this._path = dirPathArg;
}; }
getKeys() { getKeys() {
return helpers.sshKeyArrayFromDir(this._path) return helpers.sshKeyArrayFromDir(this._path);
} }
} }
+63 -64
View File
@@ -1,61 +1,63 @@
import 'typings-global' import * as plugins from './smartssh.plugins.js';
import * as plugins from './smartssh.plugins' import * as helpers from './smartssh.classes.helpers.js';
import * as helpers from './smartssh.classes.helpers'
import {SshDir} from './smartssh.classes.sshdir' import { SshDir } from './smartssh.classes.sshdir.js';
import {SshConfig} from './smartssh.classes.sshconfig' import { SshConfig } from './smartssh.classes.sshconfig.js';
import {SshKey} from './smartssh.classes.sshkey' import { SshKey } from './smartssh.classes.sshkey.js';
/**
* SshInstance is the main class dealing with ssh management
*/
export class SshInstance { export class SshInstance {
private _sshKeyArray: SshKey[] // holds all ssh keys private _sshKeyArray: SshKey[]; // holds all ssh keys
private _sshConfig: SshConfig // sshConfig (e.g. represents ~/.ssh/config) private _sshConfig: SshConfig; // sshConfig (e.g. represents ~/.ssh/config)
private _sshDir: SshDir // points to sshDir class instance. private _sshDir: SshDir; // points to sshDir class instance.
private _sshSync: boolean // if set to true, the ssh dir will be kept in sync automatically private _sshSync: boolean; // if set to true, the ssh dir will be kept in sync automatically
constructor(optionsArg: {sshDirPath?: string,sshSync?: boolean}= {}) { constructor(optionsArg: { sshDirPath?: string; sshSync?: boolean } = {}) {
optionsArg ? void(0) : optionsArg = {} optionsArg ? void 0 : (optionsArg = {});
this._sshKeyArray = [] this._sshKeyArray = [];
this._sshConfig = new SshConfig(this._sshKeyArray) this._sshConfig = new SshConfig(this._sshKeyArray);
this._sshDir = new SshDir(this._sshKeyArray,this._sshConfig,optionsArg.sshDirPath) this._sshDir = new SshDir(this._sshKeyArray, this._sshConfig, optionsArg.sshDirPath);
this._sshSync = optionsArg.sshSync this._sshSync = optionsArg.sshSync ?? false;
}; }
// altering methods // altering methods
addKey(sshKeyArg: SshKey) { addKey(sshKeyArg: SshKey) {
this._syncAuto('from') this._syncAuto('from');
this._sshKeyArray.push(sshKeyArg) this._sshKeyArray.push(sshKeyArg);
this._syncAuto('to') this._syncAuto('to');
}; }
removeKey(sshKeyArg: SshKey) { removeKey(sshKeyArg: SshKey) {
this._syncAuto('from') this._syncAuto('from');
let filteredArray = this._sshKeyArray.filter((sshKeyArg2: SshKey) => { let filteredArray = this._sshKeyArray.filter((sshKeyArg2: SshKey) => {
return (sshKeyArg != sshKeyArg2) return sshKeyArg != sshKeyArg2;
}) });
this._sshKeyArray = filteredArray this._sshKeyArray = filteredArray;
this._syncAuto('to') this._syncAuto('to');
}; }
replaceKey(sshKeyOldArg: SshKey,sshKeyNewArg: SshKey) { replaceKey(sshKeyOldArg: SshKey, sshKeyNewArg: SshKey) {
this._syncAuto('from') this._syncAuto('from');
this.removeKey(sshKeyOldArg) this.removeKey(sshKeyOldArg);
this.addKey(sshKeyNewArg) this.addKey(sshKeyNewArg);
this._syncAuto('to') this._syncAuto('to');
}; }
// // non altering methods
getKey(hostArg: string): SshKey { getKey(hostArg: string): SshKey | undefined {
this._syncAuto('from') this._syncAuto('from');
let filteredArray = this._sshKeyArray.filter(function(keyArg){ let filteredArray = this._sshKeyArray.filter(function (keyArg) {
return (keyArg.host === hostArg) return keyArg.host === hostArg;
}) });
if (filteredArray.length > 0) { if (filteredArray.length > 0) {
return filteredArray[0] return filteredArray[0];
} else { } else {
return undefined return undefined;
}
} }
};
get sshKeys(): SshKey[] { get sshKeys(): SshKey[] {
this._syncAuto('from') this._syncAuto('from');
return this._sshKeyArray return this._sshKeyArray;
}; }
// FS methods // FS methods
@@ -63,41 +65,38 @@ export class SshInstance {
* write SshInstance to disk * write SshInstance to disk
*/ */
writeToDisk(dirPathArg?: string) { writeToDisk(dirPathArg?: string) {
this._sync('to',dirPathArg) this._sync('to', dirPathArg);
} }
/** /**
* read ab SshInstance from disk * read ab SshInstance from disk
*/ */
readFromDisk(dirPathArg?: string) { readFromDisk(dirPathArg?: string) {
this._sync('from',dirPathArg) this._sync('from', dirPathArg);
} }
/* =============================================================== /* ===============================================================
========================= Private Methods ======================== ========================= Private Methods ========================
================================================================*/ ================================================================*/
private _makeConfig () {
}
/** /**
* method to invoke SshInstance _sync automatically when sshSync is true * method to invoke SshInstance _sync automatically when sshSync is true
*/ */
private _syncAuto(directionArg) { private _syncAuto(directionArg: 'from' | 'to') {
if (this._sshSync) this._sync(directionArg) if (this._sshSync) {
// if auto sync is not enabled, do nothing
this._sync(directionArg);
}
} }
/** /**
* private method to sync SshInstance * private method to sync SshInstance
*/ */
private _sync(directionArg: string,dirPathArg?: string) { private _sync(directionArg: 'from' | 'to', dirPathArg?: string) {
if (directionArg === 'from') { if (directionArg === 'from') {
this._sshDir.readFromDir(dirPathArg) // call sync method of sshDir class; this._sshDir.readFromDir(dirPathArg); // call sync method of sshDir class;
} else if (directionArg === 'to') { } else if (directionArg === 'to') {
this._sshDir.writeToDir(dirPathArg) this._sshDir.writeToDir(dirPathArg);
} else { }
throw new Error("directionArg not recognised. Must be 'to' or 'from'")
} }
};
} }
+63 -60
View File
@@ -1,99 +1,102 @@
import 'typings-global' import * as plugins from './smartssh.plugins.js';
import * as plugins from './smartssh.plugins' import * as helpers from './smartssh.classes.helpers.js';
import * as helpers from './smartssh.classes.helpers'
export class SshKey { export class SshKey {
private _privKey: string private _privKey: string;
private _pubKey: string private _pubKey: string;
private _hostVar: string private _hostVar: string;
private _authorized: boolean private _authorized: boolean;
/** /**
* the constructor for class SshKey * the constructor for class SshKey
*/ */
constructor(optionsArg: {private?: string,public?: string,host?: string,authorized?: boolean}= {}) { constructor(
this._privKey = optionsArg.private optionsArg: { private?: string; public?: string; host?: string; authorized?: boolean } = {}
this._pubKey = optionsArg.public ) {
this._hostVar = optionsArg.host this._privKey = optionsArg.private ?? '';
this._authorized = optionsArg.authorized this._pubKey = optionsArg.public ?? '';
}; this._hostVar = optionsArg.host ?? '';
this._authorized = optionsArg.authorized ?? false;
}
// this.host // this.host
get host(){ get host() {
return this._hostVar return this._hostVar;
}; }
set host(hostArg: string){ set host(hostArg: string) {
this._hostVar = hostArg this._hostVar = hostArg;
}; }
// this.privKey // this.privKey
get privKey(){ get privKey() {
return this._privKey return this._privKey;
}; }
set privKey(privateKeyArg: string){ set privKey(privateKeyArg: string) {
this._privKey = privateKeyArg this._privKey = privateKeyArg;
}; }
// this.privKeyBase64 // this.privKeyBase64
get privKeyBase64(){ get privKeyBase64() {
return plugins.smartstring.base64.encode(this._privKey) return plugins.smartstring.base64.encode(this._privKey);
} }
set privKeyBase64(privateKeyArg: string) { set privKeyBase64(privateKeyArg: string) {
this._privKey = plugins.smartstring.base64.decode(privateKeyArg) this._privKey = plugins.smartstring.base64.decode(privateKeyArg);
} }
// this.pubKey // this.pubKey
get pubKey(){ get pubKey() {
return this._pubKey return this._pubKey;
}
set pubKey(publicKeyArg: string) {
this._pubKey = publicKeyArg;
} }
set pubKey(publicKeyArg: string){
this._pubKey = publicKeyArg
};
// this.pubKeyBase64 // this.pubKeyBase64
get pubKeyBase64(){ get pubKeyBase64() {
return plugins.smartstring.base64.encode(this._pubKey) return plugins.smartstring.base64.encode(this._pubKey);
} }
set pubKeyBase64(publicKeyArg: string) { set pubKeyBase64(publicKeyArg: string) {
this._pubKey = plugins.smartstring.base64.decode(publicKeyArg) this._pubKey = plugins.smartstring.base64.decode(publicKeyArg);
} }
get authorized(){ get authorized() {
return this._authorized return this._authorized;
} }
set authorized(authorizedArg: boolean){ set authorized(authorizedArg: boolean) {
this._authorized = authorizedArg this._authorized = authorizedArg;
} }
get type(){
/**
* returns wether there is a private, a public or both keys
*/
get type() {
if (this._privKey && this._pubKey) { if (this._privKey && this._pubKey) {
return 'duplex' return 'duplex';
} else if (this._privKey) { } else if (this._privKey) {
return 'private' return 'private';
} else if (this._pubKey) { } else if (this._pubKey) {
return 'public' return 'public';
} }
}; }
set type(someVlueArg: any){ set type(someVlueArg: any) {
console.log('the type of an SshKey connot be set. This value is autpcomputed.') console.log('the type of an SshKey connot be set. This value is autocomputed.');
} }
// methods // methods
read(filePathArg) { read(filePathArg: string) {}
} async store(dirPathArg: string) {
plugins.fs.ensureDirSync(dirPathArg);
store(dirPathArg: string) { let fileNameBase = this.host;
plugins.fs.ensureDirSync(dirPathArg)
let fileNameBase = this.host
if (this._privKey) { if (this._privKey) {
let filePath = plugins.path.join(dirPathArg,fileNameBase) let filePath = plugins.path.join(dirPathArg, fileNameBase);
plugins.smartfile.memory.toFsSync(this._privKey,filePath) plugins.fs.writeFileSync(filePath, this._privKey);
plugins.shelljs.chmod(600,filePath) plugins.fs.chmodSync(filePath, 0o600);
}; }
if (this._pubKey) { if (this._pubKey) {
let filePath = plugins.path.join(dirPathArg,fileNameBase + '.pub') let filePath = plugins.path.join(dirPathArg, fileNameBase + '.pub');
plugins.smartfile.memory.toFsSync(this._pubKey,filePath) plugins.fs.writeFileSync(filePath, this._pubKey);
plugins.shelljs.chmod(600,filePath) plugins.fs.chmodSync(filePath, 0o600);
} }
} }
} }
+21 -19
View File
@@ -1,22 +1,24 @@
import 'typings-global' // node native
import * as beautylog from 'beautylog' import fs from 'fs-extra';
import * as fs from 'fs-extra' import * as path from 'path';
import * as minimatch from 'minimatch'
import * as path from 'path' export { fs, path };
import * as q from 'q'
import * as shelljs from 'shelljs' // @push.rocks scope
import * as smartfile from 'smartfile' import * as smartjson from '@push.rocks/smartjson';
import * as smartpath from 'smartpath' import * as smartcrypto from '@push.rocks/smartcrypto';
import * as smartstring from 'smartstring' import * as smartpath from '@push.rocks/smartpath';
import * as smartstring from '@push.rocks/smartstring';
export { export {
beautylog, smartjson,
fs, smartcrypto,
minimatch,
path,
q,
shelljs,
smartfile,
smartpath, smartpath,
smartstring smartstring,
} };
// third party scope
import * as minimatch from 'minimatch';
import * as nodeSsh from 'node-ssh';
export { minimatch, nodeSsh };
+16
View File
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noImplicitAny": true,
"esModuleInterop": true,
"verbatimModuleSyntax": true,
"types": ["node"]
},
"exclude": [
"dist_*/**/*.d.ts"
]
}
-3
View File
@@ -1,3 +0,0 @@
{
"extends": "tslint-config-standard"
}