diff --git a/docs/inputs/index.md b/docs/inputs/index.md index 7abceb562..09ccfcf00 100644 --- a/docs/inputs/index.md +++ b/docs/inputs/index.md @@ -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 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 e5ec4f47e..41f53048c 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 @@ -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( @@ -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, diff --git a/splunk_add_on_ucc_framework/schema/schema.json b/splunk_add_on_ucc_framework/schema/schema.json index 74271bbe4..1999b670f 100644 --- a/splunk_add_on_ucc_framework/schema/schema.json +++ b/splunk_add_on_ucc_framework/schema/schema.json @@ -807,7 +807,7 @@ "encrypted": { "$ref": "#/definitions/encrypted" }, - "validators":{ + "validators": { "$ref": "#/definitions/AnyValidator" }, "options": { @@ -2299,7 +2299,7 @@ "modifyFieldsOnValue": { "$ref": "#/definitions/modifyFieldsOnValue" }, - "validators":{ + "validators": { "$ref": "#/definitions/AnyValidator" } }, @@ -2544,7 +2544,7 @@ ], "additionalProperties": false }, - "AnyValidator":{ + "AnyValidator": { "type": "array", "description": "It is used to validate the values of fields using various validators.", "items": { @@ -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" } @@ -3216,7 +3221,7 @@ "table", "entity" ] - }, + }, "hideForPlatform": { "$ref": "#/definitions/HideForPlatform" } @@ -3335,7 +3340,7 @@ ], "additionalProperties": false }, - "HideForPlatform":{ + "HideForPlatform": { "description": "Defines for which platform element should be hidden from UI perspective.", "anyOf": [ { 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 32b840bb9..7950d7d2d 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 @@ -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 %} 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 8076a01e8..0eef4d91c 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 @@ -9,6 +9,7 @@ python.version = python3 [example_input_four] python.version = python3 +disabled = true [service_hidden_for_cloud] python.version = python3 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 08fd75367..8ec3bff2d 100644 --- a/tests/testdata/test_addons/package_global_config_everything/globalConfig.json +++ b/tests/testdata/test_addons/package_global_config_everything/globalConfig.json @@ -1606,7 +1606,8 @@ "required": true } ], - "title": "Example Input Four" + "title": "Example Input Four", + "disableNewInput": true }, { "name": "service_hidden_for_cloud", @@ -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" 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 eb65885f4..1e0f2d040 100644 --- a/tests/unit/generators/conf_files/test_create_inputs_conf.py +++ b/tests/unit/generators/conf_files/test_create_inputs_conf.py @@ -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( diff --git a/tests/unit/testdata/valid_config.json b/tests/unit/testdata/valid_config.json index 28a5010bc..e98ed556a 100644 --- a/tests/unit/testdata/valid_config.json +++ b/tests/unit/testdata/valid_config.json @@ -890,7 +890,9 @@ "options": { "isExpandable": true }, - "fields": ["collectFolderMetadata"] + "fields": [ + "collectFolderMetadata" + ] } ], "rows": [ @@ -902,7 +904,10 @@ "validators": [ { "type": "number", - "range": [1, 1200] + "range": [ + 1, + 1200 + ] } ] } @@ -968,7 +973,10 @@ "validators": [ { "type": "number", - "range": [1, 1200] + "range": [ + 1, + 1200 + ] } ] } @@ -1009,7 +1017,9 @@ "isExpandable": true, "expand": true }, - "fields": ["collectFolderCollaboration"] + "fields": [ + "collectFolderCollaboration" + ] }, { "label": "Group 3", @@ -1017,7 +1027,9 @@ "isExpandable": true, "expand": true }, - "fields": ["collectFolderMetadata"] + "fields": [ + "collectFolderMetadata" + ] } ], "rows": [ @@ -1090,7 +1102,10 @@ "validators": [ { "type": "number", - "range": [1, 60] + "range": [ + 1, + 60 + ] } ] } @@ -1099,7 +1114,8 @@ } } ], - "title": "Example Input Two" + "title": "Example Input Two", + "disableNewInput": true } ], "title": "Inputs", @@ -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" } ] } diff --git a/ui/src/types/globalConfig/pages.ts b/ui/src/types/globalConfig/pages.ts index 5fdf3bc84..aed9c7704 100644 --- a/ui/src/types/globalConfig/pages.ts +++ b/ui/src/types/globalConfig/pages.ts @@ -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(), });