From 1f6c3e36395a89884083f75d31c002af3a9e0cdc Mon Sep 17 00:00:00 2001 From: Kekoa Kaaikala Date: Thu, 7 Sep 2023 17:19:32 +0000 Subject: [PATCH] Chrome: Rename _is_valid_{file,dir} -> _{file,directory}_is_accessible --- .../src/linux_credentials_database_selector.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/monkey/agent_plugins/credentials_collectors/chrome/src/linux_credentials_database_selector.py b/monkey/agent_plugins/credentials_collectors/chrome/src/linux_credentials_database_selector.py index 669f9f1b18b..906318d81b3 100644 --- a/monkey/agent_plugins/credentials_collectors/chrome/src/linux_credentials_database_selector.py +++ b/monkey/agent_plugins/credentials_collectors/chrome/src/linux_credentials_database_selector.py @@ -40,18 +40,19 @@ def _get_login_data_paths(self, profile_dir_path: PurePath) -> Sequence[PurePath sub_profile_dirs = Path(profile_dir_path).iterdir() for subdir in sub_profile_dirs: if subdir == (profile_dir_path / LOGIN_DATABASE_FILENAME): - if self._is_valid_file(subdir): + if self._file_is_accessible(subdir): login_data_paths.append(PurePath(subdir)) login_database_path = profile_dir_path / subdir / LOGIN_DATABASE_FILENAME - if self._is_valid_file(login_database_path): + if self._file_is_accessible(login_database_path): login_data_paths.append(login_database_path) except Exception as err: logger.debug(f"Could not list {profile_dir_path}: {err}") return login_data_paths - def _is_valid_file(self, path: PurePath) -> bool: + @staticmethod + def _file_is_accessible(path: PurePath) -> bool: try: return Path(path).is_file() and os.access(path, os.R_OK) except PermissionError as err: @@ -65,7 +66,7 @@ def _get_browser_database_paths(self) -> Sequence[PurePath]: for browser_name, browser_path in CHROMIUM_BASED_DB_PATHS: browser_db_path = home_dir_path / browser_path try: - if self._is_valid_dir(browser_db_path): + if self._directory_is_accessible(browser_db_path): database_paths.append(browser_db_path) except Exception as err: logger.exception( @@ -74,14 +75,16 @@ def _get_browser_database_paths(self) -> Sequence[PurePath]: return database_paths - def _is_valid_dir(self, path: PurePath) -> bool: + @staticmethod + def _directory_is_accessible(path: PurePath) -> bool: try: return Path(path).is_dir() and os.access(path, os.R_OK) except PermissionError as err: logger.debug(f"Failed to validate path {path}: {err}") return False - def _get_home_directories(self) -> UserDirectories: + @staticmethod + def _get_home_directories() -> UserDirectories: """ Retrieve all users' home directories """