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";
|
||||
|
||||
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(
|
||||
baseMount: string,
|
||||
secretMountType: string,
|
||||
|
@ -7,25 +46,9 @@ export async function getSecret(
|
|||
name: string,
|
||||
version: string | null = null,
|
||||
): Promise<Record<string, unknown>> {
|
||||
let secretURL = "";
|
||||
if (secretMountType == "kv-v2") {
|
||||
secretURL = `/v1/${baseMount}/data/${secretPath.join("")}/${name}`;
|
||||
if (version != null) secretURL += `?version=${version}`;
|
||||
return await getSecretKV2(baseMount, secretPath, name, version)
|
||||
} else {
|
||||
secretURL = `/v1/${baseMount}/${secretPath.join("")}/${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;
|
||||
return await getSecretKV1(baseMount, secretPath, name)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue