|
1 | 1 | import { FastifyPluginAsync } from "fastify"; |
2 | | -import { AppRoles } from "../../common/roles.js"; |
| 2 | +import { allAppRoles, AppRoles } from "../../common/roles.js"; |
3 | 3 | import { zodToJsonSchema } from "zod-to-json-schema"; |
4 | 4 | import { |
5 | 5 | addToTenant, |
@@ -34,6 +34,10 @@ import { |
34 | 34 | EntraGroupActions, |
35 | 35 | entraGroupMembershipListResponse, |
36 | 36 | } from "../../common/types/iam.js"; |
| 37 | +import { |
| 38 | + AUTH_DECISION_CACHE_SECONDS, |
| 39 | + getGroupRoles, |
| 40 | +} from "api/functions/authorization.js"; |
37 | 41 |
|
38 | 42 | const dynamoClient = new DynamoDBClient({ |
39 | 43 | region: genericConfig.AwsRegion, |
@@ -61,19 +65,10 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => { |
61 | 65 | }, |
62 | 66 | }, |
63 | 67 | async (request, reply) => { |
64 | | - const groupId = (request.params as Record<string, string>).groupId; |
65 | 68 | try { |
66 | | - const command = new GetItemCommand({ |
67 | | - TableName: `${genericConfig.IAMTablePrefix}-grouproles`, |
68 | | - Key: { groupUuid: { S: groupId } }, |
69 | | - }); |
70 | | - const response = await dynamoClient.send(command); |
71 | | - if (!response.Item) { |
72 | | - throw new NotFoundError({ |
73 | | - endpointName: `/api/v1/iam/groupRoles/${groupId}`, |
74 | | - }); |
75 | | - } |
76 | | - reply.send(unmarshall(response.Item)); |
| 69 | + const groupId = (request.params as Record<string, string>).groupId; |
| 70 | + const roles = await getGroupRoles(dynamoClient, fastify, groupId); |
| 71 | + return reply.send(roles); |
77 | 72 | } catch (e: unknown) { |
78 | 73 | if (e instanceof BaseError) { |
79 | 74 | throw e; |
@@ -125,9 +120,14 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => { |
125 | 120 | createdAt: timestamp, |
126 | 121 | }), |
127 | 122 | }); |
128 | | - |
129 | 123 | await dynamoClient.send(command); |
| 124 | + fastify.nodeCache.set( |
| 125 | + `grouproles-${groupId}`, |
| 126 | + request.body.roles, |
| 127 | + AUTH_DECISION_CACHE_SECONDS, |
| 128 | + ); |
130 | 129 | } catch (e: unknown) { |
| 130 | + fastify.nodeCache.del(`grouproles-${groupId}`); |
131 | 131 | if (e instanceof BaseError) { |
132 | 132 | throw e; |
133 | 133 | } |
|
0 commit comments