Compare commits

...

11 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
20 changed files with 7797 additions and 16953 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
-128
View File
@@ -1,128 +0,0 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
before_script:
- npm install -g @shipzone/npmci
# ====================
# security stage
# ====================
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
tags:
- docker
allow_failure: true
# ====================
# test stage
# ====================
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
tags:
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
stage: metadata
script:
- npmci node install stable
- npmci npm prepare
- npmci npm install
- npmci command npm run buildDocs
tags:
- lossless
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true
+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"
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2016 Lossless GmbH 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
+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
+30 -9
View File
@@ -1,17 +1,38 @@
{ {
"npmci": { "@ship.zone/szci": {
"npmGlobalTools": [], "npmGlobalTools": [],
"npmAccessLevel": "public" "npmRegistryUrl": "registry.npmjs.org"
}, },
"gitzone": { "@git.zone/cli": {
"projectType": "npm", "projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "code.foss.global",
"gitscope": "pushrocks", "gitscope": "push.rocks",
"gitrepo": "smartssh", "gitrepo": "smartssh",
"description": "setups SSH quickly and in a painless manner", "shortDescription": "SSH configuration utilities",
"npmPackagename": "@pushrocks/smartssh", "description": "A library for setting up SSH configuration quickly and painlessly.",
"license": "MIT" "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"
} }
} }
-12983
View File
File diff suppressed because it is too large Load Diff
+33 -25
View File
@@ -1,49 +1,55 @@
{ {
"name": "@pushrocks/smartssh", "name": "@push.rocks/smartssh",
"version": "2.0.0", "version": "2.0.3",
"private": false, "private": false,
"description": "setups SSH quickly and in a painless manner", "description": "A library for setting up SSH configuration quickly and painlessly.",
"exports": {
".": "./dist_ts/index.js"
},
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
"type": "module", "type": "module",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "tstest test/",
"testDocker": "tsdocker", "testDocker": "tsdocker",
"build": "(tsbuild --allowimplicitany)", "build": "tsbuild",
"buildDocs": "tsdoc" "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": {
"@pushrocks/smartfile": "^10.0.5", "@push.rocks/smartcrypto": "^2.0.4",
"@pushrocks/smartpath": "^5.0.5", "@push.rocks/smartjson": "^6.0.1",
"@pushrocks/smartpromise": "^3.0.2", "@push.rocks/smartpath": "^6.0.0",
"@pushrocks/smartshell": "^2.0.23", "@push.rocks/smartstring": "^4.1.1",
"@pushrocks/smartstring": "^4.0.5", "@types/fs-extra": "^11.0.4",
"@types/fs-extra": "^9.0.13", "@types/ssh2": "^1.15.5",
"@types/minimatch": "^5.1.2", "fs-extra": "^11.3.4",
"fs-extra": "^10.1.0", "minimatch": "^10.2.5",
"minimatch": "^5.1.0" "node-ssh": "^13.2.1"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.11", "@git.zone/tsbuild": "^4.4.0",
"@gitzone/tsrun": "^1.2.6", "@git.zone/tstest": "^3.6.3",
"@gitzone/tstest": "^1.0.24", "@types/node": "^25.6.0"
"@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^18.8.4"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
@@ -54,6 +60,8 @@
"dist_ts_web/**/*", "dist_ts_web/**/*",
"assets/**/*", "assets/**/*",
"cli.js", "cli.js",
".smartconfig.json",
"LICENSE",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
], ],
+7197 -3678
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -0,0 +1 @@
+120 -54
View File
@@ -1,68 +1,134 @@
# @pushrocks/smartssh # @push.rocks/smartssh
setups SSH quickly and in a painless manner setup SSH quickly and in a painless manner
## Availabililty and Links ## Install
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartssh)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartssh)
* [github.com (source mirror)](https://github.com/pushrocks/smartssh)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartssh/)
## Status for master 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:
Status Category | Status Badge ```bash
-- | -- npm install @push.rocks/smartssh --save
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartssh/badges/master/pipeline.svg)](https://lossless.cloud) ```
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartssh/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartssh)](https://lossless.cloud) or
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartssh)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud) ```bash
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) yarn add @push.rocks/smartssh
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud) ```
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartssh)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartssh)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartssh)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage ## Usage
```javascript `@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.
var smartssh = require('smartssh');
var sshInstance = new smartssh.sshInstance({ #### Setting Up an SSH Instance
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; 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
}); });
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
``` ```
#### Working with SSH Keys
## Contribution SSH keys can be managed using the `SshKey` class. You can add, remove, or retrieve keys from your SSH instance.
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :) ```typescript
import { SshKey } from '@push.rocks/smartssh';
For further information read the linked docs at the top of this readme. // 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
});
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh) // Adding the SSH key to the instance
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy) mySshInstance.addKey(mySshKey);
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com) // 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.
+12 -6
View File
@@ -1,7 +1,9 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@git.zone/tstest/tapbundle';
import * as smartssh from '../ts/index.js'; import * as smartssh from '../ts/index.js';
import * as path from 'path'; import * as path from 'path';
const testDir = path.join(process.cwd(), '.nogit/test/temp');
let testSshInstance: smartssh.SshInstance; let testSshInstance: smartssh.SshInstance;
let testSshKey: smartssh.SshKey; let testSshKey: smartssh.SshKey;
tap.test('should create a valid SshKey object', async () => { tap.test('should create a valid SshKey object', async () => {
@@ -26,13 +28,13 @@ tap.test('.publicKeyBase64 should be public key base 64 encoded', async () => {
testSshKey.pubKeyBase64; testSshKey.pubKeyBase64;
}); });
tap.test('.store() should store the file to disk', async () => { tap.test('.store() should store the file to disk', async () => {
testSshKey.store(path.join(process.cwd(), 'test/temp')); await testSshKey.store(testDir);
}); });
// SSH INstance // SSH INstance
tap.test("'new' keyword should create a new SshInstance object from class", async () => { tap.test("'new' keyword should create a new SshInstance object from class", async () => {
testSshInstance = new smartssh.SshInstance({ testSshInstance = new smartssh.SshInstance({
sshDirPath: path.join(process.cwd(), 'test/temp/'), sshDirPath: testDir,
}); });
expect(testSshInstance).toBeInstanceOf(smartssh.SshInstance); expect(testSshInstance).toBeInstanceOf(smartssh.SshInstance);
}); });
@@ -69,11 +71,15 @@ tap.test('.sshKeys should point to an array of sshKeys', async () => {
}); });
tap.test('.getKey() should get a specific key selected by host', async () => { tap.test('.getKey() should get a specific key selected by host', async () => {
expect(testSshInstance.getKey('github.com').pubKey).toEqual('someGitHubPublicKey'); const sshKey = testSshInstance.getKey('github.com');
expect(sshKey).toBeInstanceOf(smartssh.SshKey);
expect(sshKey?.pubKey).toEqual('someGitHubPublicKey');
}); });
tap.test('.removeKey() should remove a key', async () => { tap.test('.removeKey() should remove a key', async () => {
testSshInstance.removeKey(testSshInstance.getKey('bitbucket.org')); const sshKey = testSshInstance.getKey('bitbucket.org');
expect(sshKey).toBeInstanceOf(smartssh.SshKey);
testSshInstance.removeKey(sshKey!);
expect(testSshInstance.sshKeys[1].host).toEqual('github.com'); expect(testSshInstance.sshKeys[1].host).toEqual('github.com');
}); });
@@ -81,4 +87,4 @@ tap.test('it should store to disk', async () => {
testSshInstance.writeToDisk(); testSshInstance.writeToDisk();
}); });
tap.start(); export default tap.start();
+4 -4
View File
@@ -1,8 +1,8 @@
/** /**
* autocreated commitinfo by @pushrocks/commitinfo * autocreated commitinfo by @push.rocks/commitinfo
*/ */
export const commitinfo = { export const commitinfo = {
name: '@pushrocks/smartssh', name: '@push.rocks/smartssh',
version: '2.0.0', version: '2.0.3',
description: 'setups SSH quickly and in a painless manner' description: 'A library for setting up SSH configuration quickly and painlessly.'
} }
+1 -1
View File
@@ -2,6 +2,6 @@ import * as plugins from './smartssh.plugins.js';
import { SshKey } from './smartssh.classes.sshkey.js'; import { SshKey } from './smartssh.classes.sshkey.js';
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;
}; };
+8 -14
View File
@@ -12,11 +12,10 @@ export class SshConfig {
* stores a config file * stores a config file
*/ */
store(dirPathArg: string) { store(dirPathArg: string) {
let done = plugins.smartpromise.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 = configString =
'Host ' + 'Host ' +
@@ -38,18 +37,13 @@ export class SshConfig {
}); });
} }
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')); plugins.fs.writeFileSync(plugins.path.join(dirPathArg, 'config'), configFile);
return done.promise;
} }
read(dirPathArg) { read(dirPathArg: string) {
let done = plugins.smartpromise.defer(); return plugins.fs.readFileSync(plugins.path.join(dirPathArg, 'config'), 'utf8');
let configArray: configObject[];
plugins.smartfile.fs.toStringSync(plugins.path.join(dirPathArg, 'config'));
return done.promise;
} }
} }
+2 -2
View File
@@ -18,7 +18,7 @@ export class SshInstance {
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
@@ -43,7 +43,7 @@ export class SshInstance {
} }
// non altering methods // 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;
+9 -13
View File
@@ -7,20 +7,16 @@ export class SshKey {
private _hostVar: string; private _hostVar: string;
private _authorized: boolean; private _authorized: boolean;
private _smarthshellInstance = new plugins.shelljs.Smartshell({
executor: 'bash',
});
/** /**
* the constructor for class SshKey * the constructor for class SshKey
*/ */
constructor( constructor(
optionsArg: { private?: string; public?: string; host?: string; authorized?: boolean } = {} optionsArg: { private?: string; public?: string; host?: string; authorized?: boolean } = {}
) { ) {
this._privKey = optionsArg.private; this._privKey = optionsArg.private ?? '';
this._pubKey = optionsArg.public; this._pubKey = optionsArg.public ?? '';
this._hostVar = optionsArg.host; this._hostVar = optionsArg.host ?? '';
this._authorized = optionsArg.authorized; this._authorized = optionsArg.authorized ?? false;
} }
// this.host // this.host
@@ -87,20 +83,20 @@ export class SshKey {
} }
// methods // methods
read(filePathArg) {} read(filePathArg: string) {}
async store(dirPathArg: string) { async store(dirPathArg: string) {
plugins.fs.ensureDirSync(dirPathArg); plugins.fs.ensureDirSync(dirPathArg);
let fileNameBase = this.host; 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);
await this._smarthshellInstance.exec(`chmod 0600 ${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);
await this._smarthshellInstance.exec(`chmod 0600 ${filePath}`); plugins.fs.chmodSync(filePath, 0o600);
} }
} }
} }
+22 -8
View File
@@ -1,10 +1,24 @@
import * as fs from 'fs-extra'; // node native
import * as minimatch from 'minimatch'; import fs from 'fs-extra';
import * as path from 'path'; import * as path from 'path';
import * as smartpromise from '@pushrocks/smartpromise';
import * as shelljs from '@pushrocks/smartshell';
import * as smartfile from '@pushrocks/smartfile';
import * as smartpath from '@pushrocks/smartpath';
import * as smartstring from '@pushrocks/smartstring';
export { fs, minimatch, path, smartpromise, shelljs, smartfile, smartpath, smartstring }; export { fs, path };
// @push.rocks scope
import * as smartjson from '@push.rocks/smartjson';
import * as smartcrypto from '@push.rocks/smartcrypto';
import * as smartpath from '@push.rocks/smartpath';
import * as smartstring from '@push.rocks/smartstring';
export {
smartjson,
smartcrypto,
smartpath,
smartstring,
};
// third party scope
import * as minimatch from 'minimatch';
import * as nodeSsh from 'node-ssh';
export { minimatch, nodeSsh };
+10 -4
View File
@@ -3,8 +3,14 @@
"experimentalDecorators": true, "experimentalDecorators": true,
"useDefineForClassFields": false, "useDefineForClassFields": false,
"target": "ES2022", "target": "ES2022",
"module": "ES2022", "module": "NodeNext",
"moduleResolution": "nodenext", "moduleResolution": "NodeNext",
"esModuleInterop": true "noImplicitAny": true,
} "esModuleInterop": true,
"verbatimModuleSyntax": true,
"types": ["node"]
},
"exclude": [
"dist_*/**/*.d.ts"
]
} }