@@ -5,13 +5,19 @@ import { zodToJsonSchema } from "zod-to-json-schema";
55import { addToTenant , getEntraIdToken } from "../functions/entraId.js" ;
66import {
77 BaseError ,
8+ DatabaseFetchError ,
89 DatabaseInsertError ,
910 EntraInvitationError ,
1011 InternalServerError ,
12+ NotFoundError ,
1113} from "../errors/index.js" ;
12- import { DynamoDBClient , PutItemCommand } from "@aws-sdk/client-dynamodb" ;
14+ import {
15+ DynamoDBClient ,
16+ GetItemCommand ,
17+ PutItemCommand ,
18+ } from "@aws-sdk/client-dynamodb" ;
1319import { genericConfig } from "../config.js" ;
14- import { marshall } from "@aws-sdk/util-dynamodb" ;
20+ import { marshall , unmarshall } from "@aws-sdk/util-dynamodb" ;
1521
1622const invitePostRequestSchema = z . object ( {
1723 emails : z . array ( z . string ( ) ) ,
@@ -45,6 +51,52 @@ const dynamoClient = new DynamoDBClient({
4551} ) ;
4652
4753const iamRoutes : FastifyPluginAsync = async ( fastify , _options ) => {
54+ fastify . get < {
55+ Body : undefined ;
56+ Querystring : { groupId : string } ;
57+ } > (
58+ "/groupRoles/:groupId" ,
59+ {
60+ schema : {
61+ querystring : {
62+ type : "object" ,
63+ properties : {
64+ groupId : {
65+ type : "string" ,
66+ } ,
67+ } ,
68+ } ,
69+ } ,
70+ onRequest : async ( request , reply ) => {
71+ await fastify . authorize ( request , reply , [ AppRoles . IAM_ADMIN ] ) ;
72+ } ,
73+ } ,
74+ async ( request , reply ) => {
75+ const groupId = ( request . params as Record < string , string > ) . groupId ;
76+ try {
77+ const command = new GetItemCommand ( {
78+ TableName : `${ genericConfig . IAMTablePrefix } -grouproles` ,
79+ Key : { groupUuid : { S : groupId } } ,
80+ } ) ;
81+ const response = await dynamoClient . send ( command ) ;
82+ if ( ! response . Item ) {
83+ throw new NotFoundError ( {
84+ endpointName : `/api/v1/iam/groupRoles/${ groupId } ` ,
85+ } ) ;
86+ }
87+ reply . send ( unmarshall ( response . Item ) ) ;
88+ } catch ( e : unknown ) {
89+ if ( e instanceof BaseError ) {
90+ throw e ;
91+ }
92+
93+ request . log . error ( e ) ;
94+ throw new DatabaseFetchError ( {
95+ message : "An error occurred finding the group role mapping." ,
96+ } ) ;
97+ }
98+ } ,
99+ ) ;
48100 fastify . post < {
49101 Body : GroupMappingCreatePostRequest ;
50102 Querystring : { groupId : string } ;
@@ -75,11 +127,13 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
75127 async ( request , reply ) => {
76128 const groupId = ( request . params as Record < string , string > ) . groupId ;
77129 try {
130+ const timestamp = new Date ( ) . toISOString ( ) ;
78131 const command = new PutItemCommand ( {
79132 TableName : `${ genericConfig . IAMTablePrefix } -grouproles` ,
80133 Item : marshall ( {
81134 groupUuid : groupId ,
82135 roles : request . body . roles ,
136+ createdAt : timestamp ,
83137 } ) ,
84138 } ) ;
85139
0 commit comments