Skip to content

Commit 274d7b2

Browse files
authored
Add secrets UI to the tree view (#406)
1 parent 2fa3fac commit 274d7b2

File tree

4 files changed

+108
-2
lines changed

4 files changed

+108
-2
lines changed

resources/secrets.svg

Lines changed: 33 additions & 0 deletions
Loading

src/tree/configurations/ConfigurationItem.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ContainerAppsItem, TreeElementBase } from "../ContainerAppsBranchDataPr
1313
import { ActionsItem } from "./ActionsItem";
1414
import { DaprEnabledItem, createDaprDisabledItem } from "./DaprItem";
1515
import { IngressDisabledItem, IngressEnabledItem } from "./IngressItem";
16+
import { SecretsItem } from "./secrets/SecretsItem";
1617

1718
const configuration: string = localize('configuration', 'Configuration');
1819

@@ -36,9 +37,9 @@ export class ConfigurationItem implements ContainerAppsItem {
3637
const result = await callWithTelemetryAndErrorHandling('getChildren', async (_context) => {
3738
const children: TreeElementBase[] = [];
3839
children.push(this.containerApp.configuration?.ingress ? new IngressEnabledItem(this.subscription, this.containerApp) : new IngressDisabledItem(this.subscription, this.containerApp));
39-
children.push(this.containerApp.configuration?.dapr?.enabled ? new DaprEnabledItem(this.containerApp, this.containerApp.configuration.dapr) : createDaprDisabledItem(this.containerApp));
40+
children.push(new SecretsItem(this.subscription, this.containerApp));
4041
children.push(new ActionsItem(this.id, ext.prefix, this.subscription, this.containerApp));
41-
// We should add secrets/registries here when we support it
42+
children.push(this.containerApp.configuration?.dapr?.enabled ? new DaprEnabledItem(this.containerApp, this.containerApp.configuration.dapr) : createDaprDisabledItem(this.containerApp));
4243
return children;
4344
});
4445

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 type { AzureSubscription } from "@microsoft/vscode-azureresources-api";
7+
import { ThemeIcon, TreeItem } from "vscode";
8+
import type { ContainerAppModel } from "../../ContainerAppItem";
9+
import type { ContainerAppsItem } from "../../ContainerAppsBranchDataProvider";
10+
import { SecretsItem } from "./SecretsItem";
11+
12+
export class SecretItem implements ContainerAppsItem {
13+
static readonly contextValue: string = 'secretItem';
14+
static readonly contextValueRegExp: RegExp = new RegExp(SecretItem.contextValue);
15+
16+
constructor(readonly subscription: AzureSubscription, readonly containerApp: ContainerAppModel, readonly secretName: string) { }
17+
18+
id: string = `${this.containerApp.id}/${SecretsItem.idSuffix}/${this.secretName}`;
19+
20+
getTreeItem(): TreeItem {
21+
return {
22+
label: this.secretName,
23+
iconPath: new ThemeIcon('key'),
24+
contextValue: SecretItem.contextValue
25+
};
26+
}
27+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 type { Secret } from "@azure/arm-appcontainers";
7+
import { nonNullProp } from "@microsoft/vscode-azext-utils";
8+
import type { AzureSubscription, ViewPropertiesModel } from "@microsoft/vscode-azureresources-api";
9+
import { TreeItem, TreeItemCollapsibleState } from "vscode";
10+
import { localize } from "../../../utils/localize";
11+
import { treeUtils } from "../../../utils/treeUtils";
12+
import type { ContainerAppModel } from "../../ContainerAppItem";
13+
import type { ContainerAppsItem, TreeElementBase } from "../../ContainerAppsBranchDataProvider";
14+
import { SecretItem } from "./SecretItem";
15+
16+
const secrets: string = localize('secrets', 'Secrets');
17+
18+
export class SecretsItem implements ContainerAppsItem {
19+
static readonly idSuffix: string = 'secrets';
20+
static readonly contextValue: string = 'secretsItem';
21+
static readonly contextValueRegExp: RegExp = new RegExp(SecretsItem.contextValue);
22+
23+
constructor(readonly subscription: AzureSubscription, readonly containerApp: ContainerAppModel) { }
24+
25+
id: string = `${this.containerApp.id}/${SecretsItem.idSuffix}`;
26+
27+
viewProperties: ViewPropertiesModel = {
28+
data: this.containerApp.configuration?.secrets ?? [],
29+
label: `${this.containerApp.name} ${secrets}`,
30+
}
31+
32+
async getChildren(): Promise<TreeElementBase[]> {
33+
const secrets: Secret[] = this.containerApp.configuration?.secrets ?? [];
34+
return secrets.map((secret) => new SecretItem(this.subscription, this.containerApp, nonNullProp(secret, 'name')));
35+
}
36+
37+
getTreeItem(): TreeItem {
38+
return {
39+
label: secrets,
40+
iconPath: treeUtils.getIconPath('secrets'),
41+
contextValue: SecretsItem.contextValue,
42+
collapsibleState: TreeItemCollapsibleState.Collapsed
43+
};
44+
}
45+
}

0 commit comments

Comments
 (0)