Trustify DA Java Client
Requires Java 21 or later.
The Trustify DA Java Client module is deployed to GitHub Package Registry.
Click here for configuring GHPR registry access.
Configure Registry Access
Create a
token
with the read:packages scope
Based on
GitHub documentation,
In Actions you can use GITHUB_TOKEN
-
Maven users
- Encrypt your token
$ mvn --encrypt-password your-ghp-token-goes-here
encrypted-token-will-appear-here
- Add a server definition in your $HOME/.m2/settings.xml
<servers>
<!-- ... other servers -->
<server>
<id>github</id>
<username>github-userid-goes-here</username>
<password>encrypted-token-goes-here-including-curly-brackets</password>
</server>
<!-- ... other servers -->
</servers>
-
Gradle users, save your token and username as environment variables
- GITHUB_USERNAME
- GITHUB_TOKEN
Usage
- Configure Registry
-
Maven users, add a repository definition in pom.xml
<repositories>
<!-- ... other repositories -->
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/guacsec/trustify-da-java-client</url>
</repository>
<!-- ... other repositories -->
</repositories>
-
Gradle users, add a maven-type repository definition in build.gradle (Groovy DSL) or build.gradle.kts (Kotlin DSL)
repositories {
// ... other repositories
maven {
url 'https://maven.pkg.github.com/guacsec/trustify-da-java-client'
credentials {
username System.getenv("GITHUB_USERNAME")
password System.getenv("GITHUB_TOKEN")
}
}
// ... other repositories
}
- Declare the dependency
-
Maven users, add a dependency in pom.xml
<dependency>
<groupId>io.github.guacsec</groupId>
<artifactId>trustify-da-java-client</artifactId>
<version>0.0.9-SNAPSHOT</version>
</dependency>
-
Gradle users, add a dependency in build.gradle
implementation 'io.github.guacsec:trustify-da-java-client:${trustify-da-java-client.version}'
-
If working with modules, configure module read
module x { // module-info.java
requires io.github.guacsec;
}
-
Code example
import io.github.guacsec.trustifyda.Api.MixedReport;
import io.github.guacsec.trustifyda.ComponentAnalysisResult;
import io.github.guacsec.trustifyda.impl.ExhortApi;
import io.github.guacsec.trustifyda.api.v5.AnalysisReport;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.CompletableFuture;
public class TrustifyExample {
public static void main(String... args) throws Exception {
// instantiate the Trustify DA Java Client implementation
var exhortApi = new ExhortApi();
// get a byte array future holding a html Stack Analysis report
CompletableFuture<byte[]> htmlStackReport = exhortApi.stackAnalysisHtml("/path/to/pom.xml");
// get a AnalysisReport future holding a deserialized Stack Analysis report
CompletableFuture<AnalysisReport> stackReport = exhortApi.stackAnalysis("/path/to/pom.xml");
// get a AnalysisReport future holding a mixed report object aggregating:
// - (json) deserialized Stack Analysis report
// - (html) html Stack Analysis report
CompletableFuture<MixedReport> mixedStackReport = exhortApi.stackAnalysisMixed("/path/to/pom.xml");
// get a AnalysisReport future holding a deserialized Component Analysis report
var manifestContent = Files.readAllBytes(Path.of("/path/to/pom.xml"));
CompletableFuture<AnalysisReport> componentReport = exhortApi.componentAnalysis("/path/to/pom.xml", manifestContent);
// get a ComponentAnalysisResult with license compatibility checking
CompletableFuture<ComponentAnalysisResult> componentWithLicense = exhortApi.componentAnalysisWithLicense("/path/to/pom.xml");
var result = componentWithLicense.get();
var report = result.report(); // standard AnalysisReport
var licenseSummary = result.licenseSummary(); // license compatibility summary (may be null)
// generate a CycloneDX SBOM locally (no backend call required)
String sbomJson = exhortApi.generateSbom("/path/to/pom.xml");
}
}
Supported Ecosystems
Excluding Packages
Excluding a package from any analysis can be achieved by marking the package for exclusion using either the trustify-da-ignore syntax.
Although both trustify-da-ignore and exhortignore patterns work identically and can be used interchangeably. The trustify-da-ignore syntax is recommended for new projects, while exhortignore continues to be supported for backwards compatibility. You can gradually migrate your projects or use both patterns in the same manifest.
-
Java Maven users can add a comment in pom.xml
<!-- Using trustify-da-ignore syntax -->
<dependency> <!--trustify-da-ignore-->
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>0.0.9-SNAPSHOT</version>
</dependency>
<!-- Using legacy exhortignore syntax -->
<dependency> <!--exhortignore-->
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>0.0.9-SNAPSHOT</version>
</dependency>
-
Javascript NPM users can add ignore arrays in package.json:
{
"name": "sample",
"version": "1.0.0",
"description": "",
"main": "index.js",
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^8.2.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.9.18"
},
"trustify-da-ignore": [
"jsonwebtoken"
]
}
-
Golang users can add in go.mod a comment with //trustify-da-ignore next to the package to be ignored, or to "piggyback" on existing comment ( e.g - //indirect) , for example:
module github.com/RHEcosystemAppEng/SaaSi/deployer
go 1.19
require (
github.com/gin-gonic/gin v1.9.1
github.com/google/uuid v1.1.2
github.com/jessevdk/go-flags v1.5.0 //trustify-da-ignore
github.com/kr/pretty v0.3.1
gopkg.in/yaml.v2 v2.4.0
k8s.io/apimachinery v0.26.1
k8s.io/client-go v0.26.1
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect trustify-da-ignore
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect trustify-da-ignore
)
-
Python pip users can add in
requirements.txt a comment with #trustify-da-ignore(or # trustify-da-ignore) to the right of the same artifact to be ignored, for example:
anyio==3.6.2
asgiref==3.4.1
beautifulsoup4==4.12.2
certifi==2023.7.22
chardet==4.0.0
click==8.0.4 #trustify-da-ignore
contextlib2==21.6.0
fastapi==0.75.1
Flask==2.0.3
h11==0.13.0
idna==2.10
immutables==0.19
importlib-metadata==4.8.3
itsdangerous==2.0.1
Jinja2==3.0.3
MarkupSafe==2.0.1
pydantic==1.9.2 # trustify-da-ignore
requests==2.25.1
six==1.16.0
sniffio==1.2.0
soupsieve==2.3.2.post1
starlette==0.17.1
typing_extensions==4.1.1
urllib3==1.26.16
uvicorn==0.17.0
Werkzeug==2.0.3
zipp==3.6.0
-
Python pyproject.toml users can add a comment with #trustify-da-ignore next to a dependency in
pyproject.toml:
[project]
name = "my-project"
dependencies = [
"requests>=2.28.1",
"flask>=2.0", # trustify-da-ignore
"click>=8.0",
]
-
Gradle users can add in build.gradle a comment with //trustify-da-ignore next to the package to be ignored:
```build.gradle
plugins {
id 'java'
}
group = 'groupName'
version = 'version'
repositories {
mavenCentral()
}
dependencies {
implementation "groupId:artifactId:version" // trustify-da-ignore
}
test {
useJUnitPlatform()
}
-
Rust Cargo users can add a comment with #trustify-da-ignore next to the package to be ignored in Cargo.toml:
[dependencies]
serde = "1.0.136" # trustify-da-ignore
tokio = { version = "1.0", features = ["full"] }
[workspace.dependencies]
regex = "1.5.4" # trustify-da-ignore
License Resolution and Compliance
The Java client includes built-in license analysis that detects your project's license, checks dependency license compatibility, and includes license information in generated SBOMs.
- License checking runs automatically during component analysis
- Supports reading licenses from
pom.xml, package.json, Cargo.toml, and LICENSE files
- Set
TRUSTIFY_DA_LICENSE_CHECK=false to disable
For full documentation, see License Resolution and Compliance.
Ignore Strategies - experimental
You can specify the method to ignore dependencies in manifest (globally), by setting the environment variable TRUSTIFY_DA_IGNORE_METHOD to one of the following values:
Possible values:
insensitive - ignoring the dependency and all of its subtree(all transitives) - default.
sensitive - ignoring the dependency but let its transitives remain if they are also transitive of another dependency in the tree or if they're direct dependency of root in the dependency tree.
Customization
There are 2 approaches for customizing Trustify DA Java Client. Using Environment Variables or
Java Properties:
System.setProperty("TRUSTIFY_DA_MVN_PATH", "/path/to/custom/mvn");
System.setProperty("TRUSTIFY_DA_NPM_PATH", "/path/to/custom/npm");
System.setProperty("TRUSTIFY_DA_PNPM_PATH", "/path/to/custom/pnpm");
System.setProperty("TRUSTIFY_DA_YARN_PATH", "/path/to/custom/yarn");
System.setProperty("TRUSTIFY_DA_GO_PATH", "/path/to/custom/go");
System.setProperty("TRUSTIFY_DA_GRADLE_PATH", "/path/to/custom/gradle");
System.setProperty("TRUSTIFY_DA_CARGO_PATH", "/path/to/custom/cargo");
//python - python3, pip3 take precedence if python version > 3 installed
System.setProperty("TRUSTIFY_DA_PYTHON3_PATH", "/path/to/python3");
System.setProperty("TRUSTIFY_DA_PIP3_PATH", "/path/to/pip3");
System.setProperty("TRUSTIFY_DA_PYTHON_PATH", "/path/to/python");
System.setProperty("TRUSTIFY_DA_PIP_PATH", "/path/to/pip");
System.setProperty("TRUSTIFY_DA_UV_PATH", "/path/to/custom/uv");
// Configure proxy for all requests
System.setProperty("TRUSTIFY_DA_PROXY_URL", "http://proxy.example.com:8080");
// Configure Maven settings and repository
System.setProperty("TRUSTIFY_DA_MVN_USER_SETTINGS", "/path/to/custom/settings.xml");
System.setProperty("TRUSTIFY_DA_MVN_LOCAL_REPO", "/path/to/custom/local/repository");
Environment variables takes precedence.
Customizing HTTP Version
The HTTP Client Library can be configured to use HTTP Protocol version through environment variables, so if there is a problem with one of the HTTP Versions, the other can be configured through a dedicated environment variable.
| Environment Variable |
Accepted Values |
Default |
| HTTP_VERSION_TRUSTIFY_DA_CLIENT |
[HTTP_1_1 , HTTP_2] |
HTTP_1_1 |
Proxy Configuration
You can configure a proxy for all HTTP requests made by the API. This is useful when your environment requires going through a proxy to access external services.
You can set the proxy URL in two ways:
- Using environment variable:
export TRUSTIFY_DA_PROXY_URL=http://proxy.example.com:8080
- Using Java Properties when calling the API programmatically:
System.setProperty("TRUSTIFY_DA_PROXY_URL", "http://proxy.example.com:8080");
Customizing Executables