mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Arc bug fix: ADS Create DC wizard should prompt for Log Analytics workspace ID and access token similar to portal (#18742)
* Added monitor log-analytics workspace list to az api * Made resource group and subscription optional for logs analytics workspace list * Added dynamic fields for workspace names, id, primary key, based on value of auto-logs checkbox * Hooked up the newly created source provider for log analytics workspaces. Dropdown now populates all workspace names. * Added workspaceUtils.ts for a valueprovider. Now workspace name maps to id automatically. * Replaced promise.all with promise.resolve * Added workspace id and primary key as env variables in the notebook * Removed extra space in package.json * Made getOptions more concise and put azApi definition in function. * Changed notebook to handle new Azure CLI command with param --clustername
This commit is contained in:
28
extensions/arc/src/common/workspaceUtils.ts
Normal file
28
extensions/arc/src/common/workspaceUtils.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { InputValueType } from 'resource-deployment';
|
||||
import * as azExt from 'az-ext';
|
||||
import * as vscode from 'vscode';
|
||||
import { errorListingLogAnalyticsWorkspaces } from '../localizedConstants';
|
||||
|
||||
export const licenseTypeVarName = 'AZDATA_NB_VAR_LOG_ANALYTICS_WORKSPACE_NAMES';
|
||||
|
||||
// Gets the Log Analytics workspace id from the workspace name.
|
||||
export async function getWorkspaceIdFromName(triggerFields: { [key: string]: InputValueType }): Promise<string | undefined> {
|
||||
try {
|
||||
const _azApi = <azExt.IExtension>vscode.extensions.getExtension(azExt.extension.name)?.exports;
|
||||
const workspaces = await _azApi.az.monitor.logAnalytics.workspace.list();
|
||||
const targetWorkspace = workspaces.stdout.find(workspace => workspace.name === triggerFields[licenseTypeVarName]);
|
||||
if (targetWorkspace) {
|
||||
return targetWorkspace.customerId;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
} catch (e) {
|
||||
vscode.window.showErrorMessage(errorListingLogAnalyticsWorkspaces(e));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@ import { AzureArcTreeDataProvider } from './ui/tree/azureArcTreeDataProvider';
|
||||
import { ControllerTreeNode } from './ui/tree/controllerTreeNode';
|
||||
import { TreeNode } from './ui/tree/treeNode';
|
||||
import * as pricing from './common/pricingUtils';
|
||||
import * as workspace from './common/workspaceUtils';
|
||||
import { LogAnalyticsWorkspaceOptionsSourceProvider } from './providers/logAnalyticsWorkspaceOptionsSourceProvider';
|
||||
|
||||
export async function activate(context: vscode.ExtensionContext): Promise<arc.IExtension> {
|
||||
IconPathHelper.setExtensionContext(context);
|
||||
@@ -61,6 +63,15 @@ export async function activate(context: vscode.ExtensionContext): Promise<arc.IE
|
||||
// register option sources
|
||||
const rdApi = <rd.IExtension>vscode.extensions.getExtension(rd.extension.name)?.exports;
|
||||
context.subscriptions.push(rdApi.registerOptionsSourceProvider(new ArcControllersOptionsSourceProvider(treeDataProvider)));
|
||||
context.subscriptions.push(rdApi.registerOptionsSourceProvider(new LogAnalyticsWorkspaceOptionsSourceProvider()));
|
||||
|
||||
// Register valueprovider for getting the Log Analytics workspace id from the workspace name.
|
||||
context.subscriptions.push(rdApi.registerValueProvider({
|
||||
id: 'workspace-name-to-id',
|
||||
getValue: async (triggerFields: { [key: string]: rd.InputValueType }) => {
|
||||
return workspace.getWorkspaceIdFromName(triggerFields);
|
||||
}
|
||||
}));
|
||||
|
||||
// Register valueprovider for getting the calculated cost per VCore.
|
||||
context.subscriptions.push(rdApi.registerValueProvider({
|
||||
|
||||
@@ -334,3 +334,4 @@ export const userCancelledError = localize('arc.userCancelledError', "User cance
|
||||
export const clusterContextConfigNoLongerValid = (configFile: string, clusterContext: string, error: any) => localize('clusterContextConfigNoLongerValid', "The cluster context information specified by config file: {0} and cluster context: {1} is no longer valid. Error is:\n\t{2}\n Do you want to update this information?", configFile, clusterContext, getErrorMessage(error));
|
||||
export const invalidConfigPath = localize('arc.invalidConfigPath', "Invalid config path");
|
||||
export const loadingClusterContextsError = (error: any): string => localize('arc.loadingClusterContextsError', "Error loading cluster contexts. {0}", getErrorMessage(error));
|
||||
export function errorListingLogAnalyticsWorkspaces(error: any): string { return localize('arc.errorListingLogAnalyticsWorkspaces', "Error listing Log Analytics workspaces {0}", getErrorMessage(error, true)); }
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azExt from 'az-ext';
|
||||
import * as rd from 'resource-deployment';
|
||||
import * as vscode from 'vscode';
|
||||
import { errorListingLogAnalyticsWorkspaces } from '../localizedConstants';
|
||||
|
||||
/**
|
||||
* Class that provides options sources for Log Analytics workspace names
|
||||
*/
|
||||
export class LogAnalyticsWorkspaceOptionsSourceProvider implements rd.IOptionsSourceProvider {
|
||||
readonly id = 'arc.logAnalyticsWorkspaceNames';
|
||||
private readonly _azApi: azExt.IExtension;
|
||||
|
||||
constructor() {
|
||||
this._azApi = <azExt.IExtension>vscode.extensions.getExtension(azExt.extension.name)?.exports;
|
||||
}
|
||||
|
||||
public async getOptions(): Promise<string[]> {
|
||||
try {
|
||||
const workspacesListResult = await this._azApi.az.monitor.logAnalytics.workspace.list();
|
||||
return workspacesListResult.stdout.map(workspace => workspace.name);
|
||||
} catch (err) {
|
||||
vscode.window.showErrorMessage(errorListingLogAnalyticsWorkspaces(err));
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user