Skip to content

Commit 8fce689

Browse files
Fix default web app to deploy compatibility (#586)
* Fix default web app to deploy compatibility * Add tests
1 parent cb3a1e1 commit 8fce689

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

extension.bundle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export * from '@microsoft/vscode-azext-utils';
1818
export * from './src/commands/tags/getTagDiagnostics';
1919
export * from './src/utils/wrapFunctionsInTelemetry';
2020
export * from './api/src/utils/wrapper';
21+
export { convertV1TreeItemId } from './src/api/compatibility/CompatibleAzExtTreeDataProvider';
2122
// Export activate/deactivate for main.js
2223
export { activateInternal, deactivateInternal } from './src/extension';
2324
export * from './src/extensionVariables';

src/api/compatibility/CompatibleAzExtTreeDataProvider.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff 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 = /^(\/subscriptions.*)(?:\/subscriptions)/i;
112+
return id.replace(regex, '/subscriptions');
113+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
});

0 commit comments

Comments
 (0)