mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
greptile review fixes
This commit is contained in:
@@ -166,14 +166,24 @@ export const registerRelayRouter = async (server: FastifyZodProvider) => {
|
||||
onRequest: (req, _, next) => {
|
||||
const authHeader = req.headers.authorization;
|
||||
|
||||
if (appCfg.RELAY_AUTH_SECRET && authHeader) {
|
||||
const expectedHeader = `Bearer ${appCfg.RELAY_AUTH_SECRET}`;
|
||||
if (
|
||||
authHeader.length === expectedHeader.length &&
|
||||
crypto.nativeCrypto.timingSafeEqual(Buffer.from(authHeader), Buffer.from(expectedHeader))
|
||||
) {
|
||||
return next();
|
||||
}
|
||||
if (!appCfg.RELAY_AUTH_SECRET) {
|
||||
throw new UnauthorizedError({
|
||||
message: "Relay authentication not configured"
|
||||
});
|
||||
}
|
||||
|
||||
if (!authHeader) {
|
||||
throw new UnauthorizedError({
|
||||
message: "Missing authorization header"
|
||||
});
|
||||
}
|
||||
|
||||
const expectedHeader = `Bearer ${appCfg.RELAY_AUTH_SECRET}`;
|
||||
if (
|
||||
authHeader.length === expectedHeader.length &&
|
||||
crypto.nativeCrypto.timingSafeEqual(Buffer.from(authHeader), Buffer.from(expectedHeader))
|
||||
) {
|
||||
return next();
|
||||
}
|
||||
|
||||
throw new UnauthorizedError({
|
||||
|
||||
@@ -30,8 +30,7 @@ export const gatewayV2DalFactory = (db: TDbClient) => {
|
||||
.select(db.ref("name").withSchema(TableName.Identity).as("identityName"));
|
||||
|
||||
if (isHeartbeatStale) {
|
||||
const oneHourAgo = new Date();
|
||||
oneHourAgo.setHours(oneHourAgo.getHours() - 1);
|
||||
const oneHourAgo = new Date(Date.now() - 60 * 60 * 1000);
|
||||
void query.where(`${TableName.GatewayV2}.heartbeat`, "<", oneHourAgo);
|
||||
void query.where((v) => {
|
||||
void v
|
||||
|
||||
@@ -902,8 +902,6 @@ export const gatewayV2ServiceFactory = ({
|
||||
"Found gateways with last heartbeat over an hour ago. Sending notifications."
|
||||
);
|
||||
|
||||
await Promise.all(unhealthyGateways.map((gw) => gatewayV2DAL.updateById(gw.id, { healthAlertedAt: new Date() })));
|
||||
|
||||
const gatewaysByOrg = unhealthyGateways.reduce<Record<string, (typeof unhealthyGateways)[number][]>>((acc, gw) => {
|
||||
if (!acc[gw.orgId]) {
|
||||
acc[gw.orgId] = [];
|
||||
@@ -944,6 +942,8 @@ export const gatewayV2ServiceFactory = ({
|
||||
},
|
||||
template: SmtpTemplates.HealthAlert
|
||||
});
|
||||
|
||||
await Promise.all(gateways.map((gw) => gatewayV2DAL.updateById(gw.id, { healthAlertedAt: new Date() })));
|
||||
} catch (error) {
|
||||
logger.error(error, `Failed to send gateway health notifications for organization [orgId=${orgId}]`);
|
||||
}
|
||||
|
||||
@@ -20,8 +20,7 @@ export const relayDalFactory = (db: TDbClient) => {
|
||||
.where(buildFindFilter(regularFilter, TableName.Relay));
|
||||
|
||||
if (isHeartbeatStale) {
|
||||
const oneHourAgo = new Date();
|
||||
oneHourAgo.setHours(oneHourAgo.getHours() - 1);
|
||||
const oneHourAgo = new Date(Date.now() - 60 * 60 * 1000);
|
||||
void query.where(`${TableName.Relay}.heartbeat`, "<", oneHourAgo);
|
||||
void query.where((v) => {
|
||||
void v
|
||||
|
||||
@@ -1209,8 +1209,6 @@ export const relayServiceFactory = ({
|
||||
};
|
||||
|
||||
const $healthcheckNotify = async () => {
|
||||
const oneHourAgo = new Date();
|
||||
oneHourAgo.setHours(oneHourAgo.getHours() - 1);
|
||||
const unhealthyRelays = await relayDAL.find({
|
||||
isHeartbeatStale: true
|
||||
});
|
||||
@@ -1222,8 +1220,6 @@ export const relayServiceFactory = ({
|
||||
"Found relays with last heartbeat over an hour ago. Sending notifications."
|
||||
);
|
||||
|
||||
await Promise.all(unhealthyRelays.map((r) => relayDAL.updateById(r.id, { healthAlertedAt: new Date() })));
|
||||
|
||||
const relaysByOrg = unhealthyRelays.reduce<Record<string, TRelays[]>>((acc, r) => {
|
||||
const key = r.orgId ?? "instance";
|
||||
if (!acc[key]) {
|
||||
@@ -1285,6 +1281,8 @@ export const relayServiceFactory = ({
|
||||
template: SmtpTemplates.HealthAlert
|
||||
});
|
||||
}
|
||||
|
||||
await Promise.all(relays.map((r) => relayDAL.updateById(r.id, { healthAlertedAt: new Date() })));
|
||||
} catch (error) {
|
||||
logger.error(error, `Failed to send relay health notifications for organization [orgId=${orgId}]`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user