Skip to content

Commit

Permalink
feat: make safety check for region
Browse files Browse the repository at this point in the history
  • Loading branch information
1101-1 committed Nov 25, 2024
1 parent 9527132 commit fce7179
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions plugins/gcp/fix_plugin_gcp/resources/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,20 @@ def _standard_edges(self, node: GcpResourceType, source: Optional[Json] = None)
if node._region:
self.add_edge(node, node=node._region, reverse=True)
return True
if "locations" in node.id:
parts = node.id.split("/")
loc_index = parts.index("locations")
if loc_index + 1 < len(parts):
location_name = parts[loc_index + 1]

parts = node.id.split("/")
if len(parts) > 3 and parts[0] == "projects":
location_types = ["locations", "zones", "regions"]
if parts[2] in location_types:
location_name = parts[3]
# Check for zone first
if zone := self.zone_by_name.get(location_name):
node._zone = zone
node._region = self.region_by_zone_name.get(zone.id)
self.add_edge(node, node=zone, reverse=True)
return True

# Then check for region
if region := self.region_by_name.get(location_name):
node._region = region
self.add_edge(node, node=region, reverse=True)
Expand Down
2 changes: 1 addition & 1 deletion plugins/gcp/fix_plugin_gcp/resources/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from attr import define, field, frozen

from fix_plugin_gcp.resources.base import GraphBuilder, GcpRegion
from fix_plugin_gcp.resources.base import GraphBuilder
from fix_plugin_gcp.gcp_client import GcpApiSpec
from fixlib.baseresources import MetricName, MetricUnit, BaseResource, StatName
from fixlib.durations import duration_str
Expand Down

0 comments on commit fce7179

Please sign in to comment.