fix: only require metrics password if set (#1715)

This commit is contained in:
Bernd Storath
2025-03-06 11:45:03 +01:00
committed by GitHub
parent 842475f799
commit 93db67bab6

View File

@@ -138,6 +138,9 @@ export const defineMetricsHandler = <
handler: MetricsHandler<TReq, TRes> handler: MetricsHandler<TReq, TRes>
) => { ) => {
return defineEventHandler(async (event) => { return defineEventHandler(async (event) => {
const metricsConfig = await Database.general.getMetricsConfig();
if (metricsConfig.password) {
const auth = getHeader(event, 'Authorization'); const auth = getHeader(event, 'Authorization');
if (!auth) { if (!auth) {
@@ -156,16 +159,6 @@ export const defineMetricsHandler = <
}); });
} }
const metricsConfig = await Database.general.getMetricsConfig();
if (metricsConfig[type] !== true) {
throw createError({
statusCode: 400,
statusMessage: 'Metrics not enabled',
});
}
if (metricsConfig.password) {
const tokenValid = await isPasswordValid(value, metricsConfig.password); const tokenValid = await isPasswordValid(value, metricsConfig.password);
if (!tokenValid) { if (!tokenValid) {
@@ -176,6 +169,13 @@ export const defineMetricsHandler = <
} }
} }
if (metricsConfig[type] !== true) {
throw createError({
statusCode: 400,
statusMessage: 'Metrics not enabled',
});
}
return await handler({ event }); return await handler({ event });
}); });
}; };