Add hybrid mode to KV View
This commit is contained in:
parent
506fdbd1cb
commit
3147482acf
|
@ -118,7 +118,7 @@ export class Settings {
|
|||
}
|
||||
|
||||
get kvAlwaysCodeView(): boolean {
|
||||
const value = this.storage.getItem("kvAlwaysCodeView") || false;
|
||||
const value = this.storage.getItem("kvAlwaysCodeView") || "false";
|
||||
return value == "true";
|
||||
}
|
||||
set kvAlwaysCodeView(value: boolean) {
|
||||
|
@ -126,6 +126,15 @@ export class Settings {
|
|||
this.alertChange("kvAlwaysCodeView");
|
||||
}
|
||||
|
||||
get kvUseHybridView(): boolean {
|
||||
const value = this.storage.getItem("kvUseHybridView") || "true";
|
||||
return value == "true";
|
||||
}
|
||||
set kvUseHybridView(value: boolean) {
|
||||
this.storage.setItem("kvUseHybridView", String(value));
|
||||
this.alertChange("kvUseHybridView");
|
||||
}
|
||||
|
||||
get kvEditorDefaultLanguage(): string {
|
||||
return this.storage.getItem("kvEditorDefaultLanguage") || "yaml";
|
||||
}
|
||||
|
|
|
@ -89,6 +89,7 @@ module.exports = {
|
|||
settings_kv_editor_indent: "Editor Indent",
|
||||
settings_kv_always_view_in_code_mode: "Always view in code mode",
|
||||
settings_kv_hide_values: "Hide values with key (comma seporated)",
|
||||
settings_kv_use_hybrid_mode: "Show Secrets in hybrid mode",
|
||||
|
||||
// Set Vault URL Page
|
||||
set_vault_url_title: "Set Vault URL",
|
||||
|
|
|
@ -113,25 +113,6 @@ export class KVSecretNormalVew extends Component<KVSecretViewDataProps> {
|
|||
</Grid>
|
||||
);
|
||||
})}
|
||||
|
||||
{(() => {
|
||||
if (this.props.data.has("__vaultui_totp_path")) {
|
||||
const value = this.props.data.get("__vaultui_totp_path") as string;
|
||||
const baseMount = value.split("/")[0];
|
||||
const totpKey = value.split("/")[1];
|
||||
|
||||
return (
|
||||
<p>
|
||||
<CopyTOTPButton api={this.props.api} baseMount={baseMount} totpKey={totpKey} />
|
||||
<Button
|
||||
text={i18next.t("kv_secret_view_totp_btn")}
|
||||
color="secondary"
|
||||
route={totpListURL(baseMount, totpKey)}
|
||||
/>
|
||||
</p>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -141,6 +122,27 @@ export type KVSecretViewProps = DefaultPageProps & {
|
|||
kvData: Record<string, unknown>;
|
||||
};
|
||||
|
||||
function KVTOTPExtra(props: KVSecretViewDataProps) {
|
||||
if (props.data.has("__vaultui_totp_path")) {
|
||||
const value = props.data.get("__vaultui_totp_path") as string;
|
||||
const baseMount = value.split("/")[0];
|
||||
const totpKey = value.split("/")[1];
|
||||
|
||||
return (
|
||||
<p>
|
||||
<CopyTOTPButton api={props.api} baseMount={baseMount} totpKey={totpKey} />
|
||||
<Button
|
||||
text={i18next.t("kv_secret_view_totp_btn")}
|
||||
color="secondary"
|
||||
route={totpListURL(baseMount, totpKey)}
|
||||
/>
|
||||
</p>
|
||||
);
|
||||
} else {
|
||||
return <></>;
|
||||
}
|
||||
}
|
||||
|
||||
export class KVSecretVew extends Component<KVSecretViewProps, { syntax: string }> {
|
||||
render(): JSX.Element {
|
||||
const secretsMap = sortedObjectMap(this.props.kvData);
|
||||
|
@ -150,10 +152,52 @@ export class KVSecretVew extends Component<KVSecretViewProps, { syntax: string }
|
|||
if (typeof value == "object") isMultiLevel = true;
|
||||
}
|
||||
|
||||
let showableAsHybrid = false;
|
||||
for (const value of secretsMap.values()) {
|
||||
if (typeof value != "object") showableAsHybrid = true;
|
||||
}
|
||||
|
||||
if (showableAsHybrid && this.props.settings.kvUseHybridView && secretsMap.size >= 1) {
|
||||
let kvNormalViewMap = new Map();
|
||||
let kvCodeViewMap = new Map();
|
||||
|
||||
for (const key of secretsMap.keys()) {
|
||||
const value = secretsMap.get(key);
|
||||
if (typeof value == "object") {
|
||||
kvCodeViewMap = kvCodeViewMap.set(key, value);
|
||||
} else {
|
||||
kvNormalViewMap = kvNormalViewMap.set(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
kvNormalViewMap = sortedObjectMap(
|
||||
Object.fromEntries(kvNormalViewMap) as Record<string, unknown>,
|
||||
);
|
||||
kvCodeViewMap = sortedObjectMap(Object.fromEntries(kvCodeViewMap) as Record<string, unknown>);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<KVSecretNormalVew {...this.props} data={kvNormalViewMap} />
|
||||
{kvCodeViewMap.size >= 1 && <KVSecretCodeVew {...this.props} data={kvCodeViewMap} />}
|
||||
<KVTOTPExtra {...this.props} data={secretsMap} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (isMultiLevel || this.props.settings.kvAlwaysCodeView) {
|
||||
return <KVSecretCodeVew {...this.props} data={secretsMap} />;
|
||||
return (
|
||||
<div>
|
||||
<KVSecretCodeVew {...this.props} data={secretsMap} />
|
||||
<KVTOTPExtra {...this.props} data={secretsMap} />
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return <KVSecretNormalVew {...this.props} data={secretsMap} />;
|
||||
return (
|
||||
<div>
|
||||
<KVSecretNormalVew {...this.props} data={secretsMap} />
|
||||
<KVTOTPExtra {...this.props} data={secretsMap} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { Checkbox } from "../../../elements/forms/Checkbox";
|
||||
import { Component, createRef } from "preact";
|
||||
import { DefaultPageProps } from "../../../../types/DefaultPageProps";
|
||||
import { InputWithTitle } from "../../../elements/InputWithTitle";
|
||||
|
@ -10,6 +11,8 @@ import i18next from "i18next";
|
|||
export class KeyValueViewSettings extends Component<DefaultPageProps> {
|
||||
viewSyntaxSelectRef = createRef<HTMLSelectElement>();
|
||||
viewIndentInputRef = createRef<HTMLInputElement>();
|
||||
hybridModeInputRef = createRef<HTMLInputElement>();
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
|
@ -47,6 +50,19 @@ export class KeyValueViewSettings extends Component<DefaultPageProps> {
|
|||
}}
|
||||
/>
|
||||
</InputWithTitle>
|
||||
|
||||
{/* Always view in code mode */}
|
||||
<InputWithTitle title={i18next.t("settings_kv_use_hybrid_mode")}>
|
||||
<Checkbox
|
||||
checkboxRef={this.hybridModeInputRef}
|
||||
checked={this.props.settings.kvUseHybridView}
|
||||
onChange={() => {
|
||||
const value = this.hybridModeInputRef.current.checked;
|
||||
this.props.settings.kvUseHybridView = value;
|
||||
settingsSavedNotification();
|
||||
}}
|
||||
/>
|
||||
</InputWithTitle>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue