Start work on transit pages.
This commit is contained in:
parent
9f40b0b22c
commit
6c6a92b094
16
src/api.js
16
src/api.js
|
@ -261,6 +261,22 @@ export async function createOrUpdateSecret(baseMount, secretPath, name, data) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function getTransitKeys(baseMount) {
|
||||
const request = new Request(getAPIURL() + `/v1/${baseMount}/keys?list=true`, {
|
||||
headers: {
|
||||
"X-Vault-Token": getToken(),
|
||||
}
|
||||
});
|
||||
return fetch(request).then(response => {
|
||||
if (response.status == 404) {
|
||||
throw DoesNotExistError;
|
||||
}
|
||||
return response.json();
|
||||
}).then(data => {
|
||||
return data.data.keys;
|
||||
});
|
||||
}
|
||||
|
||||
export async function getTOTPKeys(baseMount) {
|
||||
const request = new Request(getAPIURL() + `/v1/${baseMount}/keys?list=true`, {
|
||||
headers: {
|
||||
|
|
|
@ -23,6 +23,8 @@ import {
|
|||
LoginPage,
|
||||
SetVaultURLPage,
|
||||
UnsealPage,
|
||||
TransitViewPage,
|
||||
TransitViewSecretPage,
|
||||
KeyValueViewPage,
|
||||
KeyValueSecretsPage,
|
||||
KeyValueVersionsPage,
|
||||
|
@ -41,6 +43,8 @@ const pages = {
|
|||
LOGIN: new LoginPage(),
|
||||
SET_VAULT_URL: new SetVaultURLPage(),
|
||||
UNSEAL: new UnsealPage(),
|
||||
TRANSIT_VIEW: new TransitViewPage(),
|
||||
TRANSIT_VIEW_SECRET: new TransitViewSecretPage(),
|
||||
KEY_VALUE_VIEW: new KeyValueViewPage(),
|
||||
KEY_VALUE_SECRETS: new KeyValueSecretsPage(),
|
||||
KEY_VALUE_VERSIONS: new KeyValueVersionsPage(),
|
||||
|
|
|
@ -122,7 +122,7 @@ export class HomePage extends Page {
|
|||
if (typeof mount != 'object') return;
|
||||
if (mount == null) return;
|
||||
if (!("type" in mount)) return;
|
||||
if (!(["kv", "totp"].includes(mount.type))) return;
|
||||
if (!(["kv", "totp", "transit"].includes(mount.type))) return;
|
||||
|
||||
let mountType = mount.type == "kv" ? "kv-v" + String(mount.options.version) : mount.type;
|
||||
|
||||
|
@ -134,6 +134,9 @@ export class HomePage extends Page {
|
|||
} else if (mount.type == "totp") {
|
||||
linkText = `TOTP - ${baseMount}`;
|
||||
linkPage = pages.TOTP;
|
||||
} else if (mount.type == "transit"){
|
||||
linkText = `Transit - ${baseMount}`;
|
||||
linkPage = pages.TRANSIT_VIEW;
|
||||
}
|
||||
|
||||
navList.appendChild(makeElement({
|
||||
|
|
|
@ -71,7 +71,7 @@ export class KeyValueViewPage extends Page {
|
|||
} else {
|
||||
setErrorText(e.message);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
get name() {
|
||||
|
|
65
src/pages/TransitView.js
Normal file
65
src/pages/TransitView.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
import { Page } from "../types/Page.js";
|
||||
import { DoesNotExistError, getTransitKeys } from "../api.js";
|
||||
import { setErrorText, setTitleElement } from "../pageUtils.js";
|
||||
import { makeElement } from "../htmlUtils.js";
|
||||
|
||||
export class TransitViewPage extends Page {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
goBack() {
|
||||
changePage(pages.HOME);
|
||||
}
|
||||
async render() {
|
||||
pageState.currentSecret = "";
|
||||
|
||||
setTitleElement(pageState);
|
||||
|
||||
let newButton = makeElement({
|
||||
tag: "button",
|
||||
text: "New",
|
||||
class: ["uk-button", "uk-button-primary", "uk-margin-bottom"],
|
||||
onclick: () => {
|
||||
changePage(pages.TRANSIT_NEW_KEY);
|
||||
}
|
||||
});
|
||||
pageContent.appendChild(newButton);
|
||||
|
||||
try {
|
||||
let res = await getTransitKeys(pageState.currentBaseMount);
|
||||
|
||||
pageContent.appendChild(makeElement({
|
||||
tag: "ul",
|
||||
class: ["uk-nav", "uk-nav-default"],
|
||||
children: [
|
||||
...res.map(function (secret) {
|
||||
return makeElement({
|
||||
tag: "li",
|
||||
children: makeElement({
|
||||
tag: "a",
|
||||
text: secret,
|
||||
onclick: _ => {
|
||||
pageState.currentSecret = secret;
|
||||
changePage(pages.TRANSIT_VIEW_SECRET);
|
||||
}
|
||||
})
|
||||
});
|
||||
})
|
||||
]
|
||||
}));
|
||||
} catch (e) {
|
||||
if (e == DoesNotExistError) {
|
||||
pageContent.appendChild(makeElement({
|
||||
tag: "p",
|
||||
text: "You seem to have no transit keys here, would you like to create one?"
|
||||
}));
|
||||
} else {
|
||||
setErrorText(e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get name() {
|
||||
return "Transit View";
|
||||
}
|
||||
}
|
56
src/pages/TransitViewSecret.js
Normal file
56
src/pages/TransitViewSecret.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
import { Page } from "../types/Page.js";
|
||||
import { setPageContent, setTitleElement } from "../pageUtils.js";
|
||||
import { makeElement } from "../htmlUtils.js";
|
||||
|
||||
export class TransitViewSecretPage extends Page {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
makeTile(title, description, onclick) {
|
||||
return makeElement({
|
||||
tag: "div",
|
||||
class: ["uk-tile", "uk-tile-default", "uk-tile-primary", "uk-padding-small"],
|
||||
children: makeElement({
|
||||
tag: "a",
|
||||
class: "uk-link-heading",
|
||||
children: [
|
||||
makeElement({
|
||||
tag: "p",
|
||||
class: "uk-h4",
|
||||
text: title
|
||||
}),
|
||||
makeElement({
|
||||
tag: "span",
|
||||
class: "uk-text-muted",
|
||||
text: description
|
||||
})
|
||||
]
|
||||
})
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
async render() {
|
||||
setTitleElement(pageState);
|
||||
setPageContent(makeElement({
|
||||
tag: "div",
|
||||
class: ["uk-child-width-1-2", "uk-grid-collapse", "uk-grid-small"],
|
||||
attributes: { "uk-grid": "" },
|
||||
children: [
|
||||
makeElement({
|
||||
tag: "div",
|
||||
children: [
|
||||
this.makeTile("Encrypt", "Encrypt some plaintext or base64 encoded binary."),
|
||||
this.makeTile("Decrypt", "Decrypt some cyphertext."),
|
||||
]
|
||||
}),
|
||||
]
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
get name() {
|
||||
return "Password Generator";
|
||||
}
|
||||
}
|
|
@ -11,3 +11,5 @@ export { KeyValueNewPage } from "./KeyValueNew.js";
|
|||
export { KeyValueDeletePage } from "./KeyValueDelete.js";
|
||||
export { KeyValueSecretsEditPage } from "./KeyValueSecretsEdit.js";
|
||||
export { PwGenPage } from "./PwGen.js";
|
||||
export { TransitViewPage } from "./TransitView.js";
|
||||
export { TransitViewSecretPage } from "./TransitViewSecret.js";
|
Loading…
Reference in a new issue