From 8ab77b7dbaf4fae9077548d41c3e8ae55e054c48 Mon Sep 17 00:00:00 2001 From: Hugo Pereira Brito <101209179+HugoPBrito@users.noreply.github.com> Date: Thu, 6 Nov 2025 12:37:49 +0100 Subject: [PATCH] fix(gcp): check `check_name` has no `resource_name` error (#9169) --- prowler/CHANGELOG.md | 3 +++ prowler/lib/check/models.py | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/prowler/CHANGELOG.md b/prowler/CHANGELOG.md index fd34a5e1af..7d9f2a9857 100644 --- a/prowler/CHANGELOG.md +++ b/prowler/CHANGELOG.md @@ -36,6 +36,9 @@ All notable changes to the **Prowler SDK** are documented in this file. - Update AWS CodeArtifact service metadata to new format [(#8850)](https://github.com/prowler-cloud/prowler/pull/8850) - Rename OCI provider to oraclecloud with oci alias [(#9126)](https://github.com/prowler-cloud/prowler/pull/9126) +### Fixed +- Check `check_name` has no `resource_name` error for GCP provider [(#9169)](https://github.com/prowler-cloud/prowler/pull/9169) + --- ## [v5.13.1] (Prowler UNRELEASED) diff --git a/prowler/lib/check/models.py b/prowler/lib/check/models.py index 2398dc8267..37150f38db 100644 --- a/prowler/lib/check/models.py +++ b/prowler/lib/check/models.py @@ -588,8 +588,17 @@ class Check_Report_GCP(Check_Report): or getattr(resource, "name", None) or "" ) + + # Prefer the explicit resource_name argument, otherwise look for a name attribute on the resource + resource_name_candidate = resource_name or getattr(resource, "name", None) + if not resource_name_candidate and isinstance(resource, dict): + # Some callers pass a dict, so fall back to the dict entry if available + resource_name_candidate = resource.get("name") + if isinstance(resource_name_candidate, str): + # Trim whitespace so empty strings collapse to the default + resource_name_candidate = resource_name_candidate.strip() self.resource_name = ( - resource_name or getattr(resource, "name", "") or "GCP Project" + str(resource_name_candidate) if resource_name_candidate else "GCP Project" ) self.project_id = project_id or getattr(resource, "project_id", "") self.location = (