Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
smirnovaae committed Mar 11, 2024
1 parent 1b9cd48 commit 74f230c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class OptOutConstants {
public static final String ENDPOINT = "https://s3.amazonaws.com";
public static final String TEST_ENDPOINT = "http://127.0.0.1:8001";
public static final String TEST_FILE_NAME = "optOutDummy.txt";
public static final String TEST_BFD_BUCKET_NAME = "ab2d-opt-out-temp-349849222861-us-east-1";
public static final String TEST_BFD_BUCKET_NAME = "bfd-test-eft";
public static final Region S3_REGION = Region.US_EAST_1;
public static final String HEADER_RESP = "HDR_BENEDATARSP";
public static final String TRAILER_RESP = "TLR_BENEDATARSP";
Expand Down
30 changes: 30 additions & 0 deletions optout/src/main/java/gov/cms/ab2d/optout/OptOutS3.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,41 @@ public OptOutS3(S3Client s3Client, String fileName, String bfdBucket, LambdaLogg
this.logger = logger;
}

public void doesBucketExist(){
try {
logger.log("Bucket name: " + bfdBucket);
logger.log("File name: " + fileName);

HeadBucketRequest headBucketRequest = HeadBucketRequest.builder()
.bucket(bfdBucket).build();

s3Client.headBucket(headBucketRequest);
logger.log("Bucket exists");

} catch (SdkClientException ex) {
var errorMessage = "Unable to load credentials to connect S3 bucket";
logger.log(errorMessage);
throw new OptOutException(errorMessage, ex);
} catch (S3Exception ex) {
if (ex.statusCode() == 404) {

var errorMessage = "Object " + fileName + " does not exist. " + ex.getMessage();
logger.log(errorMessage);
throw new OptOutException(errorMessage, ex);
} else {
logger.log(ex.getMessage());
throw ex;
}
}

}

public BufferedReader openFileS3() {
try {
//Checking if object exists
logger.log("Buket name: " + bfdBucket);
logger.log("File name: " + fileName);

HeadObjectRequest headObjectRequest = HeadObjectRequest.builder()
.bucket(bfdBucket)
.key(fileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static void beforeAll() throws URISyntaxException, IOException {
}

@Test
void getTest() throws IOException, ParseException {
void getBucketAndFileNamesTest() throws IOException, ParseException {
JSONParser parser = new JSONParser();
JSONObject json = (JSONObject) parser.parse(getPayload());
var s3EventMessage = json.get("Message");
Expand Down
10 changes: 5 additions & 5 deletions optout/src/test/resources/sqsEvent.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"Type" : "Notification",
"MessageId" : "5da6e965-ca05-5123-8347-b72ad7893428",
"TopicArn" : "arn:aws:sns:us-east-1:577373831711:bfd-test-eft-inbound-received-s3-dpc",
"TopicArn" : "arn:aws:sns:test",
"Subject" : "Amazon S3 Notification",
"Message" : "{\"Records\":[{\"eventVersion\":\"2.1\",\"eventSource\":\"aws:s3\",\"awsRegion\":\"us-east-1\",\"eventTime\":\"2024-02-20T21:36:11.419Z\",\"eventName\":\"ObjectCreated:Put\",\"userIdentity\":{\"principalId\":\"AWS:AIDAYM3RJQIPTYMO35QPN\"},\"requestParameters\":{\"sourceIPAddress\":\"66.61.78.110\"},\"responseElements\":{\"x-amz-request-id\":\"JM2GMJJNSSEH9PKY\",\"x-amz-id-2\":\"gO4Fl4AxgEJ8LYteQ6LW4gHNtmB9+CcRDOnE20HW9ZumAQTsP+HG1DKDYLxQa67VCG6XIyIfSsZOW8cOfPuOQAD3+7HfBs/3\"},\"s3\":{\"s3SchemaVersion\":\"1.0\",\"configurationId\":\"bfd-test-eft-inbound-received-s3-dpc\",\"bucket\":{\"name\":\"bfd-test-eft\",\"ownerIdentity\":{\"principalId\":\"A5VBSMJFI0FCE\"},\"arn\":\"arn:aws:s3:::bfd-test-eft\"},\"object\":{\"key\":\"bfdeft01/ab2d/in/optOutDummy.txt\",\"size\":12,\"eTag\":\"fdad692379d13b4c029804195d0a4aa5\",\"sequencer\":\"0065D51B4B4098E68C\"}}}]}",
"Message" : "{\"Records\":[{\"eventVersion\":\"2.1\",\"eventSource\":\"aws:s3\",\"awsRegion\":\"us-east-1\",\"eventTime\":\"2024-02-20T21:36:11.419Z\",\"eventName\":\"ObjectCreated:Put\",\"s3\":{\"s3SchemaVersion\":\"1.0\",\"configurationId\":\"bfd-test-eft-inbound-received-s3-dpc\",\"bucket\":{\"name\":\"bfd-test-eft\",\"arn\":\"arn:aws:s3:::bfd-test-eft\"},\"object\":{\"key\":\"bfdeft01/ab2d/in/optOutDummy.txt\",\"size\":12}}}]}",
"Timestamp" : "2024-02-20T21:36:12.405Z",
"SignatureVersion" : "1",
"Signature" : "geHsbUYOSZ6HZLDo0cVnMsmbrsncnGNubwLHZfcSmAtIpm4ciCeR3tkoZeZhWySXFW8N1a9URlgo1WIy0Cf08yspRG0HCtdYJCVv0hJtxiHpS2M3qyDJY0o3hsX4Uk29PcczjUAu89/j7niPRID/zh0LQcUWkA9UPaHDrxAJR69WDV5EvPLOBl4B2gNA/zUGgIlQL7jXhYiGnvRhldNUD2ZibY+wSrlYEs/b+U/dJsid1bvzT30Dw6nwpEB6Xqpw8KH6DX32E2/XDvKOqELd5aAv1P/+uLMhohzD/DSmRd31pZUECF99/GLdT2b41/M1L1KQm31r7uF9Lvy4DrG8CQ==",
"SigningCertURL" : "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-60eadc530605d63b8e62a523676ef735.pem",
"UnsubscribeURL" : "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:577373831711:bfd-test-eft-inbound-received-s3-dpc:f14e07ab-36d0-48ec-bdcd-41b0be370fc8"
"Signature" : "TestSignature",
"SigningCertURL" : "TestSigningCertURL",
"UnsubscribeURL" : "TestUnsubscribeURL"
}

0 comments on commit 74f230c

Please sign in to comment.