Skip to content

Commit 66df1ff

Browse files
committed
Fix tests
Signed-off-by: Prabhu Subramanian <[email protected]>
1 parent 7727591 commit 66df1ff

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

depscan/lib/bom.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,13 @@ def create_bom(bom_file, src_dir=".", options=None):
196196
# For binaries, generate an sbom with blint directly
197197
techniques = options.get("techniques") or []
198198
lifecycles = options.get("lifecycles") or []
199+
project_type = options.get("project_type") or []
199200
bom_engine = options.get("bom_engine", "")
200201
# Detect if blint needs to be used for the given project type, technique, and lifecycle.
201202
if bom_engine == "BlintGenerator" or "binary-analysis" in techniques or "post-build" in lifecycles:
202203
return create_blint_bom(bom_file, src_dir, options=options)
203204
cdxgen_server = options.get("cdxgen_server")
205+
cdxgen_lib = CdxgenGenerator
204206
# Generate SBOM by calling cdxgen server
205207
if cdxgen_server or bom_engine == "CdxgenServerGenerator":
206208
if not cdxgen_server:
@@ -210,9 +212,15 @@ def create_bom(bom_file, src_dir=".", options=None):
210212
cdxgen_lib = CdxgenServerGenerator
211213
else:
212214
# Prefer the new image based generators if docker command is available in auto mode
213-
cdxgen_lib = CdxgenImageBasedGenerator if bom_engine == "CdxgenImageBasedGenerator" or (
214-
bom_engine == "auto" and shutil.which(os.getenv("DOCKER_CMD", "docker"))) else CdxgenGenerator
215-
with console.status(f"Generating BOM for the directory {src_dir} with cdxgen.", spinner=SPINNER):
215+
if bom_engine == "CdxgenImageBasedGenerator":
216+
cdxgen_lib = CdxgenImageBasedGenerator
217+
elif bom_engine == "auto":
218+
# Prefer local CLI while scanning container images
219+
if any([t in ("docker", "podman", "oci") for t in project_type]):
220+
cdxgen_lib = CdxgenGenerator
221+
elif shutil.which(os.getenv("DOCKER_CMD", "docker")):
222+
cdxgen_lib = CdxgenImageBasedGenerator
223+
with console.status(f"Generating BOM for the source {src_dir} with cdxgen.", spinner=SPINNER):
216224
bom_result = cdxgen_lib(src_dir, bom_file, logger=LOG, options=options).generate()
217225
if not bom_result.success:
218226
LOG.info("The cdxgen invocation was unsuccessful. Try generating the BOM separately.")
@@ -232,7 +240,7 @@ def create_blint_bom(bom_file, src_dir=".", options=None):
232240
if options is None:
233241
options = {}
234242
blint_lib = BlintGenerator(src_dir, bom_file, logger=LOG, options=options)
235-
with console.status(f"Generating BOM for the directory {src_dir} with blint.", spinner=SPINNER):
243+
with console.status(f"Generating BOM for the source {src_dir} with blint.", spinner=SPINNER):
236244
bom_result = blint_lib.generate()
237245
if not bom_result.success:
238246
LOG.info("The blint invocation was unsuccessful. Try generating the BOM separately.")

depscan/lib/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ def get_int_from_env(name, default):
332332
vdb_database_url = vdb_10y_database_url
333333
vdb_rafs_database_url = vdb_10y_rafs_database_url
334334

335-
# How old vdb can be before it gets re-downloaded
336-
VDB_AGE_HOURS = get_int_from_env("VDB_AGE_HOURS", 24)
335+
# How old vdb can be before it gets re-downloaded. 48 hours.
336+
VDB_AGE_HOURS = get_int_from_env("VDB_AGE_HOURS", 48)
337337

338338
# Package risk scoring using a simple weighted formula with no backing
339339
# research All parameters and their max value and weight can be overridden

depscan/lib/logger.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ class CustomHighlighter(RegexHighlighter):
3131
}
3232
)
3333

34+
IS_CI = os.getenv("CI") or os.getenv("CONTINUOUS_INTEGRATION")
35+
3436
console = Console(
3537
log_time=False,
3638
log_path=False,
3739
theme=custom_theme,
3840
color_system="256",
39-
force_terminal=True,
40-
highlight=True,
41+
force_terminal=not IS_CI,
42+
highlight=not IS_CI,
4143
highlighter=CustomHighlighter(),
4244
record=True,
4345
)

packages/xbom-lib/src/xbom_lib/cdxgen.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,11 @@ def _container_run_cmd(self) -> Tuple[str, List[str]]:
271271
if os.getenv("DEPSCAN_DOCKER_ARGS"):
272272
run_command_args += os.getenv("DEPSCAN_DOCKER_ARGS", "").split(" ")
273273
# Setup volume mounts
274-
run_command_args += ["-v", f"{self.source_dir}:{app_input_dir}:rw"]
274+
# Mount source directory as /app
275+
if os.path.isdir(self.source_dir):
276+
run_command_args += ["-v", f"{self.source_dir}:{app_input_dir}:rw"]
277+
else:
278+
run_command_args.append(self.source_dir)
275279
run_command_args += ["-v", f"{self.cdxgen_temp_dir}:/tmp:rw"]
276280
run_command_args += ["-v", f"{output_dir}:{image_output_dir}:rw"]
277281
# Mount the home directory as /root. Can be used for performance reasons.

0 commit comments

Comments
 (0)