-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #636 from DependencyTrack/epss-mirroring
Epss mirroring
- Loading branch information
Showing
44 changed files
with
809 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,4 +91,4 @@ jobs: | |
path: |- | ||
pr-commit.txt | ||
pr-number.txt | ||
target/jacoco-ut/jacoco.xml | ||
target/jacoco-ut/jacoco.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,5 +128,4 @@ final var record = new ProducerRecord<>(event.topic().name(), keyBytes, valueByt | |
|
||
return record; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/org/dependencytrack/event/kafka/processor/EpssMirrorProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* This file is part of Dependency-Track. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright (c) OWASP Foundation. All Rights Reserved. | ||
*/ | ||
package org.dependencytrack.event.kafka.processor; | ||
|
||
import alpine.common.logging.Logger; | ||
import org.apache.kafka.clients.consumer.ConsumerRecord; | ||
import org.dependencytrack.event.kafka.processor.api.BatchProcessor; | ||
import org.dependencytrack.event.kafka.processor.exception.ProcessingException; | ||
import org.dependencytrack.model.Epss; | ||
import org.dependencytrack.parser.dependencytrack.EpssModelConverter; | ||
import org.dependencytrack.persistence.QueryManager; | ||
import org.dependencytrack.proto.mirror.v1.EpssItem; | ||
|
||
import java.util.List; | ||
|
||
|
||
public class EpssMirrorProcessor implements BatchProcessor<String, EpssItem> { | ||
|
||
public static final String PROCESSOR_NAME = "epss.mirror"; | ||
private static final Logger LOGGER = Logger.getLogger(EpssMirrorProcessor.class); | ||
|
||
@Override | ||
public void process(List<ConsumerRecord<String, EpssItem>> consumerRecords) throws ProcessingException { | ||
try (QueryManager qm = new QueryManager()) { | ||
LOGGER.debug("Synchronizing batch of %s mirrored EPSS records.".formatted(consumerRecords.size())); | ||
List<Epss> epssList = consumerRecords.stream() | ||
.map(ConsumerRecord::value) | ||
.map(EpssModelConverter::convert) | ||
.toList(); | ||
if (!epssList.isEmpty()) { | ||
qm.synchronizeAllEpss(epssList); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* This file is part of Dependency-Track. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright (c) OWASP Foundation. All Rights Reserved. | ||
*/ | ||
package org.dependencytrack.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
import javax.jdo.annotations.Column; | ||
import javax.jdo.annotations.IdGeneratorStrategy; | ||
import javax.jdo.annotations.PersistenceCapable; | ||
import javax.jdo.annotations.Persistent; | ||
import javax.jdo.annotations.PrimaryKey; | ||
import javax.validation.constraints.NotBlank; | ||
import java.io.Serializable; | ||
import java.math.BigDecimal; | ||
|
||
@PersistenceCapable | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class Epss implements Serializable { | ||
|
||
@PrimaryKey | ||
@Persistent(valueStrategy = IdGeneratorStrategy.NATIVE) | ||
@JsonIgnore | ||
private long id; | ||
|
||
@Persistent | ||
@Column(name = "CVE", allowsNull = "false") | ||
@NotBlank | ||
private String cve; | ||
|
||
@Persistent | ||
@Column(name = "SCORE", scale = 5) | ||
private BigDecimal score; | ||
|
||
@Persistent | ||
@Column(name = "PERCENTILE", scale = 5) | ||
private BigDecimal percentile; | ||
|
||
public long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getCve() { | ||
return cve; | ||
} | ||
|
||
public void setCve(String cve) { | ||
this.cve = cve; | ||
} | ||
|
||
public BigDecimal getScore() { | ||
return score; | ||
} | ||
|
||
public void setScore(BigDecimal score) { | ||
this.score = score; | ||
} | ||
|
||
public BigDecimal getPercentile() { | ||
return percentile; | ||
} | ||
|
||
public void setPercentile(BigDecimal percentile) { | ||
this.percentile = percentile; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.