From 66df44ea900ad15e0e038d742cd98951ff9cbcf6 Mon Sep 17 00:00:00 2001 From: hetangmodi-crest Date: Thu, 16 Jan 2025 12:43:18 +0530 Subject: [PATCH 1/3] feat: add default values of entity in inputs.conf --- .../conf_files/create_inputs_conf.py | 18 +++++++++++++++++- .../templates/conf_files/inputs_conf.template | 7 +++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/splunk_add_on_ucc_framework/generators/conf_files/create_inputs_conf.py b/splunk_add_on_ucc_framework/generators/conf_files/create_inputs_conf.py index 122afcb1b..b31c23e90 100644 --- a/splunk_add_on_ucc_framework/generators/conf_files/create_inputs_conf.py +++ b/splunk_add_on_ucc_framework/generators/conf_files/create_inputs_conf.py @@ -30,6 +30,7 @@ def _set_attributes(self, **kwargs: Any) -> None: self.input_names: List[Dict[str, List[str]]] = [] self.disable = False self.service_name = "" + self.default_value_info: Dict[str, Dict[str, str]] = {} if self._global_config: for service in self._global_config.inputs: properties = [] @@ -42,6 +43,7 @@ def _set_attributes(self, **kwargs: Any) -> None: {service["name"]: ["placeholder = placeholder"]} ) continue + self.default_value_info[service["name"]] = {} for entity in service.get("entity", {"field": "name"}): # TODO: add the details and updates on what to skip and process if entity["field"] == "name": @@ -52,6 +54,17 @@ def _set_attributes(self, **kwargs: Any) -> None: f"{entity['field']} = {entity.get('help', '').replace(nl, ' ')} " f"{'' if entity.get('defaultValue') is None else ' Default: ' + str(entity['defaultValue'])}" ) + if entity.get("defaultValue"): + if type(entity["defaultValue"]) is bool: + self.default_value_info[service["name"]].update( + { + f"{entity['field']}": f"{str(entity['defaultValue']).lower()}" + } + ) + else: + self.default_value_info[service["name"]].update( + {f"{entity['field']}": f"{str(entity['defaultValue'])}"} + ) self.input_names.append({service["name"]: properties}) @@ -68,7 +81,10 @@ def generate_conf(self) -> Union[Dict[str, str], None]: ) rendered_content = self._template.render( - input_names=stanzas, disabled=self.disable, service_name=self.service_name + input_names=stanzas, + disabled=self.disable, + service_name=self.service_name, + default_values=self.default_value_info, ) self.writer( file_name=self.conf_file, diff --git a/splunk_add_on_ucc_framework/templates/conf_files/inputs_conf.template b/splunk_add_on_ucc_framework/templates/conf_files/inputs_conf.template index 7950d7d2d..be64ce06f 100644 --- a/splunk_add_on_ucc_framework/templates/conf_files/inputs_conf.template +++ b/splunk_add_on_ucc_framework/templates/conf_files/inputs_conf.template @@ -4,4 +4,11 @@ python.version = python3 {% if disabled and service_name == input_name%} disabled = true {% endif %} +{% for key, values in default_values.items() %} +{% if key == input_name %} +{% for item, value in values.items() %} +{{item}} = {{value}} +{% endfor %} +{% endif %} +{% endfor %} {% endfor %} From 0c061af5ec10636b3e30bdc1368b9f3b50d5dae6 Mon Sep 17 00:00:00 2001 From: hetangmodi-crest Date: Thu, 16 Jan 2025 12:43:58 +0530 Subject: [PATCH 2/3] tests: update unit and smoke testcase --- .../Splunk_TA_UCCExample/default/inputs.conf | 11 ++++++++++- .../generators/conf_files/test_create_inputs_conf.py | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/default/inputs.conf b/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/default/inputs.conf index 0eef4d91c..cf700b74c 100644 --- a/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/default/inputs.conf +++ b/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/default/inputs.conf @@ -1,8 +1,17 @@ [example_input_one] python.version = python3 +input_one_checkbox = true +input_one_radio = yes +multipleSelectTest = a|b +index = default +order_by = LastModifiedDate +use_existing_checkpoint = yes +limit = 1000 [example_input_two] python.version = python3 +index = default +use_existing_checkpoint = yes [example_input_three] python.version = python3 @@ -15,4 +24,4 @@ disabled = true python.version = python3 [service_hidden_for_enterprise] -python.version = python3 \ No newline at end of file +python.version = python3 diff --git a/tests/unit/generators/conf_files/test_create_inputs_conf.py b/tests/unit/generators/conf_files/test_create_inputs_conf.py index 1e0f2d040..da5feb5e9 100644 --- a/tests/unit/generators/conf_files/test_create_inputs_conf.py +++ b/tests/unit/generators/conf_files/test_create_inputs_conf.py @@ -123,6 +123,9 @@ def test_set_attributes_without_conf_key_and_other_fields( expected_output = [{"service1": ["other_field = help text Default: default_val"]}] assert inputs_conf.input_names == expected_output + assert inputs_conf.default_value_info == { + "service1": {"other_field": "default_val"} + } @patch( From 68d98be4747fa42c60057f7f895c47b31e7a9216 Mon Sep 17 00:00:00 2001 From: hetangmodi-crest Date: Tue, 4 Feb 2025 11:12:51 +0530 Subject: [PATCH 3/3] chore: remove redundant f-strings --- .../generators/conf_files/create_inputs_conf.py | 4 +--- .../templates/conf_files/inputs_conf.template | 6 +----- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/splunk_add_on_ucc_framework/generators/conf_files/create_inputs_conf.py b/splunk_add_on_ucc_framework/generators/conf_files/create_inputs_conf.py index b31c23e90..8c23b5293 100644 --- a/splunk_add_on_ucc_framework/generators/conf_files/create_inputs_conf.py +++ b/splunk_add_on_ucc_framework/generators/conf_files/create_inputs_conf.py @@ -57,9 +57,7 @@ def _set_attributes(self, **kwargs: Any) -> None: if entity.get("defaultValue"): if type(entity["defaultValue"]) is bool: self.default_value_info[service["name"]].update( - { - f"{entity['field']}": f"{str(entity['defaultValue']).lower()}" - } + {entity["field"]: str(entity["defaultValue"]).lower()} ) else: self.default_value_info[service["name"]].update( diff --git a/splunk_add_on_ucc_framework/templates/conf_files/inputs_conf.template b/splunk_add_on_ucc_framework/templates/conf_files/inputs_conf.template index be64ce06f..379c1027a 100644 --- a/splunk_add_on_ucc_framework/templates/conf_files/inputs_conf.template +++ b/splunk_add_on_ucc_framework/templates/conf_files/inputs_conf.template @@ -4,11 +4,7 @@ python.version = python3 {% if disabled and service_name == input_name%} disabled = true {% endif %} -{% for key, values in default_values.items() %} -{% if key == input_name %} -{% for item, value in values.items() %} +{% for item, value in default_values[input_name].items() %} {{item}} = {{value}} {% endfor %} -{% endif %} -{% endfor %} {% endfor %}