mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Azure provider cleanup and add rg property (#13030)
* Move Azure DataGrid Provider into own class * Fix compile
This commit is contained in:
@@ -43,8 +43,8 @@ import * as loc from './localizedConstants';
|
||||
import * as constants from './constants';
|
||||
import { AzureResourceGroupService } from './azureResource/providers/resourceGroup/resourceGroupService';
|
||||
import { Logger } from './utils/Logger';
|
||||
import { TokenCredentials } from '@azure/ms-rest-js';
|
||||
import { FlatAzureResourceTreeProvider } from './azureResource/tree/flatTreeProvider';
|
||||
import { AzureDataGridProvider } from './azureDataGridProvider';
|
||||
|
||||
let extensionContext: vscode.ExtensionContext;
|
||||
|
||||
@@ -90,63 +90,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<azurec
|
||||
pushDisposable(vscode.window.registerTreeDataProvider('azureResourceExplorer', azureResourceTree));
|
||||
pushDisposable(vscode.workspace.onDidChangeConfiguration(e => onDidChangeConfiguration(e), this));
|
||||
registerAzureResourceCommands(appContext, azureResourceTree);
|
||||
|
||||
const typesClause = [
|
||||
azureResource.AzureResourceType.sqlDatabase,
|
||||
azureResource.AzureResourceType.sqlServer,
|
||||
azureResource.AzureResourceType.sqlManagedInstance,
|
||||
azureResource.AzureResourceType.postgresServer,
|
||||
azureResource.AzureResourceType.azureArcService,
|
||||
azureResource.AzureResourceType.azureArcSqlManagedInstance,
|
||||
azureResource.AzureResourceType.azureArcPostgresServer
|
||||
].map(type => `type == "${type}"`).join(' or ');
|
||||
azdata.dataprotocol.registerDataGridProvider({
|
||||
providerId: constants.dataGridProviderId,
|
||||
getDataGridItems: async () => {
|
||||
const accounts = await azdata.accounts.getAllAccounts();
|
||||
const items: any[] = [];
|
||||
await Promise.all(accounts.map(async (account) => {
|
||||
await Promise.all(account.properties.tenants.map(async (tenant: { id: string; }) => {
|
||||
try {
|
||||
const tokenResponse = await azdata.accounts.getAccountSecurityToken(account, tenant.id, azdata.AzureResource.ResourceManagement);
|
||||
const token = tokenResponse.token;
|
||||
const tokenType = tokenResponse.tokenType;
|
||||
const credential = new TokenCredentials(token, tokenType);
|
||||
const subscriptionService = appContext.getService<IAzureResourceSubscriptionService>(AzureResourceServiceNames.subscriptionService);
|
||||
const subscriptions = await subscriptionService.getSubscriptions(account, credential, tenant.id);
|
||||
try {
|
||||
const newItems = (await azureResourceUtils.runResourceQuery(account, subscriptions, true, `where ${typesClause}`)).resources
|
||||
.map(item => {
|
||||
return {
|
||||
...item,
|
||||
subscriptionName: subscriptions.find(subscription => subscription.id === item.subscriptionId)?.name ?? item.subscriptionId,
|
||||
locationDisplayName: utils.getRegionDisplayName(item.location),
|
||||
typeDisplayName: utils.getResourceTypeDisplayName(item.type),
|
||||
iconPath: utils.getResourceTypeIcon(appContext, item.type)
|
||||
};
|
||||
});
|
||||
items.push(...newItems);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}));
|
||||
}));
|
||||
return items;
|
||||
},
|
||||
getDataGridColumns: async () => {
|
||||
return [
|
||||
{ id: 'icon', type: 'image', field: 'iconPath', name: '', width: 25, sortable: false, filterable: false, resizable: false, tooltip: loc.typeIcon },
|
||||
{ id: 'name', type: 'text', field: 'name', name: loc.name, width: 150 },
|
||||
{ id: 'type', type: 'text', field: 'typeDisplayName', name: loc.resourceType, width: 150 },
|
||||
{ id: 'type', type: 'text', field: 'resourceGroup', name: loc.resourceGroup, width: 150 },
|
||||
{ id: 'location', type: 'text', field: 'locationDisplayName', name: loc.location, width: 150 },
|
||||
{ id: 'subscriptionId', type: 'text', field: 'subscriptionName', name: loc.subscription, width: 150 }
|
||||
];
|
||||
}
|
||||
});
|
||||
azdata.dataprotocol.registerDataGridProvider(new AzureDataGridProvider(appContext));
|
||||
|
||||
return {
|
||||
getSubscriptions(account?: azdata.Account, ignoreErrors?: boolean, selectedOnly: boolean = false): Thenable<azurecore.GetSubscriptionsResult> {
|
||||
|
||||
Reference in New Issue
Block a user