From fa5578b2ff39be06adec065ddfd6fcb09b791786 Mon Sep 17 00:00:00 2001 From: Dante <148709693+dante-tech@users.noreply.github.com> Date: Sun, 5 May 2024 14:50:25 +0200 Subject: [PATCH] Refactor peasLoaded.py for Improved Efficiency This pull request introduces a set of improvements to the peasLoaded.py file, aimed at enhancing the readability, maintainability, and performance of the code. The key changes include: - Indentation Correction: Fixed the indentation to comply with Python standards, ensuring proper code block recognition and avoiding potential runtime errors. - List Comprehension: Implemented list comprehension for the creation of FileRecord instances, which simplifies the code structure and improves readability. - Configuration Handling: Streamlined the access to the config dictionary by extracting it once at the beginning of the loop, reducing repetitive code and potential access errors. - Default Value Usage: Utilized the .get() method with default values from DEFAULTS for both `auto_check` and `exec` keys. These changes do not alter the core functionality of the code but provide a cleaner and more efficient approach to the existing logic. Please review the changes and let me know if there are any concerns or further improvements that can be made. --- linPEAS/builder/src/peasLoaded.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/linPEAS/builder/src/peasLoaded.py b/linPEAS/builder/src/peasLoaded.py index 4ad3c26..5046e78 100644 --- a/linPEAS/builder/src/peasLoaded.py +++ b/linPEAS/builder/src/peasLoaded.py @@ -6,26 +6,24 @@ class PEASLoaded: def __init__(self): to_search = YAML_LOADED["search"] self.peasrecords = [] + for record in to_search: record_value = record["value"] - if "linpeas" in str(record_value["config"].get("disable","")).lower(): + config = record_value.get("config", {}) + + if "linpeas" in config.get("disable", "").lower(): continue - filerecords = [] - for filerecord in record_value["files"]: - filerecords.append( - FileRecord( - regex=filerecord["name"], - **filerecord["value"] - ) - ) + filerecords = [ + FileRecord(regex=filerecord["name"], **filerecord["value"]) + for filerecord in record_value["files"] + ] - name = record["name"] self.peasrecords.append( PEASRecord( - name=name, - auto_check=record_value["config"]["auto_check"], - exec=record_value["config"].get("exec", DEFAULTS["exec"]), + name=record["name"], + auto_check=config.get("auto_check", DEFAULTS["auto_check"]), + exec=config.get("exec", DEFAULTS["exec"]), filerecords=filerecords ) - ) \ No newline at end of file + )