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/genPass.zip
Binary file not shown.
11 changes: 10 additions & 1 deletion aws/src/lambdas/calcHash/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
const argon2_1 = __importDefault(require("argon2"));
const handler = async (event) => {
console.log('Received event:', JSON.stringify(event, null));
const httpMethod = event.requestContext.httpMethod;
let httpMethod;
try {
httpMethod = event.requestContext.http.method;
}
catch (error) {
if (error instanceof Error) {
console.log("APIGatewayEvent");
}
httpMethod = event.httpMethod;
}
if (httpMethod === 'OPTIONS') {
return {
statusCode: 200,
Expand Down
14 changes: 11 additions & 3 deletions aws/src/lambdas/calcHash/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { APIGatewayProxyResultV2, APIGatewayEvent } from 'aws-lambda';
import { APIGatewayEvent, APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from 'aws-lambda';
import argon2 from 'argon2'

const handler = async (event: APIGatewayEvent): Promise<APIGatewayProxyResultV2> => {
const handler = async (event: APIGatewayEvent | APIGatewayProxyEventV2): Promise<APIGatewayProxyResultV2> => {
console.log('Received event:', JSON.stringify(event, null));
const httpMethod = event.requestContext.httpMethod;
let httpMethod: string;
try {
httpMethod = (event as APIGatewayProxyEventV2).requestContext.http.method;
} catch (error) {
if (error instanceof Error) {
console.log("APIGatewayEvent");
}
httpMethod = (event as APIGatewayEvent).httpMethod;
}
if (httpMethod === 'OPTIONS') {
return {
statusCode: 200,
Expand Down
64 changes: 64 additions & 0 deletions aws/src/lambdas/genPass/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const password_generator_1 = require("./src/password_generator");
const handler = async (event) => {
console.log('Received event:', JSON.stringify(event, null));
let httpMethod;
try {
httpMethod = event.requestContext.http.method;
}
catch (error) {
if (error instanceof Error) {
console.log("APIGatewayEvent");
}
httpMethod = event.httpMethod;
}
if (httpMethod === 'OPTIONS') {
return {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type,Authorization'
},
body: ''
};
}
try {
//const dataToHash = typeof event.body === 'string' ? event.body : JSON.stringify(event.body, null, 2);
//const slt = 'my-static-salt'; // Figure out how to get this value from event as a json and stringify it like in the line above
const body = typeof event.body === "string" ? JSON.parse(event.body || "") : event.body;
const salt = body.salt;
const strong_password = await (0, password_generator_1.calculatePassword)(salt);
/*const hashValue = await argon2.hash(dataToHash, {
salt: slt,
type: argon2.argon2id,
timeCost: 2, // Number of iterations.
memoryCost: 65536, // Memory in KiB.
hashLength: 32, // Length of the resulting hash.
parallelism: 1,
});*/
return {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type,Authorization'
},
body: JSON.stringify({ hash: strong_password }),
};
}
catch (error) {
console.error('Hashing error:', error);
return {
statusCode: 500,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type,Authorization'
},
body: JSON.stringify({ error: error instanceof Error ? error.message : String(error) }),
};
}
};
module.exports = { handler };
17 changes: 13 additions & 4 deletions aws/src/lambdas/genPass/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from 'aws-lambda';
import { APIGatewayEvent, APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from 'aws-lambda';
import { calculatePassword } from './src/password_generator';

const handler = async (event: APIGatewayProxyEventV2): Promise<APIGatewayProxyResultV2> => {
const httpMethod = event.requestContext.http.method;
const handler = async (event: APIGatewayEvent | APIGatewayProxyResultV2): Promise<APIGatewayProxyResultV2> => {
console.log('Received event:', JSON.stringify(event, null));
let httpMethod: string;
try {
httpMethod = (event as APIGatewayProxyEventV2).requestContext.http.method;
} catch (error) {
if (error instanceof Error) {
console.log("APIGatewayEvent");
}
httpMethod = (event as APIGatewayEvent).httpMethod;
}
if (httpMethod === 'OPTIONS') {
return {
statusCode: 200,
Expand All @@ -18,7 +27,7 @@ const handler = async (event: APIGatewayProxyEventV2): Promise<APIGatewayProxyRe
//const dataToHash = typeof event.body === 'string' ? event.body : JSON.stringify(event.body, null, 2);
//const slt = 'my-static-salt'; // Figure out how to get this value from event as a json and stringify it like in the line above

const body = typeof event.body === "string" ? JSON.parse(event.body) : event.body;
const body = typeof (event as APIGatewayEvent).body === "string" ? JSON.parse((event as APIGatewayEvent).body || "") : (event as APIGatewayEvent).body;

const salt: string = body.salt;
const domain_name: string = body.domain_name;
Expand Down
4 changes: 3 additions & 1 deletion aws/src/lambdas/genPass/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"mysql2": "^3.14.1"
},
"scripts": {
"build": "tsc"
"build": "npx tsc",
"zip": "(zip -r genPass.zip index.js node_modules || powershell Compress-Archive -Path index.js, node_modules -DestinationPath genPass.zip)",
"move": "(mv genPass.zip ../../terraform || powershell Move-Item genPass.zip ../../terraform)"
}
}
23 changes: 22 additions & 1 deletion aws/src/lambdas/getBlockedDomains/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,28 @@ const dbConfig = {
database: process.env.DB_NAME,
};
const handler = async (event) => {
console.log('EVENT: \n' + JSON.stringify(event, null, 2));
console.log('Received event:', JSON.stringify(event, null));
let httpMethod;
try {
httpMethod = event.requestContext.http.method;
}
catch (error) {
if (error instanceof Error) {
console.log("APIGatewayEvent");
}
httpMethod = event.httpMethod;
}
if (httpMethod === 'OPTIONS') {
return {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type,Authorization'
},
body: ''
};
}
let request_body;
try {
if (event.body) {
Expand Down
26 changes: 23 additions & 3 deletions aws/src/lambdas/getBlockedDomains/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIGatewayEvent } from 'aws-lambda';
import { APIGatewayEvent, APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from 'aws-lambda';
import { createConnection, RowDataPacket } from 'mysql2/promise';

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

const handler = async (event: APIGatewayEvent) => {
console.log('EVENT: \n' + JSON.stringify(event, null, 2));
const handler = async (event: APIGatewayEvent | APIGatewayProxyEventV2 ): Promise<APIGatewayProxyResultV2> => {
console.log('Received event:', JSON.stringify(event, null));
let httpMethod: string;
try {
httpMethod = (event as APIGatewayProxyEventV2).requestContext.http.method;
} catch (error) {
if (error instanceof Error) {
console.log("APIGatewayEvent");
}
httpMethod = (event as APIGatewayEvent).httpMethod;
}
if (httpMethod === 'OPTIONS') {
return {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type,Authorization'
},
body: ''
};
}
let request_body;
try {
if (event.body) {
Expand Down
2 changes: 1 addition & 1 deletion aws/src/lambdas/getBlockedDomains/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"scripts": {
"build": "npx tsc",
"zip": "(zip getBlockedDomains.zip index.js node_modules || powershell Compress-Archive -Path index.js, node_modules -DestinationPath getBlockedDomains.zip)",
"zip": "(zip -r getBlockedDomains.zip index.js node_modules || powershell Compress-Archive -Path index.js, node_modules -DestinationPath getBlockedDomains.zip)",
"move": "(mv getBlockedDomains.zip ../../terraform || powershell Move-Item getBlockedDomains.zip ../../terraform)"
},
"devDependencies": {
Expand Down
26 changes: 23 additions & 3 deletions aws/src/lambdas/getSecurityQues/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,29 @@ const dbConfig = {
password: process.env.DB_PASS, // RDS password
database: process.env.DB_NAME,
};
const handler = async (event, context) => {
console.log('EVENT: \n' + JSON.stringify(event, null, 2));
console.log('CONTEXT: \n' + JSON.stringify(context, null));
const handler = async (event) => {
console.log('Received event:', JSON.stringify(event, null));
let httpMethod;
try {
httpMethod = event.requestContext.http.method;
}
catch (error) {
if (error instanceof Error) {
console.log("APIGatewayEvent");
}
httpMethod = event.httpMethod;
}
if (httpMethod === 'OPTIONS') {
return {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type,Authorization'
},
body: ''
};
}
let request_body;
try {
if (event.body) {
Expand Down
27 changes: 23 additions & 4 deletions aws/src/lambdas/getSecurityQues/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIGatewayEvent, Context } from "aws-lambda";
import { APIGatewayEvent, APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from 'aws-lambda';
import { createConnection } from 'mysql2/promise';

const dbConfig = {
Expand All @@ -8,9 +8,28 @@ const dbConfig = {
database: process.env.DB_NAME,
};

const handler = async (event: APIGatewayEvent, context: Context) => {
console.log('EVENT: \n' + JSON.stringify(event, null, 2));
console.log('CONTEXT: \n' + JSON.stringify(context, null));
const handler = async (event: APIGatewayEvent | APIGatewayProxyEventV2 ): Promise<APIGatewayProxyResultV2> => {
console.log('Received event:', JSON.stringify(event, null));
let httpMethod: string;
try {
httpMethod = (event as APIGatewayProxyEventV2).requestContext.http.method;
} catch (error) {
if (error instanceof Error) {
console.log("APIGatewayEvent");
}
httpMethod = (event as APIGatewayEvent).httpMethod;
}
if (httpMethod === 'OPTIONS') {
return {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type,Authorization'
},
body: ''
};
}

let request_body;
try {
Expand Down
2 changes: 1 addition & 1 deletion aws/src/lambdas/getSecurityQues/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"scripts": {
"build": "npx tsc",
"zip": "(zip getSecurityQues.zip index.js node_modules || powershell Compress-Archive -Path index.js, node_modules -DestinationPath getSecurityQues.zip)",
"zip": "(zip -r 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": {
Expand Down
6 changes: 6 additions & 0 deletions aws/src/lambdas/getUserInfo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ const dbConfig = {
database: process.env.DB_NAME,
};
const handler = async (event) => {
<<<<<<< HEAD
=======
console.log('Received event:', JSON.stringify(event, null));
>>>>>>> main
let httpMethod;
try {
httpMethod = event.requestContext.http.method;
Expand All @@ -29,7 +32,10 @@ const handler = async (event) => {
body: ''
};
}
<<<<<<< HEAD
=======
let request_body;
>>>>>>> main
try {
if (event.body) {
request_body = JSON.parse(event.body);
Expand Down
34 changes: 21 additions & 13 deletions aws/src/lambdas/getUserInfo/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {APIGatewayProxyEventV2,APIGatewayProxyResult} from "aws-lambda";
import { APIGatewayEvent, APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from 'aws-lambda';
import { createConnection } from 'mysql2/promise';

const dbConfig = {
Expand All @@ -8,20 +8,28 @@ const dbConfig = {
database: process.env.DB_NAME,
};

export const handler = async (event: APIGatewayProxyEventV2): Promise<APIGatewayProxyResult> => {
const httpMethod = event.requestContext.http.method;
export const handler = async (event: APIGatewayEvent | APIGatewayProxyEventV2): Promise<APIGatewayProxyResultV2> => {
let httpMethod: string;
try {
httpMethod = (event as APIGatewayProxyEventV2).requestContext.http.method;
} catch (error) {
if (error instanceof Error) {
console.log("APIGatewayEvent");
}
httpMethod = (event as APIGatewayEvent).httpMethod;
}
if (httpMethod === 'OPTIONS') {
return {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type,Authorization'
},
body: ''
};
return {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type,Authorization'
},
body: ''
};
}
try {
try {
console.log("Incoming event:", JSON.stringify(event, null, 2));

let request_body;
Expand Down
23 changes: 22 additions & 1 deletion aws/src/lambdas/insertBlockedDomain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,28 @@ const dbConfig = {
database: process.env.DB_NAME,
};
const handler = async (event) => {
console.log('EVENT: \n' + JSON.stringify(event, null, 2));
console.log('Received event:', JSON.stringify(event, null));
let httpMethod;
try {
httpMethod = event.requestContext.http.method;
}
catch (error) {
if (error instanceof Error) {
console.log("APIGatewayEvent");
}
httpMethod = event.httpMethod;
}
if (httpMethod === 'OPTIONS') {
return {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type,Authorization'
},
body: ''
};
}
let request_body;
try {
if (event.body) {
Expand Down
Loading
Loading