-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into 2209-footer-cutting-off-export-users-page
- Loading branch information
Showing
13 changed files
with
422 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Handler, SQSRecord } from 'aws-lambda'; | ||
import * as AWS from 'aws-sdk'; | ||
|
||
const ecs = new AWS.ECS(); | ||
const sqs = new AWS.SQS(); | ||
|
||
export const handler: Handler = async (event) => { | ||
try { | ||
// Get the SQS record and message body | ||
const sqsRecord: SQSRecord = event.Records[0]; | ||
const body: string = sqsRecord.body; | ||
|
||
console.log(body); | ||
|
||
let commandOptions; | ||
if (body === 'SHODAN') { | ||
commandOptions = './worker/shodan.sh'; | ||
} else { | ||
commandOptions = body; | ||
} | ||
// Run command in queue message in Fargate | ||
const params: AWS.ECS.RunTaskRequest = { | ||
cluster: process.env.FARGATE_CLUSTER_NAME!, | ||
taskDefinition: process.env.FARGATE_TASK_DEFINITION_NAME!, | ||
launchType: 'FARGATE', | ||
networkConfiguration: { | ||
awsvpcConfiguration: { | ||
assignPublicIp: 'ENABLED', | ||
securityGroups: [process.env.FARGATE_SG_ID!], | ||
subnets: [process.env.FARGATE_SUBNET_ID!] | ||
} | ||
}, | ||
platformVersion: '1.4.0', | ||
overrides: { | ||
containerOverrides: [ | ||
{ | ||
name: 'main', // from task definition | ||
command: [commandOptions] // Pass the command options as an array | ||
} | ||
] | ||
} | ||
}; | ||
const data = await ecs.runTask(params).promise(); | ||
console.log('Fargate task started:', data); | ||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify('Fargate task started and message sent to SQS queue') | ||
}; | ||
} catch (error) { | ||
console.error('Error starting Fargate task:', error); | ||
return { | ||
statusCode: 500, | ||
body: JSON.stringify('Error starting Fargate task') | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { handler } from '../scanExecution'; | ||
import { SQSRecord } from 'aws-lambda'; | ||
|
||
// Mock the AWS SDK methods using aws-sdk-mock | ||
jest.mock('aws-sdk', () => { | ||
return { | ||
ECS: jest.fn(() => ({ | ||
runTask: jest.fn().mockReturnThis(), | ||
promise: jest.fn() | ||
})), | ||
SQS: jest.fn(() => ({ | ||
sendMessage: jest.fn().mockReturnThis(), | ||
promise: jest.fn() | ||
})) | ||
}; | ||
}); | ||
|
||
describe('Scan Execution', () => { | ||
process.env.SQS_QUEUE_URL = 'YOUR_SQS_QUEUE_URL'; | ||
it('should handle the event', async () => { | ||
const event = { | ||
Records: [ | ||
{ | ||
body: 'test command', | ||
eventSourceARN: 'SQSQueueARN' | ||
} as SQSRecord | ||
] | ||
}; | ||
|
||
const result = await handler(event, {} as any, () => void 0); | ||
|
||
// Add your assertions here | ||
expect(result.statusCode).toEqual(200); | ||
expect(result.body).toContain( | ||
'Fargate task started and message sent to SQS queue' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
cd /app/pe-reports | ||
|
||
echo "Starting Shodan" | ||
|
||
pe-source shodan --orgs=DHS --soc_med_included | ||
|
||
echo "Done" |
Oops, something went wrong.