tidy up some code and look at some TODOs
This commit is contained in:
parent
a03a2655d0
commit
cbc52b7e63
|
@ -13,6 +13,7 @@ import yaml from "js-yaml";
|
|||
|
||||
// todo: put this in settings
|
||||
const defaultIndent = 2;
|
||||
const defaultSyntax = "json";
|
||||
|
||||
function parseData(data: string, syntax = "json"): Record<string, unknown> {
|
||||
if (syntax == "json") {
|
||||
|
@ -74,10 +75,9 @@ type KVEditState =
|
|||
export class KVEditor extends Component<KVEditProps, KVEditState> {
|
||||
constructor() {
|
||||
super();
|
||||
// TODO: add a global syntax option to settings for default
|
||||
this.state = {
|
||||
dataLoaded: false,
|
||||
syntax: "json",
|
||||
syntax: defaultSyntax,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -25,11 +25,10 @@ function SecretsList(baseMount: string, secretPath: string[], secrets: string[])
|
|||
<a
|
||||
onClick={async () => {
|
||||
if (secret.endsWith("/")) {
|
||||
// TODO: fix this mess ?
|
||||
route(
|
||||
kvListURL(
|
||||
baseMount,
|
||||
[...secretPath, secret.replace("/", "")].filter((e) => e.length > 0),
|
||||
[...secretPath, secret.replace("/", "")]
|
||||
),
|
||||
);
|
||||
} else {
|
||||
|
@ -145,7 +144,7 @@ type KeyValueListState = {
|
|||
export class KeyValueList extends Component<DefaultPageProps, KeyValueListState> {
|
||||
async componentDidMount() {
|
||||
const baseMount = this.props.matches["baseMount"];
|
||||
const secretPath = this.props.matches["secretPath"].split("/");
|
||||
const secretPath = this.props.matches["secretPath"].split("/").filter((e) => e.length > 0);
|
||||
|
||||
const mountsPath = "/sys/mounts/" + baseMount;
|
||||
const currentPath = baseMount + secretPath.join();
|
||||
|
|
|
@ -51,8 +51,13 @@ export class KeyValueNew extends Component<DefaultPageProps> {
|
|||
): Promise<void> {
|
||||
const path = formData.get("path") as string;
|
||||
|
||||
// TODO: check only do this on kv v1
|
||||
const keyData = { key: "value" };
|
||||
let keyData: Record<string, unknown> = {};
|
||||
|
||||
const mountInfo = await this.props.api.getMount(baseMount);
|
||||
if (mountInfo.options.version == "1") {
|
||||
// Can't have a empty secret on KV V1
|
||||
keyData = { "placeholder_on_kv1": "placeholder_on_kv1" };
|
||||
}
|
||||
|
||||
try {
|
||||
await this.props.api.createOrUpdateSecret(baseMount, secretPath, path, keyData);
|
||||
|
|
|
@ -37,8 +37,10 @@ export function SecretTitleElement(props: SecretTitleElementProps): JSX.Element
|
|||
</a>
|
||||
|
||||
{...secretPath.map((secretPath, index, secretPaths) => {
|
||||
// TODO: find where a '' is returned so dont need this
|
||||
// Sometimes we pass a extra / in urls
|
||||
// just ignore this.
|
||||
if (secretPath.length < 1) return;
|
||||
|
||||
return (
|
||||
<a
|
||||
test-data="secrets-title-secretPath"
|
||||
|
|
|
@ -68,9 +68,14 @@ export class RefreshingTOTPGridItem extends Component<TOTPGridItemProps, { totpV
|
|||
}
|
||||
}
|
||||
|
||||
type TOTPItem = {
|
||||
totpKey: string;
|
||||
canDelete: boolean;
|
||||
}
|
||||
|
||||
type TOTPListState = {
|
||||
capabilities?: CapabilitiesType;
|
||||
totpItems: Partial<TOTPGridItemProps>[];
|
||||
totpItems: TOTPItem[];
|
||||
};
|
||||
|
||||
export class TOTPList extends Component<DefaultPageProps, TOTPListState> {
|
||||
|
@ -88,22 +93,24 @@ export class TOTPList extends Component<DefaultPageProps, TOTPListState> {
|
|||
const mountsPath = "/sys/mounts/" + baseMount;
|
||||
const caps = await api.getCapabilitiesPath([mountsPath, baseMount]);
|
||||
|
||||
let totpItems: Partial<TOTPGridItemProps>[] = [];
|
||||
let totpItems: TOTPItem[] = [];
|
||||
|
||||
// TODO: tidy this up i guess
|
||||
try {
|
||||
totpItems = await Promise.all(
|
||||
Array.from(await api.getTOTPKeys(baseMount)).map(async (key) => {
|
||||
const totpKeys = await api.getTOTPKeys(baseMount);
|
||||
|
||||
let totpKeyPermissions = await Promise.all(Array.from(totpKeys.map(async (key) => {
|
||||
const totpCaps = await api.getCapsPath(removeDoubleSlash(baseMount + "/code/" + key));
|
||||
if (totpCaps.includes("read")) {
|
||||
return {key: key, caps: totpCaps};
|
||||
})));
|
||||
|
||||
totpItems = Array.from(totpKeyPermissions.map((keyData) => {
|
||||
// Filter out all non-readable totp keys.
|
||||
if (!keyData.caps.includes("read")) return;
|
||||
return {
|
||||
baseMount: baseMount,
|
||||
totpKey: key,
|
||||
canDelete: totpCaps.includes("delete"),
|
||||
totpKey: keyData.key,
|
||||
canDelete: keyData.caps.includes("delete"),
|
||||
};
|
||||
}
|
||||
}),
|
||||
);
|
||||
}));
|
||||
} catch (e: unknown) {
|
||||
const error = e as Error;
|
||||
if (error != DoesNotExistError) {
|
||||
|
@ -160,11 +167,9 @@ export class TOTPList extends Component<DefaultPageProps, TOTPListState> {
|
|||
return this.state.totpItems.map((totpItem) => {
|
||||
return (
|
||||
<RefreshingTOTPGridItem
|
||||
settings={this.props.settings}
|
||||
api={this.props.api}
|
||||
baseMount={totpItem.baseMount}
|
||||
totpKey={totpItem.totpKey}
|
||||
canDelete={totpItem.canDelete}
|
||||
{...this.props}
|
||||
baseMount={baseMount}
|
||||
{...totpItem}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
|
|
@ -10,6 +10,7 @@ import { Margin } from "../elements/Margin";
|
|||
import { MarginInline } from "../elements/MarginInline";
|
||||
import { PageTitle } from "../elements/PageTitle";
|
||||
import i18next from "i18next";
|
||||
import { route } from "preact-router";
|
||||
|
||||
const languageIDs = Object.getOwnPropertyNames(translations);
|
||||
|
||||
|
@ -46,9 +47,7 @@ export class SetLanguage extends Component<DefaultPageProps> {
|
|||
|
||||
const t = await i18next.changeLanguage(language);
|
||||
this.props.settings.pageDirection = t("language_direction");
|
||||
// TODO: make navbar somethingy
|
||||
//reloadNavBar(this.router);
|
||||
//route("/");
|
||||
window.location.pathname = "/";
|
||||
route("/");
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue