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