Skip to content

Commit

Permalink
refactor to accommodate the jefferson parish apps
Browse files Browse the repository at this point in the history
  • Loading branch information
lkemperman-cfa committed Jul 11, 2024
1 parent 2b3223b commit 01fda9e
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 55 deletions.
23 changes: 0 additions & 23 deletions src/main/java/org/ladocuploader/app/cli/PGPEceEncryptorImpl.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.ladocuploader.app.cli;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Slf4j
@Component("eceJeffersonPgpEncryptor")
@Profile({"production", "staging"})
public class PGPEceJeffersonEncryptorImpl extends BasePGPEncrpytorImpl {

public PGPEceJeffersonEncryptorImpl(@Value("${pgp.ece.jefferson.sigkey-password}") String sigkeyPassword,
@Value("${pgp.ece.jefferson.seckey-file-path}") String seckeyFilePath,
@Value("${pgp.ece.jefferson.pubkey-file-path}") String pubkeyFilePath,
@Value("${pgp.ece.jefferson.bucket-name}") String bucketName,
@Value("${form-flow.aws.access_key}") String accessKey,
@Value("${form-flow.aws.secret_key}") String secretKey,
@Value("${form-flow.aws.region}") String region) {
super(sigkeyPassword, seckeyFilePath, pubkeyFilePath, bucketName, accessKey, secretKey, region);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.ladocuploader.app.cli;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Slf4j
@Component("eceOrleansPgpEncryptor")
@Profile({"production", "staging"})
public class PGPEceOrleansEncryptorImpl extends BasePGPEncrpytorImpl {

public PGPEceOrleansEncryptorImpl(@Value("${pgp.ece.orleans.sigkey-password}") String sigkeyPassword,
@Value("${pgp.ece.orleans.seckey-file-path}") String seckeyFilePath,
@Value("${pgp.ece.orleans.pubkey-file-path}") String pubkeyFilePath,
@Value("${pgp.ece.orleans.bucket-name}") String bucketName,
@Value("${form-flow.aws.access_key}") String accessKey,
@Value("${form-flow.aws.secret_key}") String secretKey,
@Value("${form-flow.aws.region}") String region) {
super(sigkeyPassword, seckeyFilePath, pubkeyFilePath, bucketName, accessKey, secretKey, region);

}
}
20 changes: 3 additions & 17 deletions src/main/java/org/ladocuploader/app/cli/TransmitterCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,16 @@ public class TransmitterCommands {

private final String successfulSubmissionKey = "success";

private final List<TransmissionType> transmissionTypes = List.of(TransmissionType.ECE, TransmissionType.WIC);
private final List<TransmissionType> transmissionTypes = List.of(TransmissionType.ECE_ORLEANS, TransmissionType.ECE_JEFFERSON, TransmissionType.WIC);

private final long TWO_HOURS = 2L;

private final PGPEncryptor wicPgpEncryptor;

private final PGPEncryptor ecePgpEncryptor;

public TransmitterCommands(TransmissionRepository transmissionRepository,
SftpClient sftpClient, CsvService csvService, CloudFileRepository cloudFileRepository, PGPEncryptor wicPgpEncryptor, PGPEncryptor ecePgpEncryptor) {
this.transmissionRepository = transmissionRepository;
this.sftpClient = sftpClient;
this.csvService = csvService;
this.fileRepository = cloudFileRepository;
this.wicPgpEncryptor = wicPgpEncryptor;
this.ecePgpEncryptor = ecePgpEncryptor;
}

@Scheduled(cron="${transmissions.wic-ece-transmission-schedule}")
Expand Down Expand Up @@ -133,16 +127,8 @@ private void transmitBatch(List<Submission> submissions, TransmissionType transm
String uploadLocation = csvPackageType.getUploadLocation();
if (csvPackageType.getEncryptPackage()){
log.info("Encrypting data package");
byte [] data = new byte[]{};
if (csvPackageType == CsvPackageType.WIC_PACKAGE) {
log.info("Encrypting WIC file from memory");
data = wicPgpEncryptor.signAndEncryptPayload(fileName);
log.info("Finished encrypting WIC file");
} else if (csvPackageType == CsvPackageType.ECE_PACKAGE ){
log.info("Encrypting ECE zip file from memory");
data = ecePgpEncryptor.signAndEncryptPayload(fileName);
log.info("Finished encrypting ECE zip file");
}
PGPEncryptor encryptor = csvPackageType.getPgpEncryptor();
byte [] data = encryptor.signAndEncryptPayload(fileName);
log.info("Uploading encrypted file");
sftpClient.uploadFile(fileName, uploadLocation, data);
log.info("Finished uploading encrypted file");
Expand Down
47 changes: 37 additions & 10 deletions src/main/java/org/ladocuploader/app/csv/enums/CsvPackageType.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
package org.ladocuploader.app.csv.enums;

import lombok.Getter;

import static org.ladocuploader.app.csv.enums.CsvType.ECE_APPLICATION;
import static org.ladocuploader.app.csv.enums.CsvType.PARENT_GUARDIAN;
import static org.ladocuploader.app.csv.enums.CsvType.RELATIONSHIP;
import static org.ladocuploader.app.csv.enums.CsvType.STUDENT;
import static org.ladocuploader.app.csv.enums.CsvType.WIC_APPLICATION;
import org.ladocuploader.app.cli.PGPEncryptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.List;

import static org.ladocuploader.app.csv.enums.CsvType.*;

public enum CsvPackageType {
ECE_PACKAGE (

ECE_ORLEANS_PACKAGE (
List.of(PARENT_GUARDIAN, STUDENT, RELATIONSHIP, ECE_APPLICATION),
"nola-ps",
false,
true,
true
),
),

ECE_JEFFERSON_PACKAGE (
List.of(PARENT_GUARDIAN, STUDENT, RELATIONSHIP, ECE_APPLICATION),
"jefferson-apps",
false,
true,
true),
WIC_PACKAGE (
List.of(WIC_APPLICATION),
"dcfs",
false,
true,
false
);
false);

@Getter
private final List<CsvType> csvTypeList;
Expand All @@ -40,6 +47,26 @@ public enum CsvPackageType {

@Getter
private final Boolean createZipArchive;
@Getter
private PGPEncryptor pgpEncryptor;

@Component
public static class MyEnumInjector {
@Autowired
public MyEnumInjector(
@Qualifier("wicEncryptor") PGPEncryptor wicEncryptor,
@Qualifier("eceOrleansPgpEncryptor") PGPEncryptor eceOrleansPgpEncryptor,
@Qualifier("eceJeffersonPgpEncryptor") PGPEncryptor eceJeffersonPgpEncryptor
) {
CsvPackageType.WIC_PACKAGE.setEncryptionService(wicEncryptor);
CsvPackageType.ECE_JEFFERSON_PACKAGE.setEncryptionService(eceJeffersonPgpEncryptor);
CsvPackageType.ECE_ORLEANS_PACKAGE.setEncryptionService(eceOrleansPgpEncryptor);
}
}

private void setEncryptionService(PGPEncryptor pgpEncryptor) {
this.pgpEncryptor = pgpEncryptor;
}

CsvPackageType(List<CsvType> csvTypeList, String uploadLocation, Boolean includeDocumentation, Boolean encryptPackage,
Boolean createZipArchive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

public enum TransmissionType {
SNAP(null),
ECE(CsvPackageType.ECE_PACKAGE),
ECE_ORLEANS(CsvPackageType.ECE_ORLEANS_PACKAGE),
ECE_JEFFERSON(CsvPackageType.ECE_JEFFERSON_PACKAGE),
WIC(CsvPackageType.WIC_PACKAGE);

private final CsvPackageType packageType;
Expand Down
14 changes: 10 additions & 4 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,16 @@ pgp:
sigkey-password: ${WIC_PGP_SIGKEY_PASSWORD}
bucket-name: ${WIC_PGP_KEYS_DIR}
ece:
seckey-file-path: ${ECE_PGP_SECKEY_FILE_PATH}
pubkey-file-path: ${ECE_PGP_PUBKEY_FILE_PATH}
sigkey-password: ${ECE_PGP_SIGKEY_PASSWORD}
bucket-name: ${ECE_PGP_KEYS_DIR}
jefferson:
seckey-file-path: ${ECE_PGP_SECKEY_FILE_PATH}
pubkey-file-path: ${ECE_PGP_PUBKEY_FILE_PATH}
sigkey-password: ${ECE_PGP_SIGKEY_PASSWORD}
bucket-name: ${ECE_PGP_KEYS_DIR}
orleans:
seckey-file-path: ${ECE_PGP_SECKEY_FILE_PATH}
pubkey-file-path: ${ECE_PGP_PUBKEY_FILE_PATH}
sigkey-password: ${ECE_PGP_SIGKEY_PASSWORD}
bucket-name: ${ECE_PGP_KEYS_DIR}
sentry:
dsn: ${SENTRY_DSN}
traces-sample-rate: 0.6
Expand Down

0 comments on commit 01fda9e

Please sign in to comment.