greptile review fixes

This commit is contained in:
x032205
2025-10-08 23:58:38 -04:00
parent c6696d4fde
commit e752391dbf
5 changed files with 24 additions and 18 deletions

View File

@@ -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({

View File

@@ -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

View File

@@ -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}]`);
}

View File

@@ -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

View File

@@ -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}]`);
}