mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-03 01:25:38 -05:00
[SQL-Migration] Enable login migrations to SQL VM (#21776)
This PR adds support for migrating logins to SQL VM. Adding support for 2 scenarios supported here: VMs with private IP and public IP.
This commit is contained in:
@@ -10,12 +10,14 @@ import * as constants from '../constants/strings';
|
||||
import { getSessionIdHeader } from './utils';
|
||||
import { URL } from 'url';
|
||||
import { MigrationSourceAuthenticationType, MigrationStateModel, NetworkShare } from '../models/stateMachine';
|
||||
import { NetworkInterface } from './dataModels/azure/networkInterfaceModel';
|
||||
|
||||
const ARM_MGMT_API_VERSION = '2021-04-01';
|
||||
const SQL_VM_API_VERSION = '2021-11-01-preview';
|
||||
const SQL_MI_API_VERSION = '2021-11-01-preview';
|
||||
const SQL_SQLDB_API_VERSION = '2021-11-01-preview';
|
||||
const DMSV2_API_VERSION = '2022-03-30-preview';
|
||||
const COMPUTE_VM_API_VERSION = '2022-08-01';
|
||||
|
||||
async function getAzureCoreAPI(): Promise<azurecore.IExtension> {
|
||||
const api = (await vscode.extensions.getExtension(azurecore.extension.name)?.activate()) as azurecore.IExtension;
|
||||
@@ -168,11 +170,6 @@ export interface ServerPrivateEndpointConnection {
|
||||
readonly id?: string;
|
||||
readonly properties?: PrivateEndpointConnectionProperties;
|
||||
}
|
||||
|
||||
export function isAzureSqlDatabaseServer(instance: any): instance is AzureSqlDatabaseServer {
|
||||
return (instance as AzureSqlDatabaseServer) !== undefined;
|
||||
}
|
||||
|
||||
export interface AzureSqlDatabaseServer {
|
||||
id: string,
|
||||
name: string,
|
||||
@@ -197,6 +194,10 @@ export interface AzureSqlDatabaseServer {
|
||||
},
|
||||
}
|
||||
|
||||
export function isAzureSqlDatabaseServer(instance: any): instance is AzureSqlDatabaseServer {
|
||||
return (instance as AzureSqlDatabaseServer) !== undefined;
|
||||
}
|
||||
|
||||
export type SqlVMServer = {
|
||||
properties: {
|
||||
virtualMachineResourceId: string,
|
||||
@@ -210,9 +211,14 @@ export type SqlVMServer = {
|
||||
name: string,
|
||||
type: string,
|
||||
tenantId: string,
|
||||
subscriptionId: string
|
||||
subscriptionId: string,
|
||||
networkInterfaces: Map<string, NetworkInterface>,
|
||||
};
|
||||
|
||||
export function isSqlVMServer(instance: any): instance is SqlVMServer {
|
||||
return (instance as SqlVMServer) !== undefined;
|
||||
}
|
||||
|
||||
export type VirtualMachineInstanceView = {
|
||||
computerName: string,
|
||||
osName: string,
|
||||
@@ -224,6 +230,7 @@ export type VirtualMachineInstanceView = {
|
||||
hyperVGeneration: string,
|
||||
patchStatus: { [propertyName: string]: string; },
|
||||
statuses: InstanceViewStatus[],
|
||||
networkProfile: any,
|
||||
}
|
||||
|
||||
export type InstanceViewStatus = {
|
||||
@@ -282,7 +289,7 @@ export async function getAvailableSqlVMs(account: azdata.Account, subscription:
|
||||
|
||||
export async function getVMInstanceView(sqlVm: SqlVMServer, account: azdata.Account, subscription: Subscription): Promise<VirtualMachineInstanceView> {
|
||||
const api = await getAzureCoreAPI();
|
||||
const path = encodeURI(`/subscriptions/${subscription.id}/resourceGroups/${getResourceGroupFromId(sqlVm.id)}/providers/Microsoft.Compute/virtualMachines/${sqlVm.name}/instanceView?api-version=2022-08-01`);
|
||||
const path = encodeURI(`/subscriptions/${subscription.id}/resourceGroups/${getResourceGroupFromId(sqlVm.id)}/providers/Microsoft.Compute/virtualMachines/${sqlVm.name}/instanceView?api-version=${COMPUTE_VM_API_VERSION}`);
|
||||
const host = api.getProviderMetadataForAccount(account).settings.armResource?.endpoint;
|
||||
const response = await api.makeAzureRestRequest(account, subscription, path, azurecore.HttpRequestMethod.GET, undefined, true, host);
|
||||
|
||||
@@ -293,6 +300,24 @@ export async function getVMInstanceView(sqlVm: SqlVMServer, account: azdata.Acco
|
||||
return response.response.data;
|
||||
}
|
||||
|
||||
export async function getAzureResourceGivenId(account: azdata.Account, subscription: Subscription, id: string, apiVersion: string): Promise<any> {
|
||||
const api = await getAzureCoreAPI();
|
||||
const path = encodeURI(`${id}?api-version=${apiVersion}`);
|
||||
const host = api.getProviderMetadataForAccount(account).settings.armResource?.endpoint;
|
||||
const response = await api.makeAzureRestRequest(account, subscription, path, azurecore.HttpRequestMethod.GET, undefined, true, host);
|
||||
|
||||
if (response.errors.length > 0) {
|
||||
throw new Error(response.errors.toString());
|
||||
}
|
||||
|
||||
return response.response.data;
|
||||
}
|
||||
|
||||
export async function getComputeVM(sqlVm: SqlVMServer, account: azdata.Account, subscription: Subscription): Promise<any> {
|
||||
const path = encodeURI(`/subscriptions/${subscription.id}/resourceGroups/${getResourceGroupFromId(sqlVm.id)}/providers/Microsoft.Compute/virtualMachines/${sqlVm.name}`);
|
||||
return getAzureResourceGivenId(account, subscription, path, COMPUTE_VM_API_VERSION);
|
||||
}
|
||||
|
||||
export type StorageAccount = AzureProduct;
|
||||
export async function getAvailableStorageAccounts(account: azdata.Account, subscription: Subscription): Promise<StorageAccount[]> {
|
||||
const api = await getAzureCoreAPI();
|
||||
|
||||
Reference in New Issue
Block a user