diff --git a/src/api/API.ts b/src/api/API.ts
new file mode 100644
index 0000000..89a7223
--- /dev/null
+++ b/src/api/API.ts
@@ -0,0 +1,633 @@
+import { Settings } from "../settings/Settings";
+import { DoesNotExistError } from "../types/internalErrors";
+import { removeDoubleSlash } from "../utils";
+import { BaseAPIResponse } from "./types/api";
+import { AuthListAPIType, AuthListType } from "./types/auth";
+import { CapabilitiesType } from "./types/capabilities";
+import { MountsType, MountType, NewMountParams } from "./types/mount";
+import { SealStatusType } from "./types/seal";
+import { TokenInfo } from "./types/token";
+import {
+ DecryptionPayload,
+ DecryptionResult,
+ EncryptionPayload,
+ EncryptionResult,
+ RewrapPayload,
+ RewrapResult,
+ TransitKeyType,
+} from "./types/transit";
+import { UserType, UserTypeAPIResp } from "./types/user";
+
+async function checkResponse(resp: Response): Promise {
+ if (resp.ok) return;
+ if (resp.status == 404) throw DoesNotExistError;
+
+ let json: BaseAPIResponse;
+ try {
+ json = (await resp.json()) as BaseAPIResponse;
+ } catch {
+ // Do Nothing
+ }
+
+ if (json?.errors?.length >= 1) {
+ throw new Error(json.errors[0]);
+ }
+}
+
+export class API {
+ private settings: Settings;
+
+ constructor(settings: Settings) {
+ this.settings = settings;
+ }
+
+ getHeaders(): Record {
+ return {
+ "X-Vault-Token": this.settings.token,
+ };
+ }
+ appendAPIURL(url: string): string {
+ return this.settings.apiURL + url;
+ }
+
+ // List all supported auth methods
+ async listAuth(): Promise {
+ const request = new Request(this.appendAPIURL(`/v1/sys/auth`), {
+ headers: this.getHeaders(),
+ });
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as AuthListAPIType;
+ return data.data;
+ }
+
+ // Tries to login with username and password, returns token
+ async usernameLogin(username: string, password: string): Promise {
+ const request = new Request(this.appendAPIURL(`/v1/auth/userpass/login/${username}`), {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({ username: username, password: password }),
+ });
+
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as {
+ auth: { client_token: string };
+ };
+ return data.auth.client_token;
+ }
+
+ async createOrUpdateUserPassUser(
+ path: string,
+ username: string,
+ data: Partial,
+ ): Promise {
+ const request = new Request(
+ this.appendAPIURL(removeDoubleSlash(`/v1/auth/${path}/users/${username}`)),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ ...this.getHeaders(),
+ },
+ body: JSON.stringify(data, null, 0),
+ },
+ );
+ const resp = await fetch(request);
+ await checkResponse(resp);
+ }
+
+ async deleteUserPassUser(path: string, username: string): Promise {
+ const request = new Request(
+ this.appendAPIURL(removeDoubleSlash(`/v1/auth/${path}/users/${username}`)),
+ {
+ method: "DELETE",
+ headers: this.getHeaders(),
+ },
+ );
+ const resp = await fetch(request);
+ await checkResponse(resp);
+ }
+
+ async getUserPassUser(path: string, username: string): Promise {
+ const request = new Request(this.appendAPIURL(`/v1/auth/${path}/users/${username}`), {
+ headers: this.getHeaders(),
+ });
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as UserTypeAPIResp;
+ return data.data;
+ }
+
+ async listUserPassUsers(path: string): Promise {
+ const request = new Request(this.appendAPIURL(`/v1/auth/${path}/users?list=true`), {
+ headers: this.getHeaders(),
+ });
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as { data: { keys: string[] } };
+ return data.data.keys;
+ }
+
+ async getMount(mountName: string): Promise {
+ const request = new Request(this.appendAPIURL("/v1/sys/internal/ui/mounts/" + mountName), {
+ headers: this.getHeaders(),
+ });
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as { data: MountType };
+ return data.data;
+ }
+
+ async getMounts(): Promise {
+ const request = new Request(this.appendAPIURL("/v1/sys/internal/ui/mounts"), {
+ headers: this.getHeaders(),
+ });
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as { data: { secret: MountsType } };
+ return data.data.secret;
+ }
+
+ async newMount(parms: NewMountParams): Promise {
+ const request = new Request(
+ this.appendAPIURL(removeDoubleSlash(`/v1/sys/mounts/${parms.name}`)),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ ...this.getHeaders(),
+ },
+ body: JSON.stringify(parms),
+ },
+ );
+ const resp = await fetch(request);
+ await checkResponse(resp);
+ }
+
+ async deleteMount(mountPath: string): Promise {
+ const request = new Request(this.appendAPIURL("/v1/sys/mounts/" + mountPath), {
+ method: "DELETE",
+ headers: this.getHeaders(),
+ });
+ const resp = await fetch(request);
+ await checkResponse(resp);
+ }
+
+ async getCapabilitiesPath(path: string | string[]): Promise {
+ if (!Array.isArray(path)) {
+ path = [path];
+ }
+
+ const request = new Request(this.appendAPIURL("/v1/sys/capabilities-self"), {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ ...this.getHeaders(),
+ },
+ body: JSON.stringify({
+ paths: path,
+ }),
+ });
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as { capabilities: string[] };
+ return data;
+ }
+
+ async getCapsPath(path: string | string[]): Promise {
+ return (await this.getCapabilitiesPath(path)).capabilities;
+ }
+
+ async getCapabilities(
+ baseMount: string,
+ secretPath: string[],
+ name: string,
+ ): Promise {
+ return await this.getCapabilitiesPath(
+ removeDoubleSlash(baseMount + secretPath.join("/") + "/" + name),
+ );
+ }
+
+ async sealVault(): Promise {
+ const request = new Request(this.appendAPIURL("/v1/sys/seal"), {
+ method: "PUT",
+ headers: this.getHeaders(),
+ });
+ const resp = await fetch(request);
+ await checkResponse(resp);
+ }
+
+ async submitUnsealKey(key: string): Promise {
+ const request = new Request(this.appendAPIURL("/v1/sys/unseal"), {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ key: key,
+ }),
+ });
+ const resp = await fetch(request);
+ await checkResponse(resp);
+ }
+
+ async getSealStatus(): Promise {
+ const request = new Request(this.appendAPIURL("/v1/sys/seal-status"));
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as SealStatusType;
+ return data;
+ }
+
+ async lookupSelf(): Promise {
+ const request = new Request(this.appendAPIURL("/v1/auth/token/lookup-self"), {
+ headers: this.getHeaders(),
+ });
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as { data: TokenInfo };
+ return data.data;
+ }
+
+ async renewSelf(): Promise {
+ const request = new Request(this.appendAPIURL("/v1/auth/token/renew-self"), {
+ method: "POST",
+ headers: {
+ ...this.getHeaders(),
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({}),
+ });
+ const resp = await fetch(request);
+ await checkResponse(resp);
+ }
+
+ async createOrUpdatePolicy(name: string, policy_data: string): Promise {
+ const request = new Request(this.appendAPIURL("/v1/sys/policies/acl/" + name), {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ ...this.getHeaders(),
+ },
+ body: JSON.stringify({ policy: policy_data }, null, 0),
+ });
+
+ const resp = await fetch(request);
+ await checkResponse(resp);
+ }
+
+ async deletePolicy(name: string): Promise {
+ const request = new Request(this.appendAPIURL("/v1/sys/policies/acl/" + name), {
+ method: "DELETE",
+ headers: this.getHeaders(),
+ });
+ const resp = await fetch(request);
+ await checkResponse(resp);
+ }
+
+ async getPolicies(): Promise {
+ const request = new Request(this.appendAPIURL("/v1/sys/policies/acl?list=true"), {
+ headers: this.getHeaders(),
+ });
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as { data: { keys: string[] } };
+ return data.data.keys;
+ }
+
+ async getPolicy(name: string): Promise {
+ const request = new Request(this.appendAPIURL("/v1/sys/policies/acl/" + name), {
+ headers: this.getHeaders(),
+ });
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as { data: { policy: string } };
+ return data.data.policy;
+ }
+
+ async createOrUpdateSecret(
+ baseMount: string,
+ secretPath: string[],
+ name: string,
+ data: Record,
+ ): Promise {
+ let secretURL = "";
+ let APIData = {};
+
+ const mountInfo = await this.getMount(baseMount);
+ if (mountInfo.options.version == "2") {
+ secretURL = `/v1/${baseMount}/data/${secretPath.join("/")}/${name}`;
+ APIData = { data: data };
+ } else {
+ secretURL = `/v1/${baseMount}/${secretPath.join("/")}/${name}`;
+ APIData = data;
+ }
+
+ secretURL = removeDoubleSlash(secretURL).replace(/\/$/, "");
+ const request = new Request(this.appendAPIURL(secretURL), {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ ...this.getHeaders(),
+ },
+ body: JSON.stringify(APIData, null, 0),
+ });
+ const resp = await fetch(request);
+ await checkResponse(resp);
+ }
+
+ async deleteSecret(baseMount: string, secretPath: string[], name: string): Promise {
+ let secretURL = "";
+ let request;
+
+ const mountInfo = await this.getMount(baseMount);
+ if (mountInfo.options.version == "2") {
+ secretURL = `/v1/${baseMount}/metadata/${secretPath.join("/")}/${name}`;
+ } else {
+ secretURL = `/v1/${baseMount}/${secretPath.join("/")}/${name}`;
+ }
+ secretURL = removeDoubleSlash(secretURL).replace(/\/$/, "");
+ request = new Request(this.appendAPIURL(secretURL), {
+ method: "DELETE",
+ headers: this.getHeaders(),
+ });
+ const resp = await fetch(request);
+ await checkResponse(resp);
+ }
+
+ async getSecretKV1(
+ baseMount: string,
+ secretPath: string[],
+ name: string,
+ ): Promise> {
+ const request = new Request(
+ this.appendAPIURL(`/v1/${baseMount}/${secretPath.join("")}/${name}`),
+ {
+ headers: this.getHeaders(),
+ },
+ );
+
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as unknown;
+
+ return (data as { data: Record }).data;
+ }
+
+ async getSecretKV2(
+ baseMount: string,
+ secretPath: string[],
+ name: string,
+ ): Promise> {
+ let secretURL = "";
+
+ secretURL = `/v1/${baseMount}/data/${secretPath.join("")}/${name}`;
+
+ const request = new Request(this.appendAPIURL(secretURL), {
+ headers: this.getHeaders(),
+ });
+
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as unknown;
+ return (data as { data: { data: Record } }).data.data;
+ }
+
+ async getSecret(
+ baseMount: string,
+ secretPath: string[],
+ name: string,
+ ): Promise> {
+ const mountInfo = await this.getMount(baseMount);
+ if (mountInfo.options.version == "2") {
+ return await this.getSecretKV2(baseMount, secretPath, name);
+ } else {
+ return await this.getSecretKV1(baseMount, secretPath, name);
+ }
+ }
+
+ async getSecretMetadata(
+ baseMount: string,
+ secretPath: string[],
+ name: string,
+ ): Promise {
+ const request = new Request(
+ this.appendAPIURL(`/v1/${baseMount}/metadata/${secretPath.join("")}/${name}`),
+ {
+ headers: this.getHeaders(),
+ },
+ );
+
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as { data: SecretMetadataType };
+ return data.data;
+ }
+
+ async getSecrets(baseMount: string, secretPath: string[]): Promise {
+ let secretURL = "";
+
+ const mountInfo = await this.getMount(baseMount);
+ if (mountInfo.options.version == "2") {
+ secretURL = `/v1/${baseMount}/metadata/${secretPath.join("/")}?list=true`;
+ } else {
+ secretURL = `/v1/${baseMount}/${secretPath.join("/")}?list=true`;
+ }
+ const request = new Request(this.appendAPIURL(secretURL), {
+ headers: this.getHeaders(),
+ });
+
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as { data: { keys: string[] } };
+ return data.data.keys;
+ }
+
+ async addNewTOTP(baseMount: string, parms: { name: string }): Promise {
+ const request = new Request(
+ this.appendAPIURL(removeDoubleSlash(`/v1/${baseMount}/keys/${parms.name}`)),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ ...this.getHeaders(),
+ },
+ body: JSON.stringify(parms),
+ },
+ );
+ const resp = await fetch(request);
+ await checkResponse(resp);
+ }
+
+ async deleteTOTP(baseMount: string, name: string): Promise {
+ const request = new Request(this.appendAPIURL(`/v1/${baseMount}/keys/${name}`), {
+ method: "DELETE",
+ headers: this.getHeaders(),
+ });
+ const resp = await fetch(request);
+ await checkResponse(resp);
+ }
+
+ async getTOTPCode(baseMount: string, name: string): Promise {
+ const request = new Request(this.appendAPIURL(`/v1/${baseMount}/code/${name}`), {
+ headers: this.getHeaders(),
+ });
+
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as { data: { code: string } };
+ return data.data.code;
+ }
+
+ async getTOTPKeys(baseMount: string): Promise {
+ const request = new Request(this.appendAPIURL(`/v1/${baseMount}/keys?list=true`), {
+ headers: this.getHeaders(),
+ });
+
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as { data: { keys: string[] } };
+ return data.data.keys;
+ }
+
+ async getTransitKey(baseMount: string, name: string): Promise {
+ const request = new Request(this.appendAPIURL(`/v1/${baseMount}/keys/${name}`), {
+ headers: this.getHeaders(),
+ });
+
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as { data: TransitKeyType };
+ return data.data;
+ }
+
+ async getTransitKeys(baseMount: string): Promise {
+ const request = new Request(this.appendAPIURL(`/v1/${baseMount}/keys?list=true`), {
+ headers: this.getHeaders(),
+ });
+
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as { data: { keys: string[] } };
+ return data.data.keys;
+ }
+
+ async newTransitKey(baseMount: string, parms: { name: string; type: string }): Promise {
+ const request = new Request(
+ this.appendAPIURL(removeDoubleSlash(`/v1/${baseMount}/keys/${parms.name}`)),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ ...this.getHeaders(),
+ },
+ body: JSON.stringify(parms),
+ },
+ );
+ const resp = await fetch(request);
+ await checkResponse(resp);
+ }
+
+ async transitDecrypt(
+ baseMount: string,
+ name: string,
+ payload: DecryptionPayload,
+ ): Promise {
+ const request = new Request(
+ this.appendAPIURL(removeDoubleSlash(`/v1/${baseMount}/decrypt/${name}`)),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ ...this.getHeaders(),
+ },
+ body: JSON.stringify(payload),
+ },
+ );
+
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as {
+ data?: DecryptionResult;
+ };
+
+ return data.data;
+ }
+
+ async transitEncrypt(
+ baseMount: string,
+ name: string,
+ payload: EncryptionPayload,
+ ): Promise {
+ const request = new Request(
+ this.appendAPIURL(removeDoubleSlash(`/v1/${baseMount}/encrypt/${name}`)),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ ...this.getHeaders(),
+ },
+ body: JSON.stringify(payload),
+ },
+ );
+
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as {
+ data?: EncryptionResult;
+ };
+
+ return data.data;
+ }
+
+ async transitRewrap(
+ baseMount: string,
+ name: string,
+ payload: RewrapPayload,
+ ): Promise {
+ const request = new Request(
+ this.appendAPIURL(removeDoubleSlash(`/v1/${baseMount}/rewrap/${name}`)),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ ...this.getHeaders(),
+ },
+ body: JSON.stringify(payload),
+ },
+ );
+
+ const resp = await fetch(request);
+ await checkResponse(resp);
+
+ const data = (await resp.json()) as {
+ data?: RewrapResult;
+ };
+
+ return data.data;
+ }
+}
diff --git a/src/api/auth/listAuth.ts b/src/api/auth/listAuth.ts
deleted file mode 100644
index 8267bac..0000000
--- a/src/api/auth/listAuth.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import { AuthListAPIType, AuthListType } from "../types/auth";
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-
-export async function listAuth(): Promise {
- const request = new Request(appendAPIURL(`/v1/sys/auth`), {
- headers: getHeaders(),
- });
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as AuthListAPIType;
- return data.data;
-}
diff --git a/src/api/auth/usernameLogin.ts b/src/api/auth/usernameLogin.ts
deleted file mode 100644
index 5384c8a..0000000
--- a/src/api/auth/usernameLogin.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import { appendAPIURL, checkResponse } from "../apiUtils";
-
-export async function usernameLogin(username: string, password: string): Promise {
- const request = new Request(appendAPIURL(`/v1/auth/userpass/login/${username}`), {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({ username: username, password: password }),
- });
-
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as {
- auth: { client_token: string };
- };
- return data.auth.client_token;
-}
diff --git a/src/api/auth/userpass/createOrUpdateUserPassUser.ts b/src/api/auth/userpass/createOrUpdateUserPassUser.ts
deleted file mode 100644
index 0e15e9b..0000000
--- a/src/api/auth/userpass/createOrUpdateUserPassUser.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { UserType } from "../../types/userpass/user";
-import { appendAPIURL, checkResponse, getHeaders } from "../../apiUtils";
-import { removeDoubleSlash } from "../../../utils";
-
-export async function createOrUpdateUserPassUser(
- path: string,
- username: string,
- data: Partial,
-): Promise {
- const request = new Request(
- appendAPIURL(removeDoubleSlash(`/v1/auth/${path}/users/${username}`)),
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- ...getHeaders(),
- },
- body: JSON.stringify(data, null, 0),
- },
- );
- const resp = await fetch(request);
- await checkResponse(resp);
-}
diff --git a/src/api/auth/userpass/deleteUserPassUser.ts b/src/api/auth/userpass/deleteUserPassUser.ts
deleted file mode 100644
index 9278dd5..0000000
--- a/src/api/auth/userpass/deleteUserPassUser.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../../apiUtils";
-import { removeDoubleSlash } from "../../../utils";
-
-export async function deleteUserPassUser(path: string, username: string): Promise {
- const request = new Request(
- appendAPIURL(removeDoubleSlash(`/v1/auth/${path}/users/${username}`)),
- {
- method: "DELETE",
- headers: getHeaders(),
- },
- );
- const resp = await fetch(request);
- await checkResponse(resp);
-}
diff --git a/src/api/auth/userpass/getUserPassUser.ts b/src/api/auth/userpass/getUserPassUser.ts
deleted file mode 100644
index 5ce5b8e..0000000
--- a/src/api/auth/userpass/getUserPassUser.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import { UserType, UserTypeAPIResp } from "../../types/userpass/user";
-import { appendAPIURL, checkResponse, getHeaders } from "../../apiUtils";
-
-export async function getUserPassUser(path: string, username: string): Promise {
- const request = new Request(appendAPIURL(`/v1/auth/${path}/users/${username}`), {
- headers: getHeaders(),
- });
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as UserTypeAPIResp;
- return data.data;
-}
diff --git a/src/api/auth/userpass/listUserPassUsers.ts b/src/api/auth/userpass/listUserPassUsers.ts
deleted file mode 100644
index 417b2e6..0000000
--- a/src/api/auth/userpass/listUserPassUsers.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../../apiUtils";
-
-export async function listUserPassUsers(path: string): Promise {
- const request = new Request(appendAPIURL(`/v1/auth/${path}/users?list=true`), {
- headers: getHeaders(),
- });
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as { data: { keys: string[] } };
- return data.data.keys;
-}
diff --git a/src/api/kv/createOrUpdateSecret.ts b/src/api/kv/createOrUpdateSecret.ts
deleted file mode 100644
index f2cf946..0000000
--- a/src/api/kv/createOrUpdateSecret.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-import { getMount } from "../sys/getMounts";
-import { removeDoubleSlash } from "../../utils";
-
-export async function createOrUpdateSecret(
- baseMount: string,
- secretPath: string[],
- name: string,
- data: Record,
-): Promise {
- let secretURL = "";
- let APIData = {};
-
- const mountInfo = await getMount(baseMount);
- if (mountInfo.options.version == "2") {
- secretURL = `/v1/${baseMount}/data/${secretPath.join("/")}/${name}`;
- APIData = { data: data };
- } else {
- secretURL = `/v1/${baseMount}/${secretPath.join("/")}/${name}`;
- APIData = data;
- }
-
- secretURL = removeDoubleSlash(secretURL).replace(/\/$/, "");
- const request = new Request(appendAPIURL(secretURL), {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- ...getHeaders(),
- },
- body: JSON.stringify(APIData, null, 0),
- });
- const resp = await fetch(request);
- await checkResponse(resp);
-}
diff --git a/src/api/kv/deleteSecret.ts b/src/api/kv/deleteSecret.ts
deleted file mode 100644
index 9c450a1..0000000
--- a/src/api/kv/deleteSecret.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-import { getMount } from "../sys/getMounts";
-import { removeDoubleSlash } from "../../utils";
-
-export async function deleteSecret(
- baseMount: string,
- secretPath: string[],
- name: string,
-): Promise {
- let secretURL = "";
- let request;
-
- const mountInfo = await getMount(baseMount);
- if (mountInfo.options.version == "2") {
- secretURL = `/v1/${baseMount}/metadata/${secretPath.join("/")}/${name}`;
- } else {
- secretURL = `/v1/${baseMount}/${secretPath.join("/")}/${name}`;
- }
- secretURL = removeDoubleSlash(secretURL).replace(/\/$/, "");
- request = new Request(appendAPIURL(secretURL), {
- method: "DELETE",
- headers: getHeaders(),
- });
- const resp = await fetch(request);
- await checkResponse(resp);
-}
diff --git a/src/api/kv/getSecret.ts b/src/api/kv/getSecret.ts
deleted file mode 100644
index 156bd66..0000000
--- a/src/api/kv/getSecret.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-import { getMount } from "../sys/getMounts";
-
-export async function getSecretKV1(
- baseMount: string,
- secretPath: string[],
- name: string,
-): Promise> {
- 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 }).data;
-}
-
-export async function getSecretKV2(
- baseMount: string,
- secretPath: string[],
- name: string,
-): Promise> {
- let secretURL = "";
-
- secretURL = `/v1/${baseMount}/data/${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;
- return (data as { data: { data: Record } }).data.data;
-}
-
-export async function getSecret(
- baseMount: string,
- secretPath: string[],
- name: string,
-): Promise> {
- const mountInfo = await getMount(baseMount);
- if (mountInfo.options.version == "2") {
- return await getSecretKV2(baseMount, secretPath, name);
- } else {
- return await getSecretKV1(baseMount, secretPath, name);
- }
-}
diff --git a/src/api/kv/getSecretMetadata.ts b/src/api/kv/getSecretMetadata.ts
deleted file mode 100644
index 657db3b..0000000
--- a/src/api/kv/getSecretMetadata.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-
-type SecretMetadataType = {
- versions: Record;
-};
-
-export async function getSecretMetadata(
- baseMount: string,
- secretPath: string[],
- name: string,
-): Promise {
- const request = new Request(
- appendAPIURL(`/v1/${baseMount}/metadata/${secretPath.join("")}/${name}`),
- {
- headers: getHeaders(),
- },
- );
-
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as { data: SecretMetadataType };
- return data.data;
-}
diff --git a/src/api/kv/getSecrets.ts b/src/api/kv/getSecrets.ts
deleted file mode 100644
index d51f98f..0000000
--- a/src/api/kv/getSecrets.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-
-export async function getSecrets(baseMount: string, secretPath: string[]): Promise {
- let secretURL = "";
-
- // TODO: FIX THIS
- const secretMountType = "kv-v2";
-
- if (secretMountType == "kv-v2") {
- secretURL = `/v1/${baseMount}/metadata/${secretPath.join("/")}?list=true`;
- } else {
- // cubbyhole and v1 are identical
- secretURL = `/v1/${baseMount}/${secretPath.join("/")}?list=true`;
- }
- const request = new Request(appendAPIURL(secretURL), {
- headers: getHeaders(),
- });
-
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as { data: { keys: string[] } };
- return data.data.keys;
-}
diff --git a/src/api/kv/undeleteSecret.ts b/src/api/kv/undeleteSecret.ts
deleted file mode 100644
index 1aab24e..0000000
--- a/src/api/kv/undeleteSecret.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-import { getObjectKeys, removeDoubleSlash } from "../../utils";
-import { getSecretMetadata } from "./getSecretMetadata";
-
-export async function undeleteSecret(
- baseMount: string,
- secretPath: string[],
- name: string,
- version: string | null = null,
-): Promise {
- let secretURL = `/v1/${baseMount}/undelete/${secretPath.join("/")}/${name}`;
- secretURL = removeDoubleSlash(secretURL).replace(/\/$/, "");
- if (version == null) {
- const meta = await getSecretMetadata(baseMount, secretPath, name);
- const versions = getObjectKeys(meta.versions);
- version = String(versions[versions.length - 1]);
- }
-
- const request = new Request(appendAPIURL(secretURL), {
- method: "POST",
- headers: {
- ...getHeaders(),
- "Content-Type": "application/json",
- },
- body: JSON.stringify({ versions: [version] }),
- });
- const resp = await fetch(request);
- await checkResponse(resp);
-}
diff --git a/src/api/sys/deleteMount.ts b/src/api/sys/deleteMount.ts
deleted file mode 100644
index 4b88d34..0000000
--- a/src/api/sys/deleteMount.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-
-export async function deleteMount(mountPath: string): Promise {
- const request = new Request(appendAPIURL("/v1/sys/mounts/" + mountPath), {
- method: "DELETE",
- headers: getHeaders(),
- });
- const resp = await fetch(request);
- await checkResponse(resp);
-}
diff --git a/src/api/sys/getCapabilities.ts b/src/api/sys/getCapabilities.ts
deleted file mode 100644
index 0c30ee4..0000000
--- a/src/api/sys/getCapabilities.ts
+++ /dev/null
@@ -1,43 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-import { removeDoubleSlash } from "../../utils";
-
-export type CapabilitiesType = {
- [path: string]: string[];
- capabilities?: string[];
-};
-
-export async function getCapabilitiesPath(path: string | string[]): Promise {
- if (!Array.isArray(path)) {
- path = [path];
- }
-
- const request = new Request(appendAPIURL("/v1/sys/capabilities-self"), {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- ...getHeaders(),
- },
- body: JSON.stringify({
- paths: path,
- }),
- });
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as { capabilities: string[] };
- return data;
-}
-
-export async function getCapsPath(path: string | string[]): Promise {
- return (await getCapabilitiesPath(path)).capabilities;
-}
-
-export async function getCapabilities(
- baseMount: string,
- secretPath: string[],
- name: string,
-): Promise {
- return await getCapabilitiesPath(
- removeDoubleSlash(baseMount + secretPath.join("/") + "/" + name),
- );
-}
diff --git a/src/api/sys/getMounts.ts b/src/api/sys/getMounts.ts
deleted file mode 100644
index 1589e55..0000000
--- a/src/api/sys/getMounts.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-
-export type MountType = {
- type: string;
- options: {
- version: string;
- };
-};
-
-export type MountsType = {
- [key: string]: MountType;
-};
-
-export async function getMounts(): Promise {
- const request = new Request(appendAPIURL("/v1/sys/internal/ui/mounts"), {
- headers: getHeaders(),
- });
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as { data: { secret: MountsType } };
- return data.data.secret;
-}
-
-export async function getMount(mountName: string): Promise {
- const request = new Request(appendAPIURL("/v1/sys/internal/ui/mounts/" + mountName), {
- headers: getHeaders(),
- });
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as { data: MountType };
- return data.data;
-}
diff --git a/src/api/sys/getSealStatus.ts b/src/api/sys/getSealStatus.ts
deleted file mode 100644
index bd43066..0000000
--- a/src/api/sys/getSealStatus.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { appendAPIURL, checkResponse } from "../apiUtils";
-
-export type SealStatusType = {
- progress: number;
- t: number;
- sealed: boolean;
-};
-
-export async function getSealStatus(): Promise {
- const request = new Request(appendAPIURL("/v1/sys/seal-status"));
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as SealStatusType;
- return data;
-}
diff --git a/src/api/sys/lookupSelf.ts b/src/api/sys/lookupSelf.ts
deleted file mode 100644
index 7cc26fb..0000000
--- a/src/api/sys/lookupSelf.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import { TokenInfo } from "../types/token";
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-
-export async function lookupSelf(): Promise {
- const request = new Request(appendAPIURL("/v1/auth/token/lookup-self"), {
- headers: getHeaders(),
- });
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as { data: TokenInfo };
- return data.data;
-}
diff --git a/src/api/sys/newMount.ts b/src/api/sys/newMount.ts
deleted file mode 100644
index febf604..0000000
--- a/src/api/sys/newMount.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-import { removeDoubleSlash } from "../../utils";
-
-type NewMountParams = {
- name: string;
- type: string;
- options?: {
- version: string;
- };
-};
-
-export async function newMount(parms: NewMountParams): Promise {
- const request = new Request(appendAPIURL(removeDoubleSlash(`/v1/sys/mounts/${parms.name}`)), {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- ...getHeaders(),
- },
- body: JSON.stringify(parms),
- });
- const resp = await fetch(request);
- await checkResponse(resp);
-}
diff --git a/src/api/sys/policies/createOrUpdatePolicy.ts b/src/api/sys/policies/createOrUpdatePolicy.ts
deleted file mode 100644
index ba978bf..0000000
--- a/src/api/sys/policies/createOrUpdatePolicy.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../../apiUtils";
-
-export async function createOrUpdatePolicy(name: string, policy_data: string): Promise {
- const request = new Request(appendAPIURL("/v1/sys/policies/acl/" + name), {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- ...getHeaders(),
- },
- body: JSON.stringify({ policy: policy_data }, null, 0),
- });
-
- const resp = await fetch(request);
- await checkResponse(resp);
-}
diff --git a/src/api/sys/policies/deletePolicy.ts b/src/api/sys/policies/deletePolicy.ts
deleted file mode 100644
index fe187d8..0000000
--- a/src/api/sys/policies/deletePolicy.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../../apiUtils";
-
-export async function deletePolicy(name: string): Promise {
- const request = new Request(appendAPIURL("/v1/sys/policies/acl/" + name), {
- method: "DELETE",
- headers: getHeaders(),
- });
- const resp = await fetch(request);
- await checkResponse(resp);
-}
diff --git a/src/api/sys/policies/getPolicies.ts b/src/api/sys/policies/getPolicies.ts
deleted file mode 100644
index 2c927da..0000000
--- a/src/api/sys/policies/getPolicies.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../../apiUtils";
-
-export async function getPolicies(): Promise {
- const request = new Request(appendAPIURL("/v1/sys/policies/acl?list=true"), {
- headers: getHeaders(),
- });
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as { data: { keys: string[] } };
- return data.data.keys;
-}
diff --git a/src/api/sys/policies/getPolicy.ts b/src/api/sys/policies/getPolicy.ts
deleted file mode 100644
index e9d7746..0000000
--- a/src/api/sys/policies/getPolicy.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../../apiUtils";
-
-export async function getPolicy(name: string): Promise {
- const request = new Request(appendAPIURL("/v1/sys/policies/acl/" + name), {
- headers: getHeaders(),
- });
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as { data: { policy: string } };
- return data.data.policy;
-}
diff --git a/src/api/sys/renewSelf.ts b/src/api/sys/renewSelf.ts
deleted file mode 100644
index a13a14e..0000000
--- a/src/api/sys/renewSelf.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-
-export async function renewSelf(): Promise {
- const request = new Request(appendAPIURL("/v1/auth/token/renew-self"), {
- method: "POST",
- headers: {
- ...getHeaders(),
- "Content-Type": "application/json",
- },
- body: JSON.stringify({}),
- });
- const resp = await fetch(request);
- await checkResponse(resp);
-}
diff --git a/src/api/sys/sealVault.ts b/src/api/sys/sealVault.ts
deleted file mode 100644
index a9140ba..0000000
--- a/src/api/sys/sealVault.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-
-export async function sealVault(): Promise {
- const request = new Request(appendAPIURL("/v1/sys/seal"), {
- method: "PUT",
- headers: getHeaders(),
- });
- const resp = await fetch(request);
- await checkResponse(resp);
-}
diff --git a/src/api/sys/submitUnsealKey.ts b/src/api/sys/submitUnsealKey.ts
deleted file mode 100644
index c2a1913..0000000
--- a/src/api/sys/submitUnsealKey.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import { appendAPIURL, checkResponse } from "../apiUtils";
-
-export async function submitUnsealKey(key: string): Promise {
- const request = new Request(appendAPIURL("/v1/sys/unseal"), {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- key: key,
- }),
- });
- const resp = await fetch(request);
- await checkResponse(resp);
-}
diff --git a/src/api/totp/addNewTOTP.ts b/src/api/totp/addNewTOTP.ts
deleted file mode 100644
index 018fe26..0000000
--- a/src/api/totp/addNewTOTP.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-import { removeDoubleSlash } from "../../utils";
-
-export async function addNewTOTP(baseMount: string, parms: { name: string }): Promise {
- const request = new Request(
- appendAPIURL(removeDoubleSlash(`/v1/${baseMount}/keys/${parms.name}`)),
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- ...getHeaders(),
- },
- body: JSON.stringify(parms),
- },
- );
- const resp = await fetch(request);
- await checkResponse(resp);
-}
diff --git a/src/api/totp/deleteTOTP.ts b/src/api/totp/deleteTOTP.ts
deleted file mode 100644
index 3ac643f..0000000
--- a/src/api/totp/deleteTOTP.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-
-export async function deleteTOTP(baseMount: string, name: string): Promise {
- const request = new Request(appendAPIURL(`/v1/${baseMount}/keys/${name}`), {
- method: "DELETE",
- headers: getHeaders(),
- });
- const resp = await fetch(request);
- await checkResponse(resp);
-}
diff --git a/src/api/totp/getTOTPCode.ts b/src/api/totp/getTOTPCode.ts
deleted file mode 100644
index cbacd80..0000000
--- a/src/api/totp/getTOTPCode.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-
-export async function getTOTPCode(baseMount: string, name: string): Promise {
- const request = new Request(appendAPIURL(`/v1/${baseMount}/code/${name}`), {
- headers: getHeaders(),
- });
-
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as { data: { code: string } };
- return data.data.code;
-}
diff --git a/src/api/totp/getTOTPKeys.ts b/src/api/totp/getTOTPKeys.ts
deleted file mode 100644
index 221e6e7..0000000
--- a/src/api/totp/getTOTPKeys.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-
-export async function getTOTPKeys(baseMount: string): Promise {
- const request = new Request(appendAPIURL(`/v1/${baseMount}/keys?list=true`), {
- headers: getHeaders(),
- });
-
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as { data: { keys: string[] } };
- return data.data.keys;
-}
diff --git a/src/api/transit/getTransitKey.ts b/src/api/transit/getTransitKey.ts
deleted file mode 100644
index ad03371..0000000
--- a/src/api/transit/getTransitKey.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { TransitKeyType } from "../types/transit";
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-
-export async function getTransitKey(baseMount: string, name: string): Promise {
- const request = new Request(appendAPIURL(`/v1/${baseMount}/keys/${name}`), {
- headers: getHeaders(),
- });
-
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as { data: TransitKeyType };
- return data.data;
-}
diff --git a/src/api/transit/getTransitKeys.ts b/src/api/transit/getTransitKeys.ts
deleted file mode 100644
index 23e687f..0000000
--- a/src/api/transit/getTransitKeys.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-
-export async function getTransitKeys(baseMount: string): Promise {
- const request = new Request(appendAPIURL(`/v1/${baseMount}/keys?list=true`), {
- headers: getHeaders(),
- });
-
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as { data: { keys: string[] } };
- return data.data.keys;
-}
diff --git a/src/api/transit/newTransitKey.ts b/src/api/transit/newTransitKey.ts
deleted file mode 100644
index 92f99b3..0000000
--- a/src/api/transit/newTransitKey.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-import { removeDoubleSlash } from "../../utils";
-
-export async function newTransitKey(
- baseMount: string,
- parms: { name: string; type: string },
-): Promise {
- const request = new Request(
- appendAPIURL(removeDoubleSlash(`/v1/${baseMount}/keys/${parms.name}`)),
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- ...getHeaders(),
- },
- body: JSON.stringify(parms),
- },
- );
- const resp = await fetch(request);
- await checkResponse(resp);
-}
diff --git a/src/api/transit/transitDecrypt.ts b/src/api/transit/transitDecrypt.ts
deleted file mode 100644
index 6cf52aa..0000000
--- a/src/api/transit/transitDecrypt.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-import { removeDoubleSlash } from "../../utils";
-
-type DecryptionResult = {
- plaintext: string;
-};
-
-type DecryptionPayload = {
- ciphertext: string;
-};
-
-export async function transitDecrypt(
- baseMount: string,
- name: string,
- payload: DecryptionPayload,
-): Promise {
- const request = new Request(appendAPIURL(removeDoubleSlash(`/v1/${baseMount}/decrypt/${name}`)), {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- ...getHeaders(),
- },
- body: JSON.stringify(payload),
- });
-
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as {
- data?: DecryptionResult;
- };
-
- return data.data;
-}
diff --git a/src/api/transit/transitEncrypt.ts b/src/api/transit/transitEncrypt.ts
deleted file mode 100644
index faebab2..0000000
--- a/src/api/transit/transitEncrypt.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-import { removeDoubleSlash } from "../../utils";
-
-type EncryptionResult = {
- ciphertext: string;
-};
-
-type EncryptionPayload = {
- plaintext: string;
-};
-
-export async function transitEncrypt(
- baseMount: string,
- name: string,
- payload: EncryptionPayload,
-): Promise {
- const request = new Request(appendAPIURL(removeDoubleSlash(`/v1/${baseMount}/encrypt/${name}`)), {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- ...getHeaders(),
- },
- body: JSON.stringify(payload),
- });
-
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as {
- data?: EncryptionResult;
- };
-
- return data.data;
-}
diff --git a/src/api/transit/transitRewrap.ts b/src/api/transit/transitRewrap.ts
deleted file mode 100644
index 81ed4e8..0000000
--- a/src/api/transit/transitRewrap.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
-import { removeDoubleSlash } from "../../utils";
-
-type RewrapResult = {
- ciphertext: string;
-};
-
-type RewrapPayload = {
- ciphertext: string;
- key_version?: number;
-};
-
-export async function transitRewrap(
- baseMount: string,
- name: string,
- payload: RewrapPayload,
-): Promise {
- const request = new Request(appendAPIURL(removeDoubleSlash(`/v1/${baseMount}/rewrap/${name}`)), {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- ...getHeaders(),
- },
- body: JSON.stringify(payload),
- });
-
- const resp = await fetch(request);
- await checkResponse(resp);
-
- const data = (await resp.json()) as {
- data?: RewrapResult;
- };
-
- return data.data;
-}
diff --git a/src/api/types/capabilities.ts b/src/api/types/capabilities.ts
new file mode 100644
index 0000000..687a720
--- /dev/null
+++ b/src/api/types/capabilities.ts
@@ -0,0 +1,4 @@
+export type CapabilitiesType = {
+ [path: string]: string[];
+ capabilities?: string[];
+};
diff --git a/src/api/types/mount.ts b/src/api/types/mount.ts
new file mode 100644
index 0000000..bf443db
--- /dev/null
+++ b/src/api/types/mount.ts
@@ -0,0 +1,18 @@
+export type MountType = {
+ type: string;
+ options: {
+ version: string;
+ };
+};
+
+export type MountsType = {
+ [key: string]: MountType;
+};
+
+export type NewMountParams = {
+ name: string;
+ type: string;
+ options?: {
+ version: string;
+ };
+};
diff --git a/src/api/types/seal.ts b/src/api/types/seal.ts
new file mode 100644
index 0000000..e292eaf
--- /dev/null
+++ b/src/api/types/seal.ts
@@ -0,0 +1,5 @@
+export type SealStatusType = {
+ progress: number;
+ t: number;
+ sealed: boolean;
+};
diff --git a/src/api/types/secret.ts b/src/api/types/secret.ts
new file mode 100644
index 0000000..3e2bec8
--- /dev/null
+++ b/src/api/types/secret.ts
@@ -0,0 +1,3 @@
+type SecretMetadataType = {
+ versions: Record;
+};
diff --git a/src/api/types/transit.ts b/src/api/types/transit.ts
index 8419928..9b9e458 100644
--- a/src/api/types/transit.ts
+++ b/src/api/types/transit.ts
@@ -33,3 +33,28 @@ export type TransitKeyType = TransitKeyBaseType & {
supports_derivation: boolean;
supports_signing: boolean;
};
+
+export type DecryptionResult = {
+ plaintext: string;
+};
+
+export type DecryptionPayload = {
+ ciphertext: string;
+};
+
+export type EncryptionResult = {
+ ciphertext: string;
+};
+
+export type EncryptionPayload = {
+ plaintext: string;
+};
+
+export type RewrapResult = {
+ ciphertext: string;
+};
+
+export type RewrapPayload = {
+ ciphertext: string;
+ key_version?: number;
+};
diff --git a/src/api/types/userpass/user.ts b/src/api/types/user.ts
similarity index 100%
rename from src/api/types/userpass/user.ts
rename to src/api/types/user.ts
diff --git a/src/globalAPI.ts b/src/globalAPI.ts
new file mode 100644
index 0000000..58de8b4
--- /dev/null
+++ b/src/globalAPI.ts
@@ -0,0 +1,4 @@
+import { API } from "./api/API";
+import { settings } from "./globalSettings";
+
+export const api = new API(settings);
diff --git a/src/main.tsx b/src/main.tsx
index 181b565..6b87944 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -23,14 +23,15 @@ import translations from "./translations/index.mjs";
// Actual Imports
import { formatDistance } from "./formatDistance";
-import { getSealStatus } from "./api/sys/getSealStatus";
//import { pageList } from "./allPages";
import { render } from "preact";
import { NavBar } from "./ui/elements/NavBar";
+import { api } from "./globalAPI";
import { settings } from "./globalSettings";
import { playground } from "./playground";
import i18next from "i18next";
import { Main } from "./pages";
+import { getCurrentUrl, route } from "preact-router";
async function onLoad(): Promise {
document.documentElement.dir = settings.pageDirection;
@@ -53,18 +54,20 @@ async function onLoad(): Promise {
//await pageRouter.changePage(pageState.currentPage);
- //setInterval(async () => {
- // if ((await pageRouter.getCurrentPageID()) != "UNSEAL") {
- // if (pageState.apiURL.length != 0) {
- // return;
- // }
- // const sealStatus = await getSealStatus();
- // if (sealStatus.sealed) {
- // await pageRouter.changePage("UNSEAL");
- // return;
- // }
- // }
- //}, 5000);
+ setInterval(async () => {
+ console.log(getCurrentUrl());
+ if (getCurrentUrl() != "/unseal") {
+ // TODO: check if api is accessable, not if its not set
+ if (settings.apiURL.length == 0) {
+ return;
+ }
+ const sealStatus = await api.getSealStatus();
+ if (sealStatus.sealed) {
+ route("/unseal", false);
+ return;
+ }
+ }
+ }, 5000);
}
document.addEventListener(
diff --git a/src/pageUtils.ts b/src/pageUtils.ts
index 7c61397..9147a2f 100644
--- a/src/pageUtils.ts
+++ b/src/pageUtils.ts
@@ -1,12 +1,11 @@
import { Settings } from "./settings/Settings";
-import { getSealStatus } from "./api/sys/getSealStatus";
-import { lookupSelf } from "./api/sys/lookupSelf";
import { route } from "preact-router";
import ClipboardJS from "clipboard";
import UIkit from "uikit";
import i18next from "i18next";
+import { API } from "./api/API";
-async function prePageChecksReal(settings: Settings) {
+async function prePageChecksReal(api: API, settings: Settings) {
if (settings.language.length == 0) {
route("/set_language", true);
throw new Error("Language Not Set");
@@ -17,23 +16,23 @@ async function prePageChecksReal(settings: Settings) {
throw new Error("Vault URL Not Set");
}
- const sealStatus = await getSealStatus();
+ const sealStatus = await api.getSealStatus();
if (sealStatus.sealed) {
route("/unseal", true);
throw new Error("Vault Sealed");
}
try {
- await lookupSelf();
+ await api.lookupSelf();
} catch (e) {
route("/login", true);
throw e;
}
}
-export async function prePageChecks(settings: Settings): Promise {
+export async function prePageChecks(api: API, settings: Settings): Promise {
try {
- await prePageChecksReal(settings);
+ await prePageChecksReal(api, settings);
} catch (e) {
console.log("OHNO", e);
return false;
diff --git a/src/pages.tsx b/src/pages.tsx
index 2626333..4e98445 100644
--- a/src/pages.tsx
+++ b/src/pages.tsx
@@ -1,5 +1,6 @@
import Router from "preact-router";
import { settings } from "./globalSettings";
+import { api } from "./globalAPI";
import { DeleteSecretsEngine } from "./ui/pages/Secrets/DeleteSecretsEngine";
import { Home } from "./ui/pages/Home";
@@ -44,54 +45,94 @@ import { UserPassUserEdit } from "./ui/pages/Access/Auth/userpass/UserPassUserEd
export const Main = () => (
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
-
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
-
+
+
+
-
-
-
-
-
+
+
+
+
+
PAGE NOT YET IMPLEMENTED
diff --git a/src/types/DefaultPageProps.ts b/src/types/DefaultPageProps.ts
index fd0ce6a..28de958 100644
--- a/src/types/DefaultPageProps.ts
+++ b/src/types/DefaultPageProps.ts
@@ -1,6 +1,8 @@
+import { API } from "../api/API";
import { Settings } from "../settings/Settings";
export type DefaultPageProps = {
settings: Settings;
+ api: API;
matches?: { [key: string]: string };
};
diff --git a/src/ui/pages/Access/AccessHome.tsx b/src/ui/pages/Access/AccessHome.tsx
index 7d679ba..1a99891 100644
--- a/src/ui/pages/Access/AccessHome.tsx
+++ b/src/ui/pages/Access/AccessHome.tsx
@@ -9,7 +9,7 @@ import { PageTitle } from "../../elements/PageTitle";
export class AccessHomePage extends Component
{
async componentDidMount() {
- if (!(await prePageChecks(this.props.settings))) return;
+ if (!(await prePageChecks(this.props.api, this.props.settings))) return;
}
render() {
diff --git a/src/ui/pages/Access/Auth/AuthHome.tsx b/src/ui/pages/Access/Auth/AuthHome.tsx
index 5a24cc3..572d0e8 100644
--- a/src/ui/pages/Access/Auth/AuthHome.tsx
+++ b/src/ui/pages/Access/Auth/AuthHome.tsx
@@ -1,6 +1,5 @@
import { AuthMethod } from "../../../../api/types/auth";
import { Component, JSX } from "preact";
-import { listAuth } from "../../../../api/auth/listAuth";
import { notImplemented } from "../../../../pageUtils";
import { objectToMap } from "../../../../utils";
import i18next from "i18next";
@@ -52,7 +51,7 @@ export function AuthListElement(props: AuthListElementProps): JSX.Element {
export class AuthHome extends Component }> {
async componentDidMount() {
- const authList = objectToMap(await listAuth()) as Map;
+ const authList = objectToMap(await this.props.api.listAuth()) as Map;
this.setState({ authList });
}
render() {
diff --git a/src/ui/pages/Access/Auth/AuthViewConfig.tsx b/src/ui/pages/Access/Auth/AuthViewConfig.tsx
index 50ad75f..d4c5c4d 100644
--- a/src/ui/pages/Access/Auth/AuthViewConfig.tsx
+++ b/src/ui/pages/Access/Auth/AuthViewConfig.tsx
@@ -1,6 +1,5 @@
import { AuthMethod } from "../../../../api/types/auth";
import { HeaderAndContent } from "../../../elements/HeaderAndContent";
-import { listAuth } from "../../../../api/auth/listAuth";
import { objectToMap, toStr } from "../../../../utils";
import { Component } from "preact";
import i18next from "i18next";
@@ -10,7 +9,7 @@ import { PageTitle } from "../../../elements/PageTitle";
export class AuthViewConfig extends Component {
async componentDidMount() {
const baseMount = this.props.matches["baseMount"];
- const authList = objectToMap(await listAuth()) as Map;
+ const authList = objectToMap(await this.props.api.listAuth()) as Map;
const authMethod = authList.get(baseMount + "/");
this.setState({ authMethod: authMethod });
}
diff --git a/src/ui/pages/Access/Auth/userpass/UserPassUserDelete.tsx b/src/ui/pages/Access/Auth/userpass/UserPassUserDelete.tsx
index 565295a..6855a60 100644
--- a/src/ui/pages/Access/Auth/userpass/UserPassUserDelete.tsx
+++ b/src/ui/pages/Access/Auth/userpass/UserPassUserDelete.tsx
@@ -1,4 +1,3 @@
-import { deleteUserPassUser } from "../../../../../api/auth/userpass/deleteUserPassUser";
import { Component } from "preact";
import i18next from "i18next";
import { DefaultPageProps } from "../../../../../types/DefaultPageProps";
@@ -19,7 +18,7 @@ export class UserPassUserDelete extends Component {
diff --git a/src/ui/pages/Me.tsx b/src/ui/pages/Me.tsx
index 766a435..42fef50 100644
--- a/src/ui/pages/Me.tsx
+++ b/src/ui/pages/Me.tsx
@@ -2,10 +2,7 @@ import { Component, JSX, createRef } from "preact";
import { DefaultPageProps } from "../../types/DefaultPageProps";
import { PageTitle } from "../elements/PageTitle";
import { addClipboardNotifications, setErrorText } from "../../pageUtils";
-import { getCapsPath } from "../../api/sys/getCapabilities";
-import { renewSelf } from "../../api/sys/renewSelf";
import { route } from "preact-router";
-import { sealVault } from "../../api/sys/sealVault";
import ClipboardJS from "clipboard";
import i18next from "i18next";
@@ -45,7 +42,7 @@ export class Me extends Component {
async componentDidMount() {
let canSealVault = false;
try {
- const caps = await getCapsPath("sys/seal");
+ const caps = await this.props.api.getCapsPath("sys/seal");
canSealVault = caps.includes("sudo") && caps.includes("update");
} catch (e) {
canSealVault = false;
@@ -80,7 +77,7 @@ export class Me extends Component {
{
try {
- await renewSelf();
+ await this.props.api.renewSelf();
route("/");
} catch (e: unknown) {
const error = e as Error;
@@ -95,7 +92,7 @@ export class Me extends Component {
{
- await sealVault();
+ await this.props.api.sealVault();
route("/unseal", true);
}}
>
diff --git a/src/ui/pages/Policies/PoliciesHome.tsx b/src/ui/pages/Policies/PoliciesHome.tsx
index aa9a1d7..4b38c3a 100644
--- a/src/ui/pages/Policies/PoliciesHome.tsx
+++ b/src/ui/pages/Policies/PoliciesHome.tsx
@@ -1,5 +1,4 @@
import { Margin } from "../../elements/Margin";
-import { getPolicies } from "../../../api/sys/policies/getPolicies";
import { prePageChecks } from "../../../pageUtils";
import { Component } from "preact";
import i18next from "i18next";
@@ -10,9 +9,9 @@ import { policyNewURL, policyViewURL } from "../pageLinks";
export class PoliciesHome extends Component {
async componentDidMount() {
- if (!(await prePageChecks(this.props.settings))) return;
+ if (!(await prePageChecks(this.props.api, this.props.settings))) return;
- let policies = await getPolicies();
+ let policies = await this.props.api.getPolicies();
policies = policies.sort();
policies = policies.filter(function (policy_name) {
return policy_name !== "root";
diff --git a/src/ui/pages/Policies/PolicyDelete.tsx b/src/ui/pages/Policies/PolicyDelete.tsx
index 10d6253..aafdd1c 100644
--- a/src/ui/pages/Policies/PolicyDelete.tsx
+++ b/src/ui/pages/Policies/PolicyDelete.tsx
@@ -1,5 +1,4 @@
-import { deletePolicy } from "../../../api/sys/policies/deletePolicy";
-import { Component, render } from "preact";
+import { Component } from "preact";
import { setErrorText } from "../../../pageUtils";
import i18next from "i18next";
import { DefaultPageProps } from "../../../types/DefaultPageProps";
@@ -18,7 +17,7 @@ export class PolicyDelete extends Component {
class="uk-button uk-button-danger"
onClick={async () => {
try {
- await deletePolicy(policyName);
+ await this.props.api.deletePolicy(policyName);
route("/policies");
} catch (e: unknown) {
const error = e as Error;
diff --git a/src/ui/pages/Policies/PolicyEdit.tsx b/src/ui/pages/Policies/PolicyEdit.tsx
index ed4beae..f844eef 100644
--- a/src/ui/pages/Policies/PolicyEdit.tsx
+++ b/src/ui/pages/Policies/PolicyEdit.tsx
@@ -2,8 +2,6 @@ import { CodeEditor } from "../../elements/CodeEditor";
import { Component, JSX, render } from "preact";
import { Margin } from "../../elements/Margin";
import { MarginInline } from "../../elements/MarginInline";
-import { createOrUpdatePolicy } from "../../../api/sys/policies/createOrUpdatePolicy";
-import { getPolicy } from "../../../api/sys/policies/getPolicy";
import { setErrorText } from "../../../pageUtils";
import i18next from "i18next";
import { DefaultPageProps } from "../../../types/DefaultPageProps";
@@ -11,7 +9,7 @@ import { PageTitle } from "../../elements/PageTitle";
import { route } from "preact-router";
import { policyViewURL } from "../pageLinks";
-type PolicyEditorProps = {
+type PolicyEditorProps = DefaultPageProps & {
policyName: string;
};
@@ -37,7 +35,7 @@ export class PolicyEditor extends Component {
- const policyData = await getPolicy(this.props.policyName);
+ const policyData = await this.props.api.getPolicy(this.props.policyName);
this.setState({
dataLoaded: true,
policyData: policyData,
@@ -100,7 +98,11 @@ export class PolicyEdit extends Component {
<>
>
);
diff --git a/src/ui/pages/Policies/PolicyNew.tsx b/src/ui/pages/Policies/PolicyNew.tsx
index 49acd54..274261d 100644
--- a/src/ui/pages/Policies/PolicyNew.tsx
+++ b/src/ui/pages/Policies/PolicyNew.tsx
@@ -1,7 +1,5 @@
import { Form } from "../../elements/Form";
import { Margin } from "../../elements/Margin";
-import { createOrUpdatePolicy } from "../../../api/sys/policies/createOrUpdatePolicy";
-import { getPolicies } from "../../../api/sys/policies/getPolicies";
import { Component } from "preact";
import { setErrorText } from "../../../pageUtils";
import i18next from "i18next";
@@ -19,13 +17,13 @@ export class PolicyNew extends Component {
{this.state.mountType == "cubbyhole" && {i18next.t("kv_view_cubbyhole_text")}
}
-
+
>
);
}
diff --git a/src/ui/pages/Secrets/KeyValue/KeyValueNew.tsx b/src/ui/pages/Secrets/KeyValue/KeyValueNew.tsx
index e79c714..3dfc1ec 100644
--- a/src/ui/pages/Secrets/KeyValue/KeyValueNew.tsx
+++ b/src/ui/pages/Secrets/KeyValue/KeyValueNew.tsx
@@ -3,7 +3,6 @@ import { DefaultPageProps } from "../../../../types/DefaultPageProps";
import { Form } from "../../../elements/Form";
import { Margin } from "../../../elements/Margin";
import { SecretTitleElement } from "../SecretTitleElement";
-import { createOrUpdateSecret } from "../../../../api/kv/createOrUpdateSecret";
import { kvViewURL } from "../../pageLinks";
import { route } from "preact-router";
import { setErrorText } from "../../../../pageUtils";
@@ -57,7 +56,7 @@ export class KeyValueNew extends Component {
const keyData = { key: "value" };
try {
- await createOrUpdateSecret(baseMount, secretPath, path, keyData);
+ await this.props.api.createOrUpdateSecret(baseMount, secretPath, path, keyData);
route(kvViewURL(baseMount, secretPath, path));
} catch (e: unknown) {
const error = e as Error;
diff --git a/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx b/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx
index 089e95c..1732f52 100644
--- a/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx
+++ b/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx
@@ -4,8 +4,6 @@ import { CopyableInputBox } from "../../../elements/CopyableInputBox";
import { DefaultPageProps } from "../../../../types/DefaultPageProps";
import { Grid, GridSizes } from "../../../elements/Grid";
import { SecretTitleElement } from "../SecretTitleElement";
-import { getCapabilities } from "../../../../api/sys/getCapabilities";
-import { getSecret } from "../../../../api/kv/getSecret";
import { kvDeleteURL, kvEditURL } from "../../pageLinks";
import { route } from "preact-router";
import { sortedObjectMap } from "../../../../utils";
@@ -56,7 +54,8 @@ export class KeyValueView extends Component
const secretPath = this.props.matches["secretPath"].split("/");
const secretItem = this.props.matches["item"];
- const caps = (await getCapabilities(baseMount, secretPath, secretItem)).capabilities;
+ const caps = (await this.props.api.getCapabilities(baseMount, secretPath, secretItem))
+ .capabilities;
const secretPathAPI = secretPath.map((e) => e + "/");
// TODO: this is a big hacky, fix when redo how api arguments work
@@ -64,7 +63,7 @@ export class KeyValueView extends Component
.replace("/", "")
.toString();
- const secretInfo = await getSecret(baseMount, secretPathAPI, secretItem);
+ const secretInfo = await this.props.api.getSecret(baseMount, secretPathAPI, secretItem);
this.setState({
baseMount,
secretPath,
diff --git a/src/ui/pages/Secrets/NewEngines/NewKVEngine.tsx b/src/ui/pages/Secrets/NewEngines/NewKVEngine.tsx
index c68c1df..06527d3 100644
--- a/src/ui/pages/Secrets/NewEngines/NewKVEngine.tsx
+++ b/src/ui/pages/Secrets/NewEngines/NewKVEngine.tsx
@@ -4,12 +4,12 @@ import { Margin } from "../../../elements/Margin";
import { MarginInline } from "../../../elements/MarginInline";
import { PageTitle } from "../../../elements/PageTitle";
import { kvListURL } from "../../pageLinks";
-import { newMount } from "../../../../api/sys/newMount";
import { route } from "preact-router";
import { setErrorText } from "../../../../pageUtils";
import i18next from "i18next";
+import { DefaultPageProps } from "../../../../types/DefaultPageProps";
-export class NewKVEngine extends Component {
+export class NewKVEngine extends Component {
render() {
return (
<>
@@ -50,7 +50,7 @@ export class NewKVEngine extends Component {
const version = data.get("version") as string;
try {
- await newMount({
+ await this.props.api.newMount({
name: name,
type: "kv",
options: {
diff --git a/src/ui/pages/Secrets/NewEngines/NewTOTPEngine.tsx b/src/ui/pages/Secrets/NewEngines/NewTOTPEngine.tsx
index 65fca88..a0841fd 100644
--- a/src/ui/pages/Secrets/NewEngines/NewTOTPEngine.tsx
+++ b/src/ui/pages/Secrets/NewEngines/NewTOTPEngine.tsx
@@ -3,13 +3,13 @@ import { Form } from "../../../elements/Form";
import { Margin } from "../../../elements/Margin";
import { MarginInline } from "../../../elements/MarginInline";
import { PageTitle } from "../../../elements/PageTitle";
-import { newMount } from "../../../../api/sys/newMount";
import { route } from "preact-router";
import { setErrorText } from "../../../../pageUtils";
import { totpListURL } from "../../pageLinks";
import i18next from "i18next";
+import { DefaultPageProps } from "../../../../types/DefaultPageProps";
-export class NewTOTPEngine extends Component {
+export class NewTOTPEngine extends Component {
render() {
return (
<>
@@ -40,7 +40,7 @@ export class NewTOTPEngine extends Component {
const name = data.get("name") as string;
try {
- await newMount({
+ await this.props.api.newMount({
name: name,
type: "totp",
});
diff --git a/src/ui/pages/Secrets/NewEngines/NewTransitEngine.tsx b/src/ui/pages/Secrets/NewEngines/NewTransitEngine.tsx
index 37a98c9..c730972 100644
--- a/src/ui/pages/Secrets/NewEngines/NewTransitEngine.tsx
+++ b/src/ui/pages/Secrets/NewEngines/NewTransitEngine.tsx
@@ -3,12 +3,12 @@ import { Form } from "../../../elements/Form";
import { Margin } from "../../../elements/Margin";
import { MarginInline } from "../../../elements/MarginInline";
import { PageTitle } from "../../../elements/PageTitle";
-import { newMount } from "../../../../api/sys/newMount";
import { route } from "preact-router";
import { setErrorText } from "../../../../pageUtils";
import i18next from "i18next";
+import { DefaultPageProps } from "../../../../types/DefaultPageProps";
-export class NewTransitEngine extends Component {
+export class NewTransitEngine extends Component {
render() {
return (
<>
@@ -39,7 +39,7 @@ export class NewTransitEngine extends Component {
const name = data.get("name") as string;
try {
- await newMount({
+ await this.props.api.newMount({
name: name,
type: "transit",
});
diff --git a/src/ui/pages/Secrets/NewSecretsEngine.tsx b/src/ui/pages/Secrets/NewSecretsEngine.tsx
index ee5297a..a69f0e1 100644
--- a/src/ui/pages/Secrets/NewSecretsEngine.tsx
+++ b/src/ui/pages/Secrets/NewSecretsEngine.tsx
@@ -4,8 +4,9 @@ import { PageTitle } from "../../elements/PageTitle";
import { Tile } from "../../elements/Tile";
import { route } from "preact-router";
import i18next from "i18next";
+import { DefaultPageProps } from "../../../types/DefaultPageProps";
-export class NewSecretsEngine extends Component {
+export class NewSecretsEngine extends Component {
render() {
return (
<>
diff --git a/src/ui/pages/Secrets/SecretsHome.tsx b/src/ui/pages/Secrets/SecretsHome.tsx
index d302ee8..73c6a05 100644
--- a/src/ui/pages/Secrets/SecretsHome.tsx
+++ b/src/ui/pages/Secrets/SecretsHome.tsx
@@ -1,12 +1,11 @@
import { Component, JSX, render } from "preact";
import { DefaultPageProps } from "../../../types/DefaultPageProps";
-import { MountType, getMounts } from "../../../api/sys/getMounts";
import { PageTitle } from "../../elements/PageTitle";
-import { getCapsPath } from "../../../api/sys/getCapabilities";
import { prePageChecks } from "../../../pageUtils";
import { route } from "preact-router";
import { sortedObjectMap } from "../../../utils";
import i18next from "i18next";
+import { MountType } from "../../../api/types/mount";
const supportedMountTypes = ["kv", "totp", "transit", "cubbyhole"];
@@ -59,10 +58,10 @@ type SecretsState = {
export class Secrets extends Component {
async componentDidMount() {
- if (!(await prePageChecks(this.props.settings))) return;
+ if (!(await prePageChecks(this.props.api, this.props.settings))) return;
- const mountsCapabilities = await getCapsPath("/sys/mounts");
- const mounts = await getMounts();
+ const mountsCapabilities = await this.props.api.getCapsPath("/sys/mounts");
+ const mounts = await this.props.api.getMounts();
// sort it by secretPath so it's in alphabetical order consistantly.
const mountsMap = sortedObjectMap(mounts);
this.setState({
@@ -99,9 +98,7 @@ export class Secrets extends Component {
const mount = args[1];
console.log(baseMount, mount);
if (isSupportedMount(mount)) {
- return (
-
- );
+ return ;
}
})}
diff --git a/src/ui/pages/Secrets/TOTP/TOTPDelete.tsx b/src/ui/pages/Secrets/TOTP/TOTPDelete.tsx
index c2b2b6e..ae5f37a 100644
--- a/src/ui/pages/Secrets/TOTP/TOTPDelete.tsx
+++ b/src/ui/pages/Secrets/TOTP/TOTPDelete.tsx
@@ -1,7 +1,6 @@
import { Component, render } from "preact";
import { DefaultPageProps } from "../../../../types/DefaultPageProps";
import { SecretTitleElement } from "../SecretTitleElement";
-import { deleteTOTP } from "../../../../api/totp/deleteTOTP";
import { route } from "preact-router";
import { totpListURL } from "../../pageLinks";
import i18next from "i18next";
@@ -23,7 +22,7 @@ export class TOTPDelete extends Component {
onClick={async () => {
const baseMount = this.props.matches["baseMount"];
const item = this.props.matches["item"];
- await deleteTOTP(baseMount, item);
+ await this.props.api.deleteTOTP(baseMount, item);
route(totpListURL(baseMount));
}}
>
diff --git a/src/ui/pages/Secrets/TOTP/TOTPList.tsx b/src/ui/pages/Secrets/TOTP/TOTPList.tsx
index 08f9de8..247f68f 100644
--- a/src/ui/pages/Secrets/TOTP/TOTPList.tsx
+++ b/src/ui/pages/Secrets/TOTP/TOTPList.tsx
@@ -1,8 +1,3 @@
-import {
- CapabilitiesType,
- getCapabilitiesPath,
- getCapsPath,
-} from "../../../../api/sys/getCapabilities";
import { Component, JSX } from "preact";
import { CopyableInputBox } from "../../../elements/CopyableInputBox";
import { DefaultPageProps } from "../../../../types/DefaultPageProps";
@@ -11,14 +6,13 @@ import { Grid, GridSizes } from "../../../elements/Grid";
import { MarginInline } from "../../../elements/MarginInline";
import { SecretTitleElement } from "../SecretTitleElement";
import { delSecretsEngineURL, totpNewURL } from "../../pageLinks";
-import { getTOTPCode } from "../../../../api/totp/getTOTPCode";
-import { getTOTPKeys } from "../../../../api/totp/getTOTPKeys";
import { removeDoubleSlash } from "../../../../utils";
import { route } from "preact-router";
import { setErrorText } from "../../../../pageUtils";
import i18next from "i18next";
+import { CapabilitiesType } from "../../../../api/types/capabilities";
-type TOTPGridItemProps = {
+type TOTPGridItemProps = DefaultPageProps & {
baseMount: string;
totpKey: string;
canDelete: boolean;
@@ -32,7 +26,7 @@ export class RefreshingTOTPGridItem extends Component {
+ void this.props.api.getTOTPCode(this.props.baseMount, this.props.totpKey).then((code) => {
this.setState({ totpValue: code });
});
}
@@ -74,7 +68,7 @@ export class RefreshingTOTPGridItem extends Component[];
};
export class TOTPList extends Component {
@@ -87,17 +81,18 @@ export class TOTPList extends Component {
refresher: number;
async componentDidMount() {
+ const api = this.props.api;
const baseMount = this.props.matches["baseMount"];
const mountsPath = "/sys/mounts/" + baseMount;
- const caps = await getCapabilitiesPath([mountsPath, baseMount]);
+ const caps = await api.getCapabilitiesPath([mountsPath, baseMount]);
- let totpItems: TOTPGridItemProps[] = [];
+ let totpItems: Partial[] = [];
// TODO: tidy this up i guess
try {
totpItems = await Promise.all(
- Array.from(await getTOTPKeys(baseMount)).map(async (key) => {
- const totpCaps = await getCapsPath(removeDoubleSlash(baseMount + "/code/" + key));
+ Array.from(await api.getTOTPKeys(baseMount)).map(async (key) => {
+ const totpCaps = await api.getCapsPath(removeDoubleSlash(baseMount + "/code/" + key));
if (totpCaps.includes("read")) {
return {
baseMount: baseMount,
@@ -162,6 +157,8 @@ export class TOTPList extends Component {
return this.state.totpItems.map((totpItem) => {
return (
{
+export class TOTPNewForm extends Component<
+ { baseMount: string } & DefaultPageProps,
+ { qrMode: boolean }
+> {
constructor() {
super();
this.state = {
@@ -39,7 +41,7 @@ export class TOTPNewForm extends Component<{ baseMount: string }, { qrMode: bool
};
try {
- await addNewTOTP(this.props.baseMount, parms);
+ await this.props.api.addNewTOTP(this.props.baseMount, parms);
route("/secrets/totp/list/" + this.props.baseMount);
} catch (e: unknown) {
const error = e as Error;
@@ -128,7 +130,7 @@ export class TOTPNew extends Component {
baseMount={baseMount}
suffix={i18next.t("totp_new_suffix")}
/>
-
+
>
);
}
diff --git a/src/ui/pages/Secrets/Transit/TransitDecrypt.tsx b/src/ui/pages/Secrets/Transit/TransitDecrypt.tsx
index d692705..4113cdb 100644
--- a/src/ui/pages/Secrets/Transit/TransitDecrypt.tsx
+++ b/src/ui/pages/Secrets/Transit/TransitDecrypt.tsx
@@ -7,7 +7,6 @@ import { SecretTitleElement } from "../SecretTitleElement";
import { fileToBase64 } from "../../../../htmlUtils";
import { Component, render } from "preact";
import { setErrorText } from "../../../../pageUtils";
-import { transitDecrypt } from "../../../../api/transit/transitDecrypt";
import UIkit from "uikit";
import i18next from "i18next";
import { DefaultPageProps } from "../../../../types/DefaultPageProps";
@@ -64,7 +63,7 @@ export class TransitDecrypt extends Component {
}
try {
- const res = await transitDecrypt(baseMount, secretItem, {
+ const res = await this.props.api.transitDecrypt(baseMount, secretItem, {
ciphertext: ciphertext,
});
let plaintext = res.plaintext;
diff --git a/src/ui/pages/Secrets/Transit/TransitEncrypt.tsx b/src/ui/pages/Secrets/Transit/TransitEncrypt.tsx
index 1863f46..96ea08a 100644
--- a/src/ui/pages/Secrets/Transit/TransitEncrypt.tsx
+++ b/src/ui/pages/Secrets/Transit/TransitEncrypt.tsx
@@ -7,7 +7,6 @@ import { SecretTitleElement } from "../SecretTitleElement";
import { fileToBase64 } from "../../../../htmlUtils";
import { Component, render } from "preact";
import { setErrorText } from "../../../../pageUtils";
-import { transitEncrypt } from "../../../../api/transit/transitEncrypt";
import UIkit from "uikit";
import i18next from "i18next";
import { DefaultPageProps } from "../../../../types/DefaultPageProps";
@@ -65,7 +64,7 @@ export class TransitEncrypt extends Component {
}
try {
- const res = await transitEncrypt(baseMount, secretItem, {
+ const res = await this.props.api.transitEncrypt(baseMount, secretItem, {
plaintext: plaintext,
});
render(
diff --git a/src/ui/pages/Secrets/Transit/TransitList.tsx b/src/ui/pages/Secrets/Transit/TransitList.tsx
index fc39b55..633735a 100644
--- a/src/ui/pages/Secrets/Transit/TransitList.tsx
+++ b/src/ui/pages/Secrets/Transit/TransitList.tsx
@@ -1,18 +1,20 @@
-import { CapabilitiesType, getCapabilitiesPath } from "../../../../api/sys/getCapabilities";
-import { Component, JSX, render } from "preact";
+import { Component, JSX } from "preact";
import { DefaultPageProps } from "../../../../types/DefaultPageProps";
import { SecretTitleElement } from "../SecretTitleElement";
import { delSecretsEngineURL, transitNewSecretURL, transitViewSecretURL } from "../../pageLinks";
-import { getTransitKeys } from "../../../../api/transit/getTransitKeys";
import { route } from "preact-router";
import i18next from "i18next";
+import { CapabilitiesType } from "../../../../api/types/capabilities";
type TransitViewListState = {
contentLoaded: boolean;
transitKeysList: string[];
};
-export class TransitViewListItem extends Component<{ baseMount: string }, TransitViewListState> {
+export class TransitViewListItem extends Component<
+ { baseMount: string } & DefaultPageProps,
+ TransitViewListState
+> {
constructor() {
super();
this.state = {
@@ -24,7 +26,8 @@ export class TransitViewListItem extends Component<{ baseMount: string }, Transi
timer: unknown;
getTransitKeys(): void {
- void getTransitKeys(this.props.baseMount)
+ void this.props.api
+ .getTransitKeys(this.props.baseMount)
.then((keys) => {
this.setState({
contentLoaded: true,
@@ -75,7 +78,7 @@ export class TransitList extends Component
)}
-
+
>
);
}
diff --git a/src/ui/pages/Secrets/Transit/TransitNew.tsx b/src/ui/pages/Secrets/Transit/TransitNew.tsx
index e73d2bb..076b280 100644
--- a/src/ui/pages/Secrets/Transit/TransitNew.tsx
+++ b/src/ui/pages/Secrets/Transit/TransitNew.tsx
@@ -4,7 +4,6 @@ import { Form } from "../../../elements/Form";
import { Margin } from "../../../elements/Margin";
import { MarginInline } from "../../../elements/MarginInline";
import { SecretTitleElement } from "../SecretTitleElement";
-import { newTransitKey } from "../../../../api/transit/newTransitKey";
import { route } from "preact-router";
import { setErrorText } from "../../../../pageUtils";
import { transitViewSecretURL } from "../../pageLinks";
@@ -75,7 +74,7 @@ export class TransitNew extends Component {
const type = data.get("type") as string;
try {
- await newTransitKey(baseMount, {
+ await this.props.api.newTransitKey(baseMount, {
name: name,
type: type,
});
diff --git a/src/ui/pages/Secrets/Transit/TransitRewrap.tsx b/src/ui/pages/Secrets/Transit/TransitRewrap.tsx
index 2703a7d..e82471f 100644
--- a/src/ui/pages/Secrets/Transit/TransitRewrap.tsx
+++ b/src/ui/pages/Secrets/Transit/TransitRewrap.tsx
@@ -2,11 +2,9 @@ import { CopyableModal } from "../../../elements/CopyableModal";
import { Form } from "../../../elements/Form";
import { Margin } from "../../../elements/Margin";
import { SecretTitleElement } from "../SecretTitleElement";
-import { getTransitKey } from "../../../../api/transit/getTransitKey";
import { objectToMap } from "../../../../utils";
import { Component, render } from "preact";
import { setErrorText } from "../../../../pageUtils";
-import { transitRewrap } from "../../../../api/transit/transitRewrap";
import UIkit from "uikit";
import i18next from "i18next";
import { DefaultPageProps } from "../../../../types/DefaultPageProps";
@@ -19,7 +17,7 @@ export class TransitRewrap extends Component {
async submitKey(key: string): Promise {
try {
- await submitUnsealKey(key);
+ await this.props.api.submitUnsealKey(key);
this.updateStateWithSealStatus();
} catch (e: unknown) {
const error = e as Error;
@@ -74,7 +72,7 @@ export class Unseal extends Component {
}
updateStateWithSealStatus(): void {
- void getSealStatus().then((data) => {
+ void this.props.api.getSealStatus().then((data) => {
this.setState({
keys_submitted: data.progress,
keys_needed: data.t,