Advertisement
Guest User

arv

a guest
Apr 10th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const mysql = require('mysql2');
  2. const Promise = require('bluebird');
  3. const testConfig = {
  4.         'global.php' : {
  5.             constants : {
  6.                 "MYSQL_HOST: "clone-me-prod-20190409.chh6vulasacr.us-east-1.rds.amazonaws.com",
  7.                 "MYSQL_USER": "wickr",
  8.                 "MYSQL_PASS": "kief4thim1Ahh2qu",
  9.                 "MYSQL_DB": "wickrdb",
  10.             }
  11.         }
  12. }
  13. //const config = require('/etc/wickr/config/cronjobs-enterprise/config.json');
  14. const { constants: { MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB }} = testConfig['global.php']
  15.  
  16. const currentTimeStamp = () => Math.round(new Date().getTime() / 1000);
  17. const DELETE_OLD_SIEM_ENTRY = 'DELETE FROM siem where timestamp < ?';
  18.  
  19. async function cleanRateLimiting() {
  20.     try {
  21.         const conn = await getDbConnection();
  22.         conn.query(DELETE_OLD_SIEM_ENTRY, [currentTimeStamp()]);
  23.     }
  24. }
  25.  
  26. async function getDbPool() {
  27.    const pool = await mysql.createPool({
  28.        connectionLimit: 10,
  29.        host: CONFIG.mysql.hostname,
  30.        user: CONFIG.mysql.username,
  31.        password: CONFIG.mysql.password,
  32.        database: CONFIG.mysql.database
  33.    });
  34.    return pool.promise();
  35. }
  36.  
  37. async function getDbConnection() {
  38.     const pool = await getDbPool();
  39.     const { connection } = pool.getConnection();
  40.     return connection;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement