|
| 1 | +const { AthenaClient, StartQueryExecutionCommand, CreateNamedQueryCommand, UpdateNamedQueryCommand } = require("@aws-sdk/client-athena"); |
| 2 | +const AWS = require('aws-sdk'); |
| 3 | +const express = require('express'); |
| 4 | +const bodyParser = require('body-parser'); |
| 5 | +const app = express(); |
| 6 | +app.use(bodyParser.json()); |
| 7 | + |
| 8 | +app.post('/v3/athena/all', async (req, res) => { |
| 9 | + const userQuery = req.body.query; // $ MISSING: Source |
| 10 | + |
| 11 | + const client = new AthenaClient({ region: "us-east-1" }); |
| 12 | + |
| 13 | + const params1 = { |
| 14 | + QueryString: "SQL" + userQuery, |
| 15 | + QueryExecutionContext: { Database: "default" }, |
| 16 | + ResultConfiguration: { OutputLocation: "s3://my-results/" } |
| 17 | + }; |
| 18 | + const p = new StartQueryExecutionCommand(params1); |
| 19 | + await client.send(p); // $ MISSING: Alert |
| 20 | + |
| 21 | + const params2 = { |
| 22 | + Name: "user_query", |
| 23 | + Database: "default", |
| 24 | + QueryString: userQuery, |
| 25 | + Description: "User-provided query" |
| 26 | + }; |
| 27 | + await client.send(new CreateNamedQueryCommand(params2)); // $ MISSING: Alert -- This only stores query to database, not executed |
| 28 | + |
| 29 | + const params3 = { |
| 30 | + NamedQueryId: "namedQueryId", |
| 31 | + Name: "user_query_updated", |
| 32 | + Database: "default", |
| 33 | + QueryString: userQuery, |
| 34 | + Description: "Updated user-provided query" |
| 35 | + }; |
| 36 | + await client.send(new UpdateNamedQueryCommand(params3)); // $ MISSING: Alert -- This only stores query to database, not executed |
| 37 | + |
| 38 | + res.end(); |
| 39 | +}); |
| 40 | + |
| 41 | + |
| 42 | +app.post('/v2/athena/all', async (req, res) => { |
| 43 | + const userQuery = req.body.query; // $ MISSING: Source |
| 44 | + |
| 45 | + const athena = new AWS.Athena({ region: "us-east-1" }); |
| 46 | + |
| 47 | + const params1 = { |
| 48 | + QueryString: userQuery, // $ MISSING: Alert |
| 49 | + QueryExecutionContext: { Database: "default" }, |
| 50 | + ResultConfiguration: { OutputLocation: "s3://my-results/" } |
| 51 | + }; |
| 52 | + await athena.startQueryExecution(params1).promise(); |
| 53 | + |
| 54 | + const params2 = { |
| 55 | + Name: "user_query", |
| 56 | + Database: "default", |
| 57 | + QueryString: userQuery, // $ MISSING: Alert -- This only stores query to database, not executed |
| 58 | + Description: "User-provided query" |
| 59 | + }; |
| 60 | + await athena.createNamedQuery(params2).promise(); |
| 61 | + |
| 62 | + const params3 = { |
| 63 | + NamedQueryId: "namedQueryId", |
| 64 | + Name: "user_query_updated", |
| 65 | + Database: "default", |
| 66 | + QueryString: userQuery, // $ MISSING: Alert -- This only stores query to database, not executed |
| 67 | + Description: "Updated user-provided query" |
| 68 | + }; |
| 69 | + await athena.updateNamedQuery(params3).promise(); |
| 70 | + |
| 71 | + res.end(); |
| 72 | +}); |
0 commit comments