File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed
Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ export * from '@microsoft/vscode-azext-utils';
1818export * from './src/commands/tags/getTagDiagnostics' ;
1919export * from './src/utils/wrapFunctionsInTelemetry' ;
2020export * from './api/src/utils/wrapper' ;
21+ export { convertV1TreeItemId } from './src/api/compatibility/CompatibleAzExtTreeDataProvider' ;
2122// Export activate/deactivate for main.js
2223export { activateInternal , deactivateInternal } from './src/extension' ;
2324export * from './src/extensionVariables' ;
Original file line number Diff line number Diff line change @@ -47,7 +47,9 @@ export class CompatibleAzExtTreeDataProvider extends IntermediateCompatibleAzExt
4747 }
4848
4949 public override async findTreeItem < T > ( fullId : string ) : Promise < T | undefined > {
50- const result = await this . tdp . findItemById ( fullId ) ;
50+ // compatibility with default resource to deploy setting, which value might be a v1 tree item id
51+ const id = convertV1TreeItemId ( fullId ) ;
52+ const result = await this . tdp . findItemById ( id ) ;
5153 return isWrapper ( result ) ? result . unwrap < T > ( ) : result as unknown as T ;
5254 }
5355
@@ -100,3 +102,12 @@ class ShouldNeverBeCalledError extends Error {
100102 super ( `${ methodName } should never be called.` ) ;
101103 }
102104}
105+
106+ /**
107+ * Convert v1 tree item id to Azure resource id.
108+ */
109+ export function convertV1TreeItemId ( id : string ) : string {
110+ // if full id contains two instances of subscriptions/ then remove everything before the second instance
111+ const regex = / ^ ( \/ s u b s c r i p t i o n s .* ) (?: \/ s u b s c r i p t i o n s ) / i;
112+ return id . replace ( regex , '/subscriptions' ) ;
113+ }
Original file line number Diff line number Diff line change 1+ /*---------------------------------------------------------------------------------------------
2+ * Copyright (c) Microsoft Corporation. All rights reserved.
3+ * Licensed under the MIT License. See License.txt in the project root for license information.
4+ *--------------------------------------------------------------------------------------------*/
5+
6+ import * as assert from 'assert' ;
7+ import { convertV1TreeItemId } from '../../../extension.bundle' ;
8+
9+ suite ( 'convertV1TreeItemId' , ( ) => {
10+ const validArmId = '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Microsoft.ContainerRegistry/registries/test-registry' ;
11+ test ( "Doesn't change a valid ARM id" , ( ) => {
12+ assert . strictEqual ( convertV1TreeItemId ( validArmId ) , validArmId ) ;
13+ } ) ;
14+
15+ test ( "Converts a v1 tree item id to ARM id" , ( ) => {
16+ const v1TreeItemId = '/subscriptions/00000000-0000-0000-0000-000000000000/ContainerRegistries/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Microsoft.ContainerRegistry/registries/test-registry' ;
17+ assert . strictEqual ( convertV1TreeItemId ( v1TreeItemId ) , validArmId ) ;
18+ } ) ;
19+ } ) ;
You can’t perform that action at this time.
0 commit comments