Skip to content

Commit

Permalink
Merge c4b5c17 into ffb93e0
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Bist committed Nov 28, 2019
2 parents ffb93e0 + c4b5c17 commit 9705c24
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 8 deletions.
16 changes: 14 additions & 2 deletions src/controllers/mainController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,10 +930,22 @@ export default class MainController implements vscode.Disposable {
for (let conn of newConnections) {
// if a connection is not connected
// that means it was added manually
const uri = ObjectExplorerUtils.getNodeUriFromProfile(<IConnectionProfile>conn);
const newConnectionProfile = <IConnectionProfile>conn;
const uri = ObjectExplorerUtils.getNodeUriFromProfile(newConnectionProfile);
if (!this.connectionManager.isActiveConnection(conn) &&
!this.connectionManager.isConnecting(uri)) {
// add a disconnected node for it
// if the added connection is SQL Auth and has password
// save the password and remove it from settings
if (conn.authenticationType === Constants.sqlAuthentication &&
!Utils.isEmpty(conn.password)) {
await this.connectionManager.connectionStore.saveProfile(newConnectionProfile);
const newConnectionProfileCopy = Object.assign({}, newConnectionProfile);
newConnectionProfileCopy.password = '';
this._vscodeWrapper.setConfiguration(Constants.extensionConfigSectionName,
Constants.connectionsArrayName, newConnectionProfileCopy);
}

// add a disconnected node for the connection
needsRefresh = true;
this._objectExplorerProvider.addDisconnectedNode(conn);
}
Expand Down
7 changes: 7 additions & 0 deletions src/controllers/vscodeWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ export default class VscodeWrapper {
}

/**
* Change a configuration setting
*/
public setConfiguration(extensionName: string, resource: string, value: any): Thenable<void> {
return this.getConfiguration(extensionName, resource).update(resource, value);
}

/*
* Called when there's a change in the extensions
*/
public get onDidChangeExtensions(): vscode.Event<void> {
Expand Down
47 changes: 41 additions & 6 deletions src/objectExplorer/objectExplorerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,37 @@ export class ObjectExplorerService {
return [new AddConnectionTreeNode()];
}

/**
* Removes password from a saved profile
*/
private async removeProfilePassword(connection: IConnectionCredentials): Promise<void> {
// if the password is saved in the credential store, remove it
let profile = connection as IConnectionProfile;
await this._connectionManager.connectionStore.removeProfile(profile);
const newProfile = Object.assign({}, profile);
newProfile.password = '';
newProfile.savePassword = false;
await this._connectionManager.connectionStore.saveProfile(newProfile);
}

/**
* Handles a generic create session failure
*/
private async handleNodeCreationFailure(element: TreeNodeInfo): Promise<AccountSignInTreeNode[]> {
const signInNode = new AccountSignInTreeNode(element);
this._treeNodeToChildrenMap.set(element, [signInNode]);
return [signInNode];
}

/**
* Handles an incorrect password failure when creating a session
*/
private async handleNodePasswordFailure(element: TreeNodeInfo): Promise<ConnectTreeNode[]> {
const connectNode = new ConnectTreeNode(element);
this._treeNodeToChildrenMap.set(element, [connectNode]);
return [connectNode];
}

async getChildren(element?: TreeNodeInfo): Promise<vscode.TreeItem[]> {
if (element) {
if (element !== this._currentNode) {
Expand Down Expand Up @@ -277,15 +308,19 @@ export class ObjectExplorerService {
let node = await promise;
// if password failed
if (!node) {
const connectNode = new ConnectTreeNode(element);
this._treeNodeToChildrenMap.set(element, [connectNode]);
return [connectNode];
// remove password if it's saved in the credential store
let profile = element.connectionCredentials as IConnectionProfile;
let password = await this._connectionManager.connectionStore.lookupPassword(profile);
if (password) {
await this.removeProfilePassword(profile);
return this.handleNodeCreationFailure(element);
} else {
return this.handleNodePasswordFailure(element);
}
}
} else {
// If node create session failed
const signInNode = new AccountSignInTreeNode(element);
this._treeNodeToChildrenMap.set(element, [signInNode]);
return [signInNode];
return this.handleNodeCreationFailure(element);
}
// otherwise expand the node by refreshing the root
// to add connected context key
Expand Down

0 comments on commit 9705c24

Please sign in to comment.