-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: mehab <[email protected]>
- Loading branch information
Showing
18 changed files
with
336 additions
and
122 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/main/java/org/dependencytrack/componentmeta/AbstractMetaHandler.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,35 @@ | ||
package org.dependencytrack.componentmeta; | ||
|
||
import org.dependencytrack.event.ComponentRepositoryMetaAnalysisEvent; | ||
import org.dependencytrack.event.kafka.KafkaEventDispatcher; | ||
import org.dependencytrack.model.Component; | ||
import org.dependencytrack.model.FetchStatus; | ||
import org.dependencytrack.model.IntegrityMetaComponent; | ||
import org.dependencytrack.persistence.QueryManager; | ||
|
||
import java.time.Instant; | ||
import java.util.Date; | ||
|
||
public abstract class AbstractMetaHandler implements Handler { | ||
|
||
ComponentProjection componentProjection; | ||
QueryManager queryManager; | ||
KafkaEventDispatcher kafkaEventDispatcher; | ||
|
||
|
||
public static IntegrityMetaComponent createIntegrityMetaComponent(Component component) { | ||
IntegrityMetaComponent integrityMetaComponent1 = new IntegrityMetaComponent(); | ||
integrityMetaComponent1.setStatus(FetchStatus.IN_PROGRESS); | ||
integrityMetaComponent1.setPurl(component.getPurl().toString()); | ||
integrityMetaComponent1.setLastFetch(Date.from(Instant.now())); | ||
return integrityMetaComponent1; | ||
} | ||
|
||
public static IntegrityMetaComponent createIntegrityMetaComponent(ComponentProjection component) { | ||
IntegrityMetaComponent integrityMetaComponent1 = new IntegrityMetaComponent(); | ||
integrityMetaComponent1.setStatus(FetchStatus.IN_PROGRESS); | ||
integrityMetaComponent1.setPurl(component.purl()); | ||
integrityMetaComponent1.setLastFetch(Date.from(Instant.now())); | ||
return integrityMetaComponent1; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/org/dependencytrack/componentmeta/ComponentProjection.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,4 @@ | ||
package org.dependencytrack.componentmeta; | ||
|
||
public record ComponentProjection(String purlCoordinates, Boolean internal, String purl) { | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/dependencytrack/componentmeta/ComposerMetaHandler.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,18 @@ | ||
package org.dependencytrack.componentmeta; | ||
|
||
import org.dependencytrack.event.ComponentRepositoryMetaAnalysisEvent; | ||
import org.dependencytrack.event.kafka.KafkaEventDispatcher; | ||
import org.dependencytrack.persistence.QueryManager; | ||
|
||
public class ComposerMetaHandler extends AbstractMetaHandler{ | ||
public ComposerMetaHandler(ComponentProjection component, QueryManager qm, KafkaEventDispatcher kafkaEventDispatcher) { | ||
this.componentProjection = component; | ||
this.queryManager = qm; | ||
this.kafkaEventDispatcher = kafkaEventDispatcher; | ||
} | ||
|
||
@Override | ||
public void handle() { | ||
kafkaEventDispatcher.dispatchAsync(new ComponentRepositoryMetaAnalysisEvent(componentProjection.purlCoordinates(), componentProjection.internal(), false)); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/org/dependencytrack/componentmeta/CpanMetaHandler.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,19 @@ | ||
package org.dependencytrack.componentmeta; | ||
|
||
import org.dependencytrack.event.ComponentRepositoryMetaAnalysisEvent; | ||
import org.dependencytrack.event.kafka.KafkaEventDispatcher; | ||
import org.dependencytrack.persistence.QueryManager; | ||
|
||
public class CpanMetaHandler extends AbstractMetaHandler { | ||
|
||
public CpanMetaHandler(ComponentProjection component, QueryManager qm, KafkaEventDispatcher kafkaEventDispatcher) { | ||
this.componentProjection = component; | ||
this.queryManager = qm; | ||
this.kafkaEventDispatcher = kafkaEventDispatcher; | ||
} | ||
|
||
@Override | ||
public void handle() { | ||
kafkaEventDispatcher.dispatchAsync(new ComponentRepositoryMetaAnalysisEvent(componentProjection.purlCoordinates(), componentProjection.internal(), false)); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/dependencytrack/componentmeta/GemMetaHandler.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,18 @@ | ||
package org.dependencytrack.componentmeta; | ||
|
||
import org.dependencytrack.event.ComponentRepositoryMetaAnalysisEvent; | ||
import org.dependencytrack.event.kafka.KafkaEventDispatcher; | ||
import org.dependencytrack.persistence.QueryManager; | ||
|
||
public class GemMetaHandler extends AbstractMetaHandler{ | ||
public GemMetaHandler(ComponentProjection component, QueryManager qm, KafkaEventDispatcher kafkaEventDispatcher) { | ||
this.componentProjection = component; | ||
this.queryManager = qm; | ||
this.kafkaEventDispatcher = kafkaEventDispatcher; | ||
} | ||
|
||
@Override | ||
public void handle() { | ||
kafkaEventDispatcher.dispatchAsync(new ComponentRepositoryMetaAnalysisEvent(componentProjection.purlCoordinates(), componentProjection.internal(), false)); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/org/dependencytrack/componentmeta/GoMetaHandler.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,19 @@ | ||
package org.dependencytrack.componentmeta; | ||
|
||
import org.dependencytrack.event.ComponentRepositoryMetaAnalysisEvent; | ||
import org.dependencytrack.event.kafka.KafkaEventDispatcher; | ||
import org.dependencytrack.persistence.QueryManager; | ||
|
||
public class GoMetaHandler extends AbstractMetaHandler { | ||
|
||
public GoMetaHandler(ComponentProjection component, QueryManager qm, KafkaEventDispatcher kafkaEventDispatcher) { | ||
this.componentProjection = component; | ||
this.queryManager = qm; | ||
this.kafkaEventDispatcher = kafkaEventDispatcher; | ||
} | ||
|
||
@Override | ||
public void handle() { | ||
kafkaEventDispatcher.dispatchAsync(new ComponentRepositoryMetaAnalysisEvent(componentProjection.purlCoordinates(), componentProjection.internal(), false)); | ||
} | ||
} |
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,5 @@ | ||
package org.dependencytrack.componentmeta; | ||
|
||
public interface Handler { | ||
void handle(); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/dependencytrack/componentmeta/HexMetaHandler.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,18 @@ | ||
package org.dependencytrack.componentmeta; | ||
|
||
import org.dependencytrack.event.ComponentRepositoryMetaAnalysisEvent; | ||
import org.dependencytrack.event.kafka.KafkaEventDispatcher; | ||
import org.dependencytrack.persistence.QueryManager; | ||
|
||
public class HexMetaHandler extends AbstractMetaHandler { | ||
public HexMetaHandler(ComponentProjection component, QueryManager qm, KafkaEventDispatcher kafkaEventDispatcher) { | ||
this.componentProjection = component; | ||
this.queryManager = qm; | ||
this.kafkaEventDispatcher = kafkaEventDispatcher; | ||
} | ||
|
||
@Override | ||
public void handle() { | ||
kafkaEventDispatcher.dispatchAsync(new ComponentRepositoryMetaAnalysisEvent(componentProjection.purlCoordinates(), componentProjection.internal(), false)); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/org/dependencytrack/componentmeta/MavenMetaHandler.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,37 @@ | ||
package org.dependencytrack.componentmeta; | ||
|
||
import org.dependencytrack.event.ComponentRepositoryMetaAnalysisEvent; | ||
import org.dependencytrack.event.kafka.KafkaEventDispatcher; | ||
import org.dependencytrack.model.FetchStatus; | ||
import org.dependencytrack.model.IntegrityMetaComponent; | ||
import org.dependencytrack.persistence.QueryManager; | ||
|
||
import java.time.Instant; | ||
import java.util.Date; | ||
|
||
public class MavenMetaHandler extends AbstractMetaHandler { | ||
|
||
|
||
public MavenMetaHandler(ComponentProjection component, QueryManager qm, KafkaEventDispatcher kafkaEventDispatcher) { | ||
this.componentProjection = component; | ||
this.queryManager = qm; | ||
this.kafkaEventDispatcher = kafkaEventDispatcher; | ||
} | ||
|
||
@Override | ||
public void handle() { | ||
IntegrityMetaComponent integrityMetaComponent = queryManager.getIntegrityMetaComponent(componentProjection.purl()); | ||
if (integrityMetaComponent != null) { | ||
if (integrityMetaComponent.getStatus() == null || (integrityMetaComponent.getStatus() == FetchStatus.IN_PROGRESS && Date.from(Instant.now()).getTime()-integrityMetaComponent.getLastFetch().getTime()>60 * 60 * 1000L)) { | ||
integrityMetaComponent.setLastFetch(Date.from(Instant.now())); | ||
queryManager.updateIntegrityMetaComponent(integrityMetaComponent); | ||
kafkaEventDispatcher.dispatchAsync(new ComponentRepositoryMetaAnalysisEvent(componentProjection.purlCoordinates(), componentProjection.internal(), true)); | ||
} else { | ||
kafkaEventDispatcher.dispatchAsync(new ComponentRepositoryMetaAnalysisEvent(componentProjection.purlCoordinates(), componentProjection.internal(), false)); | ||
} | ||
} else { | ||
queryManager.createIntegrityMetaComponent(AbstractMetaHandler.createIntegrityMetaComponent(componentProjection)); | ||
kafkaEventDispatcher.dispatchAsync(new ComponentRepositoryMetaAnalysisEvent(componentProjection.purlCoordinates(), componentProjection.internal(), true)); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/org/dependencytrack/componentmeta/NpmMetaHandler.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,36 @@ | ||
package org.dependencytrack.componentmeta; | ||
|
||
import org.dependencytrack.event.ComponentRepositoryMetaAnalysisEvent; | ||
import org.dependencytrack.event.kafka.KafkaEventDispatcher; | ||
import org.dependencytrack.model.FetchStatus; | ||
import org.dependencytrack.model.IntegrityMetaComponent; | ||
import org.dependencytrack.persistence.QueryManager; | ||
|
||
import java.time.Instant; | ||
import java.util.Date; | ||
|
||
public class NpmMetaHandler extends AbstractMetaHandler { | ||
|
||
public NpmMetaHandler(ComponentProjection component, QueryManager qm, KafkaEventDispatcher kafkaEventDispatcher) { | ||
this.componentProjection = component; | ||
this.queryManager = qm; | ||
this.kafkaEventDispatcher = kafkaEventDispatcher; | ||
} | ||
|
||
@Override | ||
public void handle() { | ||
IntegrityMetaComponent integrityMetaComponent = queryManager.getIntegrityMetaComponent(componentProjection.purl()); | ||
if (integrityMetaComponent != null) { | ||
if (integrityMetaComponent.getStatus() == null || (integrityMetaComponent.getStatus() == FetchStatus.IN_PROGRESS && Date.from(Instant.now()).getTime()-integrityMetaComponent.getLastFetch().getTime()>60 * 60 * 1000L)) { | ||
integrityMetaComponent.setLastFetch(Date.from(Instant.now())); | ||
queryManager.updateIntegrityMetaComponent(integrityMetaComponent); | ||
kafkaEventDispatcher.dispatchAsync(new ComponentRepositoryMetaAnalysisEvent(componentProjection.purlCoordinates(), componentProjection.internal(), true)); | ||
} else { | ||
kafkaEventDispatcher.dispatchAsync(new ComponentRepositoryMetaAnalysisEvent(componentProjection.purlCoordinates(), componentProjection.internal(), false)); | ||
} | ||
} else { | ||
queryManager.createIntegrityMetaComponent(AbstractMetaHandler.createIntegrityMetaComponent(componentProjection)); | ||
kafkaEventDispatcher.dispatchAsync(new ComponentRepositoryMetaAnalysisEvent(componentProjection.purlCoordinates(), componentProjection.internal(), true)); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/dependencytrack/componentmeta/NugetMetaHandler.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,18 @@ | ||
package org.dependencytrack.componentmeta; | ||
|
||
import org.dependencytrack.event.ComponentRepositoryMetaAnalysisEvent; | ||
import org.dependencytrack.event.kafka.KafkaEventDispatcher; | ||
import org.dependencytrack.persistence.QueryManager; | ||
|
||
public class NugetMetaHandler extends AbstractMetaHandler{ | ||
public NugetMetaHandler(ComponentProjection component, QueryManager qm, KafkaEventDispatcher kafkaEventDispatcher) { | ||
this.componentProjection = component; | ||
this.queryManager = qm; | ||
this.kafkaEventDispatcher = kafkaEventDispatcher; | ||
} | ||
|
||
@Override | ||
public void handle() { | ||
kafkaEventDispatcher.dispatchAsync(new ComponentRepositoryMetaAnalysisEvent(componentProjection.purlCoordinates(), componentProjection.internal(), false)); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/org/dependencytrack/componentmeta/PypiMetaHandler.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,35 @@ | ||
package org.dependencytrack.componentmeta; | ||
|
||
import org.dependencytrack.event.ComponentRepositoryMetaAnalysisEvent; | ||
import org.dependencytrack.event.kafka.KafkaEventDispatcher; | ||
import org.dependencytrack.model.FetchStatus; | ||
import org.dependencytrack.model.IntegrityMetaComponent; | ||
import org.dependencytrack.persistence.QueryManager; | ||
|
||
import java.time.Instant; | ||
import java.util.Date; | ||
|
||
public class PypiMetaHandler extends AbstractMetaHandler { | ||
public PypiMetaHandler(ComponentProjection component, QueryManager qm, KafkaEventDispatcher kafkaEventDispatcher) { | ||
this.componentProjection = component; | ||
this.queryManager = qm; | ||
this.kafkaEventDispatcher = kafkaEventDispatcher; | ||
} | ||
|
||
@Override | ||
public void handle() { | ||
IntegrityMetaComponent integrityMetaComponent = queryManager.getIntegrityMetaComponent(componentProjection.purl()); | ||
if (integrityMetaComponent != null) { | ||
if (integrityMetaComponent.getStatus() == null || (integrityMetaComponent.getStatus() == FetchStatus.IN_PROGRESS && Date.from(Instant.now()).getTime()-integrityMetaComponent.getLastFetch().getTime()>60 * 60 * 1000L)) { | ||
integrityMetaComponent.setLastFetch(Date.from(Instant.now())); | ||
queryManager.updateIntegrityMetaComponent(integrityMetaComponent); | ||
kafkaEventDispatcher.dispatchAsync(new ComponentRepositoryMetaAnalysisEvent(componentProjection.purlCoordinates(), componentProjection.internal(), true)); | ||
} else { | ||
kafkaEventDispatcher.dispatchAsync(new ComponentRepositoryMetaAnalysisEvent(componentProjection.purlCoordinates(), componentProjection.internal(), false)); | ||
} | ||
} else { | ||
queryManager.createIntegrityMetaComponent(AbstractMetaHandler.createIntegrityMetaComponent(componentProjection)); | ||
kafkaEventDispatcher.dispatchAsync(new ComponentRepositoryMetaAnalysisEvent(componentProjection.purlCoordinates(), componentProjection.internal(), true)); | ||
} | ||
} | ||
} |
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.