MCPcopy Create free account
hub / github.com/hashintel/hash / renewToken

Function renewToken

libs/@local/hash-backend-utils/src/vault.ts:130–160  ·  view source on GitHub ↗
(
  vaultAddr: string,
  token: string,
  logger: Logger,
)

Source from the content-addressed store, hash-verified

128};
129
130const renewToken = async (
131 vaultAddr: string,
132 token: string,
133 logger: Logger,
134): Promise<Omit<VaultLoginResult, "client_token">> => {
135 try {
136 const { data } = await axios.post<{
137 auth: Omit<VaultLoginResult, "client_token">;
138 }>(
139 `${vaultAddr}/v1/auth/token/renew-self`,
140 {},
141 {
142 headers: { "X-Vault-Token": token },
143 timeout: 5000,
144 },
145 );
146
147 return data.auth;
148 } catch (error) {
149 let errorMessage = "Failed to renew Vault token: ";
150 if (error instanceof AxiosError) {
151 errorMessage += `(AxiosError): ${JSON.stringify(error)}`;
152 } else {
153 errorMessage += `(Non-AxiosError): ${stringifyError(error)}`;
154 }
155
156 logger.error(errorMessage);
157
158 throw new Error("Failed to renew Vault token");
159 }
160};
161
162type VaultSecret<D = unknown> = {
163 data: D;

Callers 1

ensureTokenMethod · 0.85

Calls 1

stringifyErrorFunction · 0.90

Tested by

no test coverage detected