Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add listSubscriptions to resourceApi #829

Merged
merged 6 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
269 changes: 203 additions & 66 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@
"@azure/arm-resources-profile-2020-09-01-hybrid": "^2.1.0",
"@microsoft/vscode-azext-azureauth": "^2.3.0",
"@microsoft/vscode-azext-azureutils": "^2.0.0",
"@microsoft/vscode-azext-utils": "^2.0.0",
"@microsoft/vscode-azext-utils": "^2.4.0",
"buffer": "^6.0.3",
"jsonc-parser": "^2.2.1",
"uuid": "^9.0.0",
Expand Down
9 changes: 8 additions & 1 deletion src/api/compatibility/AzureResourceGroupsExtensionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

import { AzExtTreeDataProvider, AzExtTreeItem, ITreeItemPickerContext } from '@microsoft/vscode-azext-utils';
import { Activity, AppResourceResolver, AzureHostExtensionApi, AzureResourceGroupsExtensionApi, LocalResourceProvider, PickAppResourceOptions, WorkspaceResourceProvider } from '@microsoft/vscode-azext-utils/hostapi';
import { AzureSubscription } from 'api/src';
import { Disposable, TreeView } from 'vscode';

export class InternalAzureResourceGroupsExtensionApi implements AzureHostExtensionApi, AzureResourceGroupsExtensionApi {
public static apiVersion = '0.0.1';
public static apiVersion = '0.0.2';

#appResourceTree: AzExtTreeDataProvider;
#appResourceTreeView: TreeView<unknown>;
Expand All @@ -19,6 +20,7 @@ export class InternalAzureResourceGroupsExtensionApi implements AzureHostExtensi
#registerWorkspaceResourceProvider: (id: string, resolver: WorkspaceResourceProvider) => Disposable;
#registerActivity: (activity: Activity) => Promise<void>;
#pickAppResource: <T extends AzExtTreeItem>(context: ITreeItemPickerContext, options?: PickAppResourceOptions) => Promise<T>;
#getSubscriptions: (filter: boolean) => Promise<AzureSubscription[]>;

// This `Omit` is here because the interface expects those keys to be defined, but in this object they will not be
// They are replaced with functions defined on this class that merely wrap the newly-named keys
Expand All @@ -33,6 +35,11 @@ export class InternalAzureResourceGroupsExtensionApi implements AzureHostExtensi
this.#registerWorkspaceResourceProvider = options.registerWorkspaceResourceProvider;
this.#registerActivity = options.registerActivity;
this.#pickAppResource = options.pickAppResource;
this.#getSubscriptions = options.getSubscriptions;
}

public get getSubscriptions(): (filter: boolean) => Promise<AzureSubscription[]> {
return this.#getSubscriptions;
}

public get appResourceTree(): AzExtTreeDataProvider {
Expand Down
5 changes: 5 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { registerAzureUtilsExtensionVariables, setupAzureLogger } from '@microsoft/vscode-azext-azureutils';
import { AzExtTreeDataProvider, AzureExtensionApiFactory, IActionContext, callWithTelemetryAndErrorHandling, createApiProvider, createAzExtLogOutputChannel, createExperimentationService, registerUIExtensionVariables } from '@microsoft/vscode-azext-utils';
import { AzureSubscription } from 'api/src';
import { GetApiOptions, apiUtils } from 'api/src/utils/apiUtils';
import * as vscode from 'vscode';
import { ActivityLogTreeItem } from './activityLog/ActivityLogsTreeItem';
Expand Down Expand Up @@ -152,6 +153,9 @@ export async function activate(context: vscode.ExtensionContext, perfStats: { lo
ext.appResourceTree = new CompatibleAzExtTreeDataProvider(azureResourceTreeDataProvider);
ext.workspaceTree = new CompatibleAzExtTreeDataProvider(workspaceResourceTreeDataProvider);

const getSubscriptions: (filter: boolean) => Promise<AzureSubscription[]> =
async (filter: boolean) => { return await (await azureResourceTreeDataProvider.getAzureSubscriptionProvider()).getSubscriptions(filter) };

return createApiProvider(
[
{
Expand All @@ -166,6 +170,7 @@ export async function activate(context: vscode.ExtensionContext, perfStats: { lo
registerWorkspaceResourceProvider,
registerActivity,
pickAppResource: createCompatibilityPickAppResource(),
getSubscriptions,
}),
},
v2ApiFactory,
Expand Down
2 changes: 1 addition & 1 deletion src/tree/azure/AzureResourceTreeDataProviderBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export abstract class AzureResourceTreeDataProviderBase extends ResourceTreeData
return super.isAncestorOf(element, id)
}

protected async getAzureSubscriptionProvider(): Promise<AzureSubscriptionProvider> {
public async getAzureSubscriptionProvider(): Promise<AzureSubscriptionProvider> {
// override for testing
if (ext.testing.overrideAzureSubscriptionProvider) {
return ext.testing.overrideAzureSubscriptionProvider();
Expand Down
2 changes: 1 addition & 1 deletion test/api/v1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ suite('v1 API tests', async () => {

assert.ok(apiProvider, 'API provider is undefined');

const v1Api = apiProvider.getApi('0.0.1', {
const v1Api = apiProvider.getApi('0.0.2', {
extensionId: 'ms-azuretools.vscode-azureresourcegroups-tests',
});

Expand Down
Loading