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

fix: do not require calls of _reload endpoint #1547

Merged
merged 7 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand All @@ -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:
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class MultipleModelEndpointBuilder(RestEndpointBuilder):
models=[
{models}
],
need_reload={need_reload},
)


Expand All @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class SingleModelEndpointBuilder(RestEndpointBuilder):
endpoint = SingleModel(
'{conf_name}',
model,
config_name='{config_name}'
config_name='{config_name}',
need_reload={need_reload},
)


Expand All @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"])
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"])
Expand Down
2 changes: 1 addition & 1 deletion splunk_add_on_ucc_framework/install_python_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@
endpoint = SingleModel(
'splunk_ta_uccexample_account',
model,
config_name='account'
config_name='account',
need_reload=False,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
model_logging,
model_custom_abc
],
need_reload=False,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@
endpoint = SingleModel(
'splunk_ta_uccexample_account',
model,
config_name='account'
config_name='account',
need_reload=False,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
model_logging,
model_custom_abc
],
need_reload=False,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
96 changes: 96 additions & 0 deletions tests/unit/test_endpoint.py
Original file line number Diff line number Diff line change
@@ -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,
)
"""
)
4 changes: 2 additions & 2 deletions tests/unit/test_install_python_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(
Expand Down
Loading