mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-31 09:35:39 -05:00
Fix connecting to MI login bug (#21821)
This PR fixes a regression for migration login for MI instances that was introduced in https://github.com/microsoft/azuredatastudio/pull/21776/files#diff-93c1a62583fa32d99f775b71ad27922cf31f660d10717ecc6966784306de1b6f. After that change, support for MI would fail as MI server types were going into the Sql VM path in sqlutils because the underlying logic for isSqlServerVM() was returning wrong results. The new approach uses the targetType set in StateMachine to extract the correct serverName for connection string based on the targetType. Testing: - Tested SQL VM login migration end to end - Tested SQL MI login migration end to end This change also bumps the sql-migration version to 1.3.0
This commit is contained in:
@@ -194,10 +194,6 @@ export interface AzureSqlDatabaseServer {
|
||||
},
|
||||
}
|
||||
|
||||
export function isAzureSqlDatabaseServer(instance: any): instance is AzureSqlDatabaseServer {
|
||||
return (instance as AzureSqlDatabaseServer) !== undefined;
|
||||
}
|
||||
|
||||
export type SqlVMServer = {
|
||||
properties: {
|
||||
virtualMachineResourceId: string,
|
||||
@@ -215,10 +211,6 @@ export type SqlVMServer = {
|
||||
networkInterfaces: Map<string, NetworkInterface>,
|
||||
};
|
||||
|
||||
export function isSqlVMServer(instance: any): instance is SqlVMServer {
|
||||
return (instance as SqlVMServer) !== undefined;
|
||||
}
|
||||
|
||||
export type VirtualMachineInstanceView = {
|
||||
computerName: string,
|
||||
osName: string,
|
||||
|
||||
@@ -5,11 +5,10 @@
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import { azureResource } from 'azurecore';
|
||||
import { AzureSqlDatabase, AzureSqlDatabaseServer, isAzureSqlDatabaseServer, isSqlManagedInstance, isSqlVMServer, SqlManagedInstance, SqlVMServer } from './azure';
|
||||
import { AzureSqlDatabase, AzureSqlDatabaseServer } from './azure';
|
||||
import { generateGuid } from './utils';
|
||||
import * as utils from '../api/utils';
|
||||
import { TelemetryAction, TelemetryViews, logError } from '../telemetry';
|
||||
import { NetworkInterfaceModel } from './dataModels/azure/networkInterfaceModel';
|
||||
|
||||
const query_database_tables_sql = `
|
||||
SELECT
|
||||
@@ -167,14 +166,13 @@ function getSqlDbConnectionProfile(
|
||||
}
|
||||
|
||||
export function getConnectionProfile(
|
||||
server: string | SqlManagedInstance | SqlVMServer | AzureSqlDatabaseServer,
|
||||
serverName: string,
|
||||
azureResourceId: string,
|
||||
userName: string,
|
||||
password: string,
|
||||
trustServerCert: boolean = false): azdata.IConnectionProfile {
|
||||
|
||||
const connectId = generateGuid();
|
||||
const serverName = extractNameFromServer(server);
|
||||
return {
|
||||
serverName: serverName,
|
||||
id: connectId,
|
||||
@@ -205,29 +203,6 @@ export function getConnectionProfile(
|
||||
};
|
||||
}
|
||||
|
||||
function extractNameFromServer(
|
||||
server: string | SqlManagedInstance | SqlVMServer | AzureSqlDatabaseServer): string {
|
||||
|
||||
// No need to extract name if the server is a string
|
||||
if (typeof server === 'string') {
|
||||
return server
|
||||
}
|
||||
|
||||
if (isSqlVMServer(server)) {
|
||||
// For sqlvm, we need to use ip address from the network interface to connect to the server
|
||||
const sqlVm = server as SqlVMServer;
|
||||
const networkInterfaces = Array.from(sqlVm.networkInterfaces.values());
|
||||
return NetworkInterfaceModel.getIpAddress(networkInterfaces);
|
||||
}
|
||||
|
||||
// check if the target server is a managed instance or a VM
|
||||
if (isSqlManagedInstance(server) || isAzureSqlDatabaseServer(server)) {
|
||||
return server.properties.fullyQualifiedDomainName;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
export async function collectSourceDatabaseTableInfo(sourceConnectionId: string, sourceDatabase: string): Promise<TableInfo[]> {
|
||||
const ownerUri = await azdata.connection.getUriForConnection(sourceConnectionId);
|
||||
const connectionProvider = azdata.dataprotocol.getProvider<azdata.ConnectionProvider>(
|
||||
@@ -413,14 +388,15 @@ export async function collectSourceLogins(
|
||||
}
|
||||
|
||||
export async function collectTargetLogins(
|
||||
targetServer: SqlManagedInstance | SqlVMServer | AzureSqlDatabaseServer,
|
||||
serverName: string,
|
||||
azureResourceId: string,
|
||||
userName: string,
|
||||
password: string,
|
||||
includeWindowsAuth: boolean = true): Promise<string[]> {
|
||||
|
||||
const connectionProfile = getConnectionProfile(
|
||||
targetServer,
|
||||
targetServer.id,
|
||||
serverName,
|
||||
azureResourceId,
|
||||
userName,
|
||||
password,
|
||||
true /* trustServerCertificate */);
|
||||
|
||||
Reference in New Issue
Block a user