Skip to content

Commit

Permalink
fix: get user by accessKeyId if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
psanders committed Jan 6, 2025
1 parent 41a6e6c commit 3601028
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 33 deletions.
54 changes: 28 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion src/AuthzHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from "@fonoster/authz";
import {
createGetUserByWorkspaceAccessKeyId,
createGetUserByAccessKeyId,
prisma
} from "@fonoster/identity";
import { AccountType } from "./type";
Expand All @@ -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!)
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import {
assertEnvsAreSet,
makeFetchSingleCallByCallId
createFetchSingleCallByCallId
} from "@fonoster/common";
import { AuthzServer } from "@fonoster/authz";
import { AuthzHandler } from "./AuthzHandler";
Expand All @@ -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")
);

Expand Down

0 comments on commit 3601028

Please sign in to comment.