@@ -22,7 +22,7 @@ export interface ICBImportData {
2222
2323export class CBImport {
2424
25- static async import ( importData : ICBImportData ) : Promise < void > {
25+ static async import ( importData : ICBImportData , context : vscode . ExtensionContext ) : Promise < void > {
2626 const connection = getActiveConnection ( ) ;
2727 if ( ! connection ) {
2828 return ;
@@ -44,12 +44,23 @@ export class CBImport {
4444
4545 // CMD Runner
4646 try {
47+ const password = await keytar . getPassword ( Constants . extensionID , getConnectionId ( connection ) ) ;
48+ if ( ! password ) {
49+ logger . error ( "password not found" ) ;
50+ return ;
51+ }
4752 const terminal = vscode . window . createTerminal ( "CBImport" ) ;
53+ // sending password to vscode environment variables. Note: Password is still accessible via terminal, till its removed
54+ context . environmentVariableCollection . replace ( 'CB_PASSWORD' , password ) ;
4855 let text = cmd . join ( " " ) ;
4956 logger . info ( "CB Import Command to run: " + text ) ;
5057
5158 terminal . sendText ( text ) ;
5259 terminal . show ( ) ;
60+
61+ // removing password from vscode environment variables after 5 seconds
62+ await new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) ) ;
63+ context . environmentVariableCollection . replace ( 'CB_PASSWORD' , '' ) ;
5364
5465 } catch ( err ) {
5566 logger . error ( "Error while running command for CB Import" ) ;
@@ -60,11 +71,6 @@ export class CBImport {
6071
6172 static async cmdBuilder ( importData : ICBImportData , connection : IConnection ) : Promise < string [ ] | Error > {
6273
63- const password = await keytar . getPassword ( Constants . extensionID , getConnectionId ( connection ) ) ;
64- if ( ! password ) {
65- return new Error ( "Password not found" ) ;
66- }
67-
6874 const cmd : string [ ] = [ ] ;
6975 cmd . push ( CBTools . getTool ( Type . CB_IMPORT ) . path ) ;
7076 cmd . push ( importData . fileFormat ) ;
@@ -75,8 +81,6 @@ export class CBImport {
7581 cmd . push ( connection . url ) ;
7682 cmd . push ( "-u" ) ;
7783 cmd . push ( connection . username ) ;
78- cmd . push ( "-p" ) ;
79- cmd . push ( '"' + password + '"' ) ;
8084 cmd . push ( "-b" ) ;
8185 cmd . push ( importData . bucket ) ;
8286
@@ -135,7 +139,8 @@ export class CBImport {
135139 if ( importData . verbose ) {
136140 cmd . push ( "-v" ) ;
137141 }
138-
142+ cmd . push ( "; \n" ) ;
143+ cmd . push ( "export CB_PASSWORD=''" ) ; // To make sure that password is truly unset
139144 return cmd ;
140145
141146 }
0 commit comments