|
7 | 7 | from pydantic import Field, Json, model_validator
|
8 | 8 |
|
9 | 9 | from contentctl.objects.config import build
|
10 |
| -from contentctl.objects.constants import CONTENTCTL_DASHBOARD_LABEL_TEMPLATE |
11 | 10 | from contentctl.objects.security_content_object import SecurityContentObject
|
12 | 11 |
|
13 | 12 | DEFAULT_DASHBOARD_JINJA2_TEMPLATE = """<dashboard version="2" theme="{{ dashboard.theme }}">
|
14 |
| - <label>{{ dashboard.label(config) }}</label> |
| 13 | + <label>{{ dashboard.name }}</label> |
15 | 14 | <description></description>
|
16 | 15 | <definition><![CDATA[
|
17 | 16 | {{ dashboard.pretty_print_json_obj() }}
|
@@ -50,11 +49,6 @@ class Dashboard(SecurityContentObject):
|
50 | 49 | ..., description="Valid JSON object that describes the dashboard"
|
51 | 50 | )
|
52 | 51 |
|
53 |
| - def label(self, config: build) -> str: |
54 |
| - return CONTENTCTL_DASHBOARD_LABEL_TEMPLATE.format( |
55 |
| - app_label=config.app.label, dashboard_name=self.name |
56 |
| - ) |
57 |
| - |
58 | 52 | @model_validator(mode="before")
|
59 | 53 | @classmethod
|
60 | 54 | def validate_fields_from_json(cls, data: Any) -> Any:
|
@@ -102,9 +96,16 @@ def pretty_print_json_obj(self):
|
102 | 96 | return json.dumps(self.json_obj, indent=4)
|
103 | 97 |
|
104 | 98 | def getOutputFilepathRelativeToAppRoot(self, config: build) -> pathlib.Path:
|
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" |
| 99 | + if self.file_path is None: |
| 100 | + raise FileNotFoundError( |
| 101 | + f"Dashboard {self.name} file_path was None. Dashboards must be backed by a file." |
| 102 | + ) |
| 103 | + # Prefix with the appLabel__ in order to make a search for these easy with match="__" |
| 104 | + # in the default.xml file |
| 105 | + filename = f"{config.app.label}__{self.file_path.stem}.xml".lower().replace( |
| 106 | + " ", "_" |
| 107 | + ) |
| 108 | + |
108 | 109 | return pathlib.Path("default/data/ui/views") / filename
|
109 | 110 |
|
110 | 111 | def writeDashboardFile(self, j2_env: Environment, config: build):
|
|
0 commit comments