Skip to content

Commit 8ab77b7

Browse files
authored
fix(gcp): check check_name has no resource_name error (#9169)
1 parent e038b2f commit 8ab77b7

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

prowler/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ All notable changes to the **Prowler SDK** are documented in this file.
3636
- Update AWS CodeArtifact service metadata to new format [(#8850)](https://github.com/prowler-cloud/prowler/pull/8850)
3737
- Rename OCI provider to oraclecloud with oci alias [(#9126)](https://github.com/prowler-cloud/prowler/pull/9126)
3838

39+
### Fixed
40+
- Check `check_name` has no `resource_name` error for GCP provider [(#9169)](https://github.com/prowler-cloud/prowler/pull/9169)
41+
3942
---
4043

4144
## [v5.13.1] (Prowler UNRELEASED)

prowler/lib/check/models.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,17 @@ def __init__(
588588
or getattr(resource, "name", None)
589589
or ""
590590
)
591+
592+
# Prefer the explicit resource_name argument, otherwise look for a name attribute on the resource
593+
resource_name_candidate = resource_name or getattr(resource, "name", None)
594+
if not resource_name_candidate and isinstance(resource, dict):
595+
# Some callers pass a dict, so fall back to the dict entry if available
596+
resource_name_candidate = resource.get("name")
597+
if isinstance(resource_name_candidate, str):
598+
# Trim whitespace so empty strings collapse to the default
599+
resource_name_candidate = resource_name_candidate.strip()
591600
self.resource_name = (
592-
resource_name or getattr(resource, "name", "") or "GCP Project"
601+
str(resource_name_candidate) if resource_name_candidate else "GCP Project"
593602
)
594603
self.project_id = project_id or getattr(resource, "project_id", "")
595604
self.location = (

0 commit comments

Comments
 (0)