Skip to content

Commit

Permalink
Merge pull request #27 from transcom/Debug-And-Env-Changes
Browse files Browse the repository at this point in the history
ENV variable changes and snsForcePublish added
  • Loading branch information
TevinAdams authored Oct 4, 2024
2 parents efcdd6c + 08db475 commit d03a7df
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ require TRDM_LAMBDA_MILMOVE_KEYPAIR_KEY "See 'DISABLE_AWS_VAULT_WRAPPER=1 AWS_RE
require TRDM_LAMBDA_MILMOVE_KEYPAIR_ALIAS "See 'DISABLE_AWS_VAULT_WRAPPER=1 AWS_REGION=us-gov-west-1 aws-vault exec transcom-gov-dev -- chamber read trdm-lambda-dev trdm_lambda_milmove_keypair_alias'"
require TRDM_LAMBDA_MILMOVE_KEYPAIR_TYPE "See 'DISABLE_AWS_VAULT_WRAPPER=1 AWS_REGION=us-gov-west-1 aws-vault exec transcom-gov-dev -- chamber read trdm-lambda-dev trdm_lambda_milmove_keypair_type'"
require TRDM_LAMBDA_MILMOVE_KEYPAIR_FILEPATH "See 'DISABLE_AWS_VAULT_WRAPPER=1 AWS_REGION=us-gov-west-1 aws-vault exec transcom-gov-dev -- chamber read trdm-lambda-dev trdm_lambda_milmove_keypair_filepath'"
require SNS_TOPIC_ARN "See 'DISABLE_AWS_VAULT_WRAPPER=1 AWS_REGION=us-gov-west-1 aws-vault exec transcom-gov-dev -- chamber read trdm-lambda-dev sns_topic_arn'"
require TRDM_S3_BUCKET_NAME "See 'DISABLE_AWS_VAULT_WRAPPER=1 AWS_REGION=us-gov-west-1 aws-vault exec transcom-gov-dev -- chamber read trdm_s3_bucket_name'"
require TRDM_TRUSTSTORE_KEYSTORE "See 'DISABLE_AWS_VAULT_WRAPPER=1 AWS_REGION=us-gov-west-1 aws-vault exec transcom-gov-dev -- chamber read trdm_truststore_keystore'"
require SNS_FORCE_PUBLISH "See 'DISABLE_AWS_VAULT_WRAPPER=1 AWS_REGION=us-gov-west-1 aws-vault exec transcom-gov-dev -- chamber read sns_force_publish'"

##############################################
# Load Local Overrides and Check Environment #
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>com.milmove.trdmlambda</groupId>
<artifactId>trdm-lambda</artifactId>
<version>1.0.3.16</version>
<version>1.0.3.17</version>
<name>trdm java spring interface</name>
<description>Project for deploying a Java TRDM interfacer for TGET data.</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.milmove.trdmlambda.milmove.util.SecretFetcher;

import ch.qos.logback.classic.Logger;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import software.amazon.awssdk.core.ResponseInputStream;
Expand All @@ -21,17 +23,20 @@ public class S3Service {
private Logger logger = (Logger) LoggerFactory.getLogger(S3Service.class);

private S3Client s3Client;
private final String trdmBucketName = "transcom-gov-milmove-stg-lambda-trdm-soap-us-gov-west-1";
private final String trdmTruststoreKeyName = "trdm_lambda_milmove_truststore_base64.txt";
private String trdmBucketName;
private String trdmTruststoreKeyName;

public S3Service() throws URISyntaxException {
public S3Service(SecretFetcher secretFetcher) throws URISyntaxException {
logger.info("S3Service::S3Service - starting initialization of S3 Service");

this.s3Client = S3Client.builder()
.region(Region.US_GOV_WEST_1)
.credentialsProvider(DefaultCredentialsProvider.create())
.build();

this.trdmBucketName = secretFetcher.getSecret("trdm_s3_bucket_name");
this.trdmTruststoreKeyName = secretFetcher.getSecret("trdm_truststore_keystore");

logger.info("S3Service::S3Service - finished initialization of S3 Service");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.milmove.trdmlambda.milmove.util.SecretFetcher;

import ch.qos.logback.classic.Logger;
import jakarta.mail.MessagingException;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
Expand All @@ -19,10 +21,11 @@
public class SNSService {

private Logger logger = (Logger) LoggerFactory.getLogger(SNSService.class);
private final String engGovTopicARN = "arn:aws-us-gov:sns:us-gov-west-1:015932076428:eng-gov-notification";
private String snsTopicARN;

public SNSService() throws URISyntaxException {
public SNSService(SecretFetcher secretFetcher) throws URISyntaxException {
logger.info("starting initialization of SNS Service");
this.snsTopicARN = secretFetcher.getSecret("sns_topic_arn");
logger.info("finished initializing SNS Service");
}

Expand All @@ -49,7 +52,7 @@ public void sendMalformedData(ArrayList<String> sysIds, String msgType)
msg += sysIdsListed;

logger.info("sending malformed " + msgType + " SNS");
send(engGovTopicARN, msg);
send(snsTopicARN, msg);
logger.info("finished sending malformed " + msgType + " SNS");

}
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/milmove/trdmlambda/milmove/util/Trdm.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class Trdm {
private final TransportationAccountingCodeParser tacParser;
private final LineOfAccountingParser loaParser;
private final SNSService snsService;
private String snsForcePublish;

private final Connection rdsConnection;
private static final Set<String> allowedTableNames = Set.of("transportation_accounting_codes",
Expand All @@ -65,6 +66,7 @@ public Trdm(LastTableUpdateService lastTableUpdateService,
DatabaseService databaseService,
SNSService snsService,
TransportationAccountingCodeParser tacParser,
SecretFetcher secretFetcher,
LineOfAccountingParser loaParser) throws SQLException {

this.lastTableUpdateService = lastTableUpdateService;
Expand All @@ -73,6 +75,7 @@ public Trdm(LastTableUpdateService lastTableUpdateService,
this.snsService = snsService;
this.tacParser = tacParser;
this.loaParser = loaParser;
this.snsForcePublish = secretFetcher.getSecret("sns_force_publish");

rdsConnection = databaseService.getConnection();

Expand Down Expand Up @@ -209,7 +212,7 @@ public void UpdateTGETData(XMLGregorianCalendar ourLastUpdate, String trdmTable,
databaseService.insertTransportationAccountingCodes(createTacs);
logger.info("finished inserting TACs into DB");

if (tacParser.getMalformedTacList().size() > 0) {
if (tacParser.getMalformedTacList().size() > 0 || snsForcePublish == "true") {
try {
logger.info(
"malformed TAC data detected when parsing. Sending malformed TAC data SNS notification");
Expand Down Expand Up @@ -243,7 +246,7 @@ public void UpdateTGETData(XMLGregorianCalendar ourLastUpdate, String trdmTable,
databaseService.insertLinesOfAccounting(createLoas);
logger.info("finished inserting LOAs into DB");

if (loaParser.getMalformedLoaList().size() > 0) {
if (loaParser.getMalformedLoaList().size() > 0 || snsForcePublish == "true") {
try {
logger.info(
"malformed LOA data detected when parsing. Sending malformed LOA data SNS notification");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class TrdmTest {
@Mock
private TransportationAccountingCodeParser tacParser;
@Mock
private SecretFetcher secretFetcher;
@Mock
private LineOfAccountingParser loaParser;
private XMLGregorianCalendar ourLastUpdate;
private XMLGregorianCalendar trdmLastUpdate;
Expand Down

0 comments on commit d03a7df

Please sign in to comment.