Skip to content

Commit a4f9926

Browse files
committed
feat: show URL for GitHub resources
1 parent d933470 commit a4f9926

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

backend/application/core/api/serializers_observation.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class ObservationSerializer(ModelSerializer):
9494
references = NestedReferenceSerializer(many=True)
9595
evidences = NestedEvidenceSerializer(many=True)
9696
origin_source_file_url = SerializerMethodField()
97+
origin_cloud_resource_url = SerializerMethodField()
9798
issue_tracker_issue_url = SerializerMethodField()
9899
duplicates = NestedObservationIdSerializer(many=True)
99100
assessment_needs_approval = SerializerMethodField()
@@ -116,6 +117,9 @@ def get_branch_name(self, observation: Observation) -> str:
116117
def get_origin_source_file_url(self, observation: Observation) -> Optional[str]:
117118
return _get_origin_source_file_url(observation)
118119

120+
def get_origin_cloud_resource_url(self, observation: Observation) -> Optional[str]:
121+
return _get_origin_cloud_resource_url(observation)
122+
119123
def get_issue_tracker_issue_url(self, observation: Observation) -> Optional[str]:
120124
issue_url = None
121125

@@ -164,6 +168,7 @@ class ObservationListSerializer(ModelSerializer):
164168
origin_component_name_version = SerializerMethodField()
165169
origin_source_file_short = SerializerMethodField()
166170
origin_source_file_url = SerializerMethodField()
171+
origin_cloud_resource_url = SerializerMethodField()
167172
vulnerability_id_aliases = SerializerMethodField()
168173
cve_found_in = SerializerMethodField()
169174

@@ -195,6 +200,9 @@ def get_origin_source_file_short(self, observation: Observation) -> Optional[str
195200
def get_origin_source_file_url(self, observation: Observation) -> Optional[str]:
196201
return _get_origin_source_file_url(observation)
197202

203+
def get_origin_cloud_resource_url(self, observation: Observation) -> Optional[str]:
204+
return _get_origin_cloud_resource_url(observation)
205+
198206
def get_vulnerability_id_aliases(self, observation: Observation) -> list[dict[str, str]]:
199207
return _get_vulnerability_id_aliases(observation)
200208

@@ -225,6 +233,22 @@ def _get_origin_source_file_url(observation: Observation) -> Optional[str]:
225233
return origin_source_file_url
226234

227235

236+
def _get_origin_cloud_resource_url(observation: Observation) -> Optional[str]:
237+
if (
238+
observation.origin_cloud_provider.lower() == "github"
239+
and observation.origin_cloud_account_subscription_project
240+
and observation.origin_cloud_resource
241+
):
242+
if observation.origin_cloud_resource_type.lower() == "githubrepository":
243+
return (
244+
f"https://github.com/{observation.origin_cloud_account_subscription_project}/"
245+
+ f"{observation.origin_cloud_resource}"
246+
)
247+
if observation.origin_cloud_resource_type.lower() == "githuborganization":
248+
return f"https://github.com/{observation.origin_cloud_resource}"
249+
return None
250+
251+
228252
def _create_azure_devops_url(observation: Observation, origin_source_file_url: str) -> str:
229253
origin_source_file_url += f"?path={observation.origin_source_file}"
230254
if observation.branch:

backend/application/import_observations/parsers/ocsf/parser.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,14 @@ def get_origins(finding: DetectionFinding) -> list[Origin]:
128128
)
129129
elif finding.cloud:
130130
account_name = ""
131-
if finding.cloud.account:
131+
if finding.finding_info.uid.startswith("prowler-github") and finding.cloud.region:
132+
account_name = finding.cloud.region
133+
elif finding.cloud.account:
132134
account_name = finding.cloud.account.name
133135
for resource in finding.resources:
134136
origins.append(
135137
Origin(
136-
origin_cloud_provider=finding.cloud.provider.capitalize(),
138+
origin_cloud_provider=get_provider(finding.cloud.provider),
137139
origin_cloud_account_subscription_project=account_name,
138140
origin_cloud_resource=resource.name,
139141
origin_cloud_resource_type=resource.type,
@@ -143,6 +145,14 @@ def get_origins(finding: DetectionFinding) -> list[Origin]:
143145
return origins
144146

145147

148+
def get_provider(provider: str) -> str:
149+
if provider.lower() == "github":
150+
return "GitHub"
151+
if provider.lower() == "aws":
152+
return "AWS"
153+
return provider.capitalize()
154+
155+
146156
def get_description(finding: DetectionFinding) -> str:
147157
description = finding.finding_info.desc
148158

frontend/src/core/observations/ObservationShowOrigins.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,12 @@ const ObservationShowOrigins = ({ observation, showDependencies, elevated }: Obs
211211
)}
212212
{observation.origin_cloud_resource != "" && (
213213
<Labeled>
214-
<TextField source="origin_cloud_resource" label="Resource" />
214+
<TextUrlField
215+
text={observation.origin_cloud_resource}
216+
url={observation.origin_cloud_resource_url}
217+
label="Resource"
218+
new_tab={true}
219+
/>
215220
</Labeled>
216221
)}
217222
</Stack>

0 commit comments

Comments
 (0)