Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
initialize: function(options) {
this.basePath = (options.sftp && options.sftp.home) || "";
this.sftp = new Sftp();
var self = this;
this.timeout = 0;
this.sftp.init(options.sftp, function(err) {
// throw it anyway, because it's fatal...
if (err)
throw err;
self.sftp.connect(function(err){
if (err)
throw err;
});
});
AsyncEventEmitter.DEFAULT_TIMEOUT = 10000;
},
connectToServer (): Promise {
const {host, private_key_path, user} = this.config;
const password = ROCKETRY_PW();
const spinner = ora(`Connecting to ${chalk.yellow(host)}...`).start();
// Only validate private key path if we're not using a password
if (private_key_path && !password) validatePrivateKeyPath(private_key_path);
const client = new nodeSSH();
const connectConfig: SshConnectConfigType = {
host,
username: user,
};
if (password) {
// Passwords are assumed to be base64 encoded
const decoded = Buffer.from(password, 'base64').toString();
connectConfig.password = decoded;
} else {
connectConfig.privateKey = private_key_path;
connectConfig.passphrase = this._sshPassword;
}
return client.connect(connectConfig)
async publish() {
const result = {
success: true,
message: '',
}
const client = new NodeSsh()
const { setting } = this.db
const connectConfig: sftpConnectConfig = {
host: setting.server,
port: Number(setting.port),
type: 'sftp',
username: setting.username,
}
// node-ssh: privateKey is path string.
if (setting.privateKey) {
connectConfig.privateKey = setting.privateKey
} else {
connectConfig.password = setting.password
}
const sshConnect = async ({ host, username, port, sshKeyPath }) => {
let errorMessage
// Get the local username so we can get the default key below (macOS path)
const user = await resolveUsername()
const sshKeyResolvedPath = !isEmpty(sshKeyPath)
? sshKeyPath
: `/Users/${user}/.ssh/id_rsa`
// Create a SSH connection
const ssh = new nodeSsh()
await ssh
.connect({
host: host,
username: username,
port: port,
privateKey: sshKeyResolvedPath,
})
.catch(error => (errorMessage = error))
if (errorMessage)
return new Error(
String(errorMessage).includes(
'Error: Cannot parse privateKey: Unsupported key format'
)
? `Your SSH key isn't in a format Swiff can work with\n (${sshKeyResolvedPath})\n\n1. Generate a new one with:\n ${colourNotice(
`ssh-keygen -m PEM -b 4096 -f /Users/${user}/.ssh/swiff`
)}\n\n2. Then add the key to the server:\n ${colourNotice(
private async connect(
host = "localhost",
username: string,
port = 22,
privateKey: string,
password: string,
passphrase: string,
tryKeyboard: boolean
) {
const ssh = new node_ssh();
const m1 = await this.colorize(
"orange",
`Establishing a SSH connection to ${host}.`
);
console.log(m1);
try {
await ssh.connect({
host: host,
port: port,
username: username,
password: password,
passphrase: passphrase,
privateKey: privateKey,
tryKeyboard: tryKeyboard,
onKeyboardInteractive: tryKeyboard ? keyboardFunction(password) : null
constructor(config: INodeDeployConfig) {
this.config = {
username: 'root',
port: 22,
remotePath: `/data/tcb-service/${config.name}`,
...config
}
this.ssh = new NodeSSH()
this.deployer = new NodeDeployer(this.config)
}
constructor(options: INodeUploaderOptions) {
this.ssh = new NodeSSH()
this._options = options
}