Repository navigation
Expand file tree
/
Copy pathcloud_fields.py
More file actions
153 lines (137 loc) · 4.35 KB
/
Copy pathcloud_fields.py
File metadata and controls
153 lines (137 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"""
Cloud-specific configuration fields for attack range templates.
Defines required/optional fields per provider and fixed option lists for dropdowns
(locations, regions, zones). Used by the API and app when building from a template.
"""
from typing import Any, Dict, List
# AWS regions (common subset; Terraform supports any valid AWS region)
AWS_REGIONS = [
"eu-central-1",
"eu-west-1",
"eu-west-2",
"eu-north-1",
"us-east-1",
"us-east-2",
"us-west-1",
"us-west-2",
"ap-southeast-1",
"ap-southeast-2",
"ap-northeast-1",
"ap-northeast-2",
"sa-east-1",
]
# Azure locations (display names as used in templates and Terraform)
AZURE_LOCATIONS = [
"East US",
"East US 2",
"West US",
"West US 2",
"West US 3",
"West Europe",
"North Europe",
"Central US",
"South Central US",
"UK South",
"France Central",
"Germany West Central",
"Switzerland North",
"Southeast Asia",
"East Asia",
"Australia East",
"Canada Central",
"Brazil South",
]
# GCP regions and zones (region -> list of zones for dependent dropdown)
# Format: list of (region, zone) for flat zone list, or we expose region and zone separately
GCP_REGIONS = [
"europe-west1",
"europe-west2",
"europe-west3",
"europe-west4",
"europe-north1",
"europe-central2",
"us-central1",
"us-east1",
"us-east4",
"us-west1",
"us-west2",
"us-west3",
"us-west4",
"asia-southeast1",
"asia-northeast1",
"australia-southeast1",
]
GCP_ZONES_BY_REGION: Dict[str, List[str]] = {
"europe-west1": ["europe-west1-b", "europe-west1-c", "europe-west1-d"],
"europe-west2": ["europe-west2-a", "europe-west2-b", "europe-west2-c"],
"europe-west3": ["europe-west3-a", "europe-west3-b", "europe-west3-c"],
"europe-west4": ["europe-west4-a", "europe-west4-b", "europe-west4-c"],
"europe-north1": ["europe-north1-a", "europe-north1-b", "europe-north1-c"],
"europe-central2": ["europe-central2-a", "europe-central2-b", "europe-central2-c"],
"us-central1": ["us-central1-a", "us-central1-b", "us-central1-c", "us-central1-f"],
"us-east1": ["us-east1-b", "us-east1-c", "us-east1-d"],
"us-east4": ["us-east4-a", "us-east4-b", "us-east4-c"],
"us-west1": ["us-west1-a", "us-west1-b", "us-west1-c"],
"us-west2": ["us-west2-a", "us-west2-b", "us-west2-c"],
"us-west3": ["us-west3-a", "us-west3-b", "us-west3-c"],
"us-west4": ["us-west4-a", "us-west4-b", "us-west4-c"],
"asia-southeast1": ["asia-southeast1-a", "asia-southeast1-b", "asia-southeast1-c"],
"asia-northeast1": ["asia-northeast1-a", "asia-northeast1-b", "asia-northeast1-c"],
"australia-southeast1": ["australia-southeast1-a", "australia-southeast1-b", "australia-southeast1-c"],
}
def _aws_schema() -> Dict[str, Any]:
return {
"region": {
"label": "Region",
"type": "select",
"options": AWS_REGIONS,
"required": True,
},
}
def _azure_schema() -> Dict[str, Any]:
return {
"location": {
"label": "Location",
"type": "select",
"options": AZURE_LOCATIONS,
"required": True,
},
"subscription_id": {
"label": "Subscription ID",
"type": "text",
"required": True,
},
}
def _gcp_schema() -> Dict[str, Any]:
return {
"project_id": {
"label": "Project ID",
"type": "text",
"required": True,
},
"region": {
"label": "Region",
"type": "select",
"options": GCP_REGIONS,
"required": True,
},
"zone": {
"label": "Zone",
"type": "select",
"options_from_region": True,
"required": True,
},
}
def get_cloud_fields_schema(provider: str) -> Dict[str, Any]:
"""Return the cloud-specific fields schema for a provider (for dropdowns and labels)."""
provider = (provider or "").lower()
if provider == "aws":
return _aws_schema()
if provider == "azure":
return _azure_schema()
if provider == "gcp":
return _gcp_schema()
return {}
def get_gcp_zones_for_region(region: str) -> List[str]:
"""Return list of zones for a GCP region (for dependent dropdown)."""
return GCP_ZONES_BY_REGION.get(region, [])