Skip to content

Commit

Permalink
Merge pull request #51 from carbonblack/CRE-18336v1
Browse files Browse the repository at this point in the history
Adding stix verbose error output during failed stix 2 ingestion
  • Loading branch information
jmorich-cb authored Jul 25, 2024
2 parents b19e882 + af99f61 commit 9874066
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cbc_importer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
__author__ = "Carbon Black Developer Network"
__license__ = "BSD-2-Clause"
__copyright__ = "© 2024 Broadcom. All Rights Reserved. Carbon Black."
__version__ = "1.9"
__version__ = "1.10"
5 changes: 5 additions & 0 deletions cbc_importer/stix_parsers/v2/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from stix2.exceptions import InvalidValueError
from stix2patterns.pattern import Pattern
from stix2validator import validate_file
from stix2validator import print_results
from taxii2client import as_pages

from cbc_importer.stix_parsers.v2.pattern_parser import STIXPatternParser
Expand Down Expand Up @@ -67,6 +68,10 @@ def parse_file(self, file: str) -> List[IOC_V2]:
stix_content = stix2parse(stix_file, allow_custom=True, version=self.stix_version)
return self._parse_stix_objects(stix_content)
else:
logger.error("=" * 80)
logger.error("The STIX file being passed has failed validation. The following items will need to be corrected before the feed can be imported:")
results = validate_file(file)
print_results(results)
raise ValueError(f"JSON file is not valid or empty: {validate.as_dict()}")
else:
raise ValueError("Unsupported STIX version.")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ files = ["./cbc_importer/**/*.py", "./configurator/*.py"]

[tool.poetry]
name = "carbon-black-cloud-threat-intelligence-connector"
version = "1.9"
version = "1.10"
description = "Carbon Black Cloud Threat Intelligence Connector"
authors = ["Dimitar Ganev <[email protected]>" , "Emanuela Mitreva <[email protected]>"]
license = "BSD-2-Clause"
Expand Down

0 comments on commit 9874066

Please sign in to comment.