diff --git a/package-lock.json b/package-lock.json index f2528a2..495af60 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,10 +9,10 @@ "version": "0.8.0", "license": "MIT", "dependencies": { - "@fonoster/authz": "^0.8.25", - "@fonoster/common": "^0.8.25", - "@fonoster/identity": "^0.8.25", - "@fonoster/logger": "^0.8.24", + "@fonoster/authz": "^0.8.32", + "@fonoster/common": "^0.8.31", + "@fonoster/identity": "^0.8.32", + "@fonoster/logger": "^0.8.28", "@influxdata/influxdb-client": "^1.35.0", "nats": "^2.28.2", "pb-util": "^1.0.3", @@ -961,14 +961,14 @@ } }, "node_modules/@fonoster/authz": { - "version": "0.8.25", - "resolved": "https://registry.npmjs.org/@fonoster/authz/-/authz-0.8.25.tgz", - "integrity": "sha512-5xDSoAQyTnAn5doyVdMh8dAzJagIvBniH/s+yer3BggU6v3mt7BG0JUuUz477bf4ZlGk+yu/bZYh3Wcq6cTWiw==", + "version": "0.8.32", + "resolved": "https://registry.npmjs.org/@fonoster/authz/-/authz-0.8.32.tgz", + "integrity": "sha512-Bo7JNow/pCYbiVIU9HWtqmE/i/oUjLKmsRAIWnZZmD0Ft/zGZ73w7a0iQEmESC2uut1xjLuT/D6C1CLRdTfmmQ==", "license": "MIT", "dependencies": { - "@fonoster/common": "^0.8.25", - "@fonoster/identity": "^0.8.25", - "@fonoster/logger": "^0.8.24", + "@fonoster/common": "^0.8.31", + "@fonoster/identity": "^0.8.32", + "@fonoster/logger": "^0.8.28", "@grpc/grpc-js": "~1.10.6", "deepmerge": "^4.3.1", "grpc-health-check": "^2.0.2" @@ -978,18 +978,20 @@ } }, "node_modules/@fonoster/common": { - "version": "0.8.25", - "resolved": "https://registry.npmjs.org/@fonoster/common/-/common-0.8.25.tgz", - "integrity": "sha512-svrD+AQy5OI3hqNcNyIdmVSrEX1X2C4PYEnkP2DoGFOMaCPjs6koSvKdp4hOlDjRxoqDzQiUrhNX3eA4KSzx+A==", + "version": "0.8.31", + "resolved": "https://registry.npmjs.org/@fonoster/common/-/common-0.8.31.tgz", + "integrity": "sha512-CjLqE1CtZw/3F5YagSLSo1WHALpUw3mgtloCIVmpSMR5Neilx/6E7y/1ZRmvR7JZIRSYyTFUwJYRO/UOHD2HOg==", "license": "MIT", "dependencies": { - "@fonoster/logger": "^0.8.24", + "@fonoster/logger": "^0.8.28", "@grpc/grpc-js": "~1.10.6", "@grpc/proto-loader": "^0.7.12", "@influxdata/influxdb-client": "^1.35.0", "dotenv": "^16.4.7", "grpc-health-check": "^2.0.2", "handlebars": "^4.7.8", + "jsonwebtoken": "^9.0.2", + "jwt-decode": "^4.0.0", "nodemailer": "^6.9.13", "twilio": "^5.3.4", "validator": "^13.12.0", @@ -997,14 +999,14 @@ } }, "node_modules/@fonoster/identity": { - "version": "0.8.25", - "resolved": "https://registry.npmjs.org/@fonoster/identity/-/identity-0.8.25.tgz", - "integrity": "sha512-fCGATUwy55I5AmXjn88Pjb+CRNWreD4A1DYG94P6BWgJ0880j7zmFljT6fVwqRBaE7zFNQFkicMqDCdxa9W8UQ==", + "version": "0.8.32", + "resolved": "https://registry.npmjs.org/@fonoster/identity/-/identity-0.8.32.tgz", + "integrity": "sha512-Io1vtzmi5wEt4gAIvy63m1+z+9ytJQayjiOuL/ZddWtqZtwVvvyiDBfIo+UsBuyESzcJelR+lvymLdmn07Gbog==", "license": "MIT", "dependencies": { - "@fonoster/common": "^0.8.25", - "@fonoster/logger": "^0.8.24", - "@fonoster/types": "^0.8.24", + "@fonoster/common": "^0.8.31", + "@fonoster/logger": "^0.8.28", + "@fonoster/types": "^0.8.31", "@grpc/grpc-js": "~1.10.6", "@prisma/client": "^6.0.1", "jsonwebtoken": "^9.0.2", @@ -1019,9 +1021,9 @@ } }, "node_modules/@fonoster/logger": { - "version": "0.8.24", - "resolved": "https://registry.npmjs.org/@fonoster/logger/-/logger-0.8.24.tgz", - "integrity": "sha512-4e0MM9ZrXfzV4vYJrVrAYk8GEUVEgl/C9/TmYhUkE5Uxh16PzW6YDmfHacYWZh325z/Bu9T2I61OLOiUlKCleQ==", + "version": "0.8.28", + "resolved": "https://registry.npmjs.org/@fonoster/logger/-/logger-0.8.28.tgz", + "integrity": "sha512-Z0FQB92+e4c0zMaPLkk3VCv2UczsOHsyf62eOtITOhXOvH2QYCG70MwG+FdTvdEducJMMiUPxYxs+s2BuAwZIA==", "license": "MIT", "dependencies": { "fluent-logger": "^3.4.1", @@ -1029,9 +1031,9 @@ } }, "node_modules/@fonoster/types": { - "version": "0.8.24", - "resolved": "https://registry.npmjs.org/@fonoster/types/-/types-0.8.24.tgz", - "integrity": "sha512-vk068V+t482I2IjcxL7SXFpPWRBzwow/hCVzRTCizCNWQ5CuN0qQVZp09nnIPGGpaEWuXdYttJYqRa2j7NLH3g==", + "version": "0.8.31", + "resolved": "https://registry.npmjs.org/@fonoster/types/-/types-0.8.31.tgz", + "integrity": "sha512-op7vUb/+hoYtWIQ9iflbMMGFAUYqHeUkcZo0R8izKQ5B2vvCxjv9Vq/C69yEex8y/5PSwTcsqb3/rbZ/QcZM6Q==", "license": "MIT" }, "node_modules/@grpc/grpc-js": { diff --git a/package.json b/package.json index 5663615..2aa69ec 100644 --- a/package.json +++ b/package.json @@ -28,10 +28,10 @@ "access": "public" }, "dependencies": { - "@fonoster/authz": "^0.8.25", - "@fonoster/common": "^0.8.25", - "@fonoster/identity": "^0.8.25", - "@fonoster/logger": "^0.8.24", + "@fonoster/authz": "^0.8.32", + "@fonoster/common": "^0.8.31", + "@fonoster/identity": "^0.8.32", + "@fonoster/logger": "^0.8.28", "@influxdata/influxdb-client": "^1.35.0", "nats": "^2.28.2", "pb-util": "^1.0.3", diff --git a/src/AuthzHandler.ts b/src/AuthzHandler.ts index 6b64498..d6ee39a 100644 --- a/src/AuthzHandler.ts +++ b/src/AuthzHandler.ts @@ -25,6 +25,7 @@ import { } from "@fonoster/authz"; import { createGetUserByWorkspaceAccessKeyId, + createGetUserByAccessKeyId, prisma } from "@fonoster/identity"; import { AccountType } from "./type"; @@ -42,6 +43,7 @@ import { const logger = getLogger({ service: "fnauthz", filePath: __filename }); const getUserByWorkspaceAccessKeyId = createGetUserByWorkspaceAccessKeyId(prisma); +const getUserByAccessKeyId = createGetUserByAccessKeyId(prisma); const getWorkspacesCount = makeGetWorkspacesCount(prisma); const addBillingMeterEvent = makeAddBillingMeterEvent( new Stripe(STRIPE_SECRET_KEY!) @@ -81,7 +83,9 @@ class AuthzHandler implements IAuthzHandler { // Must have both accessKeyId and method const parsedRequest = checkMethodAuthorizedRequestSchema.parse(request); - const user = await getUserByWorkspaceAccessKeyId(parsedRequest.accessKeyId); + const user = parsedRequest.accessKeyId.startsWith("US") + ? await getUserByAccessKeyId(parsedRequest.accessKeyId) + : await getUserByWorkspaceAccessKeyId(parsedRequest.accessKeyId); if (!user) { return false; diff --git a/src/server.ts b/src/server.ts index 12122c3..b8a6912 100644 --- a/src/server.ts +++ b/src/server.ts @@ -18,7 +18,7 @@ */ import { assertEnvsAreSet, - makeFetchSingleCallByCallId + createFetchSingleCallByCallId } from "@fonoster/common"; import { AuthzServer } from "@fonoster/authz"; import { AuthzHandler } from "./AuthzHandler"; @@ -43,7 +43,7 @@ new AuthzServer().listen(authzHandler); const influx = new InfluxDB({ url: INFLUXDB_URL!, token: INFLUXDB_TOKEN }); // TODO: Fix hardcode value -const fetchSingleCallByCallId = makeFetchSingleCallByCallId( +const fetchSingleCallByCallId = createFetchSingleCallByCallId( influx.getQueryApi("fonoster") );