diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-01 15:22:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-01 15:22:06 +0000 |
commit | 2ccb5c91c82c780c905ee77da144f17825610487 (patch) | |
tree | 92fd3f6a2638474bc0725714a31da365fd80a301 /scripts | |
parent | fbc7e1f503da80d993b970a74637a1edf53f7ab6 (diff) | |
download | gitlab-ce-2ccb5c91c82c780c905ee77da144f17825610487.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/ingest-reports-to-siem | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/scripts/ingest-reports-to-siem b/scripts/ingest-reports-to-siem new file mode 100755 index 00000000000..5f5397fcd72 --- /dev/null +++ b/scripts/ingest-reports-to-siem @@ -0,0 +1,38 @@ +#!/usr/bin/env node + +const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3') +const { fromIni } = require('@aws-sdk/credential-provider-ini') +const path = require('path') +const fs = require('fs') +const crypto = require('crypto') + +function getMD5HashFromFile(data) { + const hash = crypto.createHash('md5').update(data).digest('base64') + return hash +} + +(async function () { + const s3Client = new S3Client({ + region: 'us-east-2', + credentials: fromIni({ profile: 'gl-logs-for-panther' }), + }) + try { + const file = 'gl-dependency-scanning-report.json' + const data = fs.readFileSync(file) + const responseData = await s3Client.send( + new PutObjectCommand({ + Bucket: 'gl-logs-for-panther-test', + Key: path.join('package_hunter_test', path.basename(file)), + Body: data, + ContentMD5: getMD5HashFromFile(data), + }), + ) + console.log('Successfully uploaded %s', file) + } catch (err) { + if (err.name === 'CredentialsProviderError' || err.name === 'AuthorizationHeaderMalformed') + console.log('Could not upload the report. Are AWS credentials configured in ~/.aws/credentials?') + else + console.log('Unexpected error during upload.') + process.exit(1) + } +})() |