Fix HDFS support for CU5+ BDC instances (#10577)

* Fix HDFS node auth for non-root username

* more changes
This commit is contained in:
Charles Gagnon
2020-05-27 10:17:28 -07:00
committed by GitHub
parent e8dc0d15b7
commit f568ff82d8
17 changed files with 153 additions and 53 deletions

View File

@@ -76,6 +76,12 @@ export class SqlClusterConnection {
return authType && authType.toLowerCase() === constants.integratedAuth;
}
public updateUsername(username: string): void {
if (username) {
this._user = username;
}
}
public updatePassword(password: string): void {
if (password) {
this._password = password;

View File

@@ -117,10 +117,19 @@ export class MssqlObjectExplorerNodeProvider extends ProviderBase implements azd
// Only child returned when failure happens : When failed with 'Unauthorized' error, prompt for password.
if (children.length === 1 && this.hasExpansionError(children)) {
if (children[0].errorStatusCode === 401) {
//Prompt for password
let password: string = await this.promptPassword(localize('prmptPwd', "Please provide the password to connect to HDFS:"));
if (password && password.length > 0) {
session.sqlClusterConnection.updatePassword(password);
// First prompt for username (defaulting to existing username)
let username: string = await this.promptInput(localize('promptUsername', "Please provide the username to connect to HDFS:"), session.sqlClusterConnection.user);
// Only update the username if it's different than the original (the update functions ignore falsy values)
if (username === session.sqlClusterConnection.user) {
username = '';
}
session.sqlClusterConnection.updateUsername(username);
// And then prompt for password
const password: string = await this.promptPassword(localize('prmptPwd', "Please provide the password to connect to HDFS:"));
session.sqlClusterConnection.updatePassword(password);
if (username || password) {
await node.updateFileSource(session.sqlClusterConnection);
children = await node.getChildren(true);
}
@@ -141,6 +150,15 @@ export class MssqlObjectExplorerNodeProvider extends ProviderBase implements azd
this.expandCompleteEmitter.fire(expandResult);
}
private async promptInput(promptMsg: string, defaultValue: string): Promise<string> {
return await this.prompter.promptSingle(<IQuestion>{
type: QuestionTypes.input,
name: 'inputPrompt',
message: promptMsg,
default: defaultValue
}).then(confirmed => <string>confirmed);
}
private async promptPassword(promptMsg: string): Promise<string> {
return await this.prompter.promptSingle(<IQuestion>{
type: QuestionTypes.password,

View File

@@ -4,6 +4,8 @@
*--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata';
import * as bdc from 'bdc';
import * as vscode from 'vscode';
import * as constants from './constants';
import * as UUID from 'vscode-languageclient/lib/utils/uuid';
import { AppContext } from './appContext';
@@ -94,8 +96,16 @@ async function createSqlClusterConnInfo(sqlConnInfo: azdata.IConnectionProfile |
clusterConnInfo.options[constants.knoxPortPropName] = hostAndIp.port || constants.defaultKnoxPort;
let authType = clusterConnInfo.options[constants.authenticationTypePropName] = sqlConnInfo.options[constants.authenticationTypePropName];
if (authType && authType.toLowerCase() !== constants.integratedAuth) {
clusterConnInfo.options[constants.userPropName] = 'root'; //should be the same user as sql master
clusterConnInfo.options[constants.userPropName] = sqlConnInfo.options[constants.userPropName]; //should be the same user as sql master
clusterConnInfo.options[constants.passwordPropName] = credentials.password;
try {
const bdcApi = <bdc.IExtension>await vscode.extensions.getExtension(bdc.constants.extensionName).activate();
const controllerEndpoint = endpoints.find(ep => ep.serviceName.toLowerCase() === 'controller');
const controller = bdcApi.getClusterController(controllerEndpoint.endpoint, 'basic', sqlConnInfo.options[constants.userPropName], credentials.password);
clusterConnInfo.options[constants.userPropName] = await controller.getKnoxUsername(sqlConnInfo.options[constants.userPropName]);
} catch (err) {
console.log(`Unexpected error getting Knox username for SQL Cluster connection: ${err}`);
}
}
clusterConnInfo = connToConnectionParam(clusterConnInfo);

View File

@@ -6,3 +6,4 @@
/// <reference path='../../../../src/sql/azdata.d.ts'/>
/// <reference path='../../../../src/sql/azdata.proposed.d.ts'/>
/// <reference path='../../../../src/vs/vscode.d.ts'/>
/// <reference path='../../../big-data-cluster/src/bdc.d.ts'/>