Skip to content

Commit 0511500

Browse files
authored
Merge pull request #373 from splunk/dashboard_fix
fix dashboard file names
2 parents fcf60ca + 73d1a6e commit 0511500

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

contentctl/objects/constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@
124124
"{app_label} - {detection_name} - Rule"
125125
)
126126

127-
CONTENTCTL_DASHBOARD_LABEL_TEMPLATE = "{app_label} - {dashboard_name}"
128127
CONTENTCTL_BASELINE_STANZA_NAME_FORMAT_TEMPLATE = "{app_label} - {detection_name}"
129128
CONTENTCTL_RESPONSE_TASK_NAME_FORMAT_TEMPLATE = (
130129
"{app_label} - {detection_name} - Response Task"

contentctl/objects/dashboard.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
from pydantic import Field, Json, model_validator
88

99
from contentctl.objects.config import build
10-
from contentctl.objects.constants import CONTENTCTL_DASHBOARD_LABEL_TEMPLATE
1110
from contentctl.objects.security_content_object import SecurityContentObject
1211

1312
DEFAULT_DASHBOARD_JINJA2_TEMPLATE = """<dashboard version="2" theme="{{ dashboard.theme }}">
14-
<label>{{ dashboard.label(config) }}</label>
13+
<label>{{ dashboard.name }}</label>
1514
<description></description>
1615
<definition><![CDATA[
1716
{{ dashboard.pretty_print_json_obj() }}
@@ -50,11 +49,6 @@ class Dashboard(SecurityContentObject):
5049
..., description="Valid JSON object that describes the dashboard"
5150
)
5251

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-
5852
@model_validator(mode="before")
5953
@classmethod
6054
def validate_fields_from_json(cls, data: Any) -> Any:
@@ -102,9 +96,16 @@ def pretty_print_json_obj(self):
10296
return json.dumps(self.json_obj, indent=4)
10397

10498
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+
108109
return pathlib.Path("default/data/ui/views") / filename
109110

110111
def writeDashboardFile(self, j2_env: Environment, config: build):

contentctl/templates/app_template/default/data/ui/nav/default.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<view name="escu_summary" default="true"/>
33
<view name="search"/>
44
<collection label="Dashboards">
5-
<view source="unclassified" match=" - "/>
5+
<view source="unclassified" match="__"/>
66
</collection>
77
</nav>

0 commit comments

Comments
 (0)