mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 01:25:36 -05:00
Exposing Azure HTTP requests method in Azurecore extension for external consumption (#14135)
* Exposing azure HTTP request in azurecore Moving migration specific request from azurecore to migration Created a migrations typing file * Deleting the typings file in sql migration * Fixed typos in comments * Adding default host for azure https requests * Fixed operator in service url modification * Changed path and host logic * Made chagned requested in the PR * Fixed variable names * Adding / check for path. * Changing error code check * Fixed status logic in azure rest request Fixed comment logic Converting error array to string while throwing * Fixed status check * Fixed typos and cleaning up
This commit is contained in:
@@ -82,22 +82,44 @@ export async function getBlobContainers(account: azdata.Account, subscription: S
|
||||
return blobContainers!;
|
||||
}
|
||||
|
||||
export async function getMigrationController(account: azdata.Account, subscription: Subscription, resourceGroupName: string, regionName: string, controllerName: string): Promise<azureResource.MigrationController> {
|
||||
export async function getMigrationController(account: azdata.Account, subscription: Subscription, resourceGroupName: string, regionName: string, controllerName: string): Promise<MigrationController> {
|
||||
const api = await getAzureCoreAPI();
|
||||
let result = await api.getMigrationController(account, subscription, resourceGroupName, regionName, controllerName, true);
|
||||
return result.controller!;
|
||||
const host = `https://${regionName}.management.azure.com`;
|
||||
const path = `/subscriptions/${subscription.id}/resourceGroups/${resourceGroupName}/providers/Microsoft.DataMigration/Controllers/${controllerName}?api-version=2020-09-01-preview`;
|
||||
const response = await api.makeAzureRestRequest(account, subscription, path, azurecore.HttpRequestMethod.GET, undefined, true, host);
|
||||
if (response.errors.length > 0) {
|
||||
throw response.errors.toString();
|
||||
}
|
||||
|
||||
return response.response.data;
|
||||
}
|
||||
|
||||
export async function createMigrationController(account: azdata.Account, subscription: Subscription, resourceGroupName: string, regionName: string, controllerName: string): Promise<azureResource.MigrationController> {
|
||||
export async function createMigrationController(account: azdata.Account, subscription: Subscription, resourceGroupName: string, regionName: string, controllerName: string): Promise<MigrationController> {
|
||||
const api = await getAzureCoreAPI();
|
||||
let result = await api.createMigrationController(account, subscription, resourceGroupName, regionName, controllerName, true);
|
||||
return result.controller!;
|
||||
const host = `https://${regionName}.management.azure.com`;
|
||||
const path = `/subscriptions/${subscription.id}/resourceGroups/${resourceGroupName}/providers/Microsoft.DataMigration/Controllers/${controllerName}?api-version=2020-09-01-preview`;
|
||||
const requestBody = {
|
||||
'location': regionName
|
||||
};
|
||||
const response = await api.makeAzureRestRequest(account, subscription, path, azurecore.HttpRequestMethod.PUT, requestBody, true, host);
|
||||
if (response.errors.length > 0) {
|
||||
throw response.errors.toString();
|
||||
}
|
||||
return response.response.data;
|
||||
}
|
||||
|
||||
export async function getMigrationControllerAuthKeys(accounts: azdata.Account, subscription: Subscription, resourceGroupName: string, regionName: string, controllerName: string): Promise<azurecore.GetMigrationControllerAuthKeysResult> {
|
||||
export async function getMigrationControllerAuthKeys(account: azdata.Account, subscription: Subscription, resourceGroupName: string, regionName: string, controllerName: string): Promise<GetMigrationControllerAuthKeysResult> {
|
||||
const api = await getAzureCoreAPI();
|
||||
let result = await api.getMigrationControllerAuthKeys(accounts, subscription, resourceGroupName, regionName, controllerName, true);
|
||||
return result;
|
||||
const host = `https://${regionName}.management.azure.com`;
|
||||
const path = `/subscriptions/${subscription.id}/resourceGroups/${resourceGroupName}/providers/Microsoft.DataMigration/Controllers/${controllerName}/ListAuthKeys?api-version=2020-09-01-preview`;
|
||||
const response = await api.makeAzureRestRequest(account, subscription, path, azurecore.HttpRequestMethod.POST, undefined, true, host);
|
||||
if (response.errors.length > 0) {
|
||||
throw response.errors.toString();
|
||||
}
|
||||
return {
|
||||
keyName1: response?.response?.data?.keyName1 ?? '',
|
||||
keyName2: response?.response?.data?.keyName2 ?? ''
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +134,7 @@ export function getMigrationControllerRegions(): azdata.CategoryValue[] {
|
||||
];
|
||||
}
|
||||
|
||||
type SortableAzureResources = AzureProduct | azureResource.FileShare | azureResource.BlobContainer | azureResource.MigrationController | azureResource.AzureResourceSubscription;
|
||||
type SortableAzureResources = AzureProduct | azureResource.FileShare | azureResource.BlobContainer | azureResource.AzureResourceSubscription;
|
||||
function sortResourceArrayByName(resourceArray: SortableAzureResources[]): void {
|
||||
if (!resourceArray) {
|
||||
return;
|
||||
@@ -127,3 +149,29 @@ function sortResourceArrayByName(resourceArray: SortableAzureResources[]): void
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
export interface MigrationControllerProperties {
|
||||
name: string;
|
||||
subscriptionId: string;
|
||||
resourceGroup: string;
|
||||
location: string;
|
||||
provisioningState: string;
|
||||
integrationRuntimeState?: string;
|
||||
isProvisioned?: boolean;
|
||||
}
|
||||
|
||||
export interface MigrationController {
|
||||
properties: MigrationControllerProperties;
|
||||
location: string;
|
||||
id: string;
|
||||
name: string;
|
||||
error: {
|
||||
code: string,
|
||||
message: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface GetMigrationControllerAuthKeysResult {
|
||||
keyName1: string,
|
||||
keyName2: string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user