Skip to content

Commit

Permalink
feat: add option to disable inputs on creation (#1510)
Browse files Browse the repository at this point in the history
**Issue number:** ADDON-75879

### PR Type

**What kind of change does this PR introduce?**
* [x] Feature
* [ ] Bug Fix
* [x] Refactoring (no functional or API changes)
* [x] Documentation Update
* [ ] Maintenance (dependency updates, CI, etc.)

## Summary
Added a new argument so that users can disable their newly created input
of a service.

### Changes
Introduced a new argument (`disableNewInput`) in services, so that users
can specify whether a service's new input should be disabled on creation
or not.

### User experience
Users can now have disabled inputs on creation, If they mention
`disableNewInput = True` in their globalConfig.


## Checklist

If an item doesn't apply to your changes, leave it unchecked.

* [x] I have performed a self-review of this change according to the
[development
guidelines](https://splunk.github.io/addonfactory-ucc-generator/contributing/#development-guidelines)
* [x] Tests have been added/modified to cover the changes [(testing
doc)](https://splunk.github.io/addonfactory-ucc-generator/contributing/#build-and-test)
* [x] Changes are documented
* [x] PR title and description follows the [contributing
principles](https://splunk.github.io/addonfactory-ucc-generator/contributing/#pull-requests)
  • Loading branch information
hetangmodi-crest authored Jan 3, 2025
1 parent dcdb201 commit df3c5a5
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 36 deletions.
1 change: 1 addition & 0 deletions docs/inputs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ provided, a dropdown field will appear on the Inputs page. In contrast, a button
| [restHandlerModule](../advanced/custom_rest_handler.md) | string | It specify name of the REST handler script that implements the custom actions to be performed on CRUD operations for the given input. (Use with restHandlerClass) |
| [restHandlerClass](../advanced/custom_rest_handler.md) | string | It specify name of the class present in the restHandlerModule, which implements methods like handleCreate, handleEdit, handleList, handleDelete and is child class of splunktaucclib.rest_handler.admin_external.AdminExternalHandler. (Use with restHandlerModule) |
| hideForPlatform | string | Defines for which platform element should be hidden from UI perspective. Currently only two platforms are supported `cloud` or `enterprise`. |
| disableNewInput | boolean | Specifies whether a service's new input should be disabled on creation or not. If set to `True`, any new input created from the service will remain disabled until manually enabled by the user. Default: false |

### Usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ def _set_attributes(self, **kwargs: Any) -> None:
self.conf_file = "inputs.conf"
self.conf_spec_file = f"{self.conf_file}.spec"
self.input_names: List[Dict[str, List[str]]] = []
self.disable = False
self.service_name = ""
if self._global_config:
for service in self._global_config.inputs:
properties = []
if service.get("disableNewInput"):
self.disable = True
self.service_name = service["name"]
if service.get("conf") is not None:
# Add data input of self defined conf to inputs.conf.spec
self.input_names.append(
Expand Down Expand Up @@ -62,7 +67,9 @@ def generate_conf(self) -> Union[Dict[str, str], None]:
template_file_path=["conf_files"], file_name="inputs_conf.template"
)

rendered_content = self._template.render(input_names=stanzas)
rendered_content = self._template.render(
input_names=stanzas, disabled=self.disable, service_name=self.service_name
)
self.writer(
file_name=self.conf_file,
file_path=file_path,
Expand Down
15 changes: 10 additions & 5 deletions splunk_add_on_ucc_framework/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@
"encrypted": {
"$ref": "#/definitions/encrypted"
},
"validators":{
"validators": {
"$ref": "#/definitions/AnyValidator"
},
"options": {
Expand Down Expand Up @@ -2299,7 +2299,7 @@
"modifyFieldsOnValue": {
"$ref": "#/definitions/modifyFieldsOnValue"
},
"validators":{
"validators": {
"$ref": "#/definitions/AnyValidator"
}
},
Expand Down Expand Up @@ -2544,7 +2544,7 @@
],
"additionalProperties": false
},
"AnyValidator":{
"AnyValidator": {
"type": "array",
"description": "It is used to validate the values of fields using various validators.",
"items": {
Expand Down Expand Up @@ -3094,6 +3094,11 @@
"warning": {
"$ref": "#/definitions/WarningMessage"
},
"disableNewInput": {
"type": "boolean",
"description": "Defines whether a newly created input of a service should be disabled by default.",
"default": false
},
"hideForPlatform": {
"$ref": "#/definitions/HideForPlatform"
}
Expand Down Expand Up @@ -3216,7 +3221,7 @@
"table",
"entity"
]
},
},
"hideForPlatform": {
"$ref": "#/definitions/HideForPlatform"
}
Expand Down Expand Up @@ -3335,7 +3340,7 @@
],
"additionalProperties": false
},
"HideForPlatform":{
"HideForPlatform": {
"description": "Defines for which platform element should be hidden from UI perspective.",
"anyOf": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{% for input_name in input_names %}
{{ "[" ~ input_name ~ "]"}}
python.version = python3
{% if disabled and service_name == input_name%}
disabled = true
{% endif %}
{% endfor %}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ python.version = python3

[example_input_four]
python.version = python3
disabled = true

[service_hidden_for_cloud]
python.version = python3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,8 @@
"required": true
}
],
"title": "Example Input Four"
"title": "Example Input Four",
"disableNewInput": true
},
{
"name": "service_hidden_for_cloud",
Expand Down Expand Up @@ -1906,10 +1907,10 @@
"meta": {
"name": "Splunk_TA_UCCExample",
"restRoot": "splunk_ta_uccexample",
"version": "5.53.2+ed749a5ec",
"version": "5.55.0+e45124ce1",
"displayName": "Splunk UCC test Add-on",
"schemaVersion": "0.0.9",
"_uccVersion": "5.53.2",
"_uccVersion": "5.55.0",
"supportedThemes": [
"light",
"dark"
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/generators/conf_files/test_create_inputs_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ def test_set_attributes_without_conf_key_and_name_field(
)
inputs_conf._global_config = MagicMock()
inputs_conf._global_config.inputs = [
{"name": "service1", "entity": [{"field": "name"}]}
{"name": "service1", "entity": [{"field": "name"}], "disableNewInput": True}
]

inputs_conf._set_attributes()

expected_output: List[Dict[str, List[str]]] = [{"service1": []}]
assert inputs_conf.input_names == expected_output
assert inputs_conf.disable is True
assert inputs_conf.service_name == "service1"


def test_set_attributes_without_conf_key_and_other_fields(
Expand Down
68 changes: 42 additions & 26 deletions tests/unit/testdata/valid_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,9 @@
"options": {
"isExpandable": true
},
"fields": ["collectFolderMetadata"]
"fields": [
"collectFolderMetadata"
]
}
],
"rows": [
Expand All @@ -902,7 +904,10 @@
"validators": [
{
"type": "number",
"range": [1, 1200]
"range": [
1,
1200
]
}
]
}
Expand Down Expand Up @@ -968,7 +973,10 @@
"validators": [
{
"type": "number",
"range": [1, 1200]
"range": [
1,
1200
]
}
]
}
Expand Down Expand Up @@ -1009,15 +1017,19 @@
"isExpandable": true,
"expand": true
},
"fields": ["collectFolderCollaboration"]
"fields": [
"collectFolderCollaboration"
]
},
{
"label": "Group 3",
"options": {
"isExpandable": true,
"expand": true
},
"fields": ["collectFolderMetadata"]
"fields": [
"collectFolderMetadata"
]
}
],
"rows": [
Expand Down Expand Up @@ -1090,7 +1102,10 @@
"validators": [
{
"type": "number",
"range": [1, 60]
"range": [
1,
60
]
}
]
}
Expand All @@ -1099,7 +1114,8 @@
}
}
],
"title": "Example Input Two"
"title": "Example Input Two",
"disableNewInput": true
}
],
"title": "Inputs",
Expand Down Expand Up @@ -1315,29 +1331,29 @@
"schemaVersion": "0.0.3",
"os-dependentLibraries": [
{
"name": "cryptography",
"version": "41.0.5",
"platform": "win_amd64",
"python_version": "37",
"os": "windows",
"target": "3rdparty/windows"
"name": "cryptography",
"version": "41.0.5",
"platform": "win_amd64",
"python_version": "37",
"os": "windows",
"target": "3rdparty/windows"
},
{
"name": "cryptography",
"version": "41.0.5",
"platform": "macosx_10_12_universal2",
"python_version": "37",
"os": "darwin",
"target": "3rdparty/darwin"
"name": "cryptography",
"version": "41.0.5",
"platform": "macosx_10_12_universal2",
"python_version": "37",
"os": "darwin",
"target": "3rdparty/darwin"
},
{
"name": "cryptography",
"version": "41.0.5",
"dependencies": true,
"platform": "manylinux2014_x86_64",
"python_version": "37",
"os": "linux",
"target": "3rdparty/linux"
"name": "cryptography",
"version": "41.0.5",
"dependencies": true,
"platform": "manylinux2014_x86_64",
"python_version": "37",
"os": "linux",
"target": "3rdparty/linux"
}
]
}
Expand Down
1 change: 1 addition & 0 deletions ui/src/types/globalConfig/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const TableLessServiceSchema = z.object({
restHandlerClass: z.string().optional(),
warning: WarningSchema,
inputHelperModule: z.string().optional(),
disableNewInput: z.boolean().optional(),
hideForPlatform: z.enum(['cloud', 'enterprise']).optional(),
});

Expand Down

0 comments on commit df3c5a5

Please sign in to comment.