@@ -6,37 +6,14 @@ import {
6
6
SecretsManagerClient ,
7
7
GetSecretValueCommand ,
8
8
} from "@aws-sdk/client-secrets-manager" ;
9
- import { AppRoles , RunEnvironment } from "../roles.js" ;
9
+ import { AppRoles } from "../roles.js" ;
10
10
import {
11
11
BaseError ,
12
12
InternalServerError ,
13
13
UnauthenticatedError ,
14
14
UnauthorizedError ,
15
15
} from "../errors/index.js" ;
16
-
17
- const CONFIG_SECRET_NAME = "infra-events-api-config" as const ;
18
- const AzureRoleMapping : Record < RunEnvironment , Record < string , AppRoles [ ] > > = {
19
- prod : {
20
- AutonomousWriters : [ AppRoles . MANAGER ] ,
21
- } ,
22
- dev : {
23
- AutonomousWriters : [ AppRoles . MANAGER ] ,
24
- } ,
25
- } ;
26
-
27
- const GroupRoleMapping : Record < RunEnvironment , Record < string , AppRoles [ ] > > = {
28
- prod : {
29
- "48591dbc-cdcb-4544-9f63-e6b92b067e33" : [ AppRoles . MANAGER ] , // Infra Chairs
30
- "ff49e948-4587-416b-8224-65147540d5fc" : [ AppRoles . MANAGER ] , // Officers
31
- "ad81254b-4eeb-4c96-8191-3acdce9194b1" : [ AppRoles . MANAGER ] , // Exec
32
- } ,
33
- dev : {
34
- "48591dbc-cdcb-4544-9f63-e6b92b067e33" : [ AppRoles . MANAGER ] , // Infra Chairs
35
- "940e4f9e-6891-4e28-9e29-148798495cdb" : [ AppRoles . MANAGER ] , // ACM Infra Team
36
- "f8dfc4cf-456b-4da3-9053-f7fdeda5d5d6" : [ AppRoles . MANAGER ] , // Infra Leads
37
- "0" : [ AppRoles . MANAGER ] , // Dummy Group for development only
38
- } ,
39
- } ;
16
+ import { environmentConfig , genericConfig } from "../config.js" ;
40
17
41
18
function intersection < T > ( setA : Set < T > , setB : Set < T > ) : Set < T > {
42
19
const _intersection = new Set < T > ( ) ;
@@ -133,8 +110,11 @@ const authPlugin: FastifyPluginAsync = async (fastify, _options) => {
133
110
}
134
111
signingKey =
135
112
process . env . JwtSigningKey ||
136
- ( ( ( await getSecretValue ( CONFIG_SECRET_NAME ) ) || { jwt_key : "" } )
137
- . jwt_key as string ) ||
113
+ ( (
114
+ ( await getSecretValue ( genericConfig . ConfigSecretName ) ) || {
115
+ jwt_key : "" ,
116
+ }
117
+ ) . jwt_key as string ) ||
138
118
"" ;
139
119
if ( signingKey === "" ) {
140
120
throw new UnauthenticatedError ( {
@@ -181,24 +161,32 @@ const authPlugin: FastifyPluginAsync = async (fastify, _options) => {
181
161
const expectedRoles = new Set ( validRoles ) ;
182
162
if ( verifiedTokenData . groups ) {
183
163
for ( const group of verifiedTokenData . groups ) {
184
- if ( ! GroupRoleMapping [ fastify . runEnvironment ] [ group ] ) {
164
+ if (
165
+ ! environmentConfig [ fastify . runEnvironment ] [ "GroupRoleMapping" ] [
166
+ group
167
+ ]
168
+ ) {
185
169
continue ;
186
170
}
187
- for ( const role of GroupRoleMapping [ fastify . runEnvironment ] [
188
- group
189
- ] ) {
171
+ for ( const role of environmentConfig [ fastify . runEnvironment ] [
172
+ "GroupRoleMapping"
173
+ ] [ group ] ) {
190
174
userRoles . add ( role ) ;
191
175
}
192
176
}
193
177
} else {
194
178
if ( verifiedTokenData . roles ) {
195
179
for ( const group of verifiedTokenData . roles ) {
196
- if ( ! AzureRoleMapping [ fastify . runEnvironment ] [ group ] ) {
180
+ if (
181
+ ! environmentConfig [ fastify . runEnvironment ] [ "AzureRoleMapping" ] [
182
+ group
183
+ ]
184
+ ) {
197
185
continue ;
198
186
}
199
- for ( const role of AzureRoleMapping [ fastify . runEnvironment ] [
200
- group
201
- ] ) {
187
+ for ( const role of environmentConfig [ fastify . runEnvironment ] [
188
+ "AzureRoleMapping"
189
+ ] [ group ] ) {
202
190
userRoles . add ( role ) ;
203
191
}
204
192
}
0 commit comments