Skip to content

Commit

Permalink
Merge branch 'main' into DA-333-dataset-parser-issues-in-cb-import
Browse files Browse the repository at this point in the history
  • Loading branch information
lokesh-couchbase committed Nov 7, 2023
2 parents 5f235f8 + d8cbbd9 commit 4d32a70
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/commands/tools/dataImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ export class DataImport {
return "";
}

public dataImport = async () => {
public dataImport = async (context: vscode.ExtensionContext) => {
const connection = getActiveConnection();
if (!connection) {
return;
Expand Down Expand Up @@ -964,7 +964,7 @@ export class DataImport {
keysAndAdvancedSettingsData.ignoreFields,
threads: keysAndAdvancedSettingsData.threads,
verbose: keysAndAdvancedSettingsData.verboseLog,
});
}, context);

break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ export function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand(
Commands.dataExport,
async () => {
await dataExport();
await dataExport(context);
}
)
);
Expand All @@ -461,7 +461,7 @@ export function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand(
Commands.dataImport,
async () => {
await new DataImport().dataImport();
await new DataImport().dataImport(context);
}
)
);
Expand Down
5 changes: 3 additions & 2 deletions src/pages/Tools/DataExport/dataExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface IDataExportWebviewState {
webviewPanel: vscode.WebviewPanel;
}

export const dataExport = async () => {
export const dataExport = async (context: vscode.ExtensionContext) => {
const connection = getActiveConnection();
if (!connection) {
return;
Expand Down Expand Up @@ -146,7 +146,8 @@ export const dataExport = async () => {
formData.collectionFieldName,
formData.format,
formData.threads,
formData.verboseLog
formData.verboseLog,
context
);
} else {
currentPanel.webview.postMessage({
Expand Down
17 changes: 13 additions & 4 deletions src/tools/CBExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export class CBExport {
colName: string,
format: string,
threads: string,
verbose: boolean
verbose: boolean,
context: vscode.ExtensionContext
): Promise<void> {

const connection = getActiveConnection();
Expand Down Expand Up @@ -66,8 +67,8 @@ export class CBExport {
cmd.push(connection.url);
cmd.push("-u");
cmd.push(connection.username);
cmd.push("-p");
cmd.push('"' + password + '"');
// cmd.push("-p");
// cmd.push('"' + password + '"');
cmd.push("-b");
cmd.push(bucket);

Expand All @@ -93,11 +94,19 @@ export class CBExport {
cmd.push("-v");
}

cmd.push("; \n");
cmd.push("export CB_PASSWORD=''"); // To make sure that password is truly unset

// Run Command
const terminal = vscode.window.createTerminal("CBExport");
const terminal: vscode.Terminal = vscode.window.createTerminal("CBExport");
// sending password to vscode environment variables. Note: Password is still accessible via terminal, till its removed
context.environmentVariableCollection.replace('CB_PASSWORD', password);
let text = cmd.join(" ");
terminal.sendText(text);
terminal.show();
// removing password from vscode environment variables after 5 seconds
await new Promise((resolve)=>setTimeout(resolve, 5000));
context.environmentVariableCollection.replace('CB_PASSWORD', '');
} catch (error) {
console.error("An error occurred while trying to export the dataset");
console.error(error);
Expand Down
23 changes: 14 additions & 9 deletions src/tools/CBImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface ICBImportData {

export class CBImport {

static async import(importData: ICBImportData): Promise<void> {
static async import(importData: ICBImportData, context: vscode.ExtensionContext): Promise<void> {
const connection = getActiveConnection();
if(!connection){
return;
Expand All @@ -44,12 +44,23 @@ export class CBImport {

// CMD Runner
try {
const password = await keytar.getPassword(Constants.extensionID, getConnectionId(connection));
if (!password) {
logger.error("password not found");
return ;
}
const terminal = vscode.window.createTerminal("CBImport");
// sending password to vscode environment variables. Note: Password is still accessible via terminal, till its removed
context.environmentVariableCollection.replace('CB_PASSWORD', password);
let text = cmd.join(" ");
logger.info("CB Import Command to run: "+ text);

terminal.sendText(text);
terminal.show();

// removing password from vscode environment variables after 5 seconds
await new Promise((resolve)=>setTimeout(resolve, 5000));
context.environmentVariableCollection.replace('CB_PASSWORD', '');

} catch(err) {
logger.error("Error while running command for CB Import");
Expand All @@ -60,11 +71,6 @@ export class CBImport {

static async cmdBuilder(importData: ICBImportData, connection: IConnection): Promise<string[] | Error> {

const password = await keytar.getPassword(Constants.extensionID, getConnectionId(connection));
if (!password) {
return new Error("Password not found");
}

const cmd: string[] = [];
cmd.push(CBTools.getTool(Type.CB_IMPORT).path);
cmd.push(importData.fileFormat);
Expand All @@ -75,8 +81,6 @@ export class CBImport {
cmd.push(connection.url);
cmd.push("-u");
cmd.push(connection.username);
cmd.push("-p");
cmd.push('"' + password + '"');
cmd.push("-b");
cmd.push(importData.bucket);

Expand Down Expand Up @@ -135,7 +139,8 @@ export class CBImport {
if (importData.verbose) {
cmd.push("-v");
}

cmd.push("; \n");
cmd.push("export CB_PASSWORD=''"); // To make sure that password is truly unset
return cmd;

}
Expand Down

0 comments on commit 4d32a70

Please sign in to comment.