Skip to content

Commit

Permalink
Merge pull request #297 from steelbrain/housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
Steel Brain authored May 4, 2020
2 parents d830b61 + 176c55a commit 31f09c6
Show file tree
Hide file tree
Showing 44 changed files with 4,692 additions and 8,105 deletions.
10 changes: 0 additions & 10 deletions .babelrc

This file was deleted.

27 changes: 13 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,34 @@ version: 2
jobs:
build_and_test:
working_directory: ~/project
# pty.js only works upto Node v8
docker:
- image: node:8-jessie
- image: node:12
steps:
- checkout
- restore_cache:
name: Restore NPM Package Cache
name: Restore Yarn Package Cache
keys:
- npm-packages-{{ .Branch }}-{{ checksum "package-lock.json" }}
- npm-packages-{{ .Branch }}
- npm-packages-master
- npm-packages-
- yarn-packages-{{ .Branch }}-{{ checksum "yarn.lock" }}
- yarn-packages-{{ .Branch }}
- yarn-packages-master
- yarn-packages-
- run:
name: Packager Version
command: npm --version
command: yarn --version
- run:
name: Install Dependencies
command: npm install
command: yarn
- save_cache:
name: Save NPM Package Cache
key: npm-packages-{{ .Branch }}-{{ checksum "package-lock.json" }}
name: Save Yarn Package Cache
key: yarn-packages-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths:
- node_modules/
- run:
name: Compile sources
command: npm run prepare
name: Lint sources
command: yarn lint
- run:
name: Test
command: npm run test
command: yarn test

workflows:
version: 2
Expand Down
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
lib
decls
node_modules
19 changes: 18 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
{
"extends": ["steelbrain", "plugin:flowtype/recommended", "prettier", "prettier/flowtype"]
"extends": "steelbrain",
"rules": {
"camelcase": "warn",
"prettier/prettier": "off",
"no-underscore-dangle": "off",
"no-use-before-define": "off",
"no-dupe-class-members": "off",
"max-classes-per-file": "off",
"import/extensions": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/member-delimiter-style": "off"
},
"settings": {
"react": {
"version": "16.0"
}
}
}
10 changes: 0 additions & 10 deletions .flowconfig

This file was deleted.

8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.idea/
.idea
node_modules
*.log
/lib
*.DS_Store
spec/fixtures/ignored
.DS_Store
/test/fixtures/ignored
/test/fixtures/ignored-2
7 changes: 0 additions & 7 deletions .npmignore

This file was deleted.

3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"semi": false,
"printWidth": 125,
"singleQuote": true,
"trailingComma": "all"
"trailingComma": "all",
"parser": "typescript"
}
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
#### Upcoming

* Add support for Putty private key files
* Add `getDirectory` method
* Add `onChannel` support to `execCommand`
* Rename `options.options` in `execCommand` to be `options.execOptions`
* Rename `options.sftpOptions` to `options.transferOptions` in `putFiles`
* Add `withSFTP` and `withShell` methods
* Connection timed out error is now an instance of `SSHError`
* Invalid argument errors are now `AssertionError` instances
* `onKeyboardInteractive` default will only be set if a `config.password` is provided

#### 8.0.0

* Stop swallowing non-existent cwd errors in `execCommand` #272 (Thanks @dadamssg)
Expand Down
20 changes: 16 additions & 4 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014-2016 steelbrain
Copyright (c) 2014-2020 Steel Brain

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
167 changes: 130 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
Node-SSH - SSH2 with Promises
=========

