diff --git a/backend/src/services/spec/utils.ts b/backend/src/services/spec/utils.ts index c9db6f00..f0bf84d4 100644 --- a/backend/src/services/spec/utils.ts +++ b/backend/src/services/spec/utils.ts @@ -72,7 +72,18 @@ export const validateSpecSchema = (schema: any, version?: number) => { .replace(/\//g, ".") .replace(/~1/g, "/") .slice(1) - res.push(`${error.message} for field ${field}`) + let message = "" + switch (error.keyword) { + case "required": + message = `Required property '${error.params?.["missingProperty"]}' is missing from ${field}` + break + case "additionalProperties": + message = `Must not have additional property '${error.params?.["additionalProperty"]}' for ${field}` + break + default: + message = `${message} of ${field}` + } + res.push(message) } return res } diff --git a/backend/src/suricata_setup/aws-services/aws_setup.ts b/backend/src/suricata_setup/aws-services/aws_setup.ts index 95b5c21a..e628b306 100644 --- a/backend/src/suricata_setup/aws-services/aws_setup.ts +++ b/backend/src/suricata_setup/aws-services/aws_setup.ts @@ -377,9 +377,9 @@ export async function aws_mirror_target_creation({ accessKeyId: access_id, }, region: region, - }); - let resp = await create_mirror_target(client, destination_eni_id, id); - client.destroy(); + }) + let resp = await create_mirror_target(client, destination_eni_id, id) + client.destroy() return { success: "OK", status: "IN-PROGRESS", diff --git a/backend/src/suricata_setup/aws-services/create-ec2-instance.ts b/backend/src/suricata_setup/aws-services/create-ec2-instance.ts index e7d0c0c5..9d83db7f 100644 --- a/backend/src/suricata_setup/aws-services/create-ec2-instance.ts +++ b/backend/src/suricata_setup/aws-services/create-ec2-instance.ts @@ -27,7 +27,7 @@ import { DescribeInstancesCommand, TerminateInstancesCommand, DeleteKeyPairCommand, -} from "@aws-sdk/client-ec2"; +} from "@aws-sdk/client-ec2" import { STSClient, GetCallerIdentityCommand } from "@aws-sdk/client-sts" @@ -441,18 +441,18 @@ export class EC2_CONN { } public async delete_ec2_instance(instance_id: string) { - let conn = this.get_conn(); + let conn = this.get_conn() await conn.send( - new TerminateInstancesCommand({ InstanceIds: [instance_id] }) - ); - return true; + new TerminateInstancesCommand({ InstanceIds: [instance_id] }), + ) + return true } public async delete_keypair(keypair_id: string, key_name: string) { - let conn = this.get_conn(); + let conn = this.get_conn() await conn.send( - new DeleteKeyPairCommand({ KeyPairId: keypair_id, KeyName: key_name }) - ); - return true; + new DeleteKeyPairCommand({ KeyPairId: keypair_id, KeyName: key_name }), + ) + return true } } diff --git a/backend/src/suricata_setup/aws-services/delete.ts b/backend/src/suricata_setup/aws-services/delete.ts index 6a8458da..2f6aa6ca 100644 --- a/backend/src/suricata_setup/aws-services/delete.ts +++ b/backend/src/suricata_setup/aws-services/delete.ts @@ -1,12 +1,12 @@ -import { EC2Client } from "@aws-sdk/client-ec2"; -import { STEP_RESPONSE } from "@common/types"; -import { randomUUID } from "crypto"; -import { EC2_CONN } from "./create-ec2-instance"; +import { EC2Client } from "@aws-sdk/client-ec2" +import { STEP_RESPONSE } from "@common/types" +import { randomUUID } from "crypto" +import { EC2_CONN } from "./create-ec2-instance" import { delete_mirror_filter, delete_mirror_session, delete_mirror_target, -} from "./mirroring"; +} from "./mirroring" export async function delete_aws_data(aws: STEP_RESPONSE["data"]) { let client = new EC2Client({ @@ -15,44 +15,40 @@ export async function delete_aws_data(aws: STEP_RESPONSE["data"]) { secretAccessKey: aws.secret_access_key, }, region: aws.region, - }); + }) // Delete EC2 Mirror Session try { - await delete_mirror_session(client, aws.mirror_session_id, randomUUID()); + await delete_mirror_session(client, aws.mirror_session_id, randomUUID()) } catch (err) { throw new Error( - `Couldn't delete EC2 Mirror Session ${aws.mirror_session_id}` - ); + `Couldn't delete EC2 Mirror Session ${aws.mirror_session_id}`, + ) } // Delete EC2 Mirror Filter try { - await delete_mirror_filter(client, aws.mirror_filter_id, randomUUID()); + await delete_mirror_filter(client, aws.mirror_filter_id, randomUUID()) } catch (err) { - throw new Error( - `Couldn't delete EC2 Mirror Filter ${aws.mirror_filter_id}` - ); + throw new Error(`Couldn't delete EC2 Mirror Filter ${aws.mirror_filter_id}`) } // Delete EC2 Mirror Target try { - await delete_mirror_target(client, aws.mirror_target_id, randomUUID()); + await delete_mirror_target(client, aws.mirror_target_id, randomUUID()) } catch (err) { - throw new Error( - `Couldn't delete EC2 Mirror Target ${aws.mirror_target_id}` - ); + throw new Error(`Couldn't delete EC2 Mirror Target ${aws.mirror_target_id}`) } - let conn = new EC2_CONN(aws.access_id, aws.secret_access_key, aws.region); + let conn = new EC2_CONN(aws.access_id, aws.secret_access_key, aws.region) // Delete EC2 Instance try { - await conn.delete_ec2_instance(aws.mirror_instance_id); + await conn.delete_ec2_instance(aws.mirror_instance_id) } catch (err) { - throw new Error(`Couldn't delete EC2 instance ${aws.mirror_instance_id}`); + throw new Error(`Couldn't delete EC2 instance ${aws.mirror_instance_id}`) } // Delete EC2 Keypair try { - await conn.delete_keypair(aws.keypair_id, aws.keypair_name); + await conn.delete_keypair(aws.keypair_id, aws.keypair_name) } catch (err) { - throw new Error(`Couldn't delete EC2 Keyapair ${aws.keypair}`); + throw new Error(`Couldn't delete EC2 Keyapair ${aws.keypair}`) } - return `Deleted connection ${aws.id}`; + return `Deleted connection ${aws.id}` } diff --git a/backend/src/suricata_setup/utils/index.ts b/backend/src/suricata_setup/utils/index.ts index bcba5399..72e1368a 100644 --- a/backend/src/suricata_setup/utils/index.ts +++ b/backend/src/suricata_setup/utils/index.ts @@ -1,24 +1,24 @@ -import { RedisClient } from "utils/redis"; +import { RedisClient } from "utils/redis" async function addToRedis(key, data: Object) { - const redisClient = RedisClient.getInstance(); - await redisClient.set(key, JSON.stringify(data)); + const redisClient = RedisClient.getInstance() + await redisClient.set(key, JSON.stringify(data)) } function addToRedisFromPromise(key, data: Promise) { - const redisClient = RedisClient.getInstance(); + const redisClient = RedisClient.getInstance() data - .then((resp) => redisClient.set(key, JSON.stringify(resp))) - .catch((err) => redisClient.set(key, JSON.stringify(err))); + .then(resp => redisClient.set(key, JSON.stringify(resp))) + .catch(err => redisClient.set(key, JSON.stringify(err))) } async function getFromRedis(key) { - const redisClient = RedisClient.getInstance(); - return JSON.parse(await redisClient.get(key)); + const redisClient = RedisClient.getInstance() + return JSON.parse(await redisClient.get(key)) } async function deleteKeyFromRedis(key) { - const redisClient = RedisClient.getInstance(); - return await redisClient.del([key]); + const redisClient = RedisClient.getInstance() + return await redisClient.del([key]) } -export { addToRedis, addToRedisFromPromise, getFromRedis, deleteKeyFromRedis }; +export { addToRedis, addToRedisFromPromise, getFromRedis, deleteKeyFromRedis } diff --git a/backend/src/utils/index.ts b/backend/src/utils/index.ts index 00af0a7f..d502d3f8 100644 --- a/backend/src/utils/index.ts +++ b/backend/src/utils/index.ts @@ -35,7 +35,7 @@ export const getPathTokens = (path: string): string[] => { return ["/"] } const tokens = path.split("/") - return tokens.filter((token) => token.length > 0) + return tokens.filter(token => token.length > 0) } export const getPathRegex = (path: string): string => { diff --git a/backend/src/utils/redis.ts b/backend/src/utils/redis.ts index 791c3c36..c40942cd 100644 --- a/backend/src/utils/redis.ts +++ b/backend/src/utils/redis.ts @@ -1,18 +1,18 @@ -import IORedis from "ioredis"; +import IORedis from "ioredis" export class RedisClient { - private static instance: RedisClient; - private static client: IORedis; + private static instance: RedisClient + private static client: IORedis private constructor(url) { - RedisClient.client = new IORedis(url); + RedisClient.client = new IORedis(url) } public static getInstance(): IORedis { if (!RedisClient.instance) { - RedisClient.instance = new RedisClient(process.env.REDIS_URL); + RedisClient.instance = new RedisClient(process.env.REDIS_URL) } - return RedisClient.client; + return RedisClient.client } }