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:
AkshayMata
2023-02-03 06:43:39 -08:00
committed by GitHub
parent 8f638be687
commit 9f5f49e956
6 changed files with 42 additions and 55 deletions

View File

@@ -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,

View File

@@ -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 */);