Skip to content

Commit

Permalink
Change the yaml library used
Browse files Browse the repository at this point in the history
  • Loading branch information
PiranhaSa committed Dec 3, 2024
1 parent 091a3d4 commit 3fd0018
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions agent/subfinder_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging

import yaml
from ruamel.yaml import YAML
from rich import logging as rich_logging
import tld
from ostorlab.agent import agent
Expand Down Expand Up @@ -30,11 +30,14 @@ def _update_provider_config(
config_path: str = "/root/.config/subfinder/provider-config.yaml",
) -> None:
"""Update the Subfinder provider configuration file with the VirusTotal API key."""
yaml = YAML(typ="safe")
yaml.default_flow_style = False # Ensure block-style lists

Check warning on line 34 in agent/subfinder_agent.py

View check run for this annotation

Codecov / codecov/patch

agent/subfinder_agent.py#L33-L34

Added lines #L33 - L34 were not covered by tests
# Load existing configuration or initialize a new one
try:
with open(config_path, "r") as config_file:
config = yaml.safe_load(config_file) or {}
config = yaml.load(config_file) or {}
except FileNotFoundError:
config = {}
logger.warning("Configuration file not found. Creating a new one.")

Check warning on line 40 in agent/subfinder_agent.py

View check run for this annotation

Codecov / codecov/patch

agent/subfinder_agent.py#L36-L40

Added lines #L36 - L40 were not covered by tests

# Update the 'virustotal' section
if "virustotal" in config:
Expand All @@ -46,7 +49,7 @@ def _update_provider_config(
# Write back the updated configuration
try:
with open(config_path, "w") as config_file:
yaml.safe_dump(config, config_file)
yaml.dump(config, config_file)
logger.info("VirusTotal API key has been added to the configuration.")
except (IOError, OSError) as write_error:
logger.error("Failed to write configuration file: %s", write_error)

Check warning on line 55 in agent/subfinder_agent.py

View check run for this annotation

Codecov / codecov/patch

agent/subfinder_agent.py#L50-L55

Added lines #L50 - L55 were not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion requirement.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ostorlab[agent]
rich
tld
PyYAML
ruamel.yaml

0 comments on commit 3fd0018

Please sign in to comment.