XThomasBU commited on
Commit
71942e6
1 Parent(s): 3fb12d6

adding /private in gitgnore

Browse files
apps/ai_tutor/encrypt_students.py CHANGED
@@ -1,13 +1,8 @@
1
  import os
2
- from dotenv import load_dotenv
3
  import hashlib
4
  import json
5
-
6
- # Load the .env file
7
- load_dotenv()
8
-
9
- # Get the encryption key (salt)
10
- encryption_salt = os.getenv("EMAIL_ENCRYPTION_KEY").encode()
11
 
12
 
13
  # Function to deterministically hash emails
@@ -15,15 +10,44 @@ def deterministic_hash(email, salt):
15
  return hashlib.pbkdf2_hmac("sha256", email.encode(), salt, 100000).hex()
16
 
17
 
18
- # Load emails from private/students.json
19
- with open("private/students.json", "r") as file:
20
- emails = json.load(file)
21
-
22
- # Replace emails with deterministic hashed emails, {hashed_email: [roles]}
23
- hashed_emails = {
24
- deterministic_hash(email, encryption_salt): roles for email, roles in emails.items()
25
- }
26
-
27
- # Save hashed emails to private/students_encrypted.json
28
- with open("private/students_encrypted.json", "w") as file:
29
- json.dump(hashed_emails, file)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
 
2
  import hashlib
3
  import json
4
+ import argparse
5
+ from dotenv import load_dotenv
 
 
 
 
6
 
7
 
8
  # Function to deterministically hash emails
 
10
  return hashlib.pbkdf2_hmac("sha256", email.encode(), salt, 100000).hex()
11
 
12
 
13
+ def main(args):
14
+ # Load the .env file
15
+ load_dotenv()
16
+
17
+ # Get the encryption key (salt)
18
+ encryption_salt = os.getenv("EMAIL_ENCRYPTION_KEY").encode()
19
+
20
+ # Load emails from the specified JSON file
21
+ with open(args.students_file, "r") as file:
22
+ emails = json.load(file)
23
+
24
+ # Replace emails with deterministic hashed emails, {hashed_email: [roles]}
25
+ hashed_emails = {
26
+ deterministic_hash(email, encryption_salt): roles
27
+ for email, roles in emails.items()
28
+ }
29
+
30
+ # Save hashed emails to the specified encrypted JSON file
31
+ with open(args.encrypted_students_file, "w") as file:
32
+ json.dump(hashed_emails, file)
33
+
34
+
35
+ if __name__ == "__main__":
36
+ parser = argparse.ArgumentParser(
37
+ description="Encrypt student emails in a JSON file."
38
+ )
39
+ parser.add_argument(
40
+ "--students-file",
41
+ type=str,
42
+ default="private/students.json",
43
+ help="Path to the students JSON file",
44
+ )
45
+ parser.add_argument(
46
+ "--encrypted-students-file",
47
+ type=str,
48
+ default="public/files/students_encrypted.json",
49
+ help="Path to save the encrypted students JSON file",
50
+ )
51
+ args = parser.parse_args()
52
+
53
+ main(args)
apps/ai_tutor/private/students_encrypted.json DELETED
@@ -1 +0,0 @@
1
- {"7f1cacca66ee914ddde2ee20e0f2c96651d60cd8aabd310ef25a9e6d88f42df0": ["instructor", "bu"], "f74d264b6b5b2b4c10ce69e4ec16e869e01cb5eb668ed846aa8f6dae5c96cda0": ["admin", "instructor", "bu"], "53401356a874b1539775c73a8564d5e5f4f840441630c9cf649e16d201454f20": ["instructor", "bu"]}