Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decrease log levels #23

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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