mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-18 09:35:39 -05:00
* Remove extra id property from azure subs and add type name helper * case * Change a few names
61 lines
2.6 KiB
TypeScript
61 lines
2.6 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import * as vscode from 'vscode';
|
|
import * as azdata from 'azdata';
|
|
import * as azurecore from 'azurecore';
|
|
import { azureResource } from 'azureResource';
|
|
|
|
async function getAzureCoreAPI(): Promise<azurecore.IExtension> {
|
|
const api = (await vscode.extensions.getExtension(azurecore.extension.name)?.activate()) as azurecore.IExtension;
|
|
if (!api) {
|
|
throw new Error('azure core API undefined for sql-migration');
|
|
}
|
|
return api;
|
|
}
|
|
|
|
export type Subscription = azureResource.AzureResourceSubscription;
|
|
export async function getSubscriptions(account: azdata.Account): Promise<Subscription[]> {
|
|
const api = await getAzureCoreAPI();
|
|
const subscriptions = await api.getSubscriptions(account, false);
|
|
let listOfSubscriptions = subscriptions.subscriptions;
|
|
listOfSubscriptions.sort((a, b) => {
|
|
if (a.name < b.name) {
|
|
return -1;
|
|
}
|
|
if (a.name > b.name) {
|
|
return 1;
|
|
}
|
|
return 0;
|
|
});
|
|
return subscriptions.subscriptions;
|
|
}
|
|
|
|
export type AzureProduct = azureResource.AzureGraphResource;
|
|
|
|
export type SqlManagedInstance = AzureProduct;
|
|
export async function getAvailableManagedInstanceProducts(account: azdata.Account, subscription: Subscription): Promise<SqlManagedInstance[]> {
|
|
const api = await getAzureCoreAPI();
|
|
|
|
const result = await api.runGraphQuery<SqlManagedInstance>(account, [subscription], false, `where type == "${azureResource.AzureResourceType.sqlManagedInstance}"`);
|
|
return result.resources;
|
|
}
|
|
|
|
export type SqlServer = AzureProduct;
|
|
export async function getAvailableSqlServers(account: azdata.Account, subscription: Subscription): Promise<SqlServer[]> {
|
|
const api = await getAzureCoreAPI();
|
|
|
|
const result = await api.runGraphQuery<SqlServer>(account, [subscription], false, `where type == "${azureResource.AzureResourceType.sqlServer}"`);
|
|
return result.resources;
|
|
}
|
|
|
|
export type SqlVMServer = AzureProduct;
|
|
export async function getAvailableSqlVMs(account: azdata.Account, subscription: Subscription): Promise<SqlVMServer[]> {
|
|
const api = await getAzureCoreAPI();
|
|
|
|
const result = await api.runGraphQuery<SqlVMServer>(account, [subscription], false, `where type == "${azureResource.AzureResourceType.virtualMachines}" and properties.storageProfile.imageReference.publisher == "microsoftsqlserver"`);
|
|
return result.resources;
|
|
}
|