Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make configuration page as optional #1521

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ad3bb71
feat: given support for optional configuration page
hetangmodi-crest Dec 31, 2024
1aba2ef
feat: update ui files for optional configuration
hetangmodi-crest Dec 31, 2024
be85138
feat: update generation logic of configuration.xml
hetangmodi-crest Jan 2, 2025
b0c1d45
test: add unit test cases
hetangmodi-crest Jan 2, 2025
1bb56cc
fix: resolve typescript issue in configuration
rohanm-crest Jan 3, 2025
3995495
docs: updated docs regarding generated conf, xml and html files
srv-rr-github-token Jan 3, 2025
50c7a48
fix: fix congiguration.xml generation
hetangmodi-crest Jan 3, 2025
a4bc679
tests: add unit and smoke test case
hetangmodi-crest Jan 3, 2025
7264003
test: add expected addons ui files
hetangmodi-crest Jan 3, 2025
5a35c20
Merge branch 'develop' into feat/optional-configuration-page
hetangmodi-crest Jan 7, 2025
2b3a9e8
chore: lint fixes
hetangmodi-crest Jan 7, 2025
5c1b6fc
tests: add test addon and expected addon for smoke test
hetangmodi-crest Jan 7, 2025
4898e85
test(smoke): update tests to capture not generated files
hetangmodi-crest Jan 7, 2025
9e51759
Merge remote-tracking branch 'origin/develop' into feat/optional-conf…
vtsvetkov-splunk Jan 8, 2025
ffbe04c
simplify ts code
vtsvetkov-splunk Jan 8, 2025
4f2d411
chore: add validators in inputs
hetangmodi-crest Jan 9, 2025
b8bdccd
docs: updated docs
hetangmodi-crest Jan 9, 2025
0533e39
docs: updated docs regarding generated conf, xml and html files
srv-rr-github-token Jan 9, 2025
fe160a6
chore: update globalConfig file
hetangmodi-crest Jan 9, 2025
1a41cd3
chore: maintain parity across codebase
hetangmodi-crest Jan 9, 2025
38da3f8
tests: updated unit and smoke test case
hetangmodi-crest Jan 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/generated_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ The following table describes the files generated by UCC framework.
| tags.conf | output/<YOUR_ADDON_NAME>/default | Generates `tags.conf` file based on the `eventtypes.conf` created for custom alert actions. |
| _account.conf | output/&lt;YOUR_ADDON_NAME&gt;/README | Generates `<YOUR_ADDON_NAME>_account.conf.spec` file for the configuration mentioned in globalConfig |
| _settings.conf | output/&lt;YOUR_ADDON_NAME&gt;/README | Generates `<YOUR_ADDON_NAME>_settings.conf.spec` file for the Proxy, Logging or Custom Tab mentioned in globalConfig |
| configuration.xml | output/&lt;YOUR_ADDON_NAME&gt;/default/data/ui/views | Generates configuration.xml file in `default/data/ui/views/` folder if globalConfig is present. |
| dashboard.xml | output/&lt;YOUR_ADDON_NAME&gt;/default/data/ui/views | Generates dashboard.xml file based on dashboard configuration present in globalConfig in `default/data/ui/views` folder. |
| default.xml | output/&lt;YOUR_ADDON_NAME&gt;/default/data/ui/nav | Generates default.xml file based on configs present in globalConfigin in `default/data/ui/nav` folder. |
| configuration.xml | output/&lt;YOUR_ADDON_NAME&gt;/default/data/ui/views | Generates configuration.xml file in `default/data/ui/views/` folder if configuration is defined in globalConfig. |
| dashboard.xml | output/&lt;YOUR_ADDON_NAME&gt;/default/data/ui/views | Generates dashboard.xml file based on dashboard configuration present in globalConfig, in `default/data/ui/views` folder. |
| default.xml | output/&lt;YOUR_ADDON_NAME&gt;/default/data/ui/nav | Generates default.xml file based on configs present in globalConfig, in `default/data/ui/nav` folder. |
| inputs.xml | output/&lt;YOUR_ADDON_NAME&gt;/default/data/ui/views | Generates inputs.xml based on inputs configuration present in globalConfig, in `default/data/ui/views/inputs.xml` folder |
| _redirect.xml | output/&lt;YOUR_ADDON_NAME&gt;/default/data/ui/views | Generates ta_name_redirect.xml file, if oauth is mentioned in globalConfig,in `default/data/ui/views/` folder. |
| _.html | output/&lt;YOUR_ADDON_NAME&gt;/default/data/ui/alerts | Generates `alert_name.html` file based on alerts configuration present in globalConfig in `default/data/ui/alerts` folder. |
| _redirect.xml | output/&lt;YOUR_ADDON_NAME&gt;/default/data/ui/views | Generates ta_name_redirect.xml file, if oauth is mentioned in globalConfig, in `default/data/ui/views/` folder. |
| _.html | output/&lt;YOUR_ADDON_NAME&gt;/default/data/ui/alerts | Generates `alert_name.html` file based on alerts configuration present in globalConfig, in `default/data/ui/alerts` folder. |

Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,17 @@ def __add_schemas_object(
) -> OpenAPIObject:
if open_api_object.components is not None:
open_api_object.components.schemas = {}
for tab in global_config.pages.configuration.tabs: # type: ignore[attr-defined]
schema_name, schema_object = __get_schema_object(
name=tab.name, entities=tab.entity
)
open_api_object.components.schemas[schema_name] = schema_object
schema_name, schema_object = __get_schema_object(
name=tab.name, entities=tab.entity, without=["name"]
)
open_api_object.components.schemas[schema_name] = schema_object
pages = getattr(global_config, "pages", None)
if hasattr(pages, "configuration"):
for tab in global_config.pages.configuration.tabs: # type: ignore[attr-defined]
schema_name, schema_object = __get_schema_object(
name=tab.name, entities=tab.entity
)
open_api_object.components.schemas[schema_name] = schema_object
schema_name, schema_object = __get_schema_object(
name=tab.name, entities=tab.entity, without=["name"]
)
open_api_object.components.schemas[schema_name] = schema_object
if hasattr(global_config.pages, "inputs") and hasattr( # type: ignore[attr-defined]
global_config.pages.inputs, "services" # type: ignore[attr-defined]
):
Expand Down Expand Up @@ -378,18 +380,20 @@ def __assign_ta_paths(
def __add_paths(
open_api_object: OpenAPIObject, global_config: DataClasses
) -> OpenAPIObject:
for tab in global_config.pages.configuration.tabs: # type: ignore[attr-defined]
open_api_object = __assign_ta_paths(
open_api_object=open_api_object,
path=f"/{global_config.meta.restRoot}_{tab.name}" # type: ignore[attr-defined]
if hasattr(tab, "table")
else f"/{global_config.meta.restRoot}_settings/{tab.name}", # type: ignore[attr-defined]
path_name=tab.name,
actions=tab.table.actions
if hasattr(tab, "table") and hasattr(tab.table, "actions")
else None,
page=GloblaConfigPages.CONFIGURATION,
)
pages = getattr(global_config, "pages", None)
if hasattr(pages, "configuration"):
for tab in global_config.pages.configuration.tabs: # type: ignore[attr-defined]
open_api_object = __assign_ta_paths(
open_api_object=open_api_object,
path=f"/{global_config.meta.restRoot}_{tab.name}" # type: ignore[attr-defined]
if hasattr(tab, "table")
else f"/{global_config.meta.restRoot}_settings/{tab.name}", # type: ignore[attr-defined]
path_name=tab.name,
actions=tab.table.actions
if hasattr(tab, "table") and hasattr(tab.table, "actions")
else None,
page=GloblaConfigPages.CONFIGURATION,
)
if hasattr(global_config.pages, "inputs") and hasattr( # type: ignore[attr-defined]
global_config.pages.inputs, "services" # type: ignore[attr-defined]
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def _parse_builder_schema(self) -> None:
self._builder_inputs()

def _builder_configs(self) -> None:
if not self.global_config.has_configuration():
return
for config in self.global_config.configs:
name = config["name"]
endpoint = SingleModelEndpointBuilder(
Expand Down
21 changes: 15 additions & 6 deletions splunk_add_on_ucc_framework/data_ui_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ def _pretty_print_xml(string: str) -> str:


def generate_nav_default_xml(
include_inputs: bool, include_dashboard: bool, default_view: str
include_inputs: bool,
include_dashboard: bool,
include_configuration: bool,
default_view: str,
) -> str:
"""
Generates `default/data/ui/nav/default.xml` file.
Expand All @@ -40,14 +43,20 @@ def generate_nav_default_xml(
"""
nav = ET.Element("nav")
if include_inputs:
if default_view == "inputs":
if (
not (include_configuration) and default_view == "configuration"
) or default_view == "inputs":
ET.SubElement(nav, "view", attrib={"name": "inputs", "default": "true"})
else:
ET.SubElement(nav, "view", attrib={"name": "inputs"})
if default_view == "configuration":
ET.SubElement(nav, "view", attrib={"name": "configuration", "default": "true"})
else:
ET.SubElement(nav, "view", attrib={"name": "configuration"})

if include_configuration:
if default_view == "configuration":
ET.SubElement(
nav, "view", attrib={"name": "configuration", "default": "true"}
)
else:
ET.SubElement(nav, "view", attrib={"name": "configuration"})
if include_dashboard:
if default_view == "dashboard":
ET.SubElement(nav, "view", attrib={"name": "dashboard", "default": "true"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

class AlertActionsHtml(HTMLGenerator):
__description__ = (
"Generates `alert_name.html` file based on alerts configuration present in globalConfig"
"Generates `alert_name.html` file based on alerts configuration present in globalConfig,"
" in `default/data/ui/alerts` folder."
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,27 @@
# limitations under the License.
#
from splunk_add_on_ucc_framework.generators.xml_files import XMLGenerator
from typing import Any, Dict
from typing import Any, Dict, Union
from splunk_add_on_ucc_framework import data_ui_generator


class ConfigurationXml(XMLGenerator):
__description__ = "Generates configuration.xml file in `default/data/ui/views/` folder if globalConfig is present."
__description__ = (
"Generates configuration.xml file in `default/data/ui/views/` folder if "
"configuration is defined in globalConfig."
)

def _set_attributes(self, **kwargs: Any) -> None:
self.configuration_xml_content = (
data_ui_generator.generate_views_configuration_xml(
self._addon_name,
if self._global_config and self._global_config.has_configuration():
self.configuration_xml_content = (
data_ui_generator.generate_views_configuration_xml(
self._addon_name,
)
)
)

def generate_xml(self) -> Dict[str, str]:
def generate_xml(self) -> Union[Dict[str, str], None]:
if self._global_config and not self._global_config.has_configuration():
return None
file_path = self.get_file_output_path(
["default", "data", "ui", "views", "configuration.xml"]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class DashboardXml(XMLGenerator):
__description__ = (
"Generates dashboard.xml file based on dashboard configuration present in globalConfig"
"Generates dashboard.xml file based on dashboard configuration present in globalConfig,"
" in `default/data/ui/views` folder."
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

class DefaultXml(XMLGenerator):
__description__ = (
"Generates default.xml file based on configs present in globalConfig"
"in in `default/data/ui/nav` folder."
"Generates default.xml file based on configs present in globalConfig,"
" in `default/data/ui/nav` folder."
)

def _set_attributes(self, **kwargs: Any) -> None:
Expand All @@ -45,6 +45,7 @@ def _set_attributes(self, **kwargs: Any) -> None:
self.default_xml_content = data_ui_generator.generate_nav_default_xml(
include_inputs=self._global_config.has_inputs(),
include_dashboard=self._global_config.has_dashboard(),
include_configuration=self._global_config.has_configuration(),
default_view=self._global_config.meta.get(
"default_view", data_ui_generator.DEFAULT_VIEW
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class RedirectXml(XMLGenerator):
__description__ = (
"Generates ta_name_redirect.xml file, if oauth is mentioned in globalConfig,"
"in `default/data/ui/views/` folder."
" in `default/data/ui/views/` folder."
)

def _set_attributes(self, **kwargs: Any) -> None:
Expand Down
16 changes: 12 additions & 4 deletions splunk_add_on_ucc_framework/global_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@ def expand(self) -> None:
self.expand_entities()

def expand_tabs(self) -> None:
for i, tab in enumerate(self._content["pages"]["configuration"]["tabs"]):
self._content["pages"]["configuration"]["tabs"][i] = resolve_tab(tab)
if self.has_configuration():
for i, tab in enumerate(self._content["pages"]["configuration"]["tabs"]):
self._content["pages"]["configuration"]["tabs"][i] = resolve_tab(tab)

def expand_entities(self) -> None:
self._expand_entities(self._content["pages"]["configuration"]["tabs"])
self._expand_entities(
self._content["pages"].get("configuration", {}).get("tabs")
)
self._expand_entities(self._content["pages"].get("inputs", {}).get("services"))
self._expand_entities(self._content.get("alerts"))

Expand All @@ -117,7 +120,9 @@ def inputs(self) -> List[Any]:

@property
def tabs(self) -> List[Any]:
return self._content["pages"]["configuration"]["tabs"]
if "configuration" in self._content["pages"]:
return self._content["pages"]["configuration"]["tabs"]
return []

@property
def dashboard(self) -> Dict[str, Any]:
Expand Down Expand Up @@ -207,6 +212,9 @@ def add_ucc_version(self, version: str) -> None:
def has_inputs(self) -> bool:
return bool(self.inputs)

def has_configuration(self) -> bool:
return bool(self.tabs)

def has_alerts(self) -> bool:
return bool(self.alerts)

Expand Down
7 changes: 4 additions & 3 deletions splunk_add_on_ucc_framework/global_config_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,10 @@ def _dump_with_migrated_entities(
_collapse_entities(
global_config.content["pages"].get("inputs", {}).get("services"), entity_type
)
_collapse_entities(
global_config.content["pages"]["configuration"].get("tabs"), entity_type
)
if global_config.has_configuration():
_collapse_entities(
global_config.content["pages"]["configuration"].get("tabs"), entity_type
)
_collapse_entities(global_config.content.get("alerts"), entity_type)

_dump(global_config.content, path, global_config._is_global_config_yaml)
Expand Down
29 changes: 17 additions & 12 deletions splunk_add_on_ucc_framework/global_config_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ def __init__(self, source_dir: str, global_config: global_config_lib.GlobalConfi
self._config = global_config.content

@property
def config_tabs(self) -> List[Tab]:
return [
resolve_tab(tab) for tab in self._config["pages"]["configuration"]["tabs"]
]
def config_tabs(self) -> List[Any]:
if self._global_config.has_configuration():
return [
resolve_tab(tab)
for tab in self._config["pages"]["configuration"]["tabs"]
]
return []

def _validate_config_against_schema(self) -> None:
"""
Expand Down Expand Up @@ -249,10 +252,11 @@ def _validate_validators(self) -> None:
number and regex are supported.
"""
pages = self._config["pages"]
for tab in self.config_tabs:
entities = tab["entity"]
for entity in entities:
self._validate_entity_validators(entity)
if pages.get("configuration"):
for tab in self.config_tabs:
entities = tab["entity"]
for entity in entities:
self._validate_entity_validators(entity)

inputs = pages.get("inputs")
if inputs is None:
Expand Down Expand Up @@ -430,8 +434,8 @@ def _validate_duplicates(self) -> None:
not required in schema, so this checks if globalConfig has inputs
"""
pages = self._config["pages"]

self._validate_tabs_duplicates(self.config_tabs)
if pages.get("configuration"):
self._validate_tabs_duplicates(self.config_tabs)

inputs = pages.get("inputs")
if inputs:
Expand Down Expand Up @@ -711,9 +715,10 @@ def _validate_meta_default_view(self) -> None:

def validate(self) -> None:
self._validate_config_against_schema()
self._validate_configuration_tab_table_has_name_field()
if self._global_config.has_configuration():
self._validate_configuration_tab_table_has_name_field()
self._validate_file_type_entity()
self._validate_custom_rest_handlers()
self._validate_file_type_entity()
self._validate_validators()
self._validate_multilevel_menu()
self._validate_duplicates()
Expand Down
3 changes: 0 additions & 3 deletions splunk_add_on_ucc_framework/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2553,9 +2553,6 @@
"$ref": "#/definitions/DashboardPage"
}
},
"required": [
"configuration"
],
"additionalProperties": false
},
"RegexValidator": {
Expand Down
Loading
Loading