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

Commit

Permalink
shell commands, S3 and external sources
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Dec 30, 2017
1 parent 2bb88fa commit 5a6dcc1
Show file tree
Hide file tree
Showing 16 changed files with 247 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Change Log (vscode-deploy-reloaded)

## 0.10.0 (December 30th, 2017; shell commands and S3)
[![Share via Facebook](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Facebook.png)](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&quote=vscode-deploy-reloaded) [![Share via Twitter](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Twitter.png)](https://twitter.com/intent/tweet?source=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&text=vscode-deploy-reloaded:%20https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&via=mjkloubert) [![Share via Google+](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Google+.png)](https://plus.google.com/share?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded) [![Share via Pinterest](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Pinterest.png)](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&media=https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/demo1.gif&description=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.) [![Share via Reddit](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Reddit.png)](https://www.reddit.com/submit?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&title=vscode-deploy-reloaded) [![Share via LinkedIn](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/LinkedIn.png)](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&title=vscode-deploy-reloaded&summary=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.&source=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded) [![Share via Wordpress](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Wordpress.png)](https://wordpress.com/press-this.php?u=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&quote=vscode-deploy-reloaded&s=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.&i=https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/demo1.gif) [![Share via Email](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Email.png)](mailto:?subject=vscode-deploy-reloaded&body=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20'vs-deploy'%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.:%20https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded)


## 0.10.0 (December 30th, 2017; shell commands, S3 and external sources)

* added `executeOnStartup` [setting](https://github.com/mkloubert/vscode-deploy-reloaded/wiki#settings--), which runs [shell commands on startup](https://github.com/mkloubert/vscode-deploy-reloaded/wiki/execute_on_startup)
* fixed use of [if](https://github.com/mkloubert/vscode-deploy-reloaded/wiki/if) property in setting objects
* better handling of [credentials config](https://github.com/mkloubert/vscode-deploy-reloaded/wiki/target_s3bucket#credentials) of [S3 target](https://github.com/mkloubert/vscode-deploy-reloaded/wiki/target_s3bucket)
* added `dropbox`, `ftp`, `sftp` and `slack` protocol support for [external sources](https://github.com/mkloubert/vscode-deploy-reloaded/wiki/external_sources)

## 0.9.0 (December 30th, 2017; [Composer](https://getcomposer.org/))

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# vscode-deploy-reloaded

[![Share via Facebook](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Facebook.png)](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&quote=vscode-deploy-reloaded) [![Share via Twitter](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Twitter.png)](https://twitter.com/intent/tweet?source=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&text=vscode-deploy-reloaded:%20https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&via=mjkloubert) [![Share via Google+](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Google+.png)](https://plus.google.com/share?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded) [![Share via Pinterest](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Pinterest.png)](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&media=https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/demo1.gif&description=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.) [![Share via Reddit](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Reddit.png)](https://www.reddit.com/submit?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&title=vscode-deploy-reloaded) [![Share via LinkedIn](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/LinkedIn.png)](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&title=vscode-deploy-reloaded&summary=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.&source=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded) [![Share via Wordpress](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Wordpress.png)](https://wordpress.com/press-this.php?u=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&quote=vscode-deploy-reloaded&s=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.&i=https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/demo1.gif) [![Share via Email](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Email.png)](mailto:?subject=vscode-deploy-reloaded&body=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20'vs-deploy'%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.:%20https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded)


[![Latest Release](https://vsmarketplacebadge.apphb.com/version-short/mkloubert.vscode-deploy-reloaded.svg)](https://marketplace.visualstudio.com/items?itemName=mkloubert.vscode-deploy-reloaded)
[![Installs](https://vsmarketplacebadge.apphb.com/installs/mkloubert.vscode-deploy-reloaded.svg)](https://marketplace.visualstudio.com/items?itemName=mkloubert.vscode-deploy-reloaded)
[![Rating](https://vsmarketplacebadge.apphb.com/rating-short/mkloubert.vscode-deploy-reloaded.svg)](https://marketplace.visualstudio.com/items?itemName=mkloubert.vscode-deploy-reloaded#review-details)
Expand Down
1 change: 1 addition & 0 deletions copyright.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Icons:
- /icon.png (DinosoftLabs; https://www.iconfinder.com/dinosoftlabs)
- /img/share/* (https://simplesharingbuttons.com)
Binary file added img/share/Email.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/share/Facebook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/share/Google+.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/share/LinkedIn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/share/Pinboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/share/Pinterest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/share/Pocket.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/share/Reddit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/share/Tumblr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/share/Twitter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/share/Wordpress.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/clients/dropbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ export class DropBoxClient extends deploy_clients.AsyncFileListBase {
* Creates a new client.
*
* @param {DropboxOptions} opts The options for the new client.
*
* @return {DropBoxClient} The new client.
*/
export function createClient(opts: DropboxOptions) {
export function createClient(opts: DropboxOptions): DropBoxClient {
if (!opts) {
return <any>opts;
}
Expand Down
236 changes: 235 additions & 1 deletion src/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import * as deploy_clients_dropbox from './clients/dropbox';
import * as deploy_clients_ftp from './clients/ftp';
import * as deploy_clients_sftp from './clients/sftp';
import * as deploy_clients_slack from './clients/slack';
import * as deploy_helpers from './helpers';
import * as deploy_http from './http';
import * as HTTP from 'http';
Expand All @@ -23,8 +27,81 @@ import * as Path from 'path';
import * as URL from 'url';


type Downloader = (url: URL.Url) => Buffer | PromiseLike<Buffer>
type DownloadClientConfigMappings = { [ configProperty: string ]: DownloadClientConfigTargetType };

type DownloadClientConfigTargetType = undefined | null |
'bool' |
'int' |
'string_array';

type Downloader = (url: URL.Url) => Buffer | PromiseLike<Buffer>;


function createDownloadConfig(url: URL.Url, mappings: DownloadClientConfigMappings): any {
if (!mappings) {
mappings = {};
}

const CONFIG: any = {};

const PARAMS = deploy_helpers.uriParamsToObject(url);
for (const P in PARAMS) {
for (let prop in mappings) {
if (P !== deploy_helpers.normalizeString(prop)) {
continue;
}

let val: any = PARAMS[P];

const TARGET_TYPE = mappings[prop];
if (!deploy_helpers.isNullOrUndefined(TARGET_TYPE)) {
switch (TARGET_TYPE) {
case 'bool':
if (deploy_helpers.isEmptyString(val)) {
val = undefined;
}
else {
switch ( deploy_helpers.normalizeString(val) ) {
case '1':
case 'true':
case 'y':
case 'yes':
val = true;
break;

default:
val = false;
break;
}
}
break;

case 'int':
if (deploy_helpers.isEmptyString(val)) {
val = undefined;
}
else {
val = parseInt( val.trim() );
}
break;

case 'string_array':
if (deploy_helpers.isEmptyString(val)) {
val = undefined;
}
else {
val = val.split(',');
}
break;
}
}

CONFIG[prop] = val;
}
}

return CONFIG;
}

/**
* Downloads something from a source.
Expand Down Expand Up @@ -65,11 +142,27 @@ export async function download(url: string | URL.Url, scopes?: string | string[]
const PROTOCOL = deploy_helpers.normalizeString(url.protocol);

switch (PROTOCOL) {
case 'dropbox:':
downloader = download_dropbox;
break;

case 'ftp:':
downloader = download_ftp;
break;

case 'http:':
case 'https:':
downloader = download_http;
break;

case 'sftp:':
downloader = download_sftp;
break;

case 'slack:':
downloader = download_slack;
break;

default:
// handle as local file
downloader = async () => {
Expand Down Expand Up @@ -107,6 +200,46 @@ export async function download(url: string | URL.Url, scopes?: string | string[]
}


async function download_dropbox(url: URL.Url): Promise<Buffer> {
const CFG: deploy_clients_dropbox.DropboxOptions = createDownloadConfig(url, {
accessToken: null,
});

const CLIENT = deploy_clients_dropbox.createClient(CFG);
try {
return await CLIENT.downloadFile(
url.pathname,
);
}
finally {
deploy_helpers.tryDispose(CLIENT);
}
}

async function download_ftp(url: URL.Url): Promise<Buffer> {
const AUTH = getUserNameAndPassword(url);
const SERVER = getHostAndPort(url);

const CFG: deploy_clients_ftp.FTPConnectionOptions = createDownloadConfig(url, {
engine: null,
});

(<any>CFG).host = SERVER.host;
(<any>CFG).port = SERVER.port;
(<any>CFG).password = AUTH.password;
(<any>CFG).user = AUTH.user;

const CLIENT = await deploy_clients_ftp.openConnection(CFG);
try {
return await CLIENT.downloadFile(
url.pathname,
);
}
finally {
deploy_helpers.tryDispose(CLIENT);
}
}

async function download_http(url: URL.Url): Promise<Buffer> {
const RESPONSE = await deploy_http.request(url);

Expand All @@ -125,3 +258,104 @@ async function download_http(url: URL.Url): Promise<Buffer> {
throw new Error(i18.t(errorKey,
RESPONSE.statusCode, RESPONSE.statusMessage));
}

async function download_sftp(url: URL.Url): Promise<Buffer> {
const AUTH = getUserNameAndPassword(url);
const SERVER = getHostAndPort(url);

const CFG: deploy_clients_sftp.SFTPConnectionOptions = createDownloadConfig(url, {
agent: null,
agentForward: 'bool',
debug: 'bool',
hashAlgorithm: null,
hashes: 'string_array',
privateKey: null,
privateKeyPassphrase: null,
readyTimeout: 'int',
tryKeyboard: 'bool',
});

(<any>CFG).host = SERVER.host;
(<any>CFG).port = SERVER.port;
(<any>CFG).password = AUTH.password;
(<any>CFG).user = AUTH.user;

const CLIENT = await deploy_clients_sftp.openConnection(CFG);
try {
return await CLIENT.downloadFile(
url.pathname,
);
}
finally {
deploy_helpers.tryDispose(CLIENT);
}
}

async function download_slack(url: URL.Url): Promise<Buffer> {
const CHANNEL = deploy_helpers.toStringSafe(url.hostname).toUpperCase().trim();

const CFG: deploy_clients_slack.SlackOptions = createDownloadConfig(url, {
token: null,
});

const CLIENT = deploy_clients_slack.createClient(CFG);
try {
return await CLIENT.downloadFile(
CHANNEL + url.pathname,
);
}
finally {
deploy_helpers.tryDispose(CLIENT);
}
}

function getHostAndPort(url: URL.Url) {
let host = deploy_helpers.toStringSafe(url.hostname);
let port = parseInt(
deploy_helpers.toStringSafe(url.port).trim()
);

if (deploy_helpers.isEmptyString(host)) {
host = undefined;
}

if (isNaN(port)) {
port = undefined;
}

return {
host: host,
port: port,
};
}

function getUserNameAndPassword(url: URL.Url) {
let user: string;
let password: string;

const AUTH = deploy_helpers.toStringSafe(url.auth);
if (!deploy_helpers.isEmptyString(AUTH)) {
const SEP = AUTH.indexOf(':');
if (SEP > -1) {
user = AUTH.substr(0, SEP);
password = AUTH.substr(SEP + 1);
}
else {
user = AUTH;
}
}

if (deploy_helpers.isEmptyString(user)) {
user = undefined;
}

password = deploy_helpers.toStringSafe(password);
if ('' === password) {
password = undefined;
}

return {
password: password,
user: user,
};
}

0 comments on commit 5a6dcc1

Please sign in to comment.