Skip to content

Commit

Permalink
Hopefully final tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Sep 14, 2022
1 parent 274db57 commit d097509
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 68 deletions.
6 changes: 2 additions & 4 deletions src/components/encrypted-intent.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { UserMembership } from "./membership-cache";
import { APPSERVICE_LOGIN_TYPE, ClientEncryptionSession } from "./encryption";
import Logging from "./logging";
import { ReadStream } from "fs";
import { Logger } from "..";
import BotSdk, { MatrixClient } from "matrix-bot-sdk";
import { FileUploadOpts, Intent, IntentOpts } from "./intent";
import { WeakStateEvent } from "./event-types";

const log = Logging.get("EncryptedIntent");
const log = new Logger("EncryptedIntent");

export interface EncryptedIntentOpts {
sessionPromise: Promise<ClientEncryptionSession|null>;
Expand Down
5 changes: 2 additions & 3 deletions src/components/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import { MembershipCache } from "./membership-cache";
import { AppServiceBot } from "./app-service-bot";
import { WeakEvent } from "./event-types";
import { Intent } from "./intent";
import Logging from "./logging";
import { Logger } from "..";
import { MatrixClient } from "matrix-bot-sdk";
import LRU from "@alloc/quick-lru"

export const APPSERVICE_LOGIN_TYPE = "m.login.application_service";
const EVENT_CACHE_FOR_MS = 5 * 60000; // 5 minutes

export const APPSERVICE_LOGIN_TYPE = "m.login.application_service";
const EVENT_CACHE_FOR_MS = 5 * 60000; // 5 minutes
const log = new Logger('EncryptedEventBroker');

interface PantalaimonWeakEvent extends WeakEvent {
decrypted: true;
Expand Down
3 changes: 1 addition & 2 deletions src/components/intent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import { defer } from "../utils/promiseutil";
import { UserMembership } from "./membership-cache";
import { unstable } from "../errors";
import BridgeErrorReason = unstable.BridgeErrorReason;
import Logging from "./logging";
import { ReadStream } from "fs";
import BotSdk, { MatrixClient, MatrixProfileInfo, PresenceState } from "matrix-bot-sdk";
import { WeakStateEvent } from "./event-types";
import { Logger } from '..';

const log = new Logger("Intent");
export type IntentBackingStore = {
Expand Down
10 changes: 6 additions & 4 deletions src/components/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,14 @@ export class GlobalLogger {

if (cfg.json) {
const formatter = format((info) => {
const hsData = [...(info as LogEntry).data];
const logEntry = info as LogEntry;
const hsData = [...logEntry.data];
const firstArg = hsData.shift() ?? 'undefined';
const result: winston.Logform.TransformableInfo = {
level: info.level,
module: info.module,
timestamp: info.timestamp,
level: logEntry.level,
module: logEntry.module,
timestamp: logEntry.timestamp,
requestId: logEntry.requestId,
// Find the first instance of an error, subsequent errors are treated as args.
error: hsData.find(d => d instanceof Error)?.message,
message: "", // Always filled out
Expand Down
4 changes: 2 additions & 2 deletions src/provisioning/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ProvisioningStore } from "./store";
import { Server } from "http";
import { v4 as uuid } from "uuid";
import axios from "axios";
import Logs from "../components/logging";
import { ErrCode, IApiError, ProvisioningRequest, ApiError } from ".";
import { URL } from "url";
import { MatrixHostResolver } from "../utils/matrix-host-resolver";
Expand All @@ -12,6 +11,7 @@ import { isIP } from "net";
import { promises as dns } from "dns";
import ratelimiter, { RateLimitInfo, Options as RatelimitOptions, AugmentedRequest } from "express-rate-limit";
import { Methods } from "./request";
import { Logger } from "..";

// Borrowed from
// https://github.com/matrix-org/synapse/blob/91221b696156e9f1f9deecd425ae58af03ebb5d3/docs/sample_config.yaml#L215
Expand All @@ -37,7 +37,7 @@ export const DefaultDisallowedIpRanges = [
'fec0::/10'
]

const log = Logs.get("ProvisioningApi");
const log = new Logger("ProvisioningApi");

interface ExpRequestProvisioner extends Request {
matrixWidgetToken?: string;
Expand Down
9 changes: 3 additions & 6 deletions src/provisioning/request.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Logging, { LogWrapper } from "../components/logging";
import crypto from "crypto";
import { ThinRequest } from "..";
import { ThinRequest, Logger } from "..";
import { Request } from "express";
import { ParsedQs } from "qs";

Expand Down Expand Up @@ -41,7 +40,7 @@ export class ProvisioningRequest<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ReqBody = any,
ReqQuery = ParsedQs> implements ThinRequest {
public readonly log: LogWrapper;
public readonly log: Logger;
public readonly id: string;

constructor(
Expand All @@ -53,9 +52,7 @@ export class ProvisioningRequest<
) {
this.id = crypto.randomBytes(4).toString('hex');
this.fnName = fnName || expressReq.path;
this.log = Logging.get(
`ProvisionRequest ${[this.id, fnName].filter(n => !!n).join(" ")}`
);
this.log = new Logger('ProvisionRequest', { requestId: [this.id, fnName].filter(n => !!n).join(" ") });
this.log.debug(`Request ${userId} (${requestSource}) ${this.fnName}`);
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/matrix-host-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Axios } from "axios";
import { URL } from "url";
import { isIP } from "net";
import { promises as dns, SrvRecord } from "dns"
import Logging from "../components/logging";
import { Logger } from "..";

interface MatrixServerWellKnown {
"m.server": string;
Expand All @@ -19,7 +19,7 @@ const DefaultMatrixServerPort = 8448;
const MaxPortNumber = 65535;
const WellKnownTimeout = 10000;

const log = Logging.get('MatrixHostResolver');
const log = new Logger('MatrixHostResolver');

type CachedResult = {timestamp: number, result: HostResolveResult}|{timestamp: number, error: Error};

Expand Down
47 changes: 2 additions & 45 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@
resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.13.10.tgz#f5e0ce8797d2d7cc5ebeda48a52c96c4fa47a8d9"
integrity sha512-nCkHGI4w7ZgAdNkrEu0bv+4xNV/XDqW+DydknebMOQwkpDGx8G+HTlj7R7ABI8i8nKxVw0wtKPi1D+lPOkh4YQ==
dependencies:
"@types/mime" "*"
"@types/mime" "^1"
"@types/node" "*"

"@types/uuid@^8.3.1":
Expand Down Expand Up @@ -1236,6 +1236,7 @@ eslint@^8.1.5:
strip-ansi "^6.0.1"
strip-json-comments "^3.1.0"
text-table "^0.2.0"
v8-compile-cache "^2.0.3"

espree@^9.3.2:
version "9.3.2"
Expand Down Expand Up @@ -1436,14 +1437,6 @@ find-up@^4.0.0, find-up@^4.1.0:
locate-path "^5.0.0"
path-exists "^4.0.0"

find-up@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/find-up/-/find-up-5.0.0.tgz#4c92819ecb7083561e4f4a240a86be5198f536fc"
integrity sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==
dependencies:
locate-path "^6.0.0"
path-exists "^4.0.0"

flat-cache@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-3.0.4.tgz#61b0338302b2fe9f957dcc32fc2a87f1c3048b11"
Expand Down Expand Up @@ -1604,17 +1597,6 @@ glob@^7.1.3, glob@^7.1.4, glob@^7.1.6:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^8.0.3:
version "8.0.3"
resolved "https://registry.yarnpkg.com/glob/-/glob-8.0.3.tgz#415c6eb2deed9e502c68fa44a272e6da6eeca42e"
integrity sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^5.0.1"
once "^1.3.0"

globals@^11.1.0:
version "11.12.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
Expand Down Expand Up @@ -2485,27 +2467,13 @@ p-limit@^2.2.0:
dependencies:
p-try "^2.0.0"

p-limit@^3.0.2:
version "3.1.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.1.0.tgz#e1daccbe78d0d1388ca18c64fea38e3e57e3706b"
integrity sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==
dependencies:
yocto-queue "^0.1.0"

p-locate@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-4.1.0.tgz#a3428bb7088b3a60292f66919278b7c297ad4f07"
integrity sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==
dependencies:
p-limit "^2.2.0"

p-locate@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-5.0.0.tgz#83c8315c6785005e3bd021839411c9e110e6d834"
integrity sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==
dependencies:
p-limit "^3.0.2"

p-map@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/p-map/-/p-map-3.0.0.tgz#d704d9af8a2ba684e2600d9a215983d4141a979d"
Expand Down Expand Up @@ -3268,11 +3236,6 @@ v8-compile-cache-lib@^3.0.1:
resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf"
integrity sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==

v8-compile-cache@^2.0.3:
version "2.3.0"
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"
integrity sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==

vary@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
Expand Down Expand Up @@ -3333,7 +3296,6 @@ winston@^3.3.3:
resolved "https://registry.yarnpkg.com/winston/-/winston-3.8.1.tgz#76f15b3478cde170b780234e0c4cf805c5a7fb57"
integrity sha512-r+6YAiCR4uI3N8eQNOg8k3P3PqwAm20cLKlzVD9E66Ch39+LZC+VH1UKf9JemQj2B3QoUHfKD7Poewn0Pr3Y1w==
dependencies:
"@colors/colors" "1.5.0"
"@dabh/diagnostics" "^2.0.2"
async "^3.2.3"
is-stream "^2.0.0"
Expand Down Expand Up @@ -3418,8 +3380,3 @@ [email protected]:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==

yocto-queue@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==

0 comments on commit d097509

Please sign in to comment.