Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS inspector vulnerabilities and ddb warning fixes by making a single static DDB client #380

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alertlogic/paws-collector",
"version": "2.2.5",
"version": "2.2.6",
"license": "MIT",
"description": "Alert Logic AWS based API Poll Log Collector Library",
"repository": {
Expand Down Expand Up @@ -34,12 +34,12 @@
"mocha": "^10.4.0",
"nyc": "^17.0.0",
"rewire": "^7.0.0",
"sinon": "^18.0.0",
"sinon": "^19.0.2",
"yargs": "^17.7.2"
},
"dependencies": {
"@alertlogic/al-aws-collector-js": "4.1.26",
"@smithy/node-http-handler":"3.1.3",
"@alertlogic/al-aws-collector-js": "^4.1.28",
"@smithy/node-http-handler": "^3.2.4",
"async": "^3.2.5",
"datadog-lambda-js": "^9.112.0",
"debug": "^4.3.5",
Expand Down
16 changes: 7 additions & 9 deletions paws_collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ const nodeHttpHandler = new NodeHttpHandler({
httpsAgent: new https.Agent(agent)
});


const DDB_OPTIONS = {
maxAttempts: 10,
maxAttempts: 5,
requestHandler: nodeHttpHandler
}

const DDB = new DynamoDB(DDB_OPTIONS);

const DDB_DELETE_BATCH_OPTIONS = {
maxBatchSize: 25,
maxBatchSizeBytes: 16 * 1024 * 1024
Expand Down Expand Up @@ -373,8 +377,6 @@ class PawsCollector extends AlAwsCollector {
// there is a lot of logic here. not sur eif there is a better way of deduping. trying for an MVP
checkStateSqsMessage(stateSqsMsg, asyncCallback) {
const collector = this;
const DDB = new DynamoDB(DDB_OPTIONS);

const params = {
Key: {
"CollectorId": {S: collector._collectorId},
Expand Down Expand Up @@ -432,8 +434,6 @@ class PawsCollector extends AlAwsCollector {

updateStateDBEntry(stateSqsMsg, Status, asyncCallback) {
const collector = this;
const DDB = new DynamoDB(DDB_OPTIONS);

const updateParams = {
Key: {
CollectorId: {S: collector._collectorId},
Expand Down Expand Up @@ -941,7 +941,6 @@ class PawsCollector extends AlAwsCollector {
*/
removeDuplicatedItem(logs, paramName, asyncCallback) {
let collector = this;
const ddb = new DynamoDB(DDB_OPTIONS);
let uniqueLogs = [];
var promises = [];
let duplicateCount = 0;
Expand All @@ -958,7 +957,7 @@ class PawsCollector extends AlAwsCollector {
ConditionExpression: 'attribute_not_exists(Id)'
};
let promise = new Promise((resolve, reject) => {
ddb.putItem(params, (err, res) => {
DDB.putItem(params, (err, res) => {
if (err) {
if (err.name === 'ConditionalCheckFailedException') {
duplicateCount++;
Expand Down Expand Up @@ -1063,9 +1062,8 @@ class PawsCollector extends AlAwsCollector {
* @returns
*/
dDBBatchWriteItem(tableName, batch) {
const ddb = new DynamoDB(DDB_OPTIONS);
const batchParams = { RequestItems: { [tableName]: batch } };
return ddb.batchWriteItem(batchParams);
return DDB.batchWriteItem(batchParams);
}

/**
Expand Down
Loading