Move pageState.mountType to arguments in api.js.
This commit is contained in:
parent
be0a597dfb
commit
a934c2c746
26
src/api.js
26
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 = "";
|
let secretURL = "";
|
||||||
if (pageState.currentMountType == "kv-v2") {
|
if (mountType == "kv-v2") {
|
||||||
secretURL = `/v1/${baseMount}/metadata/${secretPath.join("")}?list=true`;
|
secretURL = `/v1/${baseMount}/metadata/${secretPath.join("")}?list=true`;
|
||||||
} else {
|
} else {
|
||||||
// cubbyhole and v1 are identical
|
// cubbyhole and v1 are identical
|
||||||
|
@ -177,9 +177,9 @@ export async function undeleteSecret(baseMount, secretPath, name, version = null
|
||||||
secretURL = removeDoubleSlash(secretURL).replace(/\/$/, "");
|
secretURL = removeDoubleSlash(secretURL).replace(/\/$/, "");
|
||||||
if (version == null) {
|
if (version == null) {
|
||||||
let meta = await getSecretMetadata(
|
let meta = await getSecretMetadata(
|
||||||
pageState.currentBaseMount,
|
baseMount,
|
||||||
pageState.currentSecretPath,
|
secretPath,
|
||||||
pageState.currentSecret
|
name
|
||||||
);
|
);
|
||||||
let versions = getObjectKeys(meta.versions);
|
let versions = getObjectKeys(meta.versions);
|
||||||
version = String(versions[versions.length-1]);
|
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 = "";
|
let secretURL = "";
|
||||||
if (pageState.currentMountType == "kv-v2") {
|
if (mountType == "kv-v2") {
|
||||||
secretURL = `/v1/${baseMount}/data/${secretPath.join("")}/${name}`;
|
secretURL = `/v1/${baseMount}/data/${secretPath.join("")}/${name}`;
|
||||||
if (version != null) secretURL += `?version=${version}`;
|
if (version != null) secretURL += `?version=${version}`;
|
||||||
} else {
|
} else {
|
||||||
|
@ -218,16 +218,16 @@ export async function getSecret(baseMount, secretPath, name, version = null) {
|
||||||
return fetch(request).then(response => {
|
return fetch(request).then(response => {
|
||||||
return response.json();
|
return response.json();
|
||||||
}).then(data => {
|
}).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 secretURL = "";
|
||||||
|
|
||||||
let request;
|
let request;
|
||||||
|
|
||||||
if (pageState.currentMountType == "kv-v2" && version != null) {
|
if (mountType == "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, {
|
||||||
|
@ -239,7 +239,7 @@ export async function deleteSecret(baseMount, secretPath, name, version = null)
|
||||||
body: version != null ? JSON.stringify({ "versions": [version] }) : "{}"
|
body: version != null ? JSON.stringify({ "versions": [version] }) : "{}"
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (pageState.currentMountType == "kv-v2") {
|
if (mountType == "kv-v2") {
|
||||||
secretURL = `/v1/${baseMount}/metadata/${secretPath.join("")}/${name}`;
|
secretURL = `/v1/${baseMount}/metadata/${secretPath.join("")}/${name}`;
|
||||||
} else {
|
} else {
|
||||||
secretURL = `/v1/${baseMount}/${secretPath.join("")}/${name}`;
|
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 secretURL = "";
|
||||||
let APIData = {};
|
let APIData = {};
|
||||||
|
|
||||||
if (pageState.currentMountType == "kv-v2") {
|
if (mountType == "kv-v2") {
|
||||||
secretURL = `/v1/${baseMount}/data/${secretPath.join("/")}/${name}`;
|
secretURL = `/v1/${baseMount}/data/${secretPath.join("/")}/${name}`;
|
||||||
APIData = { "data": data };
|
APIData = { "data": data };
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -31,7 +31,13 @@ export class KeyValueDeletePage extends Page {
|
||||||
class: ["uk-button", "uk-button-danger"],
|
class: ["uk-button", "uk-button-danger"],
|
||||||
text: i18next.t("kv_delete_btn"),
|
text: i18next.t("kv_delete_btn"),
|
||||||
onclick: _ => {
|
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();
|
this.goBack();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,8 @@ export class KeyValueNewPage extends Page {
|
||||||
|
|
||||||
createOrUpdateSecret(
|
createOrUpdateSecret(
|
||||||
pageState.currentBaseMount,
|
pageState.currentBaseMount,
|
||||||
|
pageState.currentMountType,
|
||||||
|
pageState.currentSecretPath,
|
||||||
pageState.currentSecretPath,
|
pageState.currentSecretPath,
|
||||||
path,
|
path,
|
||||||
keyData
|
keyData
|
||||||
|
|
|
@ -89,6 +89,7 @@ export class KeyValueSecretPage extends Page {
|
||||||
|
|
||||||
getSecret(
|
getSecret(
|
||||||
pageState.currentBaseMount,
|
pageState.currentBaseMount,
|
||||||
|
pageState.currentMountType,
|
||||||
pageState.currentSecretPath,
|
pageState.currentSecretPath,
|
||||||
pageState.currentSecret,
|
pageState.currentSecret,
|
||||||
pageState.currentSecretVersion
|
pageState.currentSecretVersion
|
||||||
|
|
|
@ -41,7 +41,12 @@ export class KeyValueSecretEditPage extends Page {
|
||||||
saveButton
|
saveButton
|
||||||
]
|
]
|
||||||
}));
|
}));
|
||||||
getSecret(pageState.currentBaseMount, pageState.currentSecretPath, pageState.currentSecret).then(secretInfo => {
|
getSecret(
|
||||||
|
pageState.currentBaseMount,
|
||||||
|
pageState.currentMountType,
|
||||||
|
pageState.currentSecretPath,
|
||||||
|
pageState.currentSecret,
|
||||||
|
).then(secretInfo => {
|
||||||
loadingText.remove();
|
loadingText.remove();
|
||||||
|
|
||||||
const secretsJSON = JSON.stringify(Object.fromEntries(new Map(Object.entries(secretInfo).sort())), null, 4);
|
const secretsJSON = JSON.stringify(Object.fromEntries(new Map(Object.entries(secretInfo).sort())), null, 4);
|
||||||
|
|
|
@ -41,7 +41,11 @@ export class KeyValueViewPage extends Page {
|
||||||
pageContent.appendChild(newButton);
|
pageContent.appendChild(newButton);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let res = await getSecrets(pageState.currentBaseMount, pageState.currentSecretPath);
|
let res = await getSecrets(
|
||||||
|
pageState.currentBaseMount,
|
||||||
|
pageState.currentMountType,
|
||||||
|
pageState.currentSecretPath,
|
||||||
|
);
|
||||||
|
|
||||||
pageContent.appendChild(makeElement({
|
pageContent.appendChild(makeElement({
|
||||||
tag: "ul",
|
tag: "ul",
|
||||||
|
|
Loading…
Reference in a new issue