mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Fix deployment warnings to only show if no resources found (#10878)
This commit is contained in:
30
extensions/resource-deployment/src/services/apiService.ts
Normal file
30
extensions/resource-deployment/src/services/apiService.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azurecore from '../../../azurecore/src/azurecore';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export interface IApiService {
|
||||
getAzurecoreApi(): Promise<azurecore.IExtension>;
|
||||
}
|
||||
|
||||
class ApiService implements IApiService {
|
||||
|
||||
private azurecoreApi: azurecore.IExtension | undefined;
|
||||
|
||||
constructor() { }
|
||||
|
||||
public async getAzurecoreApi(): Promise<azurecore.IExtension> {
|
||||
if (!this.azurecoreApi) {
|
||||
this.azurecoreApi = <azurecore.IExtension>(await vscode.extensions.getExtension(azurecore.extension.name)?.activate());
|
||||
if (!this.azurecoreApi) {
|
||||
throw new Error('Unable to retrieve azurecore API');
|
||||
}
|
||||
}
|
||||
return this.azurecoreApi;
|
||||
}
|
||||
}
|
||||
|
||||
export const apiService: IApiService = new ApiService();
|
||||
@@ -16,6 +16,7 @@ import { assert, getDateTimeString, getErrorMessage } from '../utils';
|
||||
import { WizardInfoBase } from './../interfaces';
|
||||
import { Model } from './model';
|
||||
import { RadioGroupLoadingComponentBuilder } from './radioGroupLoadingComponentBuilder';
|
||||
import { apiService } from '../services/apiService';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
@@ -839,16 +840,24 @@ async function handleSelectedAccountChanged(
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await vscode.commands.executeCommand<azurecore.GetSubscriptionsResult>('azure.accounts.getSubscriptions', selectedAccount, true /*ignoreErrors*/);
|
||||
const response = await (await apiService.getAzurecoreApi()).getSubscriptions(selectedAccount, true);
|
||||
if (!response) {
|
||||
return;
|
||||
}
|
||||
if (response.errors.length > 0) {
|
||||
context.container.message = {
|
||||
text: response.errors.join(EOL) || '',
|
||||
description: '',
|
||||
level: azdata.window.MessageLevel.Warning
|
||||
};
|
||||
// If we got back some subscriptions then don't display the errors to the user - it's normal for users
|
||||
// to not necessarily have access to all subscriptions on an account so displaying the errors
|
||||
// in that case is usually just distracting and causes confusion
|
||||
const errMsg = response.errors.join(EOL);
|
||||
if (response.subscriptions.length === 0) {
|
||||
context.container.message = {
|
||||
text: errMsg || '',
|
||||
description: '',
|
||||
level: azdata.window.MessageLevel.Error
|
||||
};
|
||||
} else {
|
||||
console.log(errMsg);
|
||||
}
|
||||
}
|
||||
subscriptionDropdown.values = response.subscriptions.map(subscription => {
|
||||
const displayName = `${subscription.name} (${subscription.id})`;
|
||||
@@ -906,17 +915,24 @@ async function handleSelectedSubscriptionChanged(context: AzureAccountFieldConte
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const response = await vscode.commands.executeCommand<azurecore.GetResourceGroupsResult>('azure.accounts.getResourceGroups', selectedAccount, selectedSubscription, true /*ignoreErrors*/);
|
||||
//.then(response => {
|
||||
const response = await (await apiService.getAzurecoreApi()).getResourceGroups(selectedAccount, selectedSubscription, true);
|
||||
if (!response) {
|
||||
return;
|
||||
}
|
||||
if (response.errors.length > 0) {
|
||||
context.container.message = {
|
||||
text: response.errors.join(EOL) || '',
|
||||
description: '',
|
||||
level: azdata.window.MessageLevel.Warning
|
||||
};
|
||||
// If we got back some RG's then don't display the errors to the user - it's normal for users
|
||||
// to not necessarily have access to all RG's on a subscription so displaying the errors
|
||||
// in that case is usually just distracting and causes confusion
|
||||
const errMsg = response.errors.join(EOL);
|
||||
if (response.resourceGroups.length === 0) {
|
||||
context.container.message = {
|
||||
text: errMsg || '',
|
||||
description: '',
|
||||
level: azdata.window.MessageLevel.Error
|
||||
};
|
||||
} else {
|
||||
console.log(errMsg);
|
||||
}
|
||||
}
|
||||
resourceGroupDropdown.values = (response.resourceGroups.length !== 0)
|
||||
? response.resourceGroups.map(resourceGroup => resourceGroup.name).sort((a: string, b: string) => a.toLocaleLowerCase().localeCompare(b.toLocaleLowerCase()))
|
||||
|
||||
Reference in New Issue
Block a user