mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 02:48:30 -05:00
Add azure data provider (#12160)
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
export const extensionConfigSectionName = 'azure';
|
||||
export const ViewType = 'view';
|
||||
|
||||
export const dataGridProviderId = 'azure-resources';
|
||||
|
||||
export enum BuiltInCommands {
|
||||
SetContext = 'setContext'
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ 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';
|
||||
|
||||
let extensionContext: vscode.ExtensionContext;
|
||||
|
||||
@@ -88,6 +89,63 @@ export async function activate(context: vscode.ExtensionContext): Promise<azurec
|
||||
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 }
|
||||
];
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
getSubscriptions(account?: azdata.Account, ignoreErrors?: boolean): Thenable<azurecore.GetSubscriptionsResult> { return azureResourceUtils.getSubscriptions(appContext, account, ignoreErrors); },
|
||||
getResourceGroups(account?: azdata.Account, subscription?: azureResource.AzureResourceSubscription, ignoreErrors?: boolean): Thenable<azurecore.GetResourceGroupsResult> { return azureResourceUtils.getResourceGroups(appContext, account, subscription, ignoreErrors); },
|
||||
|
||||
@@ -57,6 +57,7 @@ export const resourceType = localize('azurecore.resourceType', "Resource type");
|
||||
export const resourceGroup = localize('azurecore.resourceGroup', "Resource group");
|
||||
export const location = localize('azurecore.location', "Location");
|
||||
export const subscription = localize('azurecore.subscription', "Subscription");
|
||||
export const typeIcon = localize('azurecore.typeIcon', "Type Icon");
|
||||
|
||||
// Azure Resource Types
|
||||
export const sqlServer = localize('azurecore.sqlServer', "SQL server");
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import { azureResource } from 'azureResource';
|
||||
import * as loc from './localizedConstants';
|
||||
import { AzureRegion } from 'azurecore';
|
||||
import { AppContext } from './appContext';
|
||||
|
||||
/**
|
||||
* Converts a region value (@see AzureRegion) into the localized Display Name
|
||||
@@ -108,6 +109,8 @@ export function getResourceTypeDisplayName(type: string): string {
|
||||
return loc.sqlDatabase;
|
||||
case azureResource.AzureResourceType.sqlManagedInstance:
|
||||
return loc.sqlManagedInstance;
|
||||
case azureResource.AzureResourceType.postgresServer:
|
||||
return loc.postgresServer;
|
||||
case azureResource.AzureResourceType.azureArcSqlManagedInstance:
|
||||
return loc.azureArcsqlManagedInstance;
|
||||
case azureResource.AzureResourceType.azureArcService:
|
||||
@@ -117,3 +120,23 @@ export function getResourceTypeDisplayName(type: string): string {
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
export function getResourceTypeIcon(appContext: AppContext, type: string): string {
|
||||
switch (type) {
|
||||
case azureResource.AzureResourceType.sqlServer:
|
||||
return appContext.extensionContext.asAbsolutePath('resources/sqlServer.svg');
|
||||
case azureResource.AzureResourceType.sqlDatabase:
|
||||
return appContext.extensionContext.asAbsolutePath('resources/sqlDatabase.svg');
|
||||
case azureResource.AzureResourceType.sqlManagedInstance:
|
||||
return appContext.extensionContext.asAbsolutePath('resources/sqlManagedInstance.svg');
|
||||
case azureResource.AzureResourceType.postgresServer:
|
||||
return appContext.extensionContext.asAbsolutePath('resources/postgresServer.svg');
|
||||
case azureResource.AzureResourceType.azureArcSqlManagedInstance:
|
||||
return appContext.extensionContext.asAbsolutePath('resources/azureArcSqlManagedInstance.svg');
|
||||
case azureResource.AzureResourceType.azureArcService:
|
||||
return appContext.extensionContext.asAbsolutePath('resources/azureArcService.svg');
|
||||
case azureResource.AzureResourceType.azureArcPostgresServer:
|
||||
return appContext.extensionContext.asAbsolutePath('resources/azureArcPostgresServer.svg');
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user