Skip to content

Commit

Permalink
GCP CLI tooling (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
AHarmlessPyro authored Nov 8, 2022
1 parent 0fb62a4 commit 58daeec
Show file tree
Hide file tree
Showing 6 changed files with 2,170 additions and 6 deletions.
11 changes: 9 additions & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metlo/cli",
"version": "0.0.2",
"version": "0.0.3",
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -11,6 +11,9 @@
"build": "tsc",
"watch": "tsc -w",
"dev": "nodemon -r tsconfig-paths/register src/index.ts init",
"cli-gcp": "nodemon -r tsconfig-paths/register src/index.ts traffic-mirror gcp",
"cli-aws": "nodemon -r tsconfig-paths/register src/index.ts traffic-mirror aws",
"cli-gcp-prod": "node dist/index.js traffic-mirror gcp",
"format": "prettier --write './src/**/*.{ts,tsx}'"
},
"devDependencies": {
Expand All @@ -23,17 +26,21 @@
"dependencies": {
"@aws-sdk/client-ec2": "^3.198.0",
"@aws-sdk/client-sts": "^3.198.0",
"@google-cloud/compute": "^3.5.1",
"@metlo/testing": "^0.0.3",
"@types/chalk": "^2.2.0",
"@types/valid-url": "^1.0.3",
"async-retry": "^1.3.3",
"axios": "^0.27.2",
"chalk": "^4.1.2",
"commander": "^9.4.0",
"dotenv": "^16.0.2",
"enquirer": "^2.3.6",
"nodemon": "^2.0.19",
"ora": "^5.4.1",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.1.0",
"tslib": "^2.4.0",
"valid-url": "^1.0.9"
}
}
}
79 changes: 79 additions & 0 deletions cli/src/gcp/gcpUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { GCP_CONN } from "./gcp_apis"
import AsyncRetry from "async-retry"

export async function wait_for_global_operation(operation_id, conn: GCP_CONN) {
return await AsyncRetry(
async (f, at) => {
let resp = await conn.get_global_operation_status(operation_id)
if (resp[0].status === "DONE") {
return resp
} else {
throw Error("Couldn't fetch global operation")
}
},
{ retries: 5 },
)
}

export async function wait_for_regional_operation(
operation_id,
conn: GCP_CONN,
) {
return await AsyncRetry(
async (f, at) => {
let resp = await conn.get_regional_operation_status(operation_id)

if (resp[0].status === "DONE") {
return resp
} else {
throw Error("Couldn't fetch regional operation")
}
},
{ retries: 5 },
)
}

export async function wait_for_zonal_operation(operation_id, conn: GCP_CONN) {
return await AsyncRetry(
async (f, at) => {
let resp = await conn.get_zonal_operation_status(operation_id)
if (resp[0].status === "DONE") {
return resp
} else {
throw Error("Couldn't fetch regional operation")
}
},
{ retries: 5 },
)
}

export const GCP_REGIONS_SUPPORTED = [
"us-west4-c",
"us-west4-b",
"us-west4-a",
"us-west3-c",
"us-west3-b",
"us-west3-a",
"us-west2-c",
"us-west2-b",
"us-west2-a",
"us-west1-c",
"us-west1-b",
"us-west1-a",
"us-south1-c",
"us-south1-b",
"us-south1-a",
"us-east5-c",
"us-east5-b",
"us-east5-a",
"us-east4-c",
"us-east4-b",
"us-east4-a",
"us-east1-d",
"us-east1-c",
"us-east1-b",
"us-central1-f",
"us-central1-c",
"us-central1-b",
"us-central1-a",
]
Loading

0 comments on commit 58daeec

Please sign in to comment.