Skip to content

Commit ff0a28e

Browse files
refactor: move config tabs method in GlobalConfig class (#1595)
**Issue number:** ADDON-78036 ### PR Type **What kind of change does this PR introduce?** * [ ] Feature * [ ] Bug Fix * [x] Refactoring (no functional or API changes) * [ ] Documentation Update * [ ] Maintenance (dependency updates, CI, etc.) ## Summary Made `config_tabs` (which is a method in `global_config_validator.py`) as a part of `GlobalConfig` class. ### Changes Made the `config_tabs` method part of the `GlobalConfig` class and renamed the previous `tabs` method in GlobalConfig to `configuration`. ### User experience ## Checklist If an item doesn't apply to your changes, leave it unchecked. * [x] I have performed a self-review of this change according to the [development guidelines](https://splunk.github.io/addonfactory-ucc-generator/contributing/#development-guidelines) * [ ] Tests have been added/modified to cover the changes [(testing doc)](https://splunk.github.io/addonfactory-ucc-generator/contributing/#build-and-test) * [ ] Changes are documented * [x] PR title and description follows the [contributing principles](https://splunk.github.io/addonfactory-ucc-generator/contributing/#pull-requests)
1 parent f1b1068 commit ff0a28e

File tree

5 files changed

+31
-31
lines changed

5 files changed

+31
-31
lines changed

splunk_add_on_ucc_framework/global_config.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,22 @@ def inputs(self) -> List[Any]:
122122
return self._content["pages"]["inputs"]["services"]
123123
return []
124124

125+
@property
126+
def configuration(self) -> List[Any]:
127+
if self.has_pages() and "configuration" in self._content["pages"]:
128+
return self._content["pages"]["configuration"]["tabs"]
129+
return []
130+
125131
@property
126132
def pages(self) -> List[Any]:
127133
if "pages" in self._content:
128134
return self._content["pages"]
129135
return []
130136

131137
@property
132-
def tabs(self) -> List[Any]:
133-
if self.has_pages() and "configuration" in self._content["pages"]:
134-
return self._content["pages"]["configuration"]["tabs"]
138+
def resolved_configuration(self) -> List[Any]:
139+
if self.has_pages() and "configuration" in self.pages:
140+
return [resolve_tab(tab) for tab in self.configuration]
135141
return []
136142

137143
@property
@@ -141,22 +147,22 @@ def dashboard(self) -> Dict[str, Any]:
141147
@property
142148
def settings(self) -> List[Any]:
143149
settings = []
144-
for tab in self.tabs:
150+
for tab in self.configuration:
145151
if "table" not in tab:
146152
settings.append(tab)
147153
return settings
148154

149155
@property
150156
def logging_tab(self) -> Dict[str, Any]:
151-
for tab in self.tabs:
157+
for tab in self.configuration:
152158
if LoggingTab.from_definition(tab) is not None:
153159
return tab
154160
return {}
155161

156162
@property
157163
def configs(self) -> List[Any]:
158164
configs = []
159-
for tab in self.tabs:
165+
for tab in self.configuration:
160166
if "table" in tab:
161167
configs.append(tab)
162168
return configs
@@ -226,7 +232,7 @@ def has_inputs(self) -> bool:
226232
return bool(self.inputs)
227233

228234
def has_configuration(self) -> bool:
229-
return bool(self.tabs)
235+
return bool(self.configuration)
230236

231237
def has_alerts(self) -> bool:
232238
return bool(self.alerts)
@@ -235,7 +241,7 @@ def has_dashboard(self) -> bool:
235241
return self.dashboard is not None
236242

237243
def has_oauth(self) -> bool:
238-
for tab in self.tabs:
244+
for tab in self.configuration:
239245
if tab["name"] == "account":
240246
for entity in tab["entity"]:
241247
if entity["type"] == "oauth":

splunk_add_on_ucc_framework/global_config_update.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def _handle_biased_terms(conf_entities: List[Dict[str, Any]]) -> List[Dict[str,
5656

5757

5858
def _handle_biased_terms_update(global_config: global_config_lib.GlobalConfig) -> None:
59-
for tab in global_config.tabs:
59+
for tab in global_config.configuration:
6060
conf_entities = tab.get("entity")
6161

6262
if conf_entities is None:
@@ -151,7 +151,7 @@ def handle_global_config_update(global_config: global_config_lib.GlobalConfig) -
151151
logger.info("Updated globalConfig schema to version 0.0.1")
152152

153153
if _version_tuple(version) < _version_tuple("0.0.2"):
154-
for tab in global_config.tabs:
154+
for tab in global_config.configuration:
155155
if tab.get("type") in ["loggingTab", "proxyTab"]:
156156
continue
157157
if tab["name"] == "account":
@@ -325,7 +325,7 @@ def _stop_build_on_placeholder_usage(
325325
"`placeholder` option found for %s '%s'. It has been removed from UCC. "
326326
"We recommend to use `help` instead (https://splunk.github.io/addonfactory-ucc-generator/entity/)."
327327
)
328-
for tab in global_config.tabs:
328+
for tab in global_config.configuration:
329329
for entity in tab.get("entity", []):
330330
if "placeholder" in entity.get("options", {}):
331331
logger.error(

splunk_add_on_ucc_framework/global_config_validator.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from splunk_add_on_ucc_framework import dashboard as dashboard_lib
2727
from splunk_add_on_ucc_framework import global_config as global_config_lib
28-
from splunk_add_on_ucc_framework.tabs import resolve_tab, Tab
28+
from splunk_add_on_ucc_framework.tabs import Tab
2929
from splunk_add_on_ucc_framework.exceptions import GlobalConfigValidatorException
3030

3131
logger = logging.getLogger("ucc_gen")
@@ -51,15 +51,7 @@ def __init__(self, source_dir: str, global_config: global_config_lib.GlobalConfi
5151
self._source_dir = source_dir
5252
self._global_config = global_config
5353
self._config = global_config.content
54-
55-
@property
56-
def config_tabs(self) -> List[Any]:
57-
if self._global_config.has_configuration():
58-
return [
59-
resolve_tab(tab)
60-
for tab in self._config["pages"]["configuration"]["tabs"]
61-
]
62-
return []
54+
self.resolved_configuration = global_config.resolved_configuration
6355

6456
def _validate_config_against_schema(self) -> None:
6557
"""
@@ -80,7 +72,7 @@ def _validate_configuration_tab_table_has_name_field(self) -> None:
8072
Validates that if a configuration tab should be rendered as a table,
8173
then it needs to have an entity which has field "name".
8274
"""
83-
for tab in self.config_tabs:
75+
for tab in self.resolved_configuration:
8476
if "table" in tab:
8577
entities = tab["entity"]
8678
has_name_field = False
@@ -141,7 +133,7 @@ def _validate_file_type_entity(self) -> None:
141133
Also if file is encrypted but not required, this is not supported,
142134
and we need to throw a validation error.
143135
"""
144-
for tab in self.config_tabs:
136+
for tab in self.resolved_configuration:
145137
entities = tab["entity"]
146138
for entity in entities:
147139
if entity["type"] == "file":
@@ -251,7 +243,7 @@ def _validate_validators(self) -> None:
251243
number and regex are supported.
252244
"""
253245
pages = self._config["pages"]
254-
for tab in self.config_tabs:
246+
for tab in self.resolved_configuration:
255247
entities = tab["entity"]
256248
for entity in entities:
257249
self._validate_entity_validators(entity)
@@ -432,7 +424,7 @@ def _validate_duplicates(self) -> None:
432424
not required in schema, so this checks if globalConfig has inputs
433425
"""
434426
pages = self._config["pages"]
435-
self._validate_tabs_duplicates(self.config_tabs)
427+
self._validate_tabs_duplicates(self.resolved_configuration)
436428

437429
inputs = pages.get("inputs")
438430
if inputs:

tests/unit/test_global_config.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ def test_global_config_expand(tmp_path):
104104

105105
global_config = global_config_lib.GlobalConfig(global_config_path)
106106

107-
assert {"type": "loggingTab"} in global_config.tabs
107+
assert {"type": "loggingTab"} in global_config.configuration
108108
assert count_tabs(global_config, name="logging") == 0
109109
assert count_entities(global_config, type="interval") == 3
110110
assert count_entities(global_config, type="text", field="interval") == 0
111111

112112
global_config.expand()
113113

114-
assert {"type": "loggingTab"} not in global_config.tabs
114+
assert {"type": "loggingTab"} not in global_config.configuration
115115
assert count_tabs(global_config, name="logging") == 1
116116
assert count_entities(global_config, type="interval") == 0
117117
assert count_entities(global_config, type="text", field="interval") == 3
@@ -153,7 +153,7 @@ def test_global_config_add_ucc_version(global_config_only_logging, tmp_path):
153153

154154

155155
def all_entities(gc: global_config_lib.GlobalConfig) -> Iterator[Any]:
156-
objects = itertools.chain(gc.tabs, gc.alerts, gc.inputs)
156+
objects = itertools.chain(gc.configuration, gc.alerts, gc.inputs)
157157
return itertools.chain(*(obj["entity"] for obj in objects if "entity" in obj))
158158

159159

@@ -167,5 +167,7 @@ def count_entities(gc: global_config_lib.GlobalConfig, **kwargs: str) -> int:
167167

168168
def count_tabs(gc: global_config_lib.GlobalConfig, **kwargs: str) -> int:
169169
return sum(
170-
1 for tab in gc.tabs if all(tab.get(k, "") == v for k, v in kwargs.items())
170+
1
171+
for tab in gc.configuration
172+
if all(tab.get(k, "") == v for k, v in kwargs.items())
171173
)

tests/unit/test_global_config_update.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ def test_handle_biased_terms_update(filename):
5050
input_entity_2_options_keys = global_config.inputs[0]["entity"][1]["options"].keys()
5151
assert "allowList" in input_entity_2_options_keys
5252
assert "whileList" not in input_entity_2_options_keys
53-
configuration_entity_1_options_keys = global_config.tabs[0]["entity"][0][
53+
configuration_entity_1_options_keys = global_config.configuration[0]["entity"][0][
5454
"options"
5555
].keys()
5656
assert "denyList" in configuration_entity_1_options_keys
5757
assert "blackList" not in configuration_entity_1_options_keys
58-
configuration_entity_2_options_keys = global_config.tabs[0]["entity"][1][
58+
configuration_entity_2_options_keys = global_config.configuration[0]["entity"][1][
5959
"options"
6060
].keys()
6161
assert "allowList" in configuration_entity_2_options_keys

0 commit comments

Comments
 (0)