import "./secret-details.scss"; import React from "react"; import isEmpty from "lodash/isEmpty"; import { autorun, observable } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; import { t, Trans } from "@lingui/macro"; import { DrawerItem, DrawerTitle } from "../drawer"; import { Input } from "../input"; import { Button } from "../button"; import { Notifications } from "../notifications"; import { base64 } from "../../utils"; import { Icon } from "../icon"; import { secretsStore } from "./secrets.store"; import { KubeObjectDetailsProps } from "../kube-object"; import { Secret, secretsApi } from "../../api/endpoints"; import { _i18n } from "../../i18n"; import { apiManager } from "../../api/api-manager"; import { KubeObjectMeta } from "../kube-object/kube-object-meta"; interface Props extends KubeObjectDetailsProps { } @observer export class SecretDetails extends React.Component { @observable isSaving = false; @observable data: { [name: string]: string } = {}; @observable revealSecret: { [name: string]: boolean } = {}; async componentDidMount() { disposeOnUnmount(this, [ autorun(() => { const { object: secret } = this.props; if (secret) { this.data = secret.data; this.revealSecret = {}; } }) ]) } saveSecret = async () => { const { object: secret } = this.props; this.isSaving = true; try { await secretsStore.update(secret, { ...secret, data: this.data }); Notifications.ok(Secret successfully updated.); } catch (err) { Notifications.error(err); } this.isSaving = false; } editData = (name: string, value: string, encoded: boolean) => { this.data[name] = encoded ? value : base64.encode(value); } render() { const { object: secret } = this.props; if (!secret) return null; return (
Type}> {secret.type} {!isEmpty(this.data) && ( <> { Object.entries(this.data).map(([name, value]) => { const revealSecret = this.revealSecret[name]; let decodedVal = ""; try { decodedVal = base64.decode(value); } catch { decodedVal = ""; } value = revealSecret ? decodedVal : value; return (
{name}
this.editData(name, value, !revealSecret)} /> {decodedVal && ( Hide : Show} onClick={() => this.revealSecret[name] = !revealSecret} />) }
) }) }
); } } apiManager.registerViews(secretsApi, { Details: SecretDetails, })