Skip to content

Commit

Permalink
Decrease log levels (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
gergas3 authored Dec 8, 2023
1 parent abce4d5 commit 5fbf170
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion client/backoff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const retryWithBackoff = async <T>(
return;
}
const timeout = backoff.next();
logger.info(
logger.debug(
{ nextTimeout: timeout, count, error: e },
"Retrying with backoff timeout"
);
Expand Down
9 changes: 5 additions & 4 deletions server/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,34 @@ export class AuthorizationError extends Error {
}
}

// Errors would be logged on every attempt from the braekhus proxy to connect, only log with debug level
export const validateAuth = async (
authorization: string | undefined,
publicKeyGetter: PublicKeyGetter
) => {
if (!authorization) throw new AuthorizationError();
const match = authorization.match(AUTH_PATTERN);
if (!match || !match[1]) {
logger.error("Bearer token not found");
logger.debug("Bearer token not found");
throw new AuthorizationError();
}
const jwt = match[1];
const clientId = jose.decodeJwt(jwt).sub;
logger.debug({ clientId }, "Validating client ID");
if (!clientId) {
logger.error({ clientId }, "Client ID not found");
logger.debug({ clientId }, "Client ID not found");
throw new AuthorizationError();
}
const key = await publicKeyGetter(clientId);
if (!key) {
logger.error({ clientId }, "Public key not found");
logger.debug({ clientId }, "Public key not found");
throw new AuthorizationError();
}
const jwk = await jose.importJWK(key as any, ALG);
try {
await jose.jwtVerify(jwt, jwk, { subject: clientId, audience: "p0.dev" });
} catch (error: any) {
logger.error({ clientId, error }, "Error during verification");
logger.debug({ clientId, error }, "Error during verification");
throw new AuthorizationError();
}
};
5 changes: 3 additions & 2 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export class RemoteClientRpcServer extends JsonRpcServer {

onChannelConnection(channelId: ChannelId, channel: JSONRPCServerAndClient) {
channel.addMethod("setClientId", ({ clientId }) => {
this.#logger.info({ channelId, clientId }, "Setting client ID");
this.#logger.debug({ channelId, clientId }, "Setting client ID");
this.addChannel(channelId, clientId);
return { ok: true };
});
Expand Down Expand Up @@ -325,7 +325,8 @@ export class JsonRpcApp {
await validateAuth(request.headers.authorization, publicKeyGetter);
this.#rpcServer.handleUpgrade(request, socket, head);
})().catch((error: any) => {
this.#logger.error({ error }, "Error upgrading connection");
// Logged on every attempt from the braekhus proxy to connect, only log with debug level
this.#logger.debug({ error }, "Error upgrading connection");
const body = JSON.stringify({ error }, undefined, 2);
const code = error.code ?? 500;
const reason = error.reason ?? "Internal Server Error";
Expand Down

0 comments on commit 5fbf170

Please sign in to comment.