Skip to content

Commit 58daeec

Browse files
GCP CLI tooling (#75)
1 parent 0fb62a4 commit 58daeec

File tree

6 files changed

+2170
-6
lines changed

6 files changed

+2170
-6
lines changed

cli/package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metlo/cli",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"license": "MIT",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -11,6 +11,9 @@
1111
"build": "tsc",
1212
"watch": "tsc -w",
1313
"dev": "nodemon -r tsconfig-paths/register src/index.ts init",
14+
"cli-gcp": "nodemon -r tsconfig-paths/register src/index.ts traffic-mirror gcp",
15+
"cli-aws": "nodemon -r tsconfig-paths/register src/index.ts traffic-mirror aws",
16+
"cli-gcp-prod": "node dist/index.js traffic-mirror gcp",
1417
"format": "prettier --write './src/**/*.{ts,tsx}'"
1518
},
1619
"devDependencies": {
@@ -23,17 +26,21 @@
2326
"dependencies": {
2427
"@aws-sdk/client-ec2": "^3.198.0",
2528
"@aws-sdk/client-sts": "^3.198.0",
29+
"@google-cloud/compute": "^3.5.1",
2630
"@metlo/testing": "^0.0.3",
31+
"@types/chalk": "^2.2.0",
2732
"@types/valid-url": "^1.0.3",
33+
"async-retry": "^1.3.3",
2834
"axios": "^0.27.2",
2935
"chalk": "^4.1.2",
3036
"commander": "^9.4.0",
3137
"dotenv": "^16.0.2",
3238
"enquirer": "^2.3.6",
3339
"nodemon": "^2.0.19",
40+
"ora": "^5.4.1",
3441
"ts-node": "^10.9.1",
3542
"tsconfig-paths": "^4.1.0",
3643
"tslib": "^2.4.0",
3744
"valid-url": "^1.0.9"
3845
}
39-
}
46+
}

cli/src/gcp/gcpUtils.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { GCP_CONN } from "./gcp_apis"
2+
import AsyncRetry from "async-retry"
3+
4+
export async function wait_for_global_operation(operation_id, conn: GCP_CONN) {
5+
return await AsyncRetry(
6+
async (f, at) => {
7+
let resp = await conn.get_global_operation_status(operation_id)
8+
if (resp[0].status === "DONE") {
9+
return resp
10+
} else {
11+
throw Error("Couldn't fetch global operation")
12+
}
13+
},
14+
{ retries: 5 },
15+
)
16+
}
17+
18+
export async function wait_for_regional_operation(
19+
operation_id,
20+
conn: GCP_CONN,
21+
) {
22+
return await AsyncRetry(
23+
async (f, at) => {
24+
let resp = await conn.get_regional_operation_status(operation_id)
25+
26+
if (resp[0].status === "DONE") {
27+
return resp
28+
} else {
29+
throw Error("Couldn't fetch regional operation")
30+
}
31+
},
32+
{ retries: 5 },
33+
)
34+
}
35+
36+
export async function wait_for_zonal_operation(operation_id, conn: GCP_CONN) {
37+
return await AsyncRetry(
38+
async (f, at) => {
39+
let resp = await conn.get_zonal_operation_status(operation_id)
40+
if (resp[0].status === "DONE") {
41+
return resp
42+
} else {
43+
throw Error("Couldn't fetch regional operation")
44+
}
45+
},
46+
{ retries: 5 },
47+
)
48+
}
49+
50+
export const GCP_REGIONS_SUPPORTED = [
51+
"us-west4-c",
52+
"us-west4-b",
53+
"us-west4-a",
54+
"us-west3-c",
55+
"us-west3-b",
56+
"us-west3-a",
57+
"us-west2-c",
58+
"us-west2-b",
59+
"us-west2-a",
60+
"us-west1-c",
61+
"us-west1-b",
62+
"us-west1-a",
63+
"us-south1-c",
64+
"us-south1-b",
65+
"us-south1-a",
66+
"us-east5-c",
67+
"us-east5-b",
68+
"us-east5-a",
69+
"us-east4-c",
70+
"us-east4-b",
71+
"us-east4-a",
72+
"us-east1-d",
73+
"us-east1-c",
74+
"us-east1-b",
75+
"us-central1-f",
76+
"us-central1-c",
77+
"us-central1-b",
78+
"us-central1-a",
79+
]

0 commit comments

Comments
 (0)