1
0
Fork 0

Move pageState.mountType to arguments in api.js.

This commit is contained in:
Kitteh 2021-05-05 21:56:25 +01:00
parent be0a597dfb
commit a934c2c746
6 changed files with 34 additions and 16 deletions

View file

@ -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 {

View file

@ -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();
});
}

View file

@ -65,6 +65,8 @@ export class KeyValueNewPage extends Page {
createOrUpdateSecret(
pageState.currentBaseMount,
pageState.currentMountType,
pageState.currentSecretPath,
pageState.currentSecretPath,
path,
keyData

View file

@ -89,6 +89,7 @@ export class KeyValueSecretPage extends Page {
getSecret(
pageState.currentBaseMount,
pageState.currentMountType,
pageState.currentSecretPath,
pageState.currentSecret,
pageState.currentSecretVersion

View file

@ -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);

View file

@ -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",