Skip to content

Commit 4e29dca

Browse files
add risk score to query-page-generator, template and extract info (#7766)
1 parent 7ce00eb commit 4e29dca

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

.github/scripts/docs-generator/query-page-generator/query-page-generator.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,20 @@ def format_positive_tests(positive_tests : dict) -> str:
153153

154154
return result if result != '' else 'Tests Not Fround'
155155

156+
# Utility for generate ".md" documentation - gets color for a severity level
157+
def get_severity_color(severity : str) -> str:
158+
colors = {'Critical': '#ff0000', 'High': '#bb2124', 'Medium': '#ff7213', 'Low': '#edd57e', 'Info': '#5bc0de', 'Trace': '#CCCCCC'}
159+
return colors.get(severity.capitalize())
160+
156161
# Utility for generate ".md" documentation
157162
def format_severity(severity : str) -> str:
158-
colors = {'Critical': '#ff0000', 'High': '#bb2124', 'Medium': '#ff7213', 'Low': '#edd57e', 'Info': '#5bc0de', 'Trace': '#CCCCCC'}
159-
severity = severity.capitalize()
160-
color = colors.get(severity)
161-
return f'<span style="color:{color}">{severity}</span>'
163+
color = get_severity_color(severity)
164+
return f'<span style="color:{color}">{severity.capitalize()}</span>'
165+
166+
# Utility for generate ".md" documentation - formats risk score with color based on severity
167+
def format_risk_score(risk_score : str, severity : str) -> str:
168+
color = get_severity_color(severity)
169+
return f'<span style="color:{color}">{risk_score}</span>'
162170

163171
# Generates a ".md" file for each query
164172
def generate_md_docs(queries_database : str, output_path : str, template_file_path = 'template.md', delete_folders : bool = False):
@@ -198,6 +206,7 @@ def generate_md_docs(queries_database : str, output_path : str, template_file_pa
198206
'<SEVERITY>', format_severity(query_data.get('severity'))).replace(
199207
'<CATEGORY>', query_data.get('category')).replace(
200208
'<CWE>', cwe).replace(
209+
'<RISKSCORE>', format_risk_score(query_data.get('riskScore'), query_data.get('severity'))).replace(
201210
'<GITHUB_URL>', query_data.get('githubUrl')).replace(
202211
'<DESCRIPTION_TEXT>', query_data.get('descriptionText')).replace(
203212
'<DESCRIPTION_URL>', query_data.get('descriptionUrl')).replace(

.github/scripts/docs-generator/query-page-generator/templates/query-page-template.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ hide:
2121
- **Severity:** <SEVERITY>
2222
- **Category:** <CATEGORY>
2323
- **CWE:** <CWE>
24+
- **Risk score:** <RISKSCORE>
2425
- **URL:** [Github](<GITHUB_URL>)
2526

2627
### Description
@@ -32,4 +33,4 @@ hide:
3233
<POSITIVE_TESTS>
3334

3435
#### Code samples without security vulnerabilities
35-
<NEGATIVE_TESTS>
36+
<NEGATIVE_TESTS>

.github/scripts/extract-kics-info/extract-info.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class Query:
1515
descriptionID: str
1616
aggregation: int
1717
cloudProviderId: int
18+
cwe: str
19+
riskScore: str
1820

1921
def __init__(self, queryData):
2022
self.id = queryData['id']
@@ -25,6 +27,8 @@ def __init__(self, queryData):
2527
self.descriptionUrl = queryData['descriptionUrl']
2628
self.platformId = platforms.getPlatformId(queryData['platform'])
2729
self.descriptionID = queryData['descriptionID']
30+
self.riskScore = queryData['riskScore']
31+
self.cwe = queryData['cwe']
2832
if queryData.__contains__('cloudProvider'):
2933
self.cloudProviderId = cloudProviders.getCloudProviderId(
3034
queryData['cloudProvider'])

0 commit comments

Comments
 (0)