mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 13:27:22 +00:00
misc: added proper propagation of error to logs
This commit is contained in:
@@ -82,23 +82,32 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
|
|||||||
const url = new URL(providerInputs.url);
|
const url = new URL(providerInputs.url);
|
||||||
const k8sPort = url.port ? Number(url.port) : 443;
|
const k8sPort = url.port ? Number(url.port) : 443;
|
||||||
|
|
||||||
if (providerInputs.gatewayId) {
|
try {
|
||||||
const k8sHost = url.hostname;
|
if (providerInputs.gatewayId) {
|
||||||
|
const k8sHost = url.hostname;
|
||||||
|
|
||||||
await $gatewayProxyWrapper(
|
await $gatewayProxyWrapper(
|
||||||
{
|
{
|
||||||
gatewayId: providerInputs.gatewayId,
|
gatewayId: providerInputs.gatewayId,
|
||||||
targetHost: k8sHost,
|
targetHost: k8sHost,
|
||||||
targetPort: k8sPort
|
targetPort: k8sPort
|
||||||
},
|
},
|
||||||
serviceAccountGetCallback
|
serviceAccountGetCallback
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
const k8sHost = `${url.protocol}//${url.hostname}`;
|
const k8sHost = `${url.protocol}//${url.hostname}`;
|
||||||
await serviceAccountGetCallback(k8sHost, k8sPort);
|
await serviceAccountGetCallback(k8sHost, k8sPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
let errorMessage = error instanceof Error ? error.message : "Unknown error";
|
||||||
|
if (axios.isAxiosError(error) && (error.response?.data as { message: string })?.message) {
|
||||||
|
errorMessage = (error.response?.data as { message: string }).message;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`Failed to validate connection: ${errorMessage}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const create = async (inputs: unknown, expireAt: number) => {
|
const create = async (inputs: unknown, expireAt: number) => {
|
||||||
@@ -137,21 +146,30 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
|
|||||||
const k8sGatewayHost = url.hostname;
|
const k8sGatewayHost = url.hostname;
|
||||||
const k8sPort = url.port ? Number(url.port) : 443;
|
const k8sPort = url.port ? Number(url.port) : 443;
|
||||||
|
|
||||||
const tokenData = providerInputs.gatewayId
|
try {
|
||||||
? await $gatewayProxyWrapper(
|
const tokenData = providerInputs.gatewayId
|
||||||
{
|
? await $gatewayProxyWrapper(
|
||||||
gatewayId: providerInputs.gatewayId,
|
{
|
||||||
targetHost: k8sGatewayHost,
|
gatewayId: providerInputs.gatewayId,
|
||||||
targetPort: k8sPort
|
targetHost: k8sGatewayHost,
|
||||||
},
|
targetPort: k8sPort
|
||||||
tokenRequestCallback
|
},
|
||||||
)
|
tokenRequestCallback
|
||||||
: await tokenRequestCallback(k8sHost, k8sPort);
|
)
|
||||||
|
: await tokenRequestCallback(k8sHost, k8sPort);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
entityId: providerInputs.serviceAccountName,
|
entityId: providerInputs.serviceAccountName,
|
||||||
data: { TOKEN: tokenData.status.token }
|
data: { TOKEN: tokenData.status.token }
|
||||||
};
|
};
|
||||||
|
} catch (error) {
|
||||||
|
let errorMessage = error instanceof Error ? error.message : "Unknown error";
|
||||||
|
if (axios.isAxiosError(error) && (error.response?.data as { message: string })?.message) {
|
||||||
|
errorMessage = (error.response?.data as { message: string }).message;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`Failed to validate connection: ${errorMessage}`);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const revoke = async (_inputs: unknown, entityId: string) => {
|
const revoke = async (_inputs: unknown, entityId: string) => {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import crypto from "node:crypto";
|
|||||||
import net from "node:net";
|
import net from "node:net";
|
||||||
|
|
||||||
import quicDefault, * as quicModule from "@infisical/quic";
|
import quicDefault, * as quicModule from "@infisical/quic";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
import { BadRequestError } from "../errors";
|
import { BadRequestError } from "../errors";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger";
|
||||||
@@ -378,7 +379,12 @@ export const withGatewayProxy = async <T>(
|
|||||||
logger.error(new Error(proxyErrorMessage), "Failed to proxy");
|
logger.error(new Error(proxyErrorMessage), "Failed to proxy");
|
||||||
}
|
}
|
||||||
logger.error(err, "Failed to do gateway");
|
logger.error(err, "Failed to do gateway");
|
||||||
throw new BadRequestError({ message: proxyErrorMessage || (err as Error)?.message });
|
let errorMessage = proxyErrorMessage || (err as Error)?.message;
|
||||||
|
if (axios.isAxiosError(err) && (err.response?.data as { message?: string })?.message) {
|
||||||
|
errorMessage = (err.response?.data as { message: string }).message;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new BadRequestError({ message: errorMessage });
|
||||||
} finally {
|
} finally {
|
||||||
// Ensure cleanup happens regardless of success or failure
|
// Ensure cleanup happens regardless of success or failure
|
||||||
await cleanup();
|
await cleanup();
|
||||||
|
|||||||
Reference in New Issue
Block a user