Skip to content

Commit

Permalink
Merge pull request #84 from imranalisyed506/im-n18-changes2
Browse files Browse the repository at this point in the history
Update cfn template with node18 code changes and bump al-aws-collector-js version
  • Loading branch information
imranalisyed506 authored Sep 21, 2023
2 parents d58e6a8 + a988eb1 commit 2b6a0e1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 37 deletions.
70 changes: 36 additions & 34 deletions cfn/guardduty.template
Original file line number Diff line number Diff line change
Expand Up @@ -328,43 +328,45 @@
},
"Code":{
"ZipFile": {
"Fn::Join": [
"Fn::Join": [
"",
[
"const AWS = require('aws-sdk');\n",
"const response = require('./cfn-response');\n",
"\n",
"\n",
"function encrypt(event, context) {\n",
" const params = {\n",
" KeyId: event.ResourceProperties.KeyId,\n",
" Plaintext: event.ResourceProperties.Plaintext\n",
" };\n",
" const kms = new AWS.KMS();\n",
" kms.encrypt(params, function(err, data) {\n",
" if (err) {\n",
" console.log(err, err.stack); // an error occurred\n",
" return response.send(event, context, response.FAILED);\n",
" }\n",
" var base64 = Buffer.from(data.CiphertextBlob).toString('base64');\n",
" var responseData = {\n",
" EncryptedText : base64\n",
" };\n",
" return response.send(event, context, response.SUCCESS, responseData);\n",
" });\n",
"}\n",
"\n",
"\n",
"exports.handler = (event, context, callback) => {\n",
" if (event.ResourceType == 'AWS::CloudFormation::CustomResource' &&\n",
" event.RequestType == 'Create') {\n",
" return encrypt(event, context);\n",
" }\n",
" return response.send(event, context, response.SUCCESS);\n",
"}"
]
"const { KMSClient, EncryptCommand } = require('@aws-sdk/client-kms');\n",
"const response = require('./cfn-response');\n",
"async function encrypt(event, context) {\n",
" const params = {\n",
" KeyId: event.ResourceProperties.KeyId,\n",
" Plaintext: new TextEncoder().encode(event.ResourceProperties.Plaintext)\n",
" };\n",
" const kms = new KMSClient({});\n",
" try{\n",
" const encryptParams = new EncryptCommand(params);\n",
" const data = await kms.send(encryptParams);\n",
" if(data.CiphertextBlob){\n",
" var base64 = Buffer.from(data.CiphertextBlob).toString('base64');\n",
" var responseData = {\n",
" EncryptedText : base64\n",
" };\n",
" return response.send(event, context, response.SUCCESS, responseData);\n",
" } else {\n",
" return response.send(event, context, response.FAILED);\n",
" }\n",
" }catch(err){\n",
" console.log(err, err.stack); // an error occurred\n",
" return response.send(event, context, response.FAILED);\n",
" }\n",
"}\n",
"exports.handler = async(event, context, callback) => {\n",
" if (event.ResourceType == 'AWS::CloudFormation::CustomResource' &&\n",
" (event.RequestType == 'Create' || event.RequestType == 'Update')) {\n",
" await encrypt(event, context);\n",
" } else {\n",
" return response.send(event, context, response.SUCCESS);\n",
" }\n",
"}"
]
]
}
}
},
"Handler":"index.handler",
"Runtime":"nodejs18.x",
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "al-cwe-collector",
"version": "1.3.20",
"version": "1.3.21",
"license": "MIT",
"description": "Alert Logic CloudWatch Events Collector",
"repository": {
Expand All @@ -21,7 +21,6 @@
}
],
"devDependencies": {
"aws-sdk": "^2.1454.0",
"aws-sdk-mock": "^5.8.0",
"clone": "^2.1.2",
"dotenv": "^16.3.1",
Expand All @@ -33,9 +32,10 @@
"sinon": "^15.2.0"
},
"dependencies": {
"@alertlogic/al-aws-collector-js": "4.1.21",
"@alertlogic/al-aws-collector-js": "4.1.22",
"@alertlogic/al-collector-js": "3.0.10",
"async": "^3.2.4",
"aws-sdk": "^2.1454.0",
"cfn-response": "^1.0.1",
"debug": "^4.3.4",
"moment": "^2.29.4"
Expand Down

0 comments on commit 2b6a0e1

Please sign in to comment.