Skip to content
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
1 change: 1 addition & 0 deletions extension.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export * from '@microsoft/vscode-azext-utils';
export * from './src/commands/tags/getTagDiagnostics';
export * from './src/utils/wrapFunctionsInTelemetry';
export * from './api/src/utils/wrapper';
export { convertV1TreeItemId } from './src/api/compatibility/CompatibleAzExtTreeDataProvider';
// Export activate/deactivate for main.js
export { activateInternal, deactivateInternal } from './src/extension';
export * from './src/extensionVariables';
Expand Down
13 changes: 12 additions & 1 deletion src/api/compatibility/CompatibleAzExtTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export class CompatibleAzExtTreeDataProvider extends IntermediateCompatibleAzExt
}

public override async findTreeItem<T>(fullId: string): Promise<T | undefined> {
const result = await this.tdp.findItemById(fullId);
// compatibility with default resource to deploy setting, which value might be a v1 tree item id
const id = convertV1TreeItemId(fullId);
const result = await this.tdp.findItemById(id);
return isWrapper(result) ? result.unwrap<T>() : result as unknown as T;
}

Expand Down Expand Up @@ -100,3 +102,12 @@ class ShouldNeverBeCalledError extends Error {
super(`${methodName} should never be called.`);
}
}

/**
* Convert v1 tree item id to Azure resource id.
*/
export function convertV1TreeItemId(id: string): string {
// if full id contains two instances of subscriptions/ then remove everything before the second instance
const regex = /^(\/subscriptions.*)(?:\/subscriptions)/i;
return id.replace(regex, '/subscriptions');
}
19 changes: 19 additions & 0 deletions test/api/compatibility/convertV1TreeItemId.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as assert from 'assert';
import { convertV1TreeItemId } from '../../../extension.bundle';

suite('convertV1TreeItemId', () => {
const validArmId = '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Microsoft.ContainerRegistry/registries/test-registry';
test("Doesn't change a valid ARM id", () => {
assert.strictEqual(convertV1TreeItemId(validArmId), validArmId);
});

test("Converts a v1 tree item id to ARM id", () => {
const v1TreeItemId = '/subscriptions/00000000-0000-0000-0000-000000000000/ContainerRegistries/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Microsoft.ContainerRegistry/registries/test-registry';
assert.strictEqual(convertV1TreeItemId(v1TreeItemId), validArmId);
});
});