Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce new flag to avoid using pip freeze and pip show #106

Merged
merged 6 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ A New setting is introduced - `EXHORT_PYTHON_INSTALL_BEST_EFFORTS` (as both env
1. `EXHORT_PYTHON_INSTALL_BEST_EFFORTS`="false" - install requirements.txt while respecting declared versions for all packages.
2. `EXHORT_PYTHON_INSTALL_BEST_EFFORTS`="true" - install all packages from requirements.txt, not respecting the declared version, but trying to install a version tailored for the used python version, when using this setting,you must set setting `MATCH_MANIFEST_VERSIONS`="false"

##### Using `pipdeptree`
By Default, The API algorithm will use native commands of PIP installer as data source to build the dependency tree.
It's also possible, to use lightweight Python PIP utility [pipdeptree](https://pypi.org/project/pipdeptree/) as data source instead, in order to activate this,
Need to set environment variable/option - `EXHORT_PIP_USE_DEP_TREE` to true.

### Image Support

Generate vulnerability analysis report for container images.
Expand Down
36 changes: 13 additions & 23 deletions src/main/java/com/redhat/exhort/providers/PythonPipProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ public Content provideStack(Path manifestPath) throws IOException {
printDependenciesTree(dependencies);
Sbom sbom = SbomFactory.newInstance(Sbom.BelongingCondition.PURL, "sensitive");
sbom.addRoot(toPurl(DEFAULT_PIP_ROOT_COMPONENT_NAME, DEFAULT_PIP_ROOT_COMPONENT_VERSION));
dependencies.stream()
.forEach(
(component) -> {
addAllDependencies(sbom.getRoot(), component, sbom);
});
for (Map<String, Object> component : dependencies) {
addAllDependencies(sbom.getRoot(), component, sbom);
}
byte[] requirementsFile = Files.readAllBytes(manifestPath);
handleIgnoredDependencies(new String(requirementsFile), sbom);
return new Content(
Expand All @@ -92,25 +90,17 @@ public Content provideStack(Path manifestPath) throws IOException {

private void addAllDependencies(PackageURL source, Map<String, Object> component, Sbom sbom) {

sbom.addDependency(
source, toPurl((String) component.get("name"), (String) component.get("version")));
List<Map> directDeps = (List<Map>) component.get("dependencies");
if (directDeps != null)
// {
directDeps.stream()
.forEach(
dep -> {
String name = (String) dep.get("name");
String version = (String) dep.get("version");

addAllDependencies(
toPurl((String) component.get("name"), (String) component.get("version")),
dep,
sbom);
});
//
// }
PackageURL packageURL =
toPurl((String) component.get("name"), (String) component.get("version"));
sbom.addDependency(source, packageURL);

List<Map<String, Object>> directDeps =
(List<Map<String, Object>>) component.get("dependencies");
if (directDeps != null) {
for (Map<String, Object> dep : directDeps) {
addAllDependencies(packageURL, dep, sbom);
}
}
}

@Override
Expand Down
Loading
Loading