Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #31 from admin-ch/develop
Browse files Browse the repository at this point in the history
Log the verification of a code before deleting it
  • Loading branch information
fabe2913 authored Sep 29, 2020
2 parents 9a99da0 + 30df7af commit 066102a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>ch.admin.bag.covidcode</groupId>
<artifactId>ha-authcode-generation-service</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.5-SNAPSHOT</version>
<name>ha-authcode-generation-service</name>
<description>Service for generating an authorization code for the proximity tracing app</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
import ch.admin.bag.covidcode.authcodegeneration.domain.AuthorizationCodeRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

import static net.logstash.logback.argument.StructuredArguments.kv;

@Slf4j
@RequiredArgsConstructor
@Service
@ConditionalOnProperty(value="CF_INSTANCE_INDEX", havingValue = "0")
public class AuthCodeDeletionService {

private final AuthorizationCodeRepository authorizationCodeRepository;
Expand All @@ -28,6 +33,11 @@ public void deleteOldAuthCode() {
log.info("Found {} AuthCodes to delete.", expiredAuthCodes.size());

expiredAuthCodes.forEach(ac -> {

if (ac.getCallCount() > 0) {
log.info("AuthorizationCode verified: '{}', '{}', '{}', '{}', '{}'", kv("id", ac.getId()), kv("callCount", ac.getCallCount()), kv("creationDateTime", ac.getCreationDateTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)), kv("onsetDate",ac.getOnsetDate()), kv("originalOnsetDate",ac.getOriginalOnsetDate()));
}

log.info("Deleting code '{}' with expiryDate '{}'.", ac.getCode(), ac.getExpiryDate());
authorizationCodeRepository.delete(ac);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public AuthorizationCodeVerifyResponseDto verify(String code, String fake) {
}

existingCode.incrementCallCount();
log.info("AuthorizationCode verified: '{}', '{}', '{}', '{}', '{}'", kv("id", existingCode.getId()), kv("callCount", existingCode.getCallCount()), kv("creationDateTime", existingCode.getCreationDateTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)), kv("onsetDate",existingCode.getOnsetDate()), kv("originalOnsetDate",existingCode.getOriginalOnsetDate()));
log.debug("AuthorizationCode verified: '{}', '{}', '{}', '{}', '{}'", kv("id", existingCode.getId()), kv("callCount", existingCode.getCallCount()), kv("creationDateTime", existingCode.getCreationDateTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)), kv("onsetDate",existingCode.getOnsetDate()), kv("originalOnsetDate",existingCode.getOriginalOnsetDate()));
return new AuthorizationCodeVerifyResponseDto(tokenProvider.createToken(existingCode.getOnsetDate().format(DATE_FORMATTER), fake));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"spring.datasource.driver-class-name=org.h2.Driver",
"spring.datasource.url=jdbc:h2:~/test;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE",
"spring.datasource.username=sa",
"spring.datasource.password=sa"
"spring.datasource.password=sa",
"CF_INSTANCE_INDEX=0"
})
@ActiveProfiles("local")
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
Expand Down

0 comments on commit 066102a

Please sign in to comment.