Skip to content

Commit

Permalink
24 fixing lint warnings in aws.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-snodgrass committed Dec 21, 2023
1 parent 4b2a77d commit 723be2d
Showing 1 changed file with 61 additions and 44 deletions.
105 changes: 61 additions & 44 deletions api/src/lib/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import {
PutObjectCommandInput,
S3Client,
} from '@aws-sdk/client-s3'
import {ReceiveMessageCommand, SendMessageCommand, SQSClient} from '@aws-sdk/client-sqs'
import {getSignedUrl as awsGetSignedUrl} from '@aws-sdk/s3-request-presigner'
import {
ReceiveMessageCommand,
SendMessageCommand,
SQSClient,
} from '@aws-sdk/client-sqs'
import { getSignedUrl as awsGetSignedUrl } from '@aws-sdk/s3-request-presigner'

function getS3Client() {
let s3: S3Client;
let s3: S3Client
if (process.env.LOCALSTACK_HOSTNAME) {
/*
1. Make sure the local environment has awslocal installed.
Expand All @@ -18,72 +22,89 @@ function getS3Client() {
- awslocal s3api list-buckets
- awslocal s3api list-objects --bucket arpa-audit-reports
*/
console.log('------------ USING LOCALSTACK ------------');
const endpoint = `http://${process.env.LOCALSTACK_HOSTNAME}:${process.env.EDGE_PORT || 4566}`;
console.log(`endpoint: ${endpoint}`);
console.log('------------ USING LOCALSTACK ------------')
const endpoint = `http://${process.env.LOCALSTACK_HOSTNAME}:${
process.env.EDGE_PORT || 4566
}`
console.log(`endpoint: ${endpoint}`)
s3 = new S3Client({
endpoint,
forcePathStyle: true,
region: process.env.AWS_DEFAULT_REGION,
});
})
} else {
s3 = new S3Client();
s3 = new S3Client()
}
return s3;
return s3
}

async function sendPutObjectToS3Bucket(bucketName: string, key: string, body: any) {
const s3 = getS3Client();
const uploadParams : PutObjectCommandInput = {
export async function sendPutObjectToS3Bucket(
bucketName: string,
key: string,
body: any

Check warning on line 44 in api/src/lib/aws.ts

View workflow job for this annotation

GitHub Actions / qa / Lint JavaScript

Unexpected any. Specify a different type
) {
const s3 = getS3Client()
const uploadParams: PutObjectCommandInput = {
Bucket: bucketName,
Key: key,
Body: body,
ServerSideEncryption: 'AES256',
};
await s3.send(new PutObjectCommand(uploadParams));
}
await s3.send(new PutObjectCommand(uploadParams))
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function sendHeadObjectToS3Bucket(bucketName: string, key: string) {
const s3 = getS3Client();
const uploadParams : PutObjectCommandInput = {
const s3 = getS3Client()
const uploadParams: PutObjectCommandInput = {
Bucket: bucketName,
Key: key,
};
await s3.send(new PutObjectCommand(uploadParams));
}
await s3.send(new PutObjectCommand(uploadParams))
}

/**
* This function is a wrapper around the getSignedUrl function from the @aws-sdk/s3-request-presigner package.
* Exists to organize the imports and to make it easier to mock in tests.
*/

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function getSignedUrl(bucketName: string, key: string) {
const s3 = getS3Client();
const baseParams = { Bucket: bucketName, Key: key };
return awsGetSignedUrl(s3, new GetObjectCommand(baseParams), { expiresIn: 60 });
const s3 = getS3Client()
const baseParams = { Bucket: bucketName, Key: key }
return awsGetSignedUrl(s3, new GetObjectCommand(baseParams), {
expiresIn: 60,
})
}

function getSQSClient() {
let sqs: SQSClient;
let sqs: SQSClient
if (process.env.LOCALSTACK_HOSTNAME) {
console.log('------------ USING LOCALSTACK FOR SQS ------------');
const endpoint = `http://${process.env.LOCALSTACK_HOSTNAME}:${process.env.EDGE_PORT || 4566}`;
sqs = new SQSClient({ endpoint, region: process.env.AWS_DEFAULT_REGION });
console.log('------------ USING LOCALSTACK FOR SQS ------------')
const endpoint = `http://${process.env.LOCALSTACK_HOSTNAME}:${
process.env.EDGE_PORT || 4566
}`
sqs = new SQSClient({ endpoint, region: process.env.AWS_DEFAULT_REGION })
} else {
sqs = new SQSClient();
sqs = new SQSClient()
}
return sqs;
return sqs
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function sendSqsMessage(queueUrl: string, messageBody: any) {

Check warning on line 95 in api/src/lib/aws.ts

View workflow job for this annotation

GitHub Actions / qa / Lint JavaScript

Unexpected any. Specify a different type
const sqs = getSQSClient();
await sqs.send(new SendMessageCommand({
QueueUrl: queueUrl,
MessageBody: JSON.stringify(messageBody),
}));
const sqs = getSQSClient()
await sqs.send(
new SendMessageCommand({
QueueUrl: queueUrl,
MessageBody: JSON.stringify(messageBody),
})
)
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function receiveSqsMessage(queueUrl: string) {
const sqs = getSQSClient();
const sqs = getSQSClient()
// const receiveResp = await sqs.send(new ReceiveMessageCommand({
// QueueUrl: process.env.TASK_QUEUE_URL, WaitTimeSeconds: 20, MaxNumberOfMessages: 1,
// }));
Expand All @@ -92,15 +113,11 @@ async function receiveSqsMessage(queueUrl: string) {
// QueueUrl: process.env.TASK_QUEUE_URL, WaitTimeSeconds: 20, MaxNumberOfMessages: 1,
// }));

await sqs.send(new ReceiveMessageCommand({
QueueUrl: queueUrl, WaitTimeSeconds: 20, MaxNumberOfMessages: 1,
}));
await sqs.send(
new ReceiveMessageCommand({
QueueUrl: queueUrl,
WaitTimeSeconds: 20,
MaxNumberOfMessages: 1,
})
)
}

export default {
sendPutObjectToS3Bucket,
sendHeadObjectToS3Bucket,
getSignedUrl,
sendSqsMessage,
receiveSqsMessage,
};

0 comments on commit 723be2d

Please sign in to comment.