io.github.pmckeown.dependencytrack.finding.FindingsClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dependency-track-maven-plugin Show documentation
Show all versions of dependency-track-maven-plugin Show documentation
Maven plugin to integrate with a Dependency Track server to submit dependency manifests and gather project metrics.
package io.github.pmckeown.dependencytrack.finding;
import io.github.pmckeown.dependencytrack.CommonConfig;
import io.github.pmckeown.dependencytrack.Response;
import io.github.pmckeown.dependencytrack.project.Project;
import io.github.pmckeown.util.Logger;
import kong.unirest.GenericType;
import kong.unirest.HttpResponse;
import kong.unirest.jackson.JacksonObjectMapper;
import kong.unirest.Unirest;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.List;
import java.util.Optional;
import static io.github.pmckeown.dependencytrack.ObjectMapperFactory.relaxedObjectMapper;
import static io.github.pmckeown.dependencytrack.ResourceConstants.V1_FINDING_PROJECT_UUID;
import static kong.unirest.HeaderNames.ACCEPT;
import static kong.unirest.HeaderNames.ACCEPT_ENCODING;
import static kong.unirest.Unirest.get;
@Singleton
class FindingsClient {
private CommonConfig commonConfig;
private Logger logger;
@Inject
FindingsClient(CommonConfig commonConfig, Logger logger) {
this.commonConfig = commonConfig;
this.logger = logger;
}
static {
Unirest.config().setObjectMapper(new JacksonObjectMapper(relaxedObjectMapper()))
.addDefaultHeader(ACCEPT_ENCODING, "gzip, deflate")
.addDefaultHeader(ACCEPT, "application/json");
}
Response> getFindingsForProject(Project project) {
logger.debug("Getting findings for project: %s-%s", project.getName(), project.getVersion());
final HttpResponse> httpResponse = get(
commonConfig.getDependencyTrackBaseUrl() + V1_FINDING_PROJECT_UUID)
.header("X-Api-Key", commonConfig.getApiKey())
.routeParam("uuid", project.getUuid())
.asObject(new GenericType>(){});
Optional> body;
if (httpResponse.isSuccess()) {
body = Optional.of(httpResponse.getBody());
} else {
body = Optional.empty();
}
return new Response<>(httpResponse.getStatus(), httpResponse.getStatusText(),
httpResponse.isSuccess(), body);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy