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

Commit

Permalink
password prompts for azure blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Jun 4, 2017
1 parent 3a80055 commit 61c072a
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 9.16.0 (June 4th, 2017; password prompts)

* password box is shown now if no password is defined in [API](https://github.com/mkloubert/vs-deploy/wiki/target_api), [DropBox](https://github.com/mkloubert/vs-deploy/wiki/target_dropbox), [FTP](https://github.com/mkloubert/vs-deploy/wiki/target_ftp) and [mail](https://github.com/mkloubert/vs-deploy/wiki/target_mail) targets
* password box is shown now if no password / token / key is defined in [API](https://github.com/mkloubert/vs-deploy/wiki/target_api), [Azure blob](https://github.com/mkloubert/vs-deploy/wiki/target_azureblob), [DropBox](https://github.com/mkloubert/vs-deploy/wiki/target_dropbox), [FTP](https://github.com/mkloubert/vs-deploy/wiki/target_ftp) and [mail](https://github.com/mkloubert/vs-deploy/wiki/target_mail) targets

## 9.15.1 (June 4th, 2017; bugfixes and password prompt for SFTP)

Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4070,6 +4070,11 @@
"transformerOptions": {
"description": "Optional data for the transformer script."
},
"promptForKey": {
"type": "boolean",
"description": "Prompt for an access key if not defined.",
"default": true
},
"description": {
"type": "string",
"description": "A description for the target."
Expand Down Expand Up @@ -6864,7 +6869,7 @@
},
"promptForToken": {
"type": "boolean",
"description": "Prompt for a access token if not defined.",
"description": "Prompt for an access token if not defined.",
"default": true
},
"description": {
Expand Down
14 changes: 12 additions & 2 deletions src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,21 @@ export const EVENT_DEPLOYONSAVE_ENABLE = 'deploy.deployOnSave.enable';
export const EVENT_DEPLOYONSAVE_TOGGLE = 'deploy.deployOnSave.toggle';

/**
* An object that can handle passwords.
* An object that can handle access keys.
*/
export interface AccessKeyObject {
/**
* Prompt for an access key if not defined.
*/
promptForKey?: boolean;
}

/**
* An object that can handle access tokens.
*/
export interface AccessTokenObject {
/**
* Prompt for a access token if not defined.
* Prompt for an access token if not defined.
*/
promptForToken?: boolean;
}
Expand Down
1 change: 1 addition & 0 deletions src/i18.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export interface Translation {
},
},
prompts?: {
inputAccessKey?: string;
inputAccessToken?: string;
inputPassword?: string;
},
Expand Down
1 change: 1 addition & 0 deletions src/lang/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ export const translation: Translation = {
},
},
prompts: {
inputAccessKey: 'Geben Sie den Zugriffsschlüssel an...',
inputAccessToken: 'Geben Sie das Zugriffs-Token an...',
inputPassword: 'Geben Sie das Passwort an...',
},
Expand Down
1 change: 1 addition & 0 deletions src/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ export const translation: Translation = {
},
},
prompts: {
inputAccessKey: 'Input the access key...',
inputAccessToken: 'Input the access token...',
inputPassword: 'Input the password...',
},
Expand Down
81 changes: 69 additions & 12 deletions src/plugins/azureblob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ import * as i18 from '../i18';
import * as Moment from 'moment';
import * as Path from 'path';
import * as TMP from 'tmp';
import * as vscode from 'vscode';


interface DeployTargetAzureBlob extends deploy_contracts.TransformableDeployTarget {
interface DeployTargetAzureBlob extends deploy_contracts.TransformableDeployTarget, deploy_contracts.AccessKeyObject {
accessKey?: string;
account?: string;
container: string;
Expand Down Expand Up @@ -78,26 +79,82 @@ class AzureBlobPlugin extends deploy_objects.DeployPluginWithContextBase<AzureBl
}
dir += '/';

return new Promise<deploy_objects.DeployPluginContextWrapper<any>>((resolve, reject) => {
return new Promise<deploy_objects.DeployPluginContextWrapper<AzureBlobContext>>((resolve, reject) => {
let completed = (err: any, wrapper?: deploy_objects.DeployPluginContextWrapper<AzureBlobContext>) => {
if (err) {
reject(err);
}
else {
resolve(wrapper);
}
};

try {
let service = AzureStorage.createBlobService(target.account, target.accessKey,
target.host);
let accessKey = deploy_helpers.toStringSafe(target.accessKey);

let ctx: AzureBlobContext = {
container: containerName,
dir: dir,
hasCancelled: false,
service: undefined,
};

let wrapper: deploy_objects.DeployPluginContextWrapper<AzureBlobContext> = {
context: {
container: containerName,
dir: dir,
hasCancelled: false,
service: service,
},
context: ctx,
};

me.onCancelling(() => wrapper.context.hasCancelled = true, opts);

resolve(wrapper);
let prepareWrapper = (hasCancelled: boolean) => {
try {
ctx.hasCancelled = hasCancelled;

if (!ctx.hasCancelled) {
ctx.service = AzureStorage.createBlobService(target.account, accessKey,
target.host);
}

completed(null, wrapper);
}
catch (e) {
completed(e);
}
};

let askForTokenIfNeeded = () => {
let showKeyPrompt = false;
if (deploy_helpers.isEmptyString(accessKey)) {
// user defined, but no key
showKeyPrompt = deploy_helpers.toBooleanSafe(target.promptForKey, true);
}

if (showKeyPrompt) {
vscode.window.showInputBox({
placeHolder: i18.t('prompts.inputAccessKey'),
password: true,
}).then((keyFromUser) => {
if (deploy_helpers.isEmptyString(keyFromUser)) {
// cancelled
prepareWrapper(true);
}
else {
accessKey = keyFromUser;

prepareWrapper(false);
}
}, (err) => {
completed(err);
});
}
else {
prepareWrapper(false);
}
};

askForTokenIfNeeded();
}
catch (e) {
reject(e);
completed(e);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/dropbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ class DropboxPlugin extends deploy_objects.DeployPluginWithContextBase<DropboxCo
let askForTokenIfNeeded = () => {
let showTokenPrompt = false;
if (deploy_helpers.isEmptyString(ctx.token)) {
// user defined, but no password
// user defined, but no token
showTokenPrompt = deploy_helpers.toBooleanSafe(target.promptForToken, true);
}

Expand Down

0 comments on commit 61c072a

Please sign in to comment.