Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
added 'privateKeySourceFormat' and 'privateKeyTargetFormat' settings …
Browse files Browse the repository at this point in the history
…for SFTP
  • Loading branch information
mkloubert committed Aug 21, 2017
1 parent fe60e43 commit db3bd20
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log (vs-deploy)

## 9.32.0 (August 21st, 2017; SFTP private key format)

* added `privateKeySourceFormat` and `privateKeyTargetFormat` settings for [SFTP](https://github.com/mkloubert/vs-deploy/wiki/target_sftp) targets, that can define the input and output format of a private key

## 9.31.0 (August 21st, 2017; prompt target)

* added `handleAs` property for entries in a [prompt target](https://github.com/mkloubert/vs-deploy/wiki/target_prompt), which can define in what data type to convert the user's input to
Expand Down
11 changes: 10 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vs-deploy",
"displayName": "Deploy",
"description": "Commands for deploying files of your workspace to a destination.",
"version": "9.31.0",
"version": "9.32.0",
"publisher": "mkloubert",
"engines": {
"vscode": "^1.6.0"
Expand Down Expand Up @@ -19854,7 +19854,12 @@
"handleAs": {
"description": "The type to convert the user's input to.",
"type": "string",
"enum": [ "", "list", "object", "string" ],
"enum": [
"",
"list",
"object",
"string"
],
"default": "string"
},
"isPassword": {
Expand Down Expand Up @@ -24321,6 +24326,14 @@
"description": "The path to the private key file, if authentification should be done via SSH key.",
"default": "./my-private-file.key"
},
"privateKeySourceFormat": {
"type": "string",
"description": "The source format of the private key."
},
"privateKeyTargetFormat": {
"type": "string",
"description": "The custom target format of the private key."
},
"privateKeyPassphrase": {
"type": "string",
"description": "The passphrase for the key file, if needed."
Expand Down Expand Up @@ -31981,6 +31994,7 @@
"@types/mocha": "^2.2.32",
"@types/node": "^6.0.40",
"@types/ssh2-sftp-client": "^1.0.5",
"@types/sshpk": "^1.10.3",
"@types/tmp": "0.0.32",
"@types/uuid": "^2.0.29",
"mocha": "^2.3.3",
Expand Down Expand Up @@ -32028,6 +32042,7 @@
"parse-listing": "^1.1.3",
"pug": "^2.0.0-rc.1",
"ssh2-sftp-client": "^1.0.5",
"sshpk": "^1.13.1",
"tmp": "0.0.31",
"typescript": "^2.3.2",
"uglify-js": "^2.8.23",
Expand Down
32 changes: 27 additions & 5 deletions src/plugins/sftp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import * as i18 from '../i18';
import * as Moment from 'moment';
import * as Path from 'path';
const SFTP = require('ssh2-sftp-client');
import * as sshpk from 'sshpk';
import * as TMP from 'tmp';
import * as vscode from 'vscode';
import * as Workflows from 'node-workflows';
Expand Down Expand Up @@ -62,6 +63,8 @@ interface DeployTargetSFTP extends deploy_contracts.TransformableDeployTarget, d
closing?: SSHCommands;
updateModesOfDirectories?: boolean;
noCommandOutput?: boolean;
privateKeySourceFormat?: string;
privateKeyTargetFormat?: string;
}

interface FileToUpload {
Expand Down Expand Up @@ -630,11 +633,30 @@ class SFtpPlugin extends deploy_objects.DeployPluginWithContextBase<SFTPContext>
return;
}

privateKey = data;
askForPasswordIfNeeded(false,
() => privateKeyPassphrase,
(pwdToSet) => privateKeyPassphrase = pwdToSet,
'privateKeyPassphrase');
try {
let privateKeySourceFormat = me.context.replaceWithValues(target.privateKeySourceFormat);
privateKeySourceFormat = privateKeySourceFormat.trim();

if ('' !== privateKeySourceFormat) {
let privateKeyTargetFormat = me.context.replaceWithValues(target.privateKeyTargetFormat);
privateKeyTargetFormat = privateKeyTargetFormat.trim();
if ('' === privateKeyTargetFormat) {
privateKeyTargetFormat = 'ssh';
}

data = sshpk.parseKey(data, privateKeySourceFormat)
.toBuffer(privateKeyTargetFormat);
}

privateKey = data;
askForPasswordIfNeeded(false,
() => privateKeyPassphrase,
(pwdToSet) => privateKeyPassphrase = pwdToSet,
'privateKeyPassphrase');
}
catch (e) {
completed(e);
}
});
}
}
Expand Down

0 comments on commit db3bd20

Please sign in to comment.