Added argument can now be a list of arguments for list formatting
Artifact lines can now be omitted to show entire file
This commit is contained in:
parent
887fb71a27
commit
ca6fee127c
@ -217,11 +217,11 @@ from typing import TypedDict
|
||||
|
||||
class Artifact(TypedDict):
|
||||
file: str
|
||||
lines: list[int]
|
||||
lines: NotRequired[list[int]]
|
||||
|
||||
class SecurityRule(TypedDict):
|
||||
status: str
|
||||
argument: str
|
||||
argument: str | list[str]
|
||||
artifacts: NotRequired[list[Artifact]]
|
||||
|
||||
rule_schema = yaml.safe_load("""type: object
|
||||
@ -238,10 +238,17 @@ properties:
|
||||
- not applicable
|
||||
- unknown
|
||||
argument:
|
||||
anyOf:
|
||||
- type: string
|
||||
- type: array
|
||||
items:
|
||||
type: string
|
||||
artifacts:
|
||||
type: array
|
||||
items:
|
||||
additionalProperties: no
|
||||
required:
|
||||
- file
|
||||
type: object
|
||||
properties:
|
||||
file:
|
||||
@ -300,16 +307,21 @@ def artifact_to_string(info: ModelInformation, artifact: Artifact):
|
||||
file = Path(artifact['file'])
|
||||
filename = file.name
|
||||
file_url = f"https://github.com/{info['slug']}/blob/{info.get('branch', 'master')}/{artifact['file']}"
|
||||
return f"- {filename}: Line{'s'[:len(artifact['lines'])^1]}: {', '.join(f'[{line}]({file_url}#L{line})' for line in artifact['lines'])}"
|
||||
lines = artifact.get("lines")
|
||||
if lines is None:
|
||||
return f"- {filename}: [File]({file_url})"
|
||||
return f"- {filename}: Line{'s'[:len(lines)^1]}: {', '.join(f'[{line}]({file_url}#L{line})' for line in lines)}"
|
||||
|
||||
|
||||
def rule_to_string(info: ModelInformation, id: int, rule: SecurityRule | None):
|
||||
if rule is None:
|
||||
# warning(f"Rule {id} is missing!") # TODO Enable warning
|
||||
warning(f"Rule {id} is missing!")
|
||||
return ""
|
||||
argument = rule['argument']
|
||||
argument = argument if isinstance(argument, str) else "".join(f"\n1. {arg}" for arg in argument)
|
||||
text = f"""#### Rule {id}: {rule_names[id]}
|
||||
|
||||
This rule is {rule['status']}: {rule['argument']}"""
|
||||
This rule is {rule['status']}: {argument}"""
|
||||
artifacts = rule.get("artifacts", [])
|
||||
if len(artifacts) > 0:
|
||||
text = text + f"""
|
||||
|
@ -16,33 +16,24 @@
|
||||
]
|
||||
},
|
||||
"argument": {
|
||||
"type": "string"
|
||||
"anyOf": [
|
||||
{ "type": "string" },
|
||||
{ "type": "array", "items": { "type": "string" } }
|
||||
]
|
||||
},
|
||||
"artifacts": {
|
||||
"type": "array",
|
||||
"items": [
|
||||
{
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"file": {
|
||||
"type": "string"
|
||||
},
|
||||
"lines": {
|
||||
"type": "array",
|
||||
"items": [
|
||||
{
|
||||
"type": "integer"
|
||||
}
|
||||
]
|
||||
}
|
||||
"file": { "type": "string" },
|
||||
"lines": { "type": "array", "items": { "type": "integer" } }
|
||||
},
|
||||
"required": [
|
||||
"file",
|
||||
"lines"
|
||||
"file"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
Loading…
Reference in New Issue
Block a user