|
| 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