Skip to content

Commit

Permalink
Merge pull request #2441 from objectcomputing/bugfix-remove-aeskey-in…
Browse files Browse the repository at this point in the history
…jection-in-service

Remove aesKey injection in Service and resolve in Repository interface instead
  • Loading branch information
mkimberlin authored May 28, 2024
2 parents 262ab8b + 78097e3 commit 40d8f52
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.objectcomputing.checkins.services.memberprofile.csvreport;

import io.micronaut.core.annotation.NonNull;
import io.micronaut.data.annotation.ParameterExpression;
import io.micronaut.data.annotation.Query;
import io.micronaut.data.jdbc.annotation.JdbcRepository;
import io.micronaut.data.model.query.builder.sql.Dialect;
Expand Down Expand Up @@ -31,6 +32,6 @@ public interface MemberProfileReportRepository extends CrudRepository<MemberProf
"PGP_SYM_DECRYPT(cast(supervisoremail as bytea), :aesKey) as supervisorEmail " +
"FROM member_profile_record " +
"WHERE id IN (:memberIds)")
List<MemberProfileRecord> findAllByMemberIds(List<String> memberIds, String aesKey);

@ParameterExpression(name = "aesKey", expression = "#{ env['aes.key'] }")
List<MemberProfileRecord> findAllByMemberIds(List<String> memberIds);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.objectcomputing.checkins.services.memberprofile.csvreport;

import io.micronaut.context.annotation.Value;
import jakarta.inject.Singleton;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
Expand All @@ -20,9 +19,6 @@ public class MemberProfileReportServicesImpl implements MemberProfileReportServi
private final MemberProfileReportRepository memberProfileReportRepository;
private final MemberProfileFileProvider memberProfileFileProvider;

@Value("${aes.key}")
private String key;

public MemberProfileReportServicesImpl(MemberProfileReportRepository memberProfileReportRepository,
MemberProfileFileProvider memberProfileFileProvider) {
this.memberProfileReportRepository = memberProfileReportRepository;
Expand All @@ -37,7 +33,7 @@ public File generateFile(MemberProfileReportQueryDTO queryDTO) {
memberRecords.addAll(allRecords);
} else {
List<String> memberIds = queryDTO.getMemberIds().stream().map(UUID::toString).collect(Collectors.toList());
List<MemberProfileRecord> filteredRecords = memberProfileReportRepository.findAllByMemberIds(memberIds, key);
List<MemberProfileRecord> filteredRecords = memberProfileReportRepository.findAllByMemberIds(memberIds);
memberRecords.addAll(filteredRecords);
}
return createCsv(memberRecords);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public abstract class TestContainersSuite implements RepositoryFixture, TestProp
@Inject
private Flyway flyway;

@Value("${aes.key}")
protected String key;

public TestContainersSuite() {}

private void deleteAllEntities() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void testGetSelectedMemberProfileRecords() {
List<String> selectedMemberIds = new ArrayList<>();
selectedMemberIds.add(member2.getId().toString());
selectedMemberIds.add(member4.getId().toString());
List<MemberProfileRecord> records = getMemberProfileReportRepository().findAllByMemberIds(selectedMemberIds, key);
List<MemberProfileRecord> records = getMemberProfileReportRepository().findAllByMemberIds(selectedMemberIds);

assertEquals(2, records.size());
assertMemberProfileMatchesRecord(member4, records.get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void testGenerateFileWithSelectedMemberProfiles() throws IOException {
List<MemberProfileRecord> allRecords = createSampleRecords();
MemberProfileRecord expectedRecord = allRecords.get(1);
when(memberProfileReportRepository
.findAllByMemberIds(eq(List.of(expectedRecord.getId().toString())), any()))
.findAllByMemberIds(eq(List.of(expectedRecord.getId().toString()))))
.thenReturn(List.of(expectedRecord));
File tmpFile = File.createTempFile("member",".csv");
tmpFile.deleteOnExit();
Expand All @@ -98,7 +98,7 @@ void testGenerateFileNotGenerated() throws IOException {
List<MemberProfileRecord> allRecords = createSampleRecords();
MemberProfileRecord expectedRecord = allRecords.get(1);
when(memberProfileReportRepository
.findAllByMemberIds(eq(List.of(expectedRecord.getId().toString())), any()))
.findAllByMemberIds(eq(List.of(expectedRecord.getId().toString()))))
.thenReturn(List.of(expectedRecord));

when(memberProfileFileProvider.provideFile()).thenThrow(new RuntimeException());
Expand Down

0 comments on commit 40d8f52

Please sign in to comment.