Skip to content

Commit 5ee55a0

Browse files
authored
Merge pull request #87 from yma96/2.0.x
Remove checksum validation from Sidecar
2 parents efa0002 + dc53e05 commit 5ee55a0

File tree

3 files changed

+5
-157
lines changed

3 files changed

+5
-157
lines changed

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

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import javax.ws.rs.core.Context;
4343
import javax.ws.rs.core.Response;
4444
import java.io.File;
45-
import java.io.IOException;
4645
import java.io.InputStream;
4746
import java.util.Optional;
4847

@@ -92,39 +91,11 @@ public Uni<Response> get( @Parameter( in = PATH, required = true ) @PathParam( "
9291
Optional<File> download = archiveService.getLocally( path );
9392
if ( download.isPresent() && download.get().isFile() && reportService.checkValidHistoricalEntryMeta( path ) )
9493
{
95-
Uni<Boolean> checksumValidation =
96-
proxyService.validateChecksum( id, packageType, type, name, path, request );
97-
return checksumValidation.onItem().transform( result -> {
98-
if ( result != null && result )
99-
{
100-
try
101-
{
102-
InputStream inputStream = FileUtils.openInputStream( download.get() );
103-
final Response.ResponseBuilder builder =
104-
Response.ok( new TransferStreamingOutput( inputStream ) );
105-
logger.debug( "Download path: {} from historical archive.", path );
106-
publishTrackingEvent( path, id );
107-
return Uni.createFrom().item( builder.build() );
108-
}
109-
catch ( IOException e )
110-
{
111-
logger.error( "IO error for local file, path {}.", path, e );
112-
}
113-
}
114-
else
115-
{
116-
try
117-
{
118-
logger.debug( "Checksum validation failed, download from proxy: {}.", path );
119-
return proxyService.doGet( id, packageType, type, name, path, request );
120-
}
121-
catch ( Exception e )
122-
{
123-
logger.error( "Error for proxy download, path {}.", path, e );
124-
}
125-
}
126-
return null;
127-
} ).flatMap( response -> response );
94+
InputStream inputStream = FileUtils.openInputStream( download.get() );
95+
final Response.ResponseBuilder builder = Response.ok( new TransferStreamingOutput( inputStream ) );
96+
logger.debug( "Download path: {} from historical archive.", path );
97+
publishTrackingEvent( path, id );
98+
return Uni.createFrom().item( builder.build() );
12899
}
129100
else
130101
{

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

Lines changed: 0 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515
*/
1616
package org.commonjava.util.sidecar.services;
1717

18-
import io.smallrye.mutiny.Multi;
1918
import io.smallrye.mutiny.Uni;
2019
import io.vertx.core.http.HttpMethod;
2120
import io.vertx.core.http.HttpServerRequest;
2221
import kotlin.Pair;
2322
import org.commonjava.util.sidecar.config.ProxyConfiguration;
2423
import org.commonjava.util.sidecar.interceptor.ExceptionHandler;
25-
import org.commonjava.util.sidecar.model.dto.HistoricalEntryDTO;
2624
import org.commonjava.util.sidecar.util.OtelAdapter;
2725
import org.commonjava.util.sidecar.util.ProxyStreamingOutput;
2826
import org.commonjava.util.sidecar.util.UrlUtils;
@@ -33,12 +31,7 @@
3331
import javax.enterprise.context.ApplicationScoped;
3432
import javax.inject.Inject;
3533
import javax.ws.rs.core.Response;
36-
import java.io.ByteArrayOutputStream;
37-
import java.io.IOException;
3834
import java.io.InputStream;
39-
import java.util.LinkedHashMap;
40-
import java.util.List;
41-
import java.util.Map;
4235

4336
import static io.vertx.core.http.HttpMethod.HEAD;
4437
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
@@ -135,76 +128,6 @@ public Uni<Response> wrapAsyncCall( WebClientAdapter.CallAdapter asyncCall, Http
135128
return ret.onFailure().recoverWithItem( this::handleProxyException );
136129
}
137130

138-
public Uni<Boolean> validateChecksum( String trackingId, String packageType, String type, String name, String path,
139-
HttpServerRequest request )
140-
{
141-
Map<String, String> localChecksums = getChecksums( path );
142-
Multi<Boolean> multiResults = Multi.createFrom().iterable( localChecksums.keySet() ).flatMap( checksumType -> {
143-
String localChecksum = localChecksums.get( checksumType );
144-
if ( localChecksum == null )
145-
{
146-
return Multi.createFrom().item( false );
147-
}
148-
String checksumUrl = path + "." + checksumType;
149-
try
150-
{
151-
return downloadAndCompareChecksum( trackingId, packageType, type, name, checksumUrl, localChecksum,
152-
request ).onItem().invoke( result -> {
153-
if ( result != null && result )
154-
{
155-
// This is just used to skip loop to avoid unnecessary checksum download
156-
logger.debug(
157-
"Found the valid checksum compare result, stopping further checks, remote path {}",
158-
checksumUrl );
159-
throw new FoundValidChecksumException();
160-
}
161-
} ).onFailure().recoverWithItem( true ).toMulti();
162-
}
163-
catch ( Exception e )
164-
{
165-
logger.error( "Checksum download compare error for path: {}", checksumUrl, e );
166-
}
167-
return Multi.createFrom().item( false );
168-
} );
169-
170-
Uni<List<Boolean>> collectedResults = multiResults.collect().asList();
171-
return collectedResults.onItem().transform( results -> {
172-
boolean finalResult = results.stream().anyMatch( res -> res );
173-
logger.debug( "FinalResult:{}", finalResult );
174-
return finalResult;
175-
} );
176-
}
177-
178-
private Uni<Boolean> downloadAndCompareChecksum( String trackingId, String packageType, String type, String name,
179-
String checksumUrl, String localChecksum,
180-
HttpServerRequest request )
181-
throws Exception
182-
{
183-
return doGet( trackingId, packageType, type, name, checksumUrl, request ).onItem().transform( response -> {
184-
if ( response.getStatus() == Response.Status.OK.getStatusCode() )
185-
{
186-
ProxyStreamingOutput streamingOutput = (ProxyStreamingOutput) response.getEntity();
187-
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream())
188-
{
189-
streamingOutput.write( outputStream );
190-
String remoteChecksum = outputStream.toString();
191-
return localChecksum.equals( remoteChecksum );
192-
}
193-
catch ( IOException e )
194-
{
195-
logger.error( "Error to read remote checksum, path:{}.", checksumUrl, e );
196-
return null;
197-
}
198-
}
199-
else
200-
{
201-
logger.error( "Failed to download remote checksum for {}: HTTP {}.", checksumUrl,
202-
response.getStatus() );
203-
return null;
204-
}
205-
} );
206-
}
207-
208131
/**
209132
* Send status 500 with error message body.
210133
* @param t error
@@ -245,45 +168,4 @@ private boolean isHeaderAllowed( Pair<? extends String, ? extends String> header
245168
return !FORBIDDEN_HEADERS.contains( key.toLowerCase() );
246169
}
247170

248-
private Map<String, String> getChecksums( String path )
249-
{
250-
Map<String, String> result = new LinkedHashMap<>();
251-
HistoricalEntryDTO entryDTO = reportService.getHistoricalContentMap().get( path );
252-
if ( entryDTO != null )
253-
{
254-
result.put( ChecksumType.SHA1.getValue(), entryDTO.getSha1() );
255-
result.put( ChecksumType.SHA256.getValue(), entryDTO.getSha256() );
256-
result.put( ChecksumType.MD5.getValue(), entryDTO.getMd5() );
257-
}
258-
259-
return result;
260-
}
261-
262-
enum ChecksumType
263-
{
264-
SHA1( "sha1" ),
265-
SHA256( "sha256" ),
266-
MD5( "md5" );
267-
268-
private final String value;
269-
270-
ChecksumType( String value )
271-
{
272-
this.value = value;
273-
}
274-
275-
public String getValue()
276-
{
277-
return value;
278-
}
279-
}
280-
281-
class FoundValidChecksumException
282-
extends RuntimeException
283-
{
284-
public FoundValidChecksumException()
285-
{
286-
super( "Found a valid checksum, stopping further checks." );
287-
}
288-
}
289171
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,6 @@ public void storeTrackedDownload( JsonObject message )
137137
}
138138
}
139139

140-
public HashMap<String, HistoricalEntryDTO> getHistoricalContentMap()
141-
{
142-
return historicalContentMap;
143-
}
144-
145140
public boolean checkValidHistoricalEntryMeta( String trackingPath )
146141
{
147142
HistoricalEntryDTO entryDTO = historicalContentMap.get( trackingPath );

0 commit comments

Comments
 (0)