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