[![Greenkeeper badge](https://badges.greenkeeper.io/steelbrain/node-ssh.svg)](https://greenkeeper.io/)

Node-SSH is an extremely lightweight Promise wrapper for [ssh2][ssh2], Period.
Node-SSH is an extremely lightweight Promise wrapper for [ssh2][ssh2].

#### Example

```js
var path, node_ssh, ssh, fs
var path, NodeSSH, ssh, fs

fs = require('fs')
path = require('path')
node_ssh = require('node-ssh')
ssh = new node_ssh()
NodeSSH = require('node-ssh')
ssh = new NodeSSH()

ssh.connect({
host: 'localhost',
Expand Down Expand Up @@ -98,42 +96,137 @@ ssh.connect({

#### API

```js
type PutFilesOptions = {
sftp: ?Object,
sftpOptions?: Object,
concurrency?: number = 5,
```ts
// API reference in Typescript typing format:
import { Client, ConnectConfig, ClientChannel, SFTPWrapper, ExecOptions } from 'ssh2';
import { Prompt, TransferOptions } from 'ssh2-streams';
// ^ You do NOT need to import these package, these are here for reference of where the
// types are coming from.

declare type Config = ConnectConfig & {
password?: string;
privateKey?: string;
tryKeyboard?: boolean;
onKeyboardInteractive?: (
name: string,
instructions: string,
lang: string,
prompts: Prompt[],
finish: (responses: string[]) => void
) => void;
};

interface SSHExecCommandOptions {
cwd?: string;
stdin?: string;
execOptions?: ExecOptions;
encoding?: BufferEncoding;
onChannel?: (clientChannel: ClientChannel) => void;
onStdout?: (chunk: Buffer) => void;
onStderr?: (chunk: Buffer) => void;
}
type PutDirectoryOptions = {
sftp: ?Object,
sftpOptions?: Object,
concurrency?: number = 5,
recursive?: boolean,
tick?: ((localPath: string, remotePath: string, error: ?Error) => void),
validate?: ((localPath: string) => boolean),

interface SSHExecCommandResponse {
stdout: string;
stderr: string;
code: number | null;
signal: string | null;
}

interface SSHExecOptions extends SSHExecCommandOptions {
stream?: 'stdout' | 'stderr' | 'both';
}
type ExecOptions = {
cwd?: string,
options?: Object // passed to ssh2.exec
stdin?: string,
stream?: 'stdout' | 'stderr' | 'both',
onStdout?: ((chunk: Buffer) => void),
onStderr?: ((chunk: Buffer) => void),

interface SSHPutFilesOptions {
sftp?: SFTPWrapper | null;
concurrency?: number;
transferOptions?: TransferOptions;
}

class SSH{
connect(config: SSH2Config): Promise<this>
requestSFTP(): Promise<SSH2SFTP>
requestShell(): Promise<SSH2Shell>
mkdir(path: string, method: 'sftp' | 'exec' = 'sftp', givenSftp?: Object): Promise<string>
exec(command: string, parameters: Array<string>, options: ExecOptions = {}): Promise<Object | string>
execCommand(command: string, options: { cwd: string, stdin: string } = {}): Promise<{ stdout: string, options?: Object, stderr: string, signal: ?string, code: number }>
putFile(localFile: string, remoteFile: string, sftp: ?Object = null, opts: ?Object = null): Promise<void>
getFile(localFile: string, remoteFile: string, sftp: ?Object = null, opts: ?Object = null): Promise<void>
putFiles(files: Array<{ local: string, remote: string }>, options: PutFilesOptions = {}): Promise<void>
putDirectory(localDirectory: string, remoteDirectory: string, options: PutDirectoryOptions = {}): Promise<boolean>
dispose(): void
interface SSHGetPutDirectoryOptions extends SSHPutFilesOptions {
tick?: (localFile: string, remoteFile: string, error: Error | null) => void;
validate?: (path: string) => boolean;
recursive?: boolean;
}

class NodeSSH {
connection: Client | null;
connect(config: Config): Promise<this>;

requestShell(): Promise<ClientChannel>;

withShell(
callback: (channel: ClientChannel) => Promise<void>
): Promise<void>;

requestSFTP(): Promise<SFTPWrapper>;

withSFTP(
callback: (sftp: SFTPWrapper) => Promise<void>
): Promise<void>;

execCommand(
command: string,
options?: SSHExecCommandOptions
): Promise<SSHExecCommandResponse>;

exec(
command: string,
parameters: string[],
options?: SSHExecOptions & {
stream?: 'stdout' | 'stderr';
}
): Promise<string>;

exec(
command: string,
parameters: string[],
options?: SSHExecOptions & {
stream: 'both';
}
): Promise<SSHExecCommandResponse>;

mkdir(
path: string,
method?: 'sftp' | 'exec',
sftp?: SFTPWrapper | null
): Promise<void>;

getFile(
localFile: string,
remoteFile: string,
sftp?: SFTPWrapper | null,
transferOptions?: TransferOptions | null
): Promise<void>;

putFile(
localFile: string,
remoteFile: string,
sftp?: SFTPWrapper | null,
transferOptions?: TransferOptions | null
): Promise<void>;

putFiles(files: Array<{
local: string;
remote: string;
}>, options?: SSHPutFilesOptions): Promise<void>;

putDirectory(
localDirectory: string,
remoteDirectory: string,
options?: SSHGetPutDirectoryOptions
): Promise<boolean>;

getDirectory(
localDirectory: string,
remoteDirectory: string,
options?: SSHGetPutDirectoryOptions
): Promise<boolean>;

dispose(): void;
}

module.exports = NodeSSH;
```

### Keyboard-interactive user authentication
Expand Down
9 changes: 0 additions & 9 deletions decls/jasmine.js

This file was deleted.

Loading

0 comments on commit 31f09c6

Please sign in to comment.