Skip to content

Commit

Permalink
src: in index get rid of sshOptions wrapper.
Browse files Browse the repository at this point in the history
  • Loading branch information
narekhovhannisyan committed Jan 13, 2020
1 parent fcdc838 commit 6f36652
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,20 @@ const { getFromCacheAsync, storeInCache } = require('./util/cache').SINGLETON

/**
* SSH connection wrapper which uses cache for storing connections.
* @param {TSSHConnectionOptions} param0 SSH connection options.
* @param {TSSHConnectionOptions} sshOptions The connection options.
* @return {(domainOrIP: String) => Promise.<TNodeSSH>} SSH Session.
*/
const SSHCache = ({ host, username, privateKey, passphrase }) => domainOrIP => {
/**
* Creates options for further `SSH` connection.
* @param {String} domainOrIP The remote server domain.
* @return {TSSHConnectionOptions} `SSH` connection options.
* @private
*/
const sshOptions = domainOrIP => ({
host,
username,
privateKey,
passphrase
})

const SSHCache = (sshOptions) => (domainOrIP) => {
/**
* Provides new SSH connection if there is no such one, otherwise creates new one and stores in cache.
* @param {String} domainOrIP The remote server domain.
* @return {Promise.<any>} SSH connection.
*/
const connect = domainOrIP =>
const connect = (domainOrIP) =>
getFromCacheAsync(domainOrIP).then(connection => {
if (!connection) {
return new NodeSSH()
.connect(sshOptions(domainOrIP))
.connect(sshOptions)
.then(storeInCache(domainOrIP, CONNECTION_EXPIRE))
}

Expand Down

0 comments on commit 6f36652

Please sign in to comment.