diff --git a/DB/configuration/event_config.json b/DB/configuration/event_config.json new file mode 100644 index 00000000..a2a3342e --- /dev/null +++ b/DB/configuration/event_config.json @@ -0,0 +1,45 @@ +{ + "funcs": { + "create_db_instance": { + "category": "creation", + "resource_type": "DBInstance", + "message": "db instance created" + }, + "delete_db_instance": { + "category": "deletion", + "resource_type": "DBInstance", + "message": "db instance deleted" + }, + "stop_db_instance": { + "category": "deletion", + "resource_type": "DBInstance", + "message": "DB instance shutdown" + }, + "start_db_instance": { + "category": "deletion", + "resource_type": "DBInstance", + "message": "DB instance restarted" + }, + + "create_db_snapshot":{ + "category": "creation", + "resource_type": "DBSnapshot", + "message": "db snapshot created" + }, + "delete_db_snapshot":{ + "category": "creation", + "resource_type": "DBSnapshot", + "message": "db snapshot deleted" + + }, + "restore_db_instance_from_snapshot":{ + "category": "restoring", + "resource_type": "DBSnapshot", + "message": "db instance restored from snapshot" + + } + }, + "errs": { + + } +} \ No newline at end of file diff --git a/Storage_UserAdministration/Controllers/AuthenticationController.py b/Storage_UserAdministration/Controllers/AuthenticationController.py index 0c3bfd27..e980e770 100644 --- a/Storage_UserAdministration/Controllers/AuthenticationController.py +++ b/Storage_UserAdministration/Controllers/AuthenticationController.py @@ -7,8 +7,8 @@ from Services.AuthenticationService import AuthenticationService class AuthenticationController: - def __init__(self): - self.auth_service = AuthenticationService() + def __init__(self, data_file_path): + self.auth_service = AuthenticationService(data_file_path) def login(self, username, password): session_id = self.auth_service.login(username, password) @@ -41,12 +41,13 @@ def register(self, username, password): # Example usage if __name__ == "__main__": - controller = AuthenticationController() - # # Register a user - controller.register('user', 'password123') - # # Login a user - session_id = controller.login('user', 'password123') + controller = AuthenticationController('users.json') + # Register a user + controller.register('user1', 'password123') + # Login a user + session_id = controller.login('user1', 'password123') # Check if the user is authenticated - controller.check_authentication('user') - # Logout the user - controller.logout('user') + if session_id: + controller.check_authentication(session_id) + # Logout the user + controller.logout(session_id) diff --git a/Storage_UserAdministration/DataAccess/UserDAL.py b/Storage_UserAdministration/DataAccess/UserDAL.py index c44ad970..c2e0389f 100644 --- a/Storage_UserAdministration/DataAccess/UserDAL.py +++ b/Storage_UserAdministration/DataAccess/UserDAL.py @@ -1,14 +1,14 @@ import json import os -# from Models.UserModel import User -# from Models.PermissionModel import Permission -# from Models.PolicyModel import Policy -# from Models.GroupModel import Group -# from Models.QuotaModel import Quota -# from Models.RoleModel import Role +from Models.UserModel import User +from Models.PermissionModel import Permission +from Models.PolicyModel import Policy +from Models.GroupModel import Group +from Models.QuotaModel import Quota +from Models.RoleModel import Role class UserDAL: - FILE_PATH = 'users.json' + FILE_PATH = "users_data.json" def __init__(self): self.users = self.load_users_from_file() diff --git a/Storage_UserAdministration/DataAccess/__pycache__/UserDAL.cpython-311.pyc b/Storage_UserAdministration/DataAccess/__pycache__/UserDAL.cpython-311.pyc deleted file mode 100644 index 77d026fd..00000000 Binary files a/Storage_UserAdministration/DataAccess/__pycache__/UserDAL.cpython-311.pyc and /dev/null differ diff --git a/Storage_UserAdministration/Models/__pycache__/userModel.cpython-311.pyc b/Storage_UserAdministration/Models/__pycache__/userModel.cpython-311.pyc deleted file mode 100644 index de0da74e..00000000 Binary files a/Storage_UserAdministration/Models/__pycache__/userModel.cpython-311.pyc and /dev/null differ diff --git a/Storage_UserAdministration/Models/userModel.py b/Storage_UserAdministration/Models/userModel.py index 372a31fc..dc3787dc 100644 --- a/Storage_UserAdministration/Models/userModel.py +++ b/Storage_UserAdministration/Models/userModel.py @@ -1,51 +1,46 @@ -# from Models.PermissionModel import Permission -# from Models.PolicyModel import Policy -# from Models.GroupModel import Group -# from Models.QuotaModel import Quota -# from Models.RoleModel import Role -import uuid - +from Models.PermissionModel import Permission +from Models.PolicyModel import Policy +from Models.GroupModel import Group +from Models.QuotaModel import Quota +from Models.RoleModel import Role class User: def __init__( self, username: str, password: str, - email=None, - - # role: Optional[Role] = None, - # policies: Optional[List[Policy]] = None, - # quota: Optional[Quota] = None, - # groups: Optional[List[Group]] = None + email: str, + role: Optional[Role] = None, + policies: Optional[List[Policy]] = None, + quota: Optional[Quota] = None, + groups: Optional[List[Group]] = None ): self.user_id = str(uuid.uuid4()) # Unique identifier self.username = username - self.password=password + self.password_hash = hashlib.sha256(password.encode()).hexdigest() self.email = email - self.logged_in=False - self.token=None - # self.role = role - # self.policies = policies - # self.quota =quota - # self.groups = groups + self.role = role + self.policies = policies + self.quota =quota + self.groups = groups - # def hash_password(self, password): - # # Implement password hashing - # return hashlib.sha256(password.encode()).hexdigest() + def hash_password(self, password): + # Implement password hashing + return hashlib.sha256(password.encode()).hexdigest() def verify_password(self, password:str): # Verify password against the hashed password return self.password_hash == self.hash_password(password) - # def can(self, action, resource): - # return any( - # policy.evaluate(policy_name, permissions) for policy in self.policies - # ) or self.role.has_permission(permissions) + def can(self, action, resource): + return any( + policy.evaluate(policy_name, permissions) for policy in self.policies + ) or self.role.has_permission(permissions) - # def update_quota(self, quota: Quota): - # self.quota = quota + def update_quota(self, quota: Quota): + self.quota = quota - # def check_quota(self): - # return self.quota.check_exceeded() + def check_quota(self): + return self.quota.check_exceeded() diff --git a/Storage_UserAdministration/Services/AuthenticationService.py b/Storage_UserAdministration/Services/AuthenticationService.py index 06e4e51e..c91530ca 100644 --- a/Storage_UserAdministration/Services/AuthenticationService.py +++ b/Storage_UserAdministration/Services/AuthenticationService.py @@ -1,3 +1,4 @@ +# service.py import hashlib import uuid import sys @@ -5,49 +6,43 @@ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) -from DataAccess.UserDAL import UserDAL -from Models.userModel import User +from DataAccess.userManager import UserNanager + class AuthenticationService: - def __init__(self): - self.data_access =UserDAL() + def __init__(self,data_file_path): + self.data_access =UserNanager(data_file_path) + self.logged_in_users = {} def hash_password(self, password): return hashlib.sha256(password.encode()).hexdigest() def login(self, username, password): - users = self.data_access.users + users = self.data_access.load_users() user_data = users.get(username) if user_data and user_data.get('password') == self.hash_password(password): session_id = self.generate_session_id() - user_data['logged_in']=True - user_data['token']=session_id - self.data_access.save_users_to_file() + self.logged_in_users[session_id] = username return session_id else: return None - def logout(self, username): - users = self.data_access.users - user_data = users.get(username) - user_data['logged_in']=False - user_data['token']=None - self.data_access.save_users_to_file() - + def logout(self, session_id): + if session_id in self.logged_in_users: + self.logged_in_users.pop(session_id) def generate_session_id(self): return str(uuid.uuid4()) - def is_authenticated(self, username): - users = self.data_access.users - user_data = users.get(username) - return user_data['logged_in']==True + def is_authenticated(self, session_id): + return session_id in self.logged_in_users def register(self, username, password): - users = self.data_access.users + users = self.data_access.load_users() if username in users: + print(f"User {username} already exists.") return False hashed_password = self.hash_password(password) - new_user =User(username=username,password=password) - users[username] = {'password': hashed_password,'logged_in':False,'token':None} - self.data_access.save_users_to_file() - return new_user + users[username] = {'password': hashed_password} + self.data_access.save_users(users) + print(f"User {username} registered successfully.") + return True diff --git a/Storage_UserAdministration/Services/__pycache__/AuthenticationService.cpython-311.pyc b/Storage_UserAdministration/Services/__pycache__/AuthenticationService.cpython-311.pyc index 8c10488e..92f324ab 100644 Binary files a/Storage_UserAdministration/Services/__pycache__/AuthenticationService.cpython-311.pyc and b/Storage_UserAdministration/Services/__pycache__/AuthenticationService.cpython-311.pyc differ