Skip to content

Commit

Permalink
feat: hide elements for cloud or enterprise (#1364)
Browse files Browse the repository at this point in the history
**Issue number:**
https://splunk.atlassian.net/browse/ADDON-74887
## Summary

### Changes
Adds ability to hide:
1. form fields
2. tabs
3. services
based on platform (cloud vs enterprise)

schema changes: 
- adds `hideForPlatform` ('cloud' or 'enterprise') that hides this
specific element if platform matches declared one

there is a usage of `| rest/services/server/info splunk_server=local`
search to get information about platform.

> Please provide a summary of what's being changed

### User experience

> Please describe what the user experience looks like before and after
this change

## Checklist

If your change doesn't seem to apply, please leave them unchecked.

* [x] I have performed a self-review of this change
* [x] Changes have been tested
* [x] Changes are documented
* [x] PR title follows [conventional commit
semantics](https://www.conventionalcommits.org/en/v1.0.0/)

---------

Signed-off-by: Viktor Tsvetkov <[email protected]>
Co-authored-by: Viktor Tsvetkov <[email protected]>
  • Loading branch information
soleksy-splunk and vtsvetkov-splunk authored Oct 15, 2024
1 parent 82f822b commit 21aa28f
Show file tree
Hide file tree
Showing 49 changed files with 1,834 additions and 165 deletions.
1 change: 1 addition & 0 deletions docs/configurations/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ proxy configuration, and logging level configuration.
| [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) |
| customTab | Object | This property allows you to enable the [custom tab](../custom_ui_extensions/custom_tab.md) feature. |
| hideForPlatform | string | Defines for which platform element should be hidden from UI perspective. Currently only two platforms are supported `cloud` or `enterprise`. |

### Tab components

Expand Down
17 changes: 9 additions & 8 deletions docs/entity/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Entity
## Entity Properties

| Property | Type | Description | Default Value |
|------------------------------------------------------------------|---------------------------|----------------------------------------------------------------------------------------------------------------------------------|---------------|
| ---------------------------------------------------------------- | ------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ------------- |
| field<span class="required-asterisk">\*</span> | string | To define a particular entity field. | - |
| label<span class="required-asterisk">\*</span> | string | It represents a caption for a field in a user interface. | - |
| [type](./components.md)<span class="required-asterisk">\*</span> | string | To specify the type of entity to be rendered in inputs or configuration form. | - |
Expand All @@ -26,10 +26,11 @@ title: Entity

This section describes common options that can be used within the `options` object in entity properties.

| Property | Type | Description | Default Value |
|---------------------|---------|----------------------------------------------------------------------------------------|---------------|
| display | boolean | It chooses whether or not to display the field. | true |
| disableonEdit | boolean | When the form is in edit mode, the field becomes unable to be edited. | false |
| enable | boolean | The enable property sets whether a field is enabled or not. | true |
| requiredWhenVisible | boolean | It makes the field required on the UI when it appears. It is used only for visibility. | false |
| placeholder | string | (`Renounced`) The grey text is shown when the input is empty. | - |
| Property | Type | Description | Default Value |
| ------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
| display | boolean | It chooses whether or not to display the field. | true |
| disableonEdit | boolean | When the form is in edit mode, the field becomes unable to be edited. | false |
| enable | boolean | The enable property sets whether a field is enabled or not. | true |
| requiredWhenVisible | boolean | It makes the field required on the UI when it appears. It is used only for visibility. | false |
| hideForPlatform | string | Defines for which platform element should be hidden from UI perspective. Currently only two platforms are supported `cloud` or `enterprise`. | - |
| placeholder | string | (`Renounced`) The grey text is shown when the input is empty. | - |
5 changes: 3 additions & 2 deletions docs/inputs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ provided, a dropdown field will appear on the Inputs page. In contrast, a button
### Properties

| Property | Type | Description |
|---------------------------------------------------------------------------|--------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ------------------------------------------------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| title<span class="required-asterisk">\*</span> | string | - |
| description | string | It provides a brief summary of an inputs page. |
| [subDescription](../advanced/sub_description.md) | object | It provides broader description of an inputs page. |
Expand All @@ -24,7 +24,7 @@ provided, a dropdown field will appear on the Inputs page. In contrast, a button
### Services Properties

| Property | Type | Description |
|-----------------------------------------------------------------------|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| --------------------------------------------------------------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name<span class="required-asterisk">\*</span> | string | It defines the particular service name. |
| title<span class="required-asterisk">\*</span> | string | It shows the title of the service. |
| subTitle | string | It shows the subtitle (or additional information) of the service. |
Expand All @@ -39,6 +39,7 @@ provided, a dropdown field will appear on the Inputs page. In contrast, a button
| restHandlerName | string | It specify name of the REST handler script, that provides fields, models and validators for the fields supported under the specified input and any specific actions to be performed on CRUD operations for the given input. (Do NOT use with restHandlerModule or restHandlerClass) |
| [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`. |

### Usage

Expand Down
53 changes: 53 additions & 0 deletions splunk_add_on_ucc_framework/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,9 @@
"link": {
"type": "string",
"description": "It is a link where the user will be redirected."
},
"hideForPlatform": {
"$ref": "#/definitions/HideForPlatform"
}
},
"required": [
Expand Down Expand Up @@ -636,6 +639,9 @@
},
"requiredWhenVisible": {
"$ref": "#/definitions/requiredWhenVisible"
},
"hideForPlatform": {
"$ref": "#/definitions/HideForPlatform"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -731,6 +737,9 @@
"type": "number",
"default": 8,
"description": "Minimum number of rows to display."
},
"hideForPlatform": {
"$ref": "#/definitions/HideForPlatform"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -875,6 +884,9 @@
"items": {
"$ref": "#/definitions/ValueLabelPair"
}
},
"hideForPlatform": {
"$ref": "#/definitions/HideForPlatform"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -1018,6 +1030,9 @@
"type": "string",
"maxLength": 1,
"description": "It delimits each value of the field with a predefined character."
},
"hideForPlatform": {
"$ref": "#/definitions/HideForPlatform"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -1085,6 +1100,9 @@
},
"requiredWhenVisible": {
"$ref": "#/definitions/requiredWhenVisible"
},
"hideForPlatform": {
"$ref": "#/definitions/HideForPlatform"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -1296,6 +1314,9 @@
"items": {
"$ref": "#/definitions/ValueLabelPair"
}
},
"hideForPlatform": {
"$ref": "#/definitions/HideForPlatform"
}
},
"required": [
Expand Down Expand Up @@ -1394,6 +1415,9 @@
"type": "boolean",
"default": false,
"description": "It defines used encoding for files. If true base64 will be used, if false utf-8 is applied."
},
"hideForPlatform": {
"$ref": "#/definitions/HideForPlatform"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -1524,6 +1548,9 @@
"type": "boolean",
"default": false,
"description": "Used to include the state for oauth authentication"
},
"hideForPlatform": {
"$ref": "#/definitions/HideForPlatform"
}
},
"allOf": [
Expand Down Expand Up @@ -2258,6 +2285,9 @@
},
"warning": {
"$ref": "#/definitions/WarningMessage"
},
"hideForPlatform": {
"$ref": "#/definitions/HideForPlatform"
}
},
"anyOf": [
Expand Down Expand Up @@ -2495,6 +2525,9 @@
},
"markdownMessage": {
"$ref": "#/definitions/markdownMessage"
},
"hideForPlatform": {
"$ref": "#/definitions/HideForPlatform"
}
},
"required": [
Expand Down Expand Up @@ -2840,6 +2873,9 @@
},
"warning": {
"$ref": "#/definitions/WarningMessage"
},
"hideForPlatform": {
"$ref": "#/definitions/HideForPlatform"
}
},
"not": {
Expand Down Expand Up @@ -2954,6 +2990,9 @@
"table",
"entity"
]
},
"hideForPlatform": {
"$ref": "#/definitions/HideForPlatform"
}
},
"hideFieldId": {
Expand Down Expand Up @@ -2998,6 +3037,9 @@
"description": "It chooses whether or not to display the field.",
"default": true
},
"hideForPlatform": {
"$ref": "#/definitions/HideForPlatform"
},
"disableonEdit": {
"type": "boolean",
"description": "When the form is in edit mode, the field becomes unable to be edited.",
Expand Down Expand Up @@ -3062,6 +3104,17 @@
],
"additionalProperties": false
},
"HideForPlatform":{
"description": "Defines for which platform element should be hidden from UI perspective.",
"anyOf": [
{
"const": "cloud"
},
{
"const": "enterprise"
}
]
},
"IntervalValue": {
"anyOf": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ index = Default: default
input_two_checkbox = This is an example checkbox for the input two entity
input_two_multiple_select = This is an example multipleSelect for input two entity
input_two_radio = This is an example radio button for the input two entity
input_two_text_hidden_for_cloud = Should be hidden for cloud
input_two_text_hidden_for_enterprise = Should be hidden for enterprise
interval = Time interval of the data input, in seconds.
start_date = The date and time, in "YYYY-MM-DDThh:mm:ss.000z" format, after which to query and index records. The default is 90 days before today.
use_existing_checkpoint = Data input already exists. Select `No` if you want to reset the data collection. Default: yes
Expand All @@ -36,3 +38,9 @@ interval = Time interval of the data input, in seconds.

[example_input_four://<name>]
interval = Time interval of the data input, in seconds.

[service_hidden_for_cloud://<name>]
interval = Time interval of the data input, in seconds.

[service_hidden_for_enterprise://<name>]
interval = Time interval of the data input, in seconds.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ oauth_oauth_text =
password =
redirect_url =
refresh_token =
text_field_hidden_for_cloud =
text_field_hidden_for_enterprise =
token =
url =
username =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ def get_scheme(self):
required_on_create=True,
)
)
scheme.add_argument(
smi.Argument(
'input_two_text_hidden_for_cloud',
required_on_create=False,
)
)
scheme.add_argument(
smi.Argument(
'input_two_text_hidden_for_enterprise',
required_on_create=False,
)
)
scheme.add_argument(
smi.Argument(
'input_two_multiple_select',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import import_declare_test

import json
import sys

from splunklib import modularinput as smi


class SERVICE_HIDDEN_FOR_CLOUD(smi.Script):
def __init__(self):
super(SERVICE_HIDDEN_FOR_CLOUD, self).__init__()

def get_scheme(self):
scheme = smi.Scheme('service_hidden_for_cloud')
scheme.description = 'Service hidden for cloud'
scheme.use_external_validation = True
scheme.streaming_mode_xml = True
scheme.use_single_instance = False

scheme.add_argument(
smi.Argument(
'name',
title='Name',
description='Name',
required_on_create=True
)
)
return scheme

def validate_input(self, definition: smi.ValidationDefinition):
return

def stream_events(self, inputs: smi.InputDefinition, ew: smi.EventWriter):
input_items = [{'count': len(inputs.inputs)}]
for input_name, input_item in inputs.inputs.items():
input_item['name'] = input_name
input_items.append(input_item)
event = smi.Event(
data=json.dumps(input_items),
sourcetype='service_hidden_for_cloud',
)
ew.write_event(event)


if __name__ == '__main__':
exit_code = SERVICE_HIDDEN_FOR_CLOUD().run(sys.argv)
sys.exit(exit_code)
Loading

0 comments on commit 21aa28f

Please sign in to comment.