Skip to content

Commit 5c0805f

Browse files
committed
Add valid historical entry meta Check for local/proxy download
1 parent 8c33c9d commit 5c0805f

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/main/java/org/commonjava/util/sidecar/jaxrs/FoloContentAccessResource.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.commons.io.FileUtils;
2323
import org.commonjava.util.sidecar.services.ArchiveRetrieveService;
2424
import org.commonjava.util.sidecar.services.ProxyService;
25+
import org.commonjava.util.sidecar.services.ReportService;
2526
import org.commonjava.util.sidecar.util.TransferStreamingOutput;
2627
import org.eclipse.microprofile.openapi.annotations.Operation;
2728
import org.eclipse.microprofile.openapi.annotations.media.Schema;
@@ -65,6 +66,9 @@ public class FoloContentAccessResource
6566
@Inject
6667
ArchiveRetrieveService archiveService;
6768

69+
@Inject
70+
ReportService reportService;
71+
6872
@Operation( description = "Retrieve Maven/NPM artifact content from historical archive or proxy" )
6973
@APIResponse( responseCode = "200", description = "Content stream" )
7074
@APIResponse( responseCode = "404", description = "Content is not available" )
@@ -86,7 +90,7 @@ public Uni<Response> get( @Parameter( in = PATH, required = true ) @PathParam( "
8690
}
8791

8892
Optional<File> download = archiveService.getLocally( path );
89-
if ( download.isPresent() && download.get().isFile() )
93+
if ( download.isPresent() && download.get().isFile() && reportService.checkValidHistoricalEntryMeta( path ) )
9094
{
9195
Uni<Boolean> checksumValidation =
9296
proxyService.validateChecksum( id, packageType, type, name, path, request );

src/main/java/org/commonjava/util/sidecar/services/ReportService.java

+17-10
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,7 @@ public void storeTrackedDownload( JsonObject message )
109109
logger.debug( "Consuming folo record seal event for path:{}, trackingId:{}", trackingPath, trackingId );
110110

111111
HistoricalEntryDTO entryDTO = historicalContentMap.get( trackingPath );
112-
if ( null == entryDTO )
113-
{
114-
logger.warn( "No historical entry meta is found for tracking {}.", trackingPath );
115-
return;
116-
}
117112
StoreKey storeKey = entryDTO.getStoreKey();
118-
if ( null == storeKey )
119-
{
120-
logger.warn( "No StoreKey is found for tracking {} historical entry.", trackingPath );
121-
return;
122-
}
123113
String originalUrl = entryDTO.getOriginUrl() == null ? "" : entryDTO.getOriginUrl();
124114
boolean exception = false;
125115
try
@@ -151,4 +141,21 @@ public HashMap<String, HistoricalEntryDTO> getHistoricalContentMap()
151141
{
152142
return historicalContentMap;
153143
}
144+
145+
public boolean checkValidHistoricalEntryMeta( String trackingPath )
146+
{
147+
HistoricalEntryDTO entryDTO = historicalContentMap.get( trackingPath );
148+
if ( entryDTO == null )
149+
{
150+
logger.warn( "Check no matched historical entry meta is found for tracking path: {}.", trackingPath );
151+
return false;
152+
}
153+
StoreKey storeKey = entryDTO.getStoreKey();
154+
if ( storeKey == null )
155+
{
156+
logger.warn( "Check no valid historical StoreKey is found for tracking path: {}.", trackingPath );
157+
return false;
158+
}
159+
return true;
160+
}
154161
}

0 commit comments

Comments
 (0)