Skip to content

Commit

Permalink
Add log for downloaded Revocation Batches (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
f11h authored Jul 15, 2022
1 parent ad6784c commit a7711bb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ public class RevocationBatchDownload {
private String batchId;

private String signedCms;

private String country;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import eu.europa.ec.dgc.gateway.restapi.filter.CertificateAuthenticationRole;
import eu.europa.ec.dgc.gateway.restapi.mapper.RevocationBatchMapper;
import eu.europa.ec.dgc.gateway.service.RevocationListService;
import eu.europa.ec.dgc.gateway.utils.DgcMdc;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
Expand Down Expand Up @@ -75,17 +76,21 @@ public class CertificateRevocationListController {
private final RevocationBatchMapper revocationBatchMapper;

public static final String UUID_REGEX =
"^[0-9a-f]{8}\\b-[0-9a-f]{4}\\b-[0-9a-f]{4}\\b-[0-9a-f]{4}\\b-[0-9a-f]{12}$";
"^[0-9a-f]{8}\\b-[0-9a-f]{4}\\b-[0-9a-f]{4}\\b-[0-9a-f]{4}\\b-[0-9a-f]{12}$";

private static final String MDC_DOWNLOADER_COUNTRY = "downloaderCountry";
private static final String MDC_DOWNLOADED_COUNTRY = "downloadedCountry";
private static final String MDC_DOWNLOADED_BATCH_ID = "downloadedBatchId";

/**
* Endpoint to download Revocation Batch List.
*/
@CertificateAuthenticationRequired(requiredRoles = CertificateAuthenticationRole.RevocationListReader)
@GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(
security = {
@SecurityRequirement(name = OpenApiConfig.SECURITY_SCHEMA_HASH),
@SecurityRequirement(name = OpenApiConfig.SECURITY_SCHEMA_DISTINGUISH_NAME)
security = {
@SecurityRequirement(name = OpenApiConfig.SECURITY_SCHEMA_HASH),
@SecurityRequirement(name = OpenApiConfig.SECURITY_SCHEMA_DISTINGUISH_NAME)
},
tags = {"Revocation"},
summary = "Download Batch List",
Expand Down Expand Up @@ -154,25 +159,33 @@ public ResponseEntity<RevocationBatchListDto> downloadBatchList(
responseCode = "200",
description = "Response contains the batch.",
content = @Content(schema = @Schema(implementation = RevocationBatchDto.class)),
headers = @Header(name = HttpHeaders.ETAG, description = "Batch ID")),
@ApiResponse(
responseCode = "404",
description = "Batch does not exist."),
@ApiResponse(
responseCode = "410",
description = "Batch already deleted.")
headers = @Header(name = HttpHeaders.ETAG, description = "Batch ID")),
@ApiResponse(
responseCode = "404",
description = "Batch does not exist."),
@ApiResponse(
responseCode = "410",
description = "Batch already deleted.")
}
)
public ResponseEntity<String> downloadBatch(
@Valid @PathVariable("batchId") @Pattern(regexp = UUID_REGEX) String batchId) {
@Valid @PathVariable("batchId") @Pattern(regexp = UUID_REGEX) String batchId,
@RequestAttribute(CertificateAuthenticationFilter.REQUEST_PROP_COUNTRY) String downloaderCountry) {

try {
RevocationBatchDownload download = revocationListService.getRevocationBatch(batchId);


DgcMdc.put(MDC_DOWNLOADED_COUNTRY, download.getCountry());
DgcMdc.put(MDC_DOWNLOADER_COUNTRY, downloaderCountry);
DgcMdc.put(MDC_DOWNLOADED_BATCH_ID, batchId);

log.info("Revocation Batch downloaded.");

return ResponseEntity
.ok()
.header(HttpHeaders.ETAG, download.getBatchId())
.body(download.getSignedCms());
.ok()
.header(HttpHeaders.ETAG, download.getBatchId())
.body(download.getSignedCms());

} catch (RevocationListService.RevocationBatchServiceException e) {
switch (e.getReason()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,16 @@ public RevocationBatchDownload getRevocationBatch(String batchId) throws Revocat

if (entity.isEmpty()) {
throw new RevocationBatchServiceException(
RevocationBatchServiceException.Reason.NOT_FOUND, "Batch not found");
RevocationBatchServiceException.Reason.NOT_FOUND, "Batch not found");
}

if (entity.get().getDeleted()) {
throw new RevocationBatchServiceException(
RevocationBatchServiceException.Reason.GONE, "Batch already deleted.");
RevocationBatchServiceException.Reason.GONE, "Batch already deleted.");
}

return new RevocationBatchDownload(entity.get().getBatchId(), entity.get().getSignedBatch());
return new RevocationBatchDownload(
entity.get().getBatchId(), entity.get().getSignedBatch(), entity.get().getCountry());
}

/**
Expand Down

0 comments on commit a7711bb

Please sign in to comment.