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: add default values of entities to inputs.conf #1530

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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":
Expand All @@ -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()}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a NIT: f-strings can be omitted here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out, made the changes.

}
)
else:
self.default_value_info[service["name"]].update(
{f"{entity['field']}": f"{str(entity['defaultValue'])}"}
)

self.input_names.append({service["name"]: properties})

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need this double for and if. This would be enough:

{% for item, value in default_values[input_name].items() %}
{{item}} = {{value}}
{% endfor %}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the changes

{% for item, value in values.items() %}
{{item}} = {{value}}
{% endfor %}
{% endif %}
{% endfor %}
{% endfor %}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,4 +24,4 @@ disabled = true
python.version = python3

[service_hidden_for_enterprise]
python.version = python3
python.version = python3
3 changes: 3 additions & 0 deletions tests/unit/generators/conf_files/test_create_inputs_conf.py
kkedziak-splunk marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading