From c8ec0f3124c3727c4e6a24dc3bd8311da4123398 Mon Sep 17 00:00:00 2001 From: amiraabouhadid Date: Thu, 13 Jun 2024 16:00:06 +0300 Subject: [PATCH 1/6] add ip validation to check if ip exists in all farms --- .../src/dashboard/components/add_ip.vue | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/playground/src/dashboard/components/add_ip.vue b/packages/playground/src/dashboard/components/add_ip.vue index d7456a381f..ccb6db2d19 100644 --- a/packages/playground/src/dashboard/components/add_ip.vue +++ b/packages/playground/src/dashboard/components/add_ip.vue @@ -17,7 +17,8 @@ > @@ -35,7 +36,8 @@ @@ -106,6 +108,7 @@ import { getIPRange } from "get-ip-range"; import { default as PrivateIp } from "private-ip"; import { ref, watch } from "vue"; +import { gqlClient } from "@/clients"; import { IPType } from "@/utils/types"; import { useGrid } from "../../stores"; @@ -146,12 +149,20 @@ export default { { deep: true }, ); - function ipcheck() { + async function ipcheck() { if (PrivateIp(publicIP.value.split("/")[0])) { return { message: "IP is not public", }; } + + const ips = await gqlClient.publicIps({ ip: true }, { where: { ip_eq: publicIP.value } }); + if (ips.length > 0) { + return { + message: "IP exists", + }; + } + return undefined; } @@ -163,7 +174,7 @@ export default { { deep: true }, ); - function toIpCheck() { + async function toIpCheck() { if (toPublicIP.value.split("/")[1] !== publicIP.value.split("/")[1]) { return { message: "Subnet is different.", @@ -201,6 +212,12 @@ export default { message: "IP is not public.", }; } + const ips = await gqlClient.publicIps({ ip: true }, { where: { ip_eq: publicIP.value } }); + if (ips.length > 0) { + return { + message: "IP exists", + }; + } return undefined; } From b3fde3014551d070d7fb8e21ae318f051e0f73fd Mon Sep 17 00:00:00 2001 From: amiraabouhadid Date: Wed, 19 Jun 2024 07:35:42 +0300 Subject: [PATCH 2/6] extract ip check conditional to a function, remove repeated code --- .../playground/src/dashboard/components/add_ip.vue | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/playground/src/dashboard/components/add_ip.vue b/packages/playground/src/dashboard/components/add_ip.vue index ccb6db2d19..21977c94ea 100644 --- a/packages/playground/src/dashboard/components/add_ip.vue +++ b/packages/playground/src/dashboard/components/add_ip.vue @@ -156,8 +156,7 @@ export default { }; } - const ips = await gqlClient.publicIps({ ip: true }, { where: { ip_eq: publicIP.value } }); - if (ips.length > 0) { + if (await IpExistsCheck()) { return { message: "IP exists", }; @@ -173,7 +172,10 @@ export default { }, { deep: true }, ); - + async function IpExistsCheck() { + const ips = await gqlClient.publicIps({ ip: true }, { where: { ip_eq: publicIP.value } }); + return ips.length > 0; + } async function toIpCheck() { if (toPublicIP.value.split("/")[1] !== publicIP.value.split("/")[1]) { return { @@ -212,8 +214,7 @@ export default { message: "IP is not public.", }; } - const ips = await gqlClient.publicIps({ ip: true }, { where: { ip_eq: publicIP.value } }); - if (ips.length > 0) { + if (await IpExistsCheck()) { return { message: "IP exists", }; From 4a1f2e6e5956759b7f6bcd81bfe47dea8966ec54 Mon Sep 17 00:00:00 2001 From: Amira <56790126+amiraabouhadid@users.noreply.github.com> Date: Wed, 19 Jun 2024 17:00:37 +0300 Subject: [PATCH 3/6] Update packages/playground/src/dashboard/components/add_ip.vue Co-authored-by: Zainab Elgohary <40770501+zaelgohary@users.noreply.github.com> --- packages/playground/src/dashboard/components/add_ip.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/playground/src/dashboard/components/add_ip.vue b/packages/playground/src/dashboard/components/add_ip.vue index 21977c94ea..24beee8716 100644 --- a/packages/playground/src/dashboard/components/add_ip.vue +++ b/packages/playground/src/dashboard/components/add_ip.vue @@ -158,7 +158,7 @@ export default { if (await IpExistsCheck()) { return { - message: "IP exists", + message: "IP exists.", }; } From cb845e9ebabea54f0a1555d11028b9019b846c4a Mon Sep 17 00:00:00 2001 From: Amira <56790126+amiraabouhadid@users.noreply.github.com> Date: Wed, 19 Jun 2024 17:00:54 +0300 Subject: [PATCH 4/6] Update packages/playground/src/dashboard/components/add_ip.vue Co-authored-by: Zainab Elgohary <40770501+zaelgohary@users.noreply.github.com> --- packages/playground/src/dashboard/components/add_ip.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/playground/src/dashboard/components/add_ip.vue b/packages/playground/src/dashboard/components/add_ip.vue index 24beee8716..a8703a5ee9 100644 --- a/packages/playground/src/dashboard/components/add_ip.vue +++ b/packages/playground/src/dashboard/components/add_ip.vue @@ -216,7 +216,7 @@ export default { } if (await IpExistsCheck()) { return { - message: "IP exists", + message: "IP exists.", }; } return undefined; From a1f095ce0fc63508b8cd949563319ec2f1f4c942 Mon Sep 17 00:00:00 2001 From: amiraabouhadid Date: Thu, 20 Jun 2024 14:57:21 +0300 Subject: [PATCH 5/6] fix validation target value --- packages/playground/src/dashboard/components/add_ip.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/playground/src/dashboard/components/add_ip.vue b/packages/playground/src/dashboard/components/add_ip.vue index a8703a5ee9..05e590b836 100644 --- a/packages/playground/src/dashboard/components/add_ip.vue +++ b/packages/playground/src/dashboard/components/add_ip.vue @@ -156,7 +156,7 @@ export default { }; } - if (await IpExistsCheck()) { + if (await IpExistsCheck(toPublicIP.value)) { return { message: "IP exists.", }; @@ -172,8 +172,8 @@ export default { }, { deep: true }, ); - async function IpExistsCheck() { - const ips = await gqlClient.publicIps({ ip: true }, { where: { ip_eq: publicIP.value } }); + async function IpExistsCheck(pubIp: string) { + const ips = await gqlClient.publicIps({ ip: true }, { where: { ip_eq: pubIp } }); return ips.length > 0; } async function toIpCheck() { @@ -214,7 +214,7 @@ export default { message: "IP is not public.", }; } - if (await IpExistsCheck()) { + if (await IpExistsCheck(publicIP.value)) { return { message: "IP exists.", }; From 55b31079e15c42e1231267b6fef410cbe1b5495a Mon Sep 17 00:00:00 2001 From: amiraabouhadid Date: Thu, 20 Jun 2024 14:58:58 +0300 Subject: [PATCH 6/6] fix validation value --- packages/playground/src/dashboard/components/add_ip.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/playground/src/dashboard/components/add_ip.vue b/packages/playground/src/dashboard/components/add_ip.vue index 05e590b836..011fff3692 100644 --- a/packages/playground/src/dashboard/components/add_ip.vue +++ b/packages/playground/src/dashboard/components/add_ip.vue @@ -156,7 +156,7 @@ export default { }; } - if (await IpExistsCheck(toPublicIP.value)) { + if (await IpExistsCheck(publicIP.value)) { return { message: "IP exists.", }; @@ -214,7 +214,7 @@ export default { message: "IP is not public.", }; } - if (await IpExistsCheck(publicIP.value)) { + if (await IpExistsCheck(toPublicIP.value)) { return { message: "IP exists.", };