Skip to content

Commit 84ff056

Browse files
committed
Save hashed UIN to a generic user info table
1 parent a0f3106 commit 84ff056

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

src/api/functions/uin.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { DynamoDBClient, PutItemCommand } from "@aws-sdk/client-dynamodb";
1+
import {
2+
DynamoDBClient,
3+
PutItemCommand,
4+
UpdateItemCommand,
5+
} from "@aws-sdk/client-dynamodb";
26
import { marshall } from "@aws-sdk/util-dynamodb";
37
import { argon2id, hash } from "argon2";
48
import { genericConfig } from "common/config.js";
@@ -160,13 +164,22 @@ export async function saveHashedUserUin({
160164
}: SaveHashedUserUin) {
161165
const uinHash = await getHashedUserUin({ uiucAccessToken, pepper });
162166
await dynamoClient.send(
163-
new PutItemCommand({
164-
TableName: genericConfig.UinHashTable,
165-
Item: marshall({
166-
uinHash,
167-
netId,
168-
updatedAt: new Date().toISOString(),
169-
}),
167+
new UpdateItemCommand({
168+
TableName: genericConfig.UserInfoTable,
169+
Key: {
170+
id: { S: `${netId}@illinois.edu` },
171+
},
172+
UpdateExpression:
173+
"SET #uinHash = :uinHash, #netId = :netId, #updatedAt = :updatedAt",
174+
ExpressionAttributeNames: {
175+
"#uinHash": "uinHash",
176+
"#netId": "netId",
177+
"#updatedAt": "updatedAt",
178+
},
179+
ExpressionAttributeValues: {
180+
":uinHash": { S: uinHash },
181+
":updatedAt": { S: new Date().toISOString() },
182+
},
170183
}),
171184
);
172185
}

src/common/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export type GenericConfigType = {
5555
TestingCredentialsSecret: string;
5656
UinHashingSecret: string;
5757
UinExtendedAttributeName: string;
58-
UinHashTable: string;
58+
UserInfoTable: string;
5959
};
6060

6161
type EnvironmentConfigType = {
@@ -96,7 +96,7 @@ const genericConfig: GenericConfigType = {
9696
TestingCredentialsSecret: "infra-core-api-testing-credentials",
9797
UinHashingSecret: "infra-core-api-uin-pepper",
9898
UinExtendedAttributeName: "extension_a70c2e1556954056a6a8edfb1f42f556_uiucEduUIN",
99-
UinHashTable: "infra-core-api-uin-mapping",
99+
UserInfoTable: "infra-core-api-user-info"
100100
} as const;
101101

102102
const environmentConfig: EnvironmentConfigType = {

terraform/modules/dynamo/main.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,28 @@ resource "aws_dynamodb_table" "iam_user_roles" {
190190
}
191191
}
192192

193+
resource "aws_dynamodb_table" "user_info" {
194+
billing_mode = "PAY_PER_REQUEST"
195+
name = "${var.ProjectId}-user-info"
196+
deletion_protection_enabled = true
197+
hash_key = "id"
198+
point_in_time_recovery {
199+
enabled = true
200+
}
201+
attribute {
202+
name = "id"
203+
type = "S"
204+
}
205+
attribute {
206+
name = "uinHash"
207+
type = "S"
208+
}
209+
global_secondary_index {
210+
name = "UinHashIndex"
211+
hash_key = "uinHash"
212+
projection_type = "KEYS_ONLY"
213+
}
214+
}
193215

194216
resource "aws_dynamodb_table" "events" {
195217
billing_mode = "PAY_PER_REQUEST"

0 commit comments

Comments
 (0)