|
| 1 | +import json |
| 2 | +import pathlib |
| 3 | +from enum import StrEnum |
1 | 4 | from typing import Any
|
2 |
| -from pydantic import Field, Json, model_validator |
3 | 5 |
|
4 |
| -import pathlib |
5 | 6 | from jinja2 import Environment
|
6 |
| -import json |
7 |
| -from contentctl.objects.security_content_object import SecurityContentObject |
| 7 | +from pydantic import Field, Json, model_validator |
| 8 | + |
8 | 9 | from contentctl.objects.config import build
|
9 |
| -from enum import StrEnum |
| 10 | +from contentctl.objects.constants import CONTENTCTL_DASHBOARD_LABEL_TEMPLATE |
| 11 | +from contentctl.objects.security_content_object import SecurityContentObject |
10 | 12 |
|
11 | 13 | DEFAULT_DASHBAORD_JINJA2_TEMPLATE = """<dashboard version="2" theme="{{ dashboard.theme }}">
|
12 | 14 | <label>{{ dashboard.label(config) }}</label>
|
@@ -49,7 +51,9 @@ class Dashboard(SecurityContentObject):
|
49 | 51 | )
|
50 | 52 |
|
51 | 53 | def label(self, config: build) -> str:
|
52 |
| - return f"{config.app.label} - {self.name}" |
| 54 | + return CONTENTCTL_DASHBOARD_LABEL_TEMPLATE.format( |
| 55 | + app_label=config.app.label, dashboard_name=self.name |
| 56 | + ) |
53 | 57 |
|
54 | 58 | @model_validator(mode="before")
|
55 | 59 | @classmethod
|
@@ -98,7 +102,9 @@ def pretty_print_json_obj(self):
|
98 | 102 | return json.dumps(self.json_obj, indent=4)
|
99 | 103 |
|
100 | 104 | def getOutputFilepathRelativeToAppRoot(self, config: build) -> pathlib.Path:
|
101 |
| - filename = f"{self.file_path.stem}.xml".lower() |
| 105 | + # for clarity, the name of the dashboard file will follow the same convention |
| 106 | + # as we use for detections, prefixing it with app_name - |
| 107 | + filename = f"{self.label(config)}.xml" |
102 | 108 | return pathlib.Path("default/data/ui/views") / filename
|
103 | 109 |
|
104 | 110 | def writeDashboardFile(self, j2_env: Environment, config: build):
|
|
0 commit comments