Skip to content

Commit

Permalink
Ran ruff linter and fixed issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fenrisl authored and hezanathos committed Jul 25, 2024
1 parent 8bcdcea commit fb3ceb7
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 12 deletions.
9 changes: 6 additions & 3 deletions cli/bin/airgap/download_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ def download_scripts(destination_folder, CBW_API, verify_ssl=False, with_attachm
print("\033[A\033[A\nDownload complete ! Scripts are located in '" + str(destination_folder) + "'" + " " * 20)

def append_extension(target_os):
if target_os in ("Aix", "Linux", "Macos", "Vmware"): return ".sh"
if target_os == "Windows": return ".ps1"
if target_os in ("Aix", "Linux", "Macos", "Vmware"):
return ".sh"
if target_os == "Windows":
return ".ps1"
return ""

def download_individual_script(scriptID, base_dir, CBW_API, with_attachment=False, verify_ssl=False):
script = retrieve_scripts(str(scriptID), CBW_API, verify_ssl)
if script is None or script["type"] is None: return None, None
if script is None or script["type"] is None:
return None, None

target_os, script_name = script["type"].split("::")[1:]
script_dir = join(base_dir + "/" + target_os)
Expand Down
2 changes: 1 addition & 1 deletion cli/bin/airgap/upload_compliance_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def manager(arguments, CBW_API, verify_ssl=False):
help()

elif not options.files:
if not "cyberwatch-airgap-compliance" in os.listdir("."):
if "cyberwatch-airgap-compliance" not in os.listdir("."):
help()
else:
print("No file has been specified, searching through the `cyberwatch-airgap-compliance/uploads/` directory.\n--")
Expand Down
2 changes: 1 addition & 1 deletion cli/bin/airgap/upload_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def manager(arguments, CBW_API, verify_ssl=False):
help()

elif not options.files:
if not "cyberwatch-airgap" in os.listdir("."):
if "cyberwatch-airgap" not in os.listdir("."):
help()
else:
print("No file has been specified, searching through the `cyberwatch-airgap/uploads/` directory.\n--")
Expand Down
8 changes: 5 additions & 3 deletions cyberwatch_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def wrapper(*args, **kwargs):
parameter_value = (kwargs.get("params",{}).get(parameter) or kwargs.get("body_params",{}).get(parameter))
endpoint = endpoint.replace("{" + parameter + "}", str(parameter_value))
# Deleting the 'parameter' from the kwargs arguments if it exists
[kwargs[key].pop(parameter, "") for key in kwargs if type(kwargs[key]) == dict]
[kwargs[key].pop(parameter, "") for key in kwargs if isinstance(kwargs[key], dict)]

kwargs.update({"endpoint": endpoint})
return f(*args, **kwargs)
Expand Down Expand Up @@ -125,8 +125,10 @@ def request(self, **kwargs) -> Generator[requests.models.Response, None, None]:
"""
Only accessible method, handles every step of the API call
"""
if not isinstance(kwargs.get("method"), str): raise Exception("The type of endpoint parameter should be str")
if kwargs.get("timeout") and not isinstance(kwargs.get("timeout"), int): raise Exception("The type of timeout parameter should be int")
if not isinstance(kwargs.get("method"), str):
raise Exception("The type of endpoint parameter should be str")
if kwargs.get("timeout") and not isinstance(kwargs.get("timeout"), int):
raise Exception("The type of timeout parameter should be int")

method = str(kwargs.get("method")).upper()
timeout = kwargs.get("timeout") or 10
Expand Down
1 change: 0 additions & 1 deletion examples/add_windows_os_to_rules_of_repository.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from cyberwatch_api import Cyberwatch_Pyhelper
from datetime import datetime

"""
This script will fetch all the rules associated to the repository list defined, and
Expand Down
1 change: 0 additions & 1 deletion examples/change_asset_group_from_hostname.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# This script will replace asset's groups by another one
from cyberwatch_api import Cyberwatch_Pyhelper
import json
import requests
from urllib3.exceptions import InsecureRequestWarning

Expand Down
3 changes: 2 additions & 1 deletion examples/retrieve_assets_with_kb_patch_available.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def retrieve_asset_cves_patches(assetID):
def launch_script():
assets = retrieve_assets()
print("[+] " + str(len(assets)) + " assets were found on this cyberwatch node")
if not assets: return
if not assets:
return

assets_with_KB_patch_available = {} # All assets with at least one KB patch available

Expand Down
3 changes: 2 additions & 1 deletion examples/retrieve_high_priorities_cve.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ def launch_script():

# Outputing
print("\n\n================= " + str(len(high_priority_cve_set)) + " new high-priority CVEs found ================='")
for key, value in high_priority_cve_set.items(): print("{: >20} : {}".format(key, value))
for key, value in high_priority_cve_set.items():
print("{: >20} : {}".format(key, value))

# Send the email
try:
Expand Down

0 comments on commit fb3ceb7

Please sign in to comment.