Skip to content

Commit

Permalink
feature(mirroring) Support mirroring on AWS and set it on user behalf (
Browse files Browse the repository at this point in the history
  • Loading branch information
AHarmlessPyro authored Aug 15, 2022
1 parent 168bbb2 commit e535cdd
Show file tree
Hide file tree
Showing 32 changed files with 2,200 additions and 651 deletions.
3 changes: 3 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
"@aws-sdk/client-pricing": "^3.142.0",
"aws-sdk": "^2.1189.0",
"body-parser": "^1.20.0",
"connect-typeorm": "^2.0.0",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"express-session": "^1.17.3",
"js-yaml": "^4.1.0",
"multer": "^1.4.5-lts.1",
"node-schedule": "^2.1.0",
Expand All @@ -38,6 +40,7 @@
},
"devDependencies": {
"@types/express": "^4.17.13",
"@types/express-session": "^1.17.5",
"@types/js-yaml": "^4.0.5",
"@types/multer": "^1.4.7",
"@types/node": "^18.6.1",
Expand Down
87 changes: 87 additions & 0 deletions backend/src/api/setup/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { Request, Response } from "express";
import ApiResponseHandler from "api-response-handler";
import { STEP_RESPONSE } from "@common/types";
import { ConnectionType } from "@common/enums";
import { setup } from "aws-services/setup-suricata";
import "express-session";
import { EC2_CONN } from "~/aws-services/create-ec2-instance";
import { VirtualizationType } from "@aws-sdk/client-ec2";

declare module "express-session" {
interface SessionData {
connection_config: Record<
string, // id
{
step?: STEP_RESPONSE["step_number"];
status?: STEP_RESPONSE["status"];
id?: string;
type?: ConnectionType;
data?: STEP_RESPONSE["data"];
}
>;
}
}

export const setup_connection = async (
req: Request,
res: Response
): Promise<void> => {
const { step, id, status, type, params } = req.body;
if (!req.session.connection_config) {
req.session.connection_config = {};
}
if (!req.session.connection_config[id]) {
req.session.connection_config[id] = {
status: "STARTED",
id,
type,
data: {},
};
}

let combined_params = {
...req.session.connection_config[id].data,
...params,
};
let resp = await setup(step, type, combined_params);
req.session.connection_config[id] = {
...req.session.connection_config[id],
...resp,
};

delete resp.data;

await ApiResponseHandler.success(res, resp);
};

export const aws_os_choices = async (
req: Request,
res: Response
): Promise<void> => {
const { id } = req.body;
const { access_id, secret_access_key } =
req.session.connection_config[id].data;
let conn = new EC2_CONN(access_id, secret_access_key);
let choices = await conn.get_latest_image();
await ApiResponseHandler.success(res, [
[choices.Description, choices.ImageId],
]);
};

export const aws_instance_choices = async (
req: Request,
res: Response
): Promise<void> => {
const { id, specs } = req.body;
const { access_id, secret_access_key, virtualization_type } =
req.session.connection_config[id].data;
let conn = new EC2_CONN(access_id, secret_access_key);
let choices = await conn.get_valid_types(
virtualization_type as VirtualizationType,
specs
);
await ApiResponseHandler.success(
res,
choices.map((v) => v.InstanceType)
);
};
Loading

0 comments on commit e535cdd

Please sign in to comment.