Seporate getSecret into v1 and v2.
This commit is contained in:
parent
56aeb9b514
commit
77105dca45
|
@ -1,5 +1,44 @@
|
||||||
import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
|
import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
|
||||||
|
|
||||||
|
export async function getSecretKV1(
|
||||||
|
baseMount: string,
|
||||||
|
secretPath: string[],
|
||||||
|
name: string,
|
||||||
|
): Promise<Record<string, unknown>> {
|
||||||
|
const request = new Request(appendAPIURL(`/v1/${baseMount}/${secretPath.join("")}/${name}`), {
|
||||||
|
headers: getHeaders(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const resp = await fetch(request);
|
||||||
|
await checkResponse(resp);
|
||||||
|
|
||||||
|
const data = (await resp.json()) as unknown;
|
||||||
|
|
||||||
|
return (data as { data: Record<string, unknown> }).data;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getSecretKV2(
|
||||||
|
baseMount: string,
|
||||||
|
secretPath: string[],
|
||||||
|
name: string,
|
||||||
|
version: string | null = null,
|
||||||
|
): Promise<Record<string, unknown>> {
|
||||||
|
let secretURL = "";
|
||||||
|
|
||||||
|
secretURL = `/v1/${baseMount}/data/${secretPath.join("")}/${name}`;
|
||||||
|
if (version != null) secretURL += `?version=${version}`;
|
||||||
|
|
||||||
|
const request = new Request(appendAPIURL(secretURL), {
|
||||||
|
headers: getHeaders(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const resp = await fetch(request);
|
||||||
|
await checkResponse(resp);
|
||||||
|
|
||||||
|
const data = (await resp.json()) as unknown;
|
||||||
|
return (data as { data: { data: Record<string, unknown> } }).data.data;
|
||||||
|
}
|
||||||
|
|
||||||
export async function getSecret(
|
export async function getSecret(
|
||||||
baseMount: string,
|
baseMount: string,
|
||||||
secretMountType: string,
|
secretMountType: string,
|
||||||
|
@ -7,25 +46,9 @@ export async function getSecret(
|
||||||
name: string,
|
name: string,
|
||||||
version: string | null = null,
|
version: string | null = null,
|
||||||
): Promise<Record<string, unknown>> {
|
): Promise<Record<string, unknown>> {
|
||||||
let secretURL = "";
|
|
||||||
if (secretMountType == "kv-v2") {
|
if (secretMountType == "kv-v2") {
|
||||||
secretURL = `/v1/${baseMount}/data/${secretPath.join("")}/${name}`;
|
return await getSecretKV2(baseMount, secretPath, name, version)
|
||||||
if (version != null) secretURL += `?version=${version}`;
|
|
||||||
} else {
|
} else {
|
||||||
secretURL = `/v1/${baseMount}/${secretPath.join("")}/${name}`;
|
return await getSecretKV1(baseMount, secretPath, name)
|
||||||
}
|
|
||||||
const request = new Request(appendAPIURL(secretURL), {
|
|
||||||
headers: getHeaders(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const resp = await fetch(request);
|
|
||||||
await checkResponse(resp);
|
|
||||||
|
|
||||||
|
|
||||||
const data = (await resp.json()) as unknown;
|
|
||||||
if (secretMountType == "kv-v2") {
|
|
||||||
return (data as { data: { data: Record<string, unknown> } }).data.data;
|
|
||||||
} else {
|
|
||||||
return (data as { data: Record<string, unknown> }).data;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue