diff --git a/splunk_add_on_ucc_framework/commands/rest_builder/endpoint/base.py b/splunk_add_on_ucc_framework/commands/rest_builder/endpoint/base.py index 0d620cd92..ff9ee2aa4 100644 --- a/splunk_add_on_ucc_framework/commands/rest_builder/endpoint/base.py +++ b/splunk_add_on_ucc_framework/commands/rest_builder/endpoint/base.py @@ -123,7 +123,7 @@ def generate_rh(self) -> str: class RestEndpointBuilder: - def __init__(self, name: Optional[str], namespace: str, **kwargs: str): + def __init__(self, name: Optional[str], namespace: str, **kwargs: Any): self._name = name self._namespace = namespace self._entities: List[RestEntityBuilder] = [] @@ -144,6 +144,7 @@ def __init__(self, name: Optional[str], namespace: str, **kwargs: str): self._rest_handler_name = f"{self._namespace}_rh_{self._name}" self._rest_handler_module = kwargs.get("rest_handler_module") self._rest_handler_class = kwargs.get("rest_handler_class") + self._need_reload = kwargs.get("need_reload", False) @property def name(self) -> str: @@ -173,6 +174,10 @@ def rh_class(self) -> Optional[str]: def entities(self) -> List[RestEntityBuilder]: return self._entities + @property + def need_reload(self) -> bool: + return self._need_reload + def add_entity(self, entity: RestEntityBuilder) -> None: self._entities.append(entity) diff --git a/splunk_add_on_ucc_framework/commands/rest_builder/endpoint/multiple_model.py b/splunk_add_on_ucc_framework/commands/rest_builder/endpoint/multiple_model.py index ff4aa8061..3cffdbce9 100644 --- a/splunk_add_on_ucc_framework/commands/rest_builder/endpoint/multiple_model.py +++ b/splunk_add_on_ucc_framework/commands/rest_builder/endpoint/multiple_model.py @@ -57,6 +57,7 @@ class MultipleModelEndpointBuilder(RestEndpointBuilder): models=[ {models} ], + need_reload={need_reload}, ) @@ -81,4 +82,5 @@ def generate_rh(self) -> str: entities="\n".join(entities), models=indent(models_lines, 2), conf_name=self.conf_name, + need_reload=self.need_reload, ) diff --git a/splunk_add_on_ucc_framework/commands/rest_builder/endpoint/single_model.py b/splunk_add_on_ucc_framework/commands/rest_builder/endpoint/single_model.py index 24e2c560d..f79bb2af3 100644 --- a/splunk_add_on_ucc_framework/commands/rest_builder/endpoint/single_model.py +++ b/splunk_add_on_ucc_framework/commands/rest_builder/endpoint/single_model.py @@ -62,7 +62,8 @@ class SingleModelEndpointBuilder(RestEndpointBuilder): endpoint = SingleModel( '{conf_name}', model, - config_name='{config_name}' + config_name='{config_name}', + need_reload={need_reload}, ) @@ -85,4 +86,5 @@ def generate_rh(self) -> str: entity=entity.generate_rh(), conf_name=self.conf_name, config_name=self._name, + need_reload=self.need_reload, ) diff --git a/splunk_add_on_ucc_framework/commands/rest_builder/global_config_builder_schema.py b/splunk_add_on_ucc_framework/commands/rest_builder/global_config_builder_schema.py index 4d9ef94ef..8e303ba43 100644 --- a/splunk_add_on_ucc_framework/commands/rest_builder/global_config_builder_schema.py +++ b/splunk_add_on_ucc_framework/commands/rest_builder/global_config_builder_schema.py @@ -84,6 +84,10 @@ def oauth_conf_file_names(self) -> List[str]: def endpoints(self) -> List[RestEndpointBuilder]: return list(self._endpoints.values()) + @property + def need_reload(self) -> bool: + return False + def _parse_builder_schema(self) -> None: self._builder_configs() self._builder_settings() @@ -102,6 +106,7 @@ def _builder_configs(self) -> None: rest_handler_class=config.get( "restHandlerClass", REST_HANDLER_DEFAULT_CLASS ), + need_reload=self.need_reload, ) self._endpoints[name] = endpoint content = self._get_oauth_enitities(config["entity"]) @@ -140,6 +145,7 @@ def _builder_settings(self) -> None: namespace=self.global_config.namespace, rest_handler_module=REST_HANDLER_DEFAULT_MODULE, rest_handler_class=REST_HANDLER_DEFAULT_CLASS, + need_reload=self.need_reload, ) self._endpoints["settings"] = endpoint for setting in self.global_config.settings: @@ -173,6 +179,7 @@ def _builder_inputs(self) -> None: rest_handler_name=rest_handler_name, rest_handler_module=rest_handler_module, rest_handler_class=rest_handler_class, + need_reload=self.need_reload, ) self._endpoints[name] = single_model_endpoint content = self._get_oauth_enitities(input_item["entity"]) diff --git a/splunk_add_on_ucc_framework/install_python_libraries.py b/splunk_add_on_ucc_framework/install_python_libraries.py index d62d74ee4..c0ba0f180 100644 --- a/splunk_add_on_ucc_framework/install_python_libraries.py +++ b/splunk_add_on_ucc_framework/install_python_libraries.py @@ -28,7 +28,7 @@ logger = logging.getLogger("ucc_gen") -LIBS_REQUIRED_FOR_UI = {"splunktaucclib": "6.4.0"} +LIBS_REQUIRED_FOR_UI = {"splunktaucclib": "6.6.0"} LIBS_REQUIRED_FOR_OAUTH = {"solnlib": "5.5.0"} diff --git a/tests/testdata/expected_addons/expected_output_global_config_configuration/Splunk_TA_UCCExample/bin/splunk_ta_uccexample_rh_account.py b/tests/testdata/expected_addons/expected_output_global_config_configuration/Splunk_TA_UCCExample/bin/splunk_ta_uccexample_rh_account.py index 62a50565d..644cda463 100644 --- a/tests/testdata/expected_addons/expected_output_global_config_configuration/Splunk_TA_UCCExample/bin/splunk_ta_uccexample_rh_account.py +++ b/tests/testdata/expected_addons/expected_output_global_config_configuration/Splunk_TA_UCCExample/bin/splunk_ta_uccexample_rh_account.py @@ -152,7 +152,8 @@ endpoint = SingleModel( 'splunk_ta_uccexample_account', model, - config_name='account' + config_name='account', + need_reload=False, ) diff --git a/tests/testdata/expected_addons/expected_output_global_config_configuration/Splunk_TA_UCCExample/bin/splunk_ta_uccexample_rh_settings.py b/tests/testdata/expected_addons/expected_output_global_config_configuration/Splunk_TA_UCCExample/bin/splunk_ta_uccexample_rh_settings.py index 701ec38f1..6076fa044 100644 --- a/tests/testdata/expected_addons/expected_output_global_config_configuration/Splunk_TA_UCCExample/bin/splunk_ta_uccexample_rh_settings.py +++ b/tests/testdata/expected_addons/expected_output_global_config_configuration/Splunk_TA_UCCExample/bin/splunk_ta_uccexample_rh_settings.py @@ -172,6 +172,7 @@ model_logging, model_custom_abc ], + need_reload=False, ) diff --git a/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/bin/splunk_ta_uccexample_rh_account.py b/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/bin/splunk_ta_uccexample_rh_account.py index a321bc1c2..784538f3f 100644 --- a/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/bin/splunk_ta_uccexample_rh_account.py +++ b/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/bin/splunk_ta_uccexample_rh_account.py @@ -239,7 +239,8 @@ endpoint = SingleModel( 'splunk_ta_uccexample_account', model, - config_name='account' + config_name='account', + need_reload=False, ) diff --git a/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/bin/splunk_ta_uccexample_rh_settings.py b/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/bin/splunk_ta_uccexample_rh_settings.py index 90d173b7c..17f2c3e3a 100644 --- a/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/bin/splunk_ta_uccexample_rh_settings.py +++ b/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/bin/splunk_ta_uccexample_rh_settings.py @@ -177,6 +177,7 @@ model_logging, model_custom_abc ], + need_reload=False, ) diff --git a/tests/testdata/test_addons/package_files_conflict_test/globalConfig.json b/tests/testdata/test_addons/package_files_conflict_test/globalConfig.json index 184d29cb3..091fea5d7 100644 --- a/tests/testdata/test_addons/package_files_conflict_test/globalConfig.json +++ b/tests/testdata/test_addons/package_files_conflict_test/globalConfig.json @@ -199,7 +199,7 @@ "meta": { "name": "test_addon", "restRoot": "test_addon", - "version": "5.56.0+12f4cd8cd", + "version": "5.57.0+f11804ebf", "displayName": "This is my add-on", "schemaVersion": "0.0.9" } diff --git a/tests/testdata/test_addons/package_global_config_everything/globalConfig.json b/tests/testdata/test_addons/package_global_config_everything/globalConfig.json index bb730aadc..2b9977ff2 100644 --- a/tests/testdata/test_addons/package_global_config_everything/globalConfig.json +++ b/tests/testdata/test_addons/package_global_config_everything/globalConfig.json @@ -1897,7 +1897,7 @@ "meta": { "name": "Splunk_TA_UCCExample", "restRoot": "splunk_ta_uccexample", - "version": "5.56.0+12f4cd8cd", + "version": "5.57.0+f11804ebf", "displayName": "Splunk UCC test Add-on", "schemaVersion": "0.0.9", "supportedThemes": [ diff --git a/tests/testdata/test_addons/package_global_config_everything_uccignore/globalConfig.json b/tests/testdata/test_addons/package_global_config_everything_uccignore/globalConfig.json index aa7624300..2f1d5859a 100644 --- a/tests/testdata/test_addons/package_global_config_everything_uccignore/globalConfig.json +++ b/tests/testdata/test_addons/package_global_config_everything_uccignore/globalConfig.json @@ -1246,7 +1246,7 @@ "meta": { "name": "Splunk_TA_UCCExample", "restRoot": "splunk_ta_uccexample", - "version": "5.56.0+12f4cd8cd", + "version": "5.57.0+f11804ebf", "displayName": "Splunk UCC test Add-on", "schemaVersion": "0.0.9" } diff --git a/tests/testdata/test_addons/package_global_config_multi_input/globalConfig.json b/tests/testdata/test_addons/package_global_config_multi_input/globalConfig.json index 582030268..33a4d317a 100644 --- a/tests/testdata/test_addons/package_global_config_multi_input/globalConfig.json +++ b/tests/testdata/test_addons/package_global_config_multi_input/globalConfig.json @@ -769,7 +769,7 @@ "meta": { "name": "Splunk_TA_UCCExample", "restRoot": "splunk_ta_uccexample", - "version": "5.56.0+12f4cd8cd", + "version": "5.57.0+f11804ebf", "displayName": "Splunk UCC test Add-on", "schemaVersion": "0.0.9" } diff --git a/tests/testdata/test_addons/package_global_config_only_one_tab/globalConfig.json b/tests/testdata/test_addons/package_global_config_only_one_tab/globalConfig.json index 4dad66c1c..9edc96a6b 100644 --- a/tests/testdata/test_addons/package_global_config_only_one_tab/globalConfig.json +++ b/tests/testdata/test_addons/package_global_config_only_one_tab/globalConfig.json @@ -36,7 +36,7 @@ "meta": { "name": "Splunk_TA_UCCExample", "restRoot": "splunk_ta_uccexample", - "version": "5.56.0+12f4cd8cd", + "version": "5.57.0+f11804ebf", "displayName": "Splunk UCC test Add-on", "schemaVersion": "0.0.9" } diff --git a/tests/unit/test_endpoint.py b/tests/unit/test_endpoint.py new file mode 100644 index 000000000..aea455c07 --- /dev/null +++ b/tests/unit/test_endpoint.py @@ -0,0 +1,96 @@ +from textwrap import dedent + +import pytest + +from splunk_add_on_ucc_framework.commands.rest_builder.endpoint.multiple_model import ( + MultipleModelEndpointBuilder, +) +from splunk_add_on_ucc_framework.commands.rest_builder.endpoint.single_model import ( + SingleModelEndpointBuilder, + SingleModelEntityBuilder, +) + + +@pytest.mark.parametrize("need_reload", [True, False]) +def test_multiple_model_endpoint_builder_need_reload(need_reload): + endpoint = MultipleModelEndpointBuilder("test", "test", need_reload=need_reload) + assert endpoint.generate_rh() == dedent( + f""" + import import_declare_test + + from splunktaucclib.rest_handler.endpoint import ( + field, + validator, + RestModel, + MultipleModel, + ) + from splunktaucclib.rest_handler import admin_external, util + from None import None + import logging + + util.remove_http_proxy_env_vars() + + + + endpoint = MultipleModel( + 'test_test', + models=[ + + ], + need_reload={need_reload}, + ) + + + if __name__ == '__main__': + logging.getLogger().addHandler(logging.NullHandler()) + admin_external.handle( + endpoint, + handler=None, + ) + """ + ) + + +@pytest.mark.parametrize("need_reload", [True, False]) +def test_single_model_endpoint_builder_need_reload(need_reload): + endpoint = SingleModelEndpointBuilder("test", "test", need_reload=need_reload) + endpoint.add_entity(SingleModelEntityBuilder("test_entity", [])) + assert endpoint.generate_rh() == dedent( + f""" + import import_declare_test + + from splunktaucclib.rest_handler.endpoint import ( + field, + validator, + RestModel, + SingleModel, + ) + from splunktaucclib.rest_handler import admin_external, util + from None import None + import logging + + util.remove_http_proxy_env_vars() + + + fields = [ + + ] + model = RestModel(fields, name='test_entity') + + + endpoint = SingleModel( + 'test_test', + model, + config_name='test', + need_reload={need_reload}, + ) + + + if __name__ == '__main__': + logging.getLogger().addHandler(logging.NullHandler()) + admin_external.handle( + endpoint, + handler=None, + ) + """ + ) diff --git a/tests/unit/test_install_python_libraries.py b/tests/unit/test_install_python_libraries.py index f16e60135..7e5968531 100644 --- a/tests/unit/test_install_python_libraries.py +++ b/tests/unit/test_install_python_libraries.py @@ -160,7 +160,7 @@ def test_install_libraries_when_no_splunktaucclib_is_present_but_has_ui(tmp_path expected_msg = ( f"This add-on has an UI, so the splunktaucclib is required but not found in {tmp_lib_reqs_file}. " - f"Please add it there and make sure it is at least version 6.4.0." + f"Please add it there and make sure it is at least version 6.6.0." ) with pytest.raises(SplunktaucclibNotFound) as exc: @@ -180,7 +180,7 @@ def test_install_libraries_when_wrong_splunktaucclib_is_present_but_has_ui(tmp_p tmp_lib_reqs_file = tmp_lib_path / "requirements.txt" tmp_lib_reqs_file.write_text("splunktaucclib==6.3\n") - expected_msg = "splunktaucclib found but has the wrong version. Please make sure it is at least version 6.4.0." + expected_msg = "splunktaucclib found but has the wrong version. Please make sure it is at least version 6.6.0." with pytest.raises(WrongSplunktaucclibVersion) as exc: install_python_libraries(