Skip to content

Commit 23b81ed

Browse files
Rewrite extension for v2 API (#235)
1 parent 5922a89 commit 23b81ed

File tree

75 files changed

+2257
-2352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2257
-2352
lines changed

package-lock.json

Lines changed: 366 additions & 751 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"icon": "resources/azure-containerapps.png",
88
"aiKey": "0c6ae279ed8443289764825290e4f9e2-1a736e7c-1324-4338-be46-fc2a58ae4d14-7255",
99
"engines": {
10-
"vscode": "^1.66.0"
10+
"vscode": "^1.74.0"
1111
},
1212
"repository": {
1313
"type": "git",
@@ -27,31 +27,17 @@
2727
"multi-root ready"
2828
],
2929
"preview": true,
30-
"activationEvents": [
31-
"onCommand:containerApps.viewProperties",
32-
"onCommand:containerApps.openInPortal",
33-
"onCommand:containerApps.reportIssue",
34-
"onCommand:containerApps.createContainerApp",
35-
"onCommand:containerApps.deployImage",
36-
"onCommand:containerApps.deleteManagedEnvironment",
37-
"onCommand:containerApps.deleteContainerApp",
38-
"onCommand:containerApps.disableIngress",
39-
"onCommand:containerApps.enableIngress",
40-
"onCommand:containerApps.toggleVisibility",
41-
"onCommand:containerApps.editTargetPort",
42-
"onCommand:containerApps.chooseRevisionMode",
43-
"onCommand:containerApps.activateRevision",
44-
"onCommand:containerApps.deactivateRevision",
45-
"onCommand:containerApps.restartRevision",
46-
"onCommand:containerApps.createManagedEnvironment",
47-
"onCommand:containerApps.browse",
48-
"onCommand:containerApps.openConsoleInPortal",
49-
"onCommand:containerApps.editScalingRange",
50-
"onCommand:containerApps.addScaleRule"
51-
],
30+
"activationEvents": [],
5231
"main": "./main.js",
5332
"contributes": {
5433
"x-azResources": {
34+
"azure": {
35+
"branches": [
36+
{
37+
"type": "ContainerAppsEnvironment"
38+
}
39+
]
40+
},
5541
"activation": {
5642
"onResolve": [
5743
"microsoft.app/managedenvironments"
@@ -67,16 +53,6 @@
6753
]
6854
},
6955
"commands": [
70-
{
71-
"command": "containerApps.viewProperties",
72-
"title": "%containerApps.viewProperties%",
73-
"category": "Azure Container Apps"
74-
},
75-
{
76-
"command": "containerApps.openInPortal",
77-
"title": "%containerApps.openInPortal%",
78-
"category": "Azure Container Apps"
79-
},
8056
{
8157
"command": "containerApps.reportIssue",
8258
"title": "%containerApps.reportIssue%",
@@ -171,16 +147,6 @@
171147
],
172148
"menus": {
173149
"view/item/context": [
174-
{
175-
"command": "containerApps.viewProperties",
176-
"when": "view == azureResourceGroups && viewItem =~ /azResource/i && viewItem =~ /^(?!.*containerEnvironment).*/i",
177-
"group": "z@1"
178-
},
179-
{
180-
"command": "containerApps.openInPortal",
181-
"when": "view == azureResourceGroups && viewItem =~ /containerApp[^s]/i",
182-
"group": "z@2"
183-
},
184150
{
185151
"command": "containerApps.createManagedEnvironment",
186152
"when": "view == azureResourceGroups && viewItem =~ /azureResourceTypeGroup/i && viewItem =~ /containerAppsEnvironment/i",
@@ -266,16 +232,6 @@
266232
"when": "view == azureResourceGroups && viewItem =~ /scaleRules/i",
267233
"group": "1@1"
268234
}
269-
],
270-
"commandPalette": [
271-
{
272-
"command": "containerApps.viewProperties",
273-
"when": "never"
274-
},
275-
{
276-
"command": "containerApps.openInPortal",
277-
"when": "never"
278-
}
279235
]
280236
},
281237
"configuration": [
@@ -327,7 +283,7 @@
327283
},
328284
"devDependencies": {
329285
"@microsoft/eslint-config-azuretools": "^0.1.0",
330-
"@microsoft/vscode-azext-dev": "^0.1.2",
286+
"@microsoft/vscode-azext-dev": "^0.1.5",
331287
"@types/fs-extra": "^8.1.1",
332288
"@types/git-url-parse": "^9.0.0",
333289
"@types/gulp": "^4.0.6",
@@ -345,8 +301,8 @@
345301
"mocha": "^10.1.0",
346302
"mocha-junit-reporter": "^2.0.0",
347303
"mocha-multi-reporters": "^1.1.7",
348-
"ts-node": "^7.0.1",
349-
"typescript": "^4.3.5",
304+
"ts-node": "^10.9.1",
305+
"typescript": "^4.9.4",
350306
"vsce": "^1.87.1",
351307
"vscode-test": "^1.5.2",
352308
"webpack": "^5.28.0",
@@ -359,8 +315,8 @@
359315
"@azure/arm-resources": "^4.2.2",
360316
"@azure/container-registry": "1.0.0-beta.5",
361317
"@azure/ms-rest-js": "^2.2.1",
362-
"@microsoft/vscode-azext-azureutils": "^0.3.4",
363-
"@microsoft/vscode-azext-utils": "^0.3.14",
318+
"@microsoft/vscode-azext-azureutils": "^0.3.7",
319+
"@microsoft/vscode-azext-utils": "^0.4.0",
364320
"dayjs": "^1.11.3",
365321
"dotenv": "^16.0.0",
366322
"open": "^8.0.4",

resources/managedEnvironment.svg

Lines changed: 33 additions & 0 deletions
Loading

src/ContainerAppsResolver.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/commands/api/revealTreeItem.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/commands/browse.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/commands/browseContainerApp.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 { ContainerApp } from '@azure/arm-appcontainers';
7+
import { IActionContext } from '@microsoft/vscode-azext-utils';
8+
import { ContainerAppItem, isIngressEnabled } from '../tree/ContainerAppItem';
9+
import { localize } from '../utils/localize';
10+
import { openUrl } from '../utils/openUrl';
11+
import { pickContainerApp } from '../utils/pickContainerApp';
12+
13+
export async function browseContainerAppNode(context: IActionContext, node?: ContainerAppItem): Promise<void> {
14+
node ??= await pickContainerApp(context)
15+
await browseContainerApp(node.containerApp);
16+
}
17+
18+
export async function browseContainerApp(containerApp: ContainerApp): Promise<void> {
19+
if (isIngressEnabled(containerApp)) {
20+
return await openUrl(`https://${containerApp.configuration.ingress.fqdn}`);
21+
}
22+
23+
throw new Error(localize('enableIngress', 'Enable ingress to perform this action.'));
24+
}

src/commands/chooseRevisionMode.ts

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,61 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { KnownActiveRevisionsMode } from "@azure/arm-appcontainers";
67
import { IActionContext, IAzureQuickPickItem } from "@microsoft/vscode-azext-utils";
78
import { ProgressLocation, window } from "vscode";
8-
import { RevisionConstants, rootFilter } from "../constants";
99
import { ext } from "../extensionVariables";
10-
import { ContainerAppTreeItem } from "../tree/ContainerAppTreeItem";
11-
import { RevisionsTreeItem } from "../tree/RevisionsTreeItem";
10+
import { ContainerAppModel, refreshContainerApp } from "../tree/ContainerAppItem";
11+
import { ContainerAppsItem } from "../tree/ContainerAppsBranchDataProvider";
1212
import { localize } from "../utils/localize";
13-
import { nonNullValue } from "../utils/nonNull";
13+
import { pickContainerApp } from "../utils/pickContainerApp";
1414
import { updateContainerApp } from "./updateContainerApp";
1515

16-
export async function chooseRevisionMode(context: IActionContext, node?: ContainerAppTreeItem | RevisionsTreeItem): Promise<void> {
17-
if (!node) {
18-
node = await ext.rgApi.pickAppResource<ContainerAppTreeItem>(context, {
19-
filter: rootFilter,
20-
expectedChildContextValue: ContainerAppTreeItem.contextValueRegExp
21-
});
22-
}
16+
export async function chooseRevisionMode(context: IActionContext, node?: ContainerAppsItem): Promise<void> {
17+
const { subscription, containerApp } = node ?? await pickContainerApp(context);
2318

24-
if (node instanceof RevisionsTreeItem) {
25-
node = node.parent;
26-
}
19+
const pickedRevisionMode = await pickRevisionsMode(context, containerApp);
20+
// only update it if it's actually different
21+
if (containerApp.revisionsMode !== pickedRevisionMode) {
22+
const updating = localize('updatingRevision', 'Updating revision mode of "{0}" to "{1}"...', containerApp.name, pickedRevisionMode);
23+
ext.outputChannel.appendLog(updating);
2724

28-
const picks: IAzureQuickPickItem<string>[] = [RevisionConstants.single, RevisionConstants.multiple];
29-
const placeHolder = localize('chooseRevision', 'Choose revision mode');
25+
await window.withProgress({ location: ProgressLocation.Notification, title: updating }, async (): Promise<void> => {
26+
await updateContainerApp(context, subscription, containerApp, { configuration: { activeRevisionsMode: pickedRevisionMode } });
27+
refreshContainerApp(containerApp.id);
28+
});
3029

31-
for (const pick of picks) {
32-
pick.description = pick.data === node.getRevisionMode() ? localize('current', ' current') : undefined;
30+
const updated = localize('updatedRevision', 'Updated revision mode of "{0}" to "{1}".', containerApp.name, pickedRevisionMode);
31+
void window.showInformationMessage(updated);
32+
ext.outputChannel.appendLog(updated);
3333
}
34+
}
3435

35-
const result = await context.ui.showQuickPick(picks, { placeHolder, suppressPersistence: true });
36-
37-
// only update it if it's actually different
38-
if (node.getRevisionMode() !== result.data) {
39-
const updating = localize('updatingRevision', 'Updating revision mode of "{0}" to "{1}"...', node.name, result.data);
40-
const updated = localize('updatedRevision', 'Updated revision mode of "{0}" to "{1}".', node.name, result.data);
36+
function getRevisionsModePicks(containerApp: ContainerAppModel): IAzureQuickPickItem<KnownActiveRevisionsMode>[] {
4137

42-
await window.withProgress({ location: ProgressLocation.Notification, title: updating }, async (): Promise<void> => {
43-
const pNode = nonNullValue(node) as ContainerAppTreeItem;
44-
ext.outputChannel.appendLog(updating);
38+
function appendCurrent(description: string, revisionsMode: KnownActiveRevisionsMode): string {
39+
return revisionsMode === containerApp.revisionsMode ? `${description} (current)` : description;
40+
}
4541

46-
await updateContainerApp(context, pNode, { configuration: { activeRevisionsMode: result.data } });
47-
await node?.parent?.refresh(context);
42+
return [
43+
{
44+
label: localize('multiple', 'Multiple'),
45+
description: appendCurrent(localize('multipleDesc', 'Several revisions active simultaneously'), KnownActiveRevisionsMode.Multiple),
46+
data: KnownActiveRevisionsMode.Multiple,
47+
},
48+
{
49+
label: localize('single', 'Single'),
50+
description: appendCurrent(localize('singleDesc', 'One active revision at a time'), KnownActiveRevisionsMode.Single),
51+
data: KnownActiveRevisionsMode.Single,
52+
},
53+
];
54+
}
4855

49-
void window.showInformationMessage(updated);
50-
ext.outputChannel.appendLog(updated);
51-
});
52-
}
56+
async function pickRevisionsMode(context: IActionContext, containerApp: ContainerAppModel): Promise<KnownActiveRevisionsMode> {
57+
const placeHolder = localize('chooseRevision', 'Choose revision mode');
58+
const result = await context.ui.showQuickPick(getRevisionsModePicks(containerApp), {
59+
placeHolder,
60+
suppressPersistence: true,
61+
});
62+
return result.data;
5363
}

src/commands/createContainerApp/ContainerAppCreateStep.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { ContainerAppsAPIClient, Ingress, RegistryCredentials, Secret } from "@azure/arm-appcontainers";
6+
import { ContainerAppsAPIClient, Ingress, KnownActiveRevisionsMode, RegistryCredentials, Secret } from "@azure/arm-appcontainers";
77
import { LocationListStep } from "@microsoft/vscode-azext-azureutils";
88
import { AzureWizardExecuteStep } from "@microsoft/vscode-azext-utils";
99
import { Progress } from "vscode";
10-
import { containerAppsWebProvider, RevisionConstants } from "../../constants";
10+
import { containerAppsWebProvider } from "../../constants";
1111
import { ext } from "../../extensionVariables";
12+
import { ContainerAppItem } from "../../tree/ContainerAppItem";
1213
import { createContainerAppsAPIClient } from "../../utils/azureClients";
1314
import { localize } from "../../utils/localize";
1415
import { nonNullProp } from "../../utils/nonNull";
@@ -67,14 +68,14 @@ export class ContainerAppCreateStep extends AzureWizardExecuteStep<IContainerApp
6768
context.image ||= `${getLoginServer(context)}/${context.repositoryName}:${context.tag}`;
6869
const name = getContainerNameForImage(context.image);
6970

70-
context.containerApp = await appClient.containerApps.beginCreateOrUpdateAndWait(nonNullProp(context, 'newResourceGroupName'), nonNullProp(context, 'newContainerAppName'), {
71+
context.containerApp = ContainerAppItem.CreateContainerAppModel(await appClient.containerApps.beginCreateOrUpdateAndWait(nonNullProp(context, 'newResourceGroupName'), nonNullProp(context, 'newContainerAppName'), {
7172
location: (await LocationListStep.getLocation(context, containerAppsWebProvider)).name,
7273
managedEnvironmentId: context.managedEnvironmentId,
7374
configuration: {
7475
ingress,
7576
secrets,
7677
registries,
77-
activeRevisionsMode: RevisionConstants.single.data
78+
activeRevisionsMode: KnownActiveRevisionsMode.Multiple,
7879
},
7980
template: {
8081
containers: [
@@ -83,7 +84,7 @@ export class ContainerAppCreateStep extends AzureWizardExecuteStep<IContainerApp
8384
}
8485
]
8586
}
86-
});
87+
}));
8788
}
8889

8990
public shouldExecute(_wizardContext: IContainerAppContext): boolean {

0 commit comments

Comments
 (0)