Skip to content

Commit 72d8524

Browse files
committed
fix: few needed adjustments
Signed-off-by: Zvi Grinberg <[email protected]>
1 parent a63d18d commit 72d8524

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

src/vuln_analysis/functions/cve_agent.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,28 @@ async def _create_agent(config: CVEAgentExecutorToolConfig, builder: Builder,
6969
tools = builder.get_tools(tool_names=config.tool_names, wrapper_type=LLMFrameworkEnum.LANGCHAIN)
7070
llm = await builder.get_llm(llm_name=config.llm_name, wrapper_type=LLMFrameworkEnum.LANGCHAIN)
7171
prompt = PromptTemplate.from_template(get_agent_prompt(config.prompt, config.prompt_examples))
72-
72+
ecosystem = state.original_input.input.image.ecosystem
73+
transitive_search_tool_supports_ecosystem: bool = True
74+
# I
75+
if ecosystem:
76+
try:
77+
get_language_function_parser(ecosystem)
78+
except NotImplementedError:
79+
transitive_search_tool_supports_ecosystem = False
80+
logger.warning(f"Transitive code search tool doesn't support programming language {ecosystem},"
81+
f" disabling tool...")
7382
# Filter tools that are not available
7483
tools = [
7584
tool for tool in tools
7685
if not ((tool.name == "Container Image Code QA System" and state.code_vdb_path is None) or
7786
(tool.name == "Container Image Developer Guide QA System" and state.doc_vdb_path is None) or
7887
(tool.name == "Lexical Search Container Image Code QA System" and state.code_index_path is None) or
7988
(tool.name == "Transitive code search tool" and (not config.transitive_search_tool_enabled or
80-
state.code_index_path is None)) or
89+
state.code_index_path is None or
90+
not transitive_search_tool_supports_ecosystem)) or
8191
(tool.name == "Calling Function Name Extractor" and (not config.transitive_search_tool_enabled or
82-
state.code_index_path is None)) or
83-
(tool.name == "Package and Function Locator" and (not config.transitive_search_tool_enabled or
84-
state.code_index_path is None))
85-
92+
state.code_index_path is None or
93+
not transitive_search_tool_supports_ecosystem))
8694
)
8795
]
8896

src/vuln_analysis/functions/cve_generate_vdbs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
from vuln_analysis.data_models.common import AnalysisType
3030
from vuln_analysis.logging.loggers_factory import LoggingFactory, trace_id
31+
from vuln_analysis.utils.dep_tree import Ecosystem
3132

3233
logger = LoggingFactory.get_agent_logger(__name__)
3334

@@ -98,7 +99,7 @@ async def generate_vdb(config: CVEGenerateVDBsToolConfig, builder: Builder):
9899
pickle_cache_directory=config.base_pickle_dir)
99100

100101
def _create_code_index(source_infos: list[SourceDocumentsInfo], embedder: DocumentEmbedding,
101-
output_path: Path) -> bool :
102+
output_path: Path) -> bool:
102103
logger.info("Collecting documents from git repos. Source Infos: %s",
103104
json.dumps([x.model_dump(mode="json") for x in source_infos]))
104105

@@ -135,7 +136,8 @@ def _create_code_index(source_infos: list[SourceDocumentsInfo], embedder: Docume
135136
logger.info("Completed code indexing in %.2f seconds for '%s'", time.time() - indexing_start_time, output_path)
136137
return True
137138

138-
def _build_code_index(source_infos: list[SourceDocumentsInfo], ecosystem, manifest_path) -> Path | None:
139+
def _build_code_index(source_infos: list[SourceDocumentsInfo], ecosystem: Ecosystem = None,
140+
manifest_path: str = None) -> Path | None:
139141
code_index_path: Path | None = None
140142

141143
# Filter to only code sources

src/vuln_analysis/tools/transitive_code_search.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
logger = LoggingFactory.get_agent_logger(__name__)
3838

3939

40+
41+
4042
class TransitiveCodeSearchToolConfig(FunctionBaseConfig, name="transitive_code_search"):
4143
"""
4244
Transitive code search tool used to search source code.

src/vuln_analysis/utils/functions_parsers/lang_functions_parsers_factory.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ def get_language_function_parser(ecosystem: Ecosystem, tree: DependencyTree | No
1111
:param ecosystem: the desired programming language parser.
1212
:param tree: the dependency tree for the ecosystem, can be None.
1313
:return:
14-
The right language functions parser associated to the ecosystem, if not exists, return ABC parent that
15-
doesn't do anything
14+
The right language functions parser associated to the ecosystem, if not exists, throw an NotImplementedError
1615
"""
1716
if ecosystem == Ecosystem.GO:
1817
return GoLanguageFunctionsParser()
@@ -24,4 +23,4 @@ def get_language_function_parser(ecosystem: Ecosystem, tree: DependencyTree | No
2423
parser_obj.init_CParser(tree)
2524
return parser_obj
2625
else:
27-
return LanguageFunctionsParser()
26+
raise NotImplementedError(f"Language functions parser for {ecosystem} not implemented.")

0 commit comments

Comments
 (0)