From a934c2c7460fd0aa38a57fb1305ba5bd5dae503a Mon Sep 17 00:00:00 2001 From: Kitteh Date: Wed, 5 May 2021 21:56:25 +0100 Subject: [PATCH] Move pageState.mountType to arguments in api.js. --- src/api.js | 26 +++++++++++------------ src/pages/KeyValue/KeyValueDelete.js | 8 ++++++- src/pages/KeyValue/KeyValueNew.js | 2 ++ src/pages/KeyValue/KeyValueSecret.js | 1 + src/pages/KeyValue/KeyValueSecretsEdit.js | 7 +++++- src/pages/KeyValue/KeyValueView.js | 6 +++++- 6 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/api.js b/src/api.js index baee3e6..8f8522d 100644 --- a/src/api.js +++ b/src/api.js @@ -134,9 +134,9 @@ export async function getCapabilitiesPath(path) { }); } -export async function getSecrets(baseMount, secretPath) { +export async function getSecrets(baseMount, mountType, secretPath) { let secretURL = ""; - if (pageState.currentMountType == "kv-v2") { + if (mountType == "kv-v2") { secretURL = `/v1/${baseMount}/metadata/${secretPath.join("")}?list=true`; } else { // cubbyhole and v1 are identical @@ -177,9 +177,9 @@ export async function undeleteSecret(baseMount, secretPath, name, version = null secretURL = removeDoubleSlash(secretURL).replace(/\/$/, ""); if (version == null) { let meta = await getSecretMetadata( - pageState.currentBaseMount, - pageState.currentSecretPath, - pageState.currentSecret + baseMount, + secretPath, + name ); let versions = getObjectKeys(meta.versions); version = String(versions[versions.length-1]); @@ -201,9 +201,9 @@ export async function undeleteSecret(baseMount, secretPath, name, version = null } -export async function getSecret(baseMount, secretPath, name, version = null) { +export async function getSecret(baseMount, mountType, secretPath, name, version = null) { let secretURL = ""; - if (pageState.currentMountType == "kv-v2") { + if (mountType == "kv-v2") { secretURL = `/v1/${baseMount}/data/${secretPath.join("")}/${name}`; if (version != null) secretURL += `?version=${version}`; } else { @@ -218,16 +218,16 @@ export async function getSecret(baseMount, secretPath, name, version = null) { return fetch(request).then(response => { return response.json(); }).then(data => { - return pageState.currentMountType == "kv-v2" ? data.data.data : data.data; + return mountType == "kv-v2" ? data.data.data : data.data; }); } -export async function deleteSecret(baseMount, secretPath, name, version = null) { +export async function deleteSecret(baseMount, mountType, secretPath, name, version = null) { let secretURL = ""; let request; - if (pageState.currentMountType == "kv-v2" && version != null) { + if (mountType == "kv-v2" && version != null) { secretURL = `/v1/${baseMount}/delete/${secretPath.join("")}/${name}`; secretURL = removeDoubleSlash(secretURL).replace(/\/$/, ""); request = new Request(getAPIURL() + secretURL, { @@ -239,7 +239,7 @@ export async function deleteSecret(baseMount, secretPath, name, version = null) body: version != null ? JSON.stringify({ "versions": [version] }) : "{}" }); } else { - if (pageState.currentMountType == "kv-v2") { + if (mountType == "kv-v2") { secretURL = `/v1/${baseMount}/metadata/${secretPath.join("")}/${name}`; } else { secretURL = `/v1/${baseMount}/${secretPath.join("")}/${name}`; @@ -261,11 +261,11 @@ export async function deleteSecret(baseMount, secretPath, name, version = null) } } -export async function createOrUpdateSecret(baseMount, secretPath, name, data) { +export async function createOrUpdateSecret(baseMount, mountType, secretPath, name, data) { let secretURL = ""; let APIData = {}; - if (pageState.currentMountType == "kv-v2") { + if (mountType == "kv-v2") { secretURL = `/v1/${baseMount}/data/${secretPath.join("/")}/${name}`; APIData = { "data": data }; } else { diff --git a/src/pages/KeyValue/KeyValueDelete.js b/src/pages/KeyValue/KeyValueDelete.js index c496fba..e352ba5 100644 --- a/src/pages/KeyValue/KeyValueDelete.js +++ b/src/pages/KeyValue/KeyValueDelete.js @@ -31,7 +31,13 @@ export class KeyValueDeletePage extends Page { class: ["uk-button", "uk-button-danger"], text: i18next.t("kv_delete_btn"), onclick: _ => { - deleteSecret(pageState.currentBaseMount, pageState.currentSecretPath, pageState.currentSecret, pageState.currentSecretVersion).then(() => { + deleteSecret( + pageState.currentBaseMount, + pageState.currentMountType, + pageState.currentSecretPath, + pageState.currentSecret, + pageState.currentSecretVersion, + ).then(() => { this.goBack(); }); } diff --git a/src/pages/KeyValue/KeyValueNew.js b/src/pages/KeyValue/KeyValueNew.js index 45e8346..6b02e3f 100644 --- a/src/pages/KeyValue/KeyValueNew.js +++ b/src/pages/KeyValue/KeyValueNew.js @@ -65,6 +65,8 @@ export class KeyValueNewPage extends Page { createOrUpdateSecret( pageState.currentBaseMount, + pageState.currentMountType, + pageState.currentSecretPath, pageState.currentSecretPath, path, keyData diff --git a/src/pages/KeyValue/KeyValueSecret.js b/src/pages/KeyValue/KeyValueSecret.js index 6cf56d0..dcf03d5 100644 --- a/src/pages/KeyValue/KeyValueSecret.js +++ b/src/pages/KeyValue/KeyValueSecret.js @@ -89,6 +89,7 @@ export class KeyValueSecretPage extends Page { getSecret( pageState.currentBaseMount, + pageState.currentMountType, pageState.currentSecretPath, pageState.currentSecret, pageState.currentSecretVersion diff --git a/src/pages/KeyValue/KeyValueSecretsEdit.js b/src/pages/KeyValue/KeyValueSecretsEdit.js index 519b3fd..d11de7e 100644 --- a/src/pages/KeyValue/KeyValueSecretsEdit.js +++ b/src/pages/KeyValue/KeyValueSecretsEdit.js @@ -41,7 +41,12 @@ export class KeyValueSecretEditPage extends Page { saveButton ] })); - getSecret(pageState.currentBaseMount, pageState.currentSecretPath, pageState.currentSecret).then(secretInfo => { + getSecret( + pageState.currentBaseMount, + pageState.currentMountType, + pageState.currentSecretPath, + pageState.currentSecret, + ).then(secretInfo => { loadingText.remove(); const secretsJSON = JSON.stringify(Object.fromEntries(new Map(Object.entries(secretInfo).sort())), null, 4); diff --git a/src/pages/KeyValue/KeyValueView.js b/src/pages/KeyValue/KeyValueView.js index f648ee3..e0cec16 100644 --- a/src/pages/KeyValue/KeyValueView.js +++ b/src/pages/KeyValue/KeyValueView.js @@ -41,7 +41,11 @@ export class KeyValueViewPage extends Page { pageContent.appendChild(newButton); try { - let res = await getSecrets(pageState.currentBaseMount, pageState.currentSecretPath); + let res = await getSecrets( + pageState.currentBaseMount, + pageState.currentMountType, + pageState.currentSecretPath, + ); pageContent.appendChild(makeElement({ tag: "ul",