Skip to content

Commit

Permalink
Add Logging for Downloaded Keys (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
f11h committed May 21, 2021
1 parent c74858b commit dad5234
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
2 changes: 2 additions & 0 deletions docs/software-design-dgc-gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ These key-value-pairs can be followed by additional attributes. The additional a
| Created new AuditEvent (id = event type) | INFO | Created AuditEvent | auditId, country |
| **General**
| Uncaught Exception was thrown in DGCG | ERROR | Uncaught exception | exception |
| **Download Interface**
| Trust List was downloaded by a country | INFO | Downloaded TrustList | downloadedKeys (Number of Keys), downloadedKeysCountry (Downloader Country), downloadedKeysType (optional) |



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import eu.europa.ec.dgc.gateway.restapi.dto.CertificateTypeDto;
import eu.europa.ec.dgc.gateway.restapi.dto.ProblemReportDto;
import eu.europa.ec.dgc.gateway.restapi.dto.TrustListDto;
import eu.europa.ec.dgc.gateway.restapi.filter.CertificateAuthenticationFilter;
import eu.europa.ec.dgc.gateway.restapi.filter.CertificateAuthenticationRequired;
import eu.europa.ec.dgc.gateway.restapi.mapper.GwTrustListMapper;
import eu.europa.ec.dgc.gateway.service.TrustListService;
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 All @@ -39,24 +41,32 @@
import javax.validation.Valid;
import javax.validation.constraints.Size;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/trustList")
@RequiredArgsConstructor
@Validated
@Slf4j
public class TrustListController {

private final TrustListService trustListService;

private final GwTrustListMapper trustListMapper;

private static final String MDC_PROP_DOWNLOAD_KEYS_COUNT = "downloadedKeys";
private static final String MDC_PROP_DOWNLOAD_KEYS_TYPE = "downloadedKeysType";
private static final String MDC_PROP_DOWNLOAD_KEYS_COUNTRY = "downloadedKeysCountry";
private static final String DOWNLOADED_TRUSTLIST_LOG_MESSAGE = "Downloaded TrustList";

/**
* TrustList Download Controller.
*/
Expand All @@ -80,8 +90,17 @@ public class TrustListController {
schema = @Schema(implementation = ProblemReportDto.class)
))
})
public ResponseEntity<List<TrustListDto>> downloadTrustList() {
return ResponseEntity.ok(trustListMapper.trustListToTrustListDto(trustListService.getTrustList()));
public ResponseEntity<List<TrustListDto>> downloadTrustList(
@RequestAttribute(CertificateAuthenticationFilter.REQUEST_PROP_COUNTRY) String downloaderCountryCode
) {
List<TrustListDto> trustList = trustListMapper.trustListToTrustListDto(trustListService.getTrustList());

DgcMdc.put(MDC_PROP_DOWNLOAD_KEYS_COUNT, trustList.size());
DgcMdc.put(MDC_PROP_DOWNLOAD_KEYS_COUNTRY, downloaderCountryCode);

log.info(DOWNLOADED_TRUSTLIST_LOG_MESSAGE);

return ResponseEntity.ok(trustList);
}

/**
Expand Down Expand Up @@ -123,14 +142,22 @@ public ResponseEntity<List<TrustListDto>> downloadTrustList() {
))
})
public ResponseEntity<List<TrustListDto>> downloadTrustListFilteredByType(
@Valid @PathVariable("type") CertificateTypeDto type
@Valid @PathVariable("type") CertificateTypeDto type,
@RequestAttribute(CertificateAuthenticationFilter.REQUEST_PROP_COUNTRY) String downloaderCountryCode
) {

TrustListType mappedType = trustListMapper.certificateTypeDtoToTrustListType(type);

return ResponseEntity.ok(
trustListMapper.trustListToTrustListDto(
trustListService.getTrustList(mappedType)));
List<TrustListDto> trustList = trustListMapper.trustListToTrustListDto(
trustListService.getTrustList(mappedType));

DgcMdc.put(MDC_PROP_DOWNLOAD_KEYS_COUNT, trustList.size());
DgcMdc.put(MDC_PROP_DOWNLOAD_KEYS_TYPE, type.name());
DgcMdc.put(MDC_PROP_DOWNLOAD_KEYS_COUNTRY, downloaderCountryCode);

log.info(DOWNLOADED_TRUSTLIST_LOG_MESSAGE);

return ResponseEntity.ok(trustList);
}

/**
Expand Down Expand Up @@ -179,15 +206,23 @@ public ResponseEntity<List<TrustListDto>> downloadTrustListFilteredByType(
})
public ResponseEntity<List<TrustListDto>> downloadTrustListFilteredByCountryAndType(
@Valid @PathVariable("type") CertificateTypeDto type,
@Valid @Size(max = 2, min = 2) @PathVariable("country") String countryCode
@Valid @Size(max = 2, min = 2) @PathVariable("country") String countryCode,
@RequestAttribute(CertificateAuthenticationFilter.REQUEST_PROP_COUNTRY) String downloaderCountryCode
) {

TrustListType mappedType = trustListMapper.certificateTypeDtoToTrustListType(type);
countryCode = countryCode.toUpperCase(Locale.ROOT);

return ResponseEntity.ok(
trustListMapper.trustListToTrustListDto(
trustListService.getTrustList(mappedType, countryCode)));
List<TrustListDto> trustList = trustListMapper.trustListToTrustListDto(
trustListService.getTrustList(mappedType, countryCode));

DgcMdc.put(MDC_PROP_DOWNLOAD_KEYS_COUNT, trustList.size());
DgcMdc.put(MDC_PROP_DOWNLOAD_KEYS_TYPE, type.name());
DgcMdc.put(MDC_PROP_DOWNLOAD_KEYS_COUNTRY, downloaderCountryCode);

log.info(DOWNLOADED_TRUSTLIST_LOG_MESSAGE);

return ResponseEntity.ok(trustList);
}

}

0 comments on commit dad5234

Please sign in to comment.