Skip to content

Commit

Permalink
Check network on packet mirroring (#141)
Browse files Browse the repository at this point in the history
Signed-off-by: Ninad Sinha <[email protected]>
  • Loading branch information
AHarmlessPyro authored Nov 29, 2022
1 parent 36f3a55 commit d34d74b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metlo/cli",
"version": "0.0.11",
"version": "0.0.12",
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
13 changes: 8 additions & 5 deletions cli/src/gcp/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ export async function cleanupGCP(
conn: GCP_CONN,
zone: string,
project: string,
network: string
networkUrl: string
) {
const region = zone.substring(0, zone.length - 2)
const [mirroring] = await conn.list_packet_mirroring()
let [mirroring] = await conn.list_packet_mirroring()
mirroring = mirroring
.filter(mirror => mirror.network.url == networkUrl)
.filter((mirror) => mirror.name.startsWith("metlo"))
if (mirroring.length == 0) {
throw new Error("No existing packet mirroring instances found")
}
Expand All @@ -27,7 +30,7 @@ export async function cleanupGCP(
name: "_packetMirrorName",
message: "Select Packet Mirroring instance",
initial: 0,
choices: mirroring.filter((inst) => inst.name.startsWith("metlo")).map((inst) => inst.name)
choices: mirroring.map((inst) => inst.name)
}]
)
let packetMirrorName = identifySourceResp["_packetMirrorName"]
Expand Down Expand Up @@ -243,7 +246,7 @@ const verifyAccountDetails = async () => {
{
type: "input",
name: "_projectName",
message: "GCP Project Name",
message: "GCP Project ID",
}, {
type: "input",
initial: "default",
Expand Down Expand Up @@ -297,7 +300,7 @@ export const gcpTrafficMirrorCleanUp = async () => {
data["zone"] = zone
data["project"] = project

await cleanupGCP(conn, zone, project, network)
await cleanupGCP(conn, zone, project, networkUrl)
} catch (e) {
spinner.fail()
console.log(chalk.bgRedBright("Metlo packet mirroring item removal failed. This might help in debugging it."))
Expand Down
2 changes: 1 addition & 1 deletion cli/src/gcp/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const verifyAccountDetails = async () => {
{
type: "input",
name: "_projectName",
message: "GCP Project Name",
message: "GCP Project ID",
}, {
type: "input",
initial: "default",
Expand Down
5 changes: 3 additions & 2 deletions cli/src/gcp/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const verifyAccountDetails = async () => {
{
type: "input",
name: "_projectName",
message: "GCP Project Name",
message: "GCP Project ID",
}, {
type: "input",
initial: "default",
Expand Down Expand Up @@ -185,7 +185,8 @@ export const gcpTrafficMirrorDelete = async () => {
data["zone"] = zone
data["project"] = project

const [packetMirrors] = await conn.list_packet_mirroring()
let [packetMirrors] = await conn.list_packet_mirroring()
packetMirrors = packetMirrors.filter(mirror => mirror.network.url == networkUrl)

await deletePacketMirroringResources(conn, packetMirrors)
} catch (e) {
Expand Down
5 changes: 3 additions & 2 deletions cli/src/gcp/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const verifyAccountDetails = async () => {
{
type: "input",
name: "_projectName",
message: "GCP Project Name",
message: "GCP Project ID",
}, {
type: "input",
initial: "default",
Expand Down Expand Up @@ -591,7 +591,8 @@ export const gcpTrafficMirrorSetup = async () => {
data["zone"] = zone
data["project"] = project

const [packetMirrors] = await conn.list_packet_mirroring()
let [packetMirrors] = await conn.list_packet_mirroring()
packetMirrors = packetMirrors.filter(mirror => mirror.network.url == networkUrl)

if (packetMirrors.length > 0) {
console.log(chalk.blue("Updating the existing Packet Mirroring instance instead of creating new."))
Expand Down

0 comments on commit d34d74b

Please sign in to comment.