Rework versions and get deletion to work properly.
This commit is contained in:
parent
c13b7d04e8
commit
dfa448e375
|
@ -68,10 +68,12 @@ export class PageState extends Page {
|
|||
}
|
||||
|
||||
get currentSecretVersion() {
|
||||
return localStorage.getItem('currentSecretVersion') || "0";
|
||||
let result = localStorage.getItem('currentSecretVersion')
|
||||
|
||||
return result != "null" ? result || null : null;
|
||||
}
|
||||
set currentSecretVersion(value) {
|
||||
localStorage.setItem('currentSecretVersion', value);
|
||||
localStorage.setItem('currentSecretVersion', String(value));
|
||||
}
|
||||
|
||||
get currentSecret() {
|
||||
|
|
25
src/api.js
25
src/api.js
|
@ -172,9 +172,20 @@ export async function getSecretMetadata(baseMount, secretPath, name) {
|
|||
});
|
||||
}
|
||||
|
||||
export async function undeleteSecret(baseMount, secretPath, name, version) {
|
||||
let secretURL = `/v1/${baseMount}/undelete/${secretPath.join("")}/${name}`;
|
||||
export async function undeleteSecret(baseMount, secretPath, name, version = null) {
|
||||
let secretURL = `/v1/${baseMount}/undelete/${secretPath.join("/")}/${name}`;
|
||||
secretURL = removeDoubleSlash(secretURL).replace(/\/$/, "");
|
||||
if (version == null) {
|
||||
let meta = await getSecretMetadata(
|
||||
pageState.currentBaseMount,
|
||||
pageState.currentSecretPath,
|
||||
pageState.currentSecret
|
||||
);
|
||||
console.log(meta.versions);
|
||||
let versions = Array.from(new Map(Object.entries(meta.versions)).keys())
|
||||
version = String(versions[versions.length-1])
|
||||
}
|
||||
|
||||
let request = new Request(getAPIURL() + secretURL, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
@ -191,11 +202,11 @@ export async function undeleteSecret(baseMount, secretPath, name, version) {
|
|||
}
|
||||
|
||||
|
||||
export async function getSecret(baseMount, secretPath, name, version = "0") {
|
||||
export async function getSecret(baseMount, secretPath, name, version = null) {
|
||||
let secretURL = "";
|
||||
if (pageState.currentMountType == "kv-v2") {
|
||||
secretURL = `/v1/${baseMount}/data/${secretPath.join("")}/${name}`;
|
||||
if (version != 0) secretURL += `?version=${version}`;
|
||||
if (version != null) secretURL += `?version=${version}`;
|
||||
} else {
|
||||
secretURL = `/v1/${baseMount}/${secretPath.join("")}/${name}`;
|
||||
}
|
||||
|
@ -212,12 +223,12 @@ export async function getSecret(baseMount, secretPath, name, version = "0") {
|
|||
});
|
||||
}
|
||||
|
||||
export async function deleteSecret(baseMount, secretPath, name, version) {
|
||||
export async function deleteSecret(baseMount, secretPath, name, version = null) {
|
||||
let secretURL = "";
|
||||
|
||||
let request;
|
||||
|
||||
if (pageState.currentMountType == "kv-v2" && version != "0") {
|
||||
if (pageState.currentMountType == "kv-v2" && version != null) {
|
||||
secretURL = `/v1/${baseMount}/delete/${secretPath.join("")}/${name}`;
|
||||
secretURL = removeDoubleSlash(secretURL).replace(/\/$/, "");
|
||||
request = new Request(getAPIURL() + secretURL, {
|
||||
|
@ -226,7 +237,7 @@ export async function deleteSecret(baseMount, secretPath, name, version) {
|
|||
'X-Vault-Token': getToken(),
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ "versions": [version] })
|
||||
body: version != null ? JSON.stringify({ "versions": [version] }) : "{}"
|
||||
});
|
||||
} else {
|
||||
if (pageState.currentMountType == "kv-v2") {
|
||||
|
|
|
@ -106,7 +106,7 @@ function currentTitleSecretText() {
|
|||
let currentSecretText = pageState.currentSecret;
|
||||
currentSecretText += pageState.currentPage.titleSuffix;
|
||||
|
||||
if (pageState.currentSecretVersion != "0") currentSecretText += ` (v${pageState.currentSecretVersion})`;
|
||||
if (pageState.currentSecretVersion !== null) currentSecretText += ` (v${pageState.currentSecretVersion})`;
|
||||
return currentSecretText;
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ export function setTitleElement(pageState) {
|
|||
onclick: _ => {
|
||||
pageState.currentSecretPath = [];
|
||||
pageState.currentSecret = "";
|
||||
pageState.currentSecretVersion = "0";
|
||||
pageState.currentSecretVersion = null;
|
||||
|
||||
if (pageState.currentMountType.startsWith("kv") || pageState.currentMountType == "cubbyhole") {
|
||||
changePage("KEY_VALUE_VIEW");
|
||||
|
@ -136,7 +136,7 @@ export function setTitleElement(pageState) {
|
|||
tag: "a",
|
||||
text: secretPath + " ",
|
||||
onclick: _ => {
|
||||
pageState.currentSecretVersion = "0";
|
||||
pageState.currentSecretVersion = null;
|
||||
if (pageState.currentMountType.startsWith("kv")) {
|
||||
pageState.currentSecretPath = secretPaths.slice(0, index + 1);
|
||||
changePage("KEY_VALUE_VIEW");
|
||||
|
|
|
@ -55,7 +55,7 @@ export class HomePage extends Page {
|
|||
pageState.currentBaseMount = "";
|
||||
pageState.currentSecretPath = [];
|
||||
pageState.currentSecret = "";
|
||||
pageState.currentSecretVersion = "0";
|
||||
pageState.currentSecretVersion = null;
|
||||
|
||||
const navList = makeElement({ tag: "ul", class: ["uk-nav", "uk-nav-default", "uk-margin-top"] });
|
||||
pageContent.appendChild(navList);
|
||||
|
|
|
@ -9,8 +9,8 @@ export class KeyValueDeletePage extends Page {
|
|||
super();
|
||||
}
|
||||
goBack() {
|
||||
if (pageState.currentSecretVersion != "0") {
|
||||
pageState.currentSecretVersion = "0";
|
||||
if (pageState.currentSecretVersion != null) {
|
||||
pageState.currentSecretVersion = null;
|
||||
changePage("KEY_VALUE_SECRET");
|
||||
} else {
|
||||
pageState.currentSecret = "";
|
||||
|
|
|
@ -64,7 +64,6 @@ export class KeyValueNewPage extends Page {
|
|||
keyData = { "key": "value" };
|
||||
}
|
||||
|
||||
console.log(splitPath)
|
||||
createOrUpdateSecret(
|
||||
pageState.currentBaseMount,
|
||||
pageState.currentSecretPath,
|
||||
|
|
|
@ -12,8 +12,8 @@ export class KeyValueSecretPage extends Page {
|
|||
super();
|
||||
}
|
||||
goBack() {
|
||||
if (pageState.currentSecretVersion != "0") {
|
||||
pageState.currentSecretVersion = "0";
|
||||
if (pageState.currentSecretVersion != null) {
|
||||
pageState.currentSecretVersion = null;
|
||||
changePage("KEY_VALUE_VERSIONS");
|
||||
} else {
|
||||
pageState.currentSecret = "";
|
||||
|
@ -48,9 +48,9 @@ export class KeyValueSecretPage extends Page {
|
|||
let caps = await getCapabilities(pageState.currentBaseMount, pageState.currentSecretPath, pageState.currentSecret);
|
||||
if (caps.includes("delete")) {
|
||||
let deleteButtonText = i18next.t("kv_secret_delete_btn");
|
||||
if (pageState.currentMountType == "kv-v2" && pageState.currentSecretVersion == "0") {
|
||||
if (pageState.currentMountType == "kv-v2" && pageState.currentSecretVersion == null) {
|
||||
deleteButtonText = i18next.t("kv_secret_delete_all_btn");
|
||||
} else if (pageState.currentMountType == "kv-v2" && pageState.currentSecretVersion != "0") {
|
||||
} else if (pageState.currentMountType == "kv-v2" && pageState.currentSecretVersion != null) {
|
||||
deleteButtonText = i18next.t(
|
||||
"kv_secret_delete_version_btn",
|
||||
{
|
||||
|
@ -67,7 +67,7 @@ export class KeyValueSecretPage extends Page {
|
|||
}));
|
||||
}
|
||||
if (caps.includes("update")) {
|
||||
if (pageState.currentSecretVersion == "0") {
|
||||
if (pageState.currentSecretVersion == null) {
|
||||
buttonsBlock.appendChild(makeElement({
|
||||
tag: "button",
|
||||
id: "editButton",
|
||||
|
|
|
@ -10,8 +10,8 @@ export class KeyValueVersionsPage extends Page {
|
|||
super();
|
||||
}
|
||||
goBack() {
|
||||
if (pageState.currentSecretVersion != "0") {
|
||||
pageState.currentSecretVersion = "0";
|
||||
if (pageState.currentSecretVersion != null) {
|
||||
pageState.currentSecretVersion = null;
|
||||
}
|
||||
changePage("KEY_VALUE_SECRET");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue