Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed aws/src/lambdas/calcHash/calcHash.zip
Binary file not shown.
28 changes: 7 additions & 21 deletions aws/src/lambdas/calcHash/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const argon2 = require('argon2');
const argon2_1 = __importDefault(require("argon2"));
const handler = async (event) => {
const httpMethod = event.requestContext.http.method;
console.log('Received event:', JSON.stringify(event, null));
const httpMethod = event.requestContext.httpMethod;
if (httpMethod === 'OPTIONS') {
return {
statusCode: 200,
Expand All @@ -18,26 +19,11 @@ const handler = async (event) => {
};
}
try {
const raw = event.body;

// Parse JSON if input is a JSON object or read raw text
let textToHash;
try {
const parsed = JSON.parse(raw);
if (parsed && typeof parsed.textToHash === 'string') {
textToHash = parsed.textToHash;
} else {
textToHash = typeof parsed === 'string' ? parsed : raw;
}
} catch {
textToHash = raw;
}

console.log("Data to Hash: ", textToHash);
const dataToHash = typeof event.body === 'string' ? event.body : JSON.stringify(event.body, null, 2);
const slt = Buffer.from('my-static-salt', 'utf8');
const hashValue = await argon2.hash(textToHash, {
const hashValue = await argon2_1.default.hash(dataToHash, {
salt: slt,
type: argon2.argon2id,
type: argon2_1.default.argon2id,
timeCost: 2, // Number of iterations.
memoryCost: 65536, // Memory in KiB.
hashLength: 32, // Length of the resulting hash.
Expand Down Expand Up @@ -66,4 +52,4 @@ const handler = async (event) => {
};
}
};
module.exports = { handler };
module.exports = { handler };
8 changes: 4 additions & 4 deletions aws/src/lambdas/calcHash/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { APIGatewayEvent, Context } from "aws-lambda";
import { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from 'aws-lambda';
import { APIGatewayProxyResultV2, APIGatewayEvent } from 'aws-lambda';
import argon2 from 'argon2'

const handler = async (event: APIGatewayProxyEventV2): Promise<APIGatewayProxyResultV2> => {
const httpMethod = event.requestContext.http.method;
const handler = async (event: APIGatewayEvent): Promise<APIGatewayProxyResultV2> => {
console.log('Received event:', JSON.stringify(event, null));
const httpMethod = event.requestContext.httpMethod;
if (httpMethod === 'OPTIONS') {
return {
statusCode: 200,
Expand Down
5 changes: 5 additions & 0 deletions aws/src/lambdas/calcHash/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"scripts": {
"build": "npx tsc",
"zip": "(zip calcHash.zip index.js node_modules || powershell Compress-Archive -Path index.js, node_modules -DestinationPath calcHash.zip)",
"move": "(mv calcHash.zip ../../terraform || powershell Move-Item calcHash.zip ../../terraform)"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.147",
"@types/node": "^22.13.13",
Expand Down
1 change: 0 additions & 1 deletion aws/src/lambdas/calcHash/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"module": "CommonJS",
"lib": ["ES2020"],
"moduleResolution": "Node",
"outDir": "build",
"rootDir": "./",
"strict": true,
"esModuleInterop": true
Expand Down
Binary file removed aws/src/lambdas/getSecurityQues/getSecurityQues.zip
Binary file not shown.
5 changes: 5 additions & 0 deletions aws/src/lambdas/getSecurityQues/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"scripts": {
"build": "npx tsc",
"zip": "(zip getSecurityQues.zip index.js node_modules || powershell Compress-Archive -Path index.js, node_modules -DestinationPath getSecurityQues.zip)",
"move": "(mv getSecurityQues.zip ../../terraform || powershell Move-Item getSecurityQues.zip ../../terraform)"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.147",
"typescript": "^5.7.3"
Expand Down
54 changes: 54 additions & 0 deletions aws/src/lambdas/getUserInfo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handler = void 0;
const promise_1 = require("mysql2/promise");
const dbConfig = {
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
};
const handler = async (event) => {
try {
console.log("Incoming event:", JSON.stringify(event, null, 2));
let request_body;
if (event.body) {
request_body = JSON.parse(event.body);
}
else {
console.log("No body found");
return {
statusCode: 400,
body: JSON.stringify({ message: "No body found" }),
};
}
const { UUID } = request_body;
console.log("Parsed UUID:", UUID);
try {
const connection = await (0, promise_1.createConnection)(dbConfig);
const [rows] = await connection.execute('SELECT enc_email, enc_name, enc_phone_num FROM users WHERE uuid = ?', [UUID]);
await connection.end();
return {
statusCode: 200,
body: JSON.stringify(rows),
};
}
catch (error) {
console.error("Database error:", error);
return {
statusCode: 500,
body: JSON.stringify({ message: "Database connection failed", error: error }),
};
}
}
catch (error) {
console.error("Unhandled error in handler:", error);
return {
statusCode: 500,
body: JSON.stringify({
message: "Internal Server Error"
}),
};
}
};
exports.handler = handler;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import mysql from 'mysql2/promise';
import { APIGatewayEvent } from "aws-lambda";
import { createConnection } from 'mysql2/promise';

const dbConfig = {
host: process.env.DB_HOST,
Expand All @@ -7,7 +8,7 @@ const dbConfig = {
database: process.env.DB_NAME,
};

export const handler = async (event) => {
export const handler = async (event: APIGatewayEvent) => {
try {
console.log("Incoming event:", JSON.stringify(event, null, 2));

Expand All @@ -27,7 +28,7 @@ export const handler = async (event) => {
console.log("Parsed UUID:", UUID);

try {
const connection = await mysql.createConnection(dbConfig);
const connection = await createConnection(dbConfig);
const [rows] = await connection.execute('SELECT enc_email, enc_name, enc_phone_num FROM users WHERE uuid = ?', [UUID]);
await connection.end();

Expand All @@ -40,7 +41,7 @@ export const handler = async (event) => {
console.error("Database error:", error);
return {
statusCode: 500,
body: JSON.stringify({ message: "Database connection failed", error: error.message }),
body: JSON.stringify({ message: "Database connection failed", error: error }),
};
}
} catch (error) {
Expand Down
20 changes: 9 additions & 11 deletions aws/src/lambdas/getUserInfo/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{
"name": "getuserinfo",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"build": "npx tsc",
"zip": "(zip getUserInfo.zip index.js node_modules || powershell Compress-Archive -Path index.js, node_modules -DestinationPath getUserInfo.zip)",
"move": "(mv getUserInfo.zip ../../terraform || powershell Move-Item getUserInfo.zip ../../terraform)"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.147",
"typescript": "^5.7.3"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"mysql2": "^3.14.0"
"mysql2": "^3.13.0"
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"module": "CommonJS",
"lib": ["ES2020"],
"moduleResolution": "Node",
"outDir": "build",
"rootDir": "./",
"strict": true,
"esModuleInterop": true
Expand Down
60 changes: 60 additions & 0 deletions aws/src/lambdas/insertDomainName/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handler = void 0;
const promise_1 = require("mysql2/promise");
const dbConfig = {
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
};
const handler = async (event) => {
console.log("Incoming event:", JSON.stringify(event, null, 2));
let request_body;
if (event.body) {
request_body = JSON.parse(event.body);
}
else {
console.log("No body found");
return {
statusCode: 400,
body: JSON.stringify({ message: "No body found" }),
};
}
const { UUID, domain } = request_body;
try {
const connection = await (0, promise_1.createConnection)(dbConfig);
const [rows] = await connection.execute('SELECT 1 FROM users WHERE uuid = ? LIMIT 1', [UUID]);
const uuidExists = rows.length > 0;
if (!uuidExists) {
await connection.end();
return {
statusCode: 400,
body: JSON.stringify({ message: "UUID does not exist" }),
};
}
try {
const [result] = await connection.execute('INSERT INTO user_websites (uuid, domain_id) VALUES (?, ?)', [UUID, domain]);
console.log('Insert successful:', result);
return {
statusCode: 200,
body: JSON.stringify("Domain Name added to Database"),
};
}
catch (error) {
console.error('Failed to insert into user_websites:', error);
return {
statusCode: 401,
body: JSON.stringify({ message: "Failed to insert domain" }),
};
}
}
catch (error) {
console.error("Database error:", error);
return {
statusCode: 500,
body: JSON.stringify({ message: "Database connection failed", error: error }),
};
}
};
exports.handler = handler;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import mysql from 'mysql2/promise';
import { APIGatewayEvent } from "aws-lambda";
import { createConnection, RowDataPacket } from 'mysql2/promise';

const dbConfig = {
host: process.env.DB_HOST,
Expand All @@ -7,7 +8,7 @@ const dbConfig = {
database: process.env.DB_NAME,
};

export const handler = async (event) => {
export const handler = async (event: APIGatewayEvent) => {
console.log("Incoming event:", JSON.stringify(event, null, 2));

let request_body;
Expand All @@ -24,8 +25,8 @@ export const handler = async (event) => {
const { UUID, domain } = request_body;

try {
const connection = await mysql.createConnection(dbConfig);
const [rows] = await connection.execute('SELECT 1 FROM users WHERE uuid = ? LIMIT 1', [UUID]);
const connection = await createConnection(dbConfig);
const [rows] = await connection.execute<RowDataPacket[]>('SELECT 1 FROM users WHERE uuid = ? LIMIT 1', [UUID]);
const uuidExists = rows.length > 0;
if (!uuidExists) {
await connection.end();
Expand Down Expand Up @@ -57,7 +58,7 @@ export const handler = async (event) => {
console.error("Database error:", error);
return {
statusCode: 500,
body: JSON.stringify({ message: "Database connection failed", error: error.message }),
body: JSON.stringify({ message: "Database connection failed", error: error }),
};
}
};
17 changes: 8 additions & 9 deletions aws/src/lambdas/insertDomainName/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"name": "my-lambda",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"build": "npx tsc",
"zip": "(zip insertDomainName.zip index.js node_modules || powershell Compress-Archive -Path index.js, node_modules -DestinationPath insertDomainName.zip)",
"move": "(mv insertDomainName.zip ../../terraform || powershell Move-Item insertDomainName.zip ../../terraform)"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.147",
"typescript": "^5.7.3"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"mysql2": "^3.14.0"
"mysql2": "^3.13.0"
}
}

11 changes: 11 additions & 0 deletions aws/src/lambdas/insertDomainName/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "CommonJS",
"lib": ["ES2020"],
"moduleResolution": "Node",
"rootDir": "./",
"strict": true,
"esModuleInterop": true
}
}
2 changes: 1 addition & 1 deletion aws/src/lambdas/insertSecurityQues/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"scripts": {
"build": "npx tsc",
"zip": "(rm insertSecurityQues.zip || powershell Remove-Item insertSecurityQues.zip) && (zip insertSecurityQues.zip index.js node_modules || powershell Compress-Archive -Path index.js, node_modules -DestinationPath insertSecurityQues.zip)",
"zip": "(zip insertSecurityQues.zip index.js node_modules || powershell Compress-Archive -Path index.js, node_modules -DestinationPath insertSecurityQues.zip)",
"move": "(mv insertSecurityQues.zip ../../terraform || powershell Move-Item insertSecurityQues.zip ../../terraform)"
},
"devDependencies": {
Expand Down
13 changes: 0 additions & 13 deletions aws/src/lambdas/login/index.ts

This file was deleted.

Binary file removed aws/src/lambdas/login/login.zip
Binary file not shown.
9 changes: 0 additions & 9 deletions aws/src/lambdas/login/package.json

This file was deleted.

Loading
Loading