Skip to content

Commit

Permalink
feat: v5.18.0 release (#583)
Browse files Browse the repository at this point in the history
What was done:

* Support for `textarea` component
* Support for `file` component
* Support for custom REST handlers for modular inputs
* Fixed some bugs
  • Loading branch information
artemrys authored Dec 12, 2022
1 parent 9d5c07c commit 312839e
Show file tree
Hide file tree
Showing 58 changed files with 4,378 additions and 461 deletions.
170 changes: 170 additions & 0 deletions docs/advanced/custom_rest_handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def _validate_organization(organization_id, organization_api_key):
# Some code to validate the API key.
# Should return nothing if the configuration is valid.
# Should raise an exception splunktaucclib.rest_handler.error.RestError if the configuration is not valid.
...


class CustomRestHandler(AdminExternalHandler):
Expand Down Expand Up @@ -105,3 +106,172 @@ if __name__ == "__main__":
handler=CustomRestHandler,
)
```

### Native support from UCC

> UCC 5.18.0 natively supports custom REST handlers for the modular inputs.
One of the common scenarios is to delete a checkpoint after you are deleting an
input in the Inputs page. Otherwise, users may face the wierd consequences if
they create an input with the same name as the input that was deleted and this
newly created input will be reusing the old checkpoint because the names of
the inputs are the same. We would like to avoid this situation in the add-on.

This can be done without a need to modify the REST handler code generated
automatically by running `ucc-gen`.

Below is the automatically generated REST handler code for a modular input REST
handler.

```python

import import_declare_test

from splunktaucclib.rest_handler.endpoint import (
field,
validator,
RestModel,
DataInputModel,
)
from splunktaucclib.rest_handler import admin_external, util
from splunktaucclib.rest_handler.admin_external import AdminExternalHandler
import logging

util.remove_http_proxy_env_vars()


fields = [
field.RestField(
'interval',
required=True,
encrypted=False,
default=None,
validator=validator.Pattern(
regex=r"""^\-[1-9]\d*$|^\d*$""",
)
),

field.RestField(
'disabled',
required=False,
validator=None
)

]
model = RestModel(fields, name=None)



endpoint = DataInputModel(
'example_input_one',
model,
)


if __name__ == '__main__':
logging.getLogger().addHandler(logging.NullHandler())
admin_external.handle(
endpoint,
handler=AdminExternalHandler,
)
```

New file needs to be created in the `bin` folder of the add-on. Let's call it
`splunk_ta_uccexample_delete_checkpoint_rh.py` (name can be different).

And put the following content into the file.

```python
import import_declare_test

from splunktaucclib.rest_handler.admin_external import AdminExternalHandler


class CustomRestHandlerDeleteCheckpoint(AdminExternalHandler):
def __init__(self, *args, **kwargs):
AdminExternalHandler.__init__(self, *args, **kwargs)

def handleList(self, confInfo):
AdminExternalHandler.handleList(self, confInfo)

def handleEdit(self, confInfo):
AdminExternalHandler.handleEdit(self, confInfo)

def handleCreate(self, confInfo):
AdminExternalHandler.handleCreate(self, confInfo)

def handleRemove(self, confInfo):
# Add your code here to delete the checkpoint!
AdminExternalHandler.handleRemove(self, confInfo)
```

Then, in globalConfig file you need to change the behaviour of the UCC to reuse
the REST handler that was just created.

```
{
"name": "example_input_one",
"restHandlerModule": "splunk_ta_uccexample_delete_checkpoint_rh", <----- new field
"restHandlerClass": "CustomRestHandlerDeleteCheckpoint", <----- new field
"entity": [
"..."
],
"title": "Example Input One"
}
```

After `ucc-gen` command is executed again, the generated REST handler for this
input will be changed to the following.

```python

import import_declare_test

from splunktaucclib.rest_handler.endpoint import (
field,
validator,
RestModel,
DataInputModel,
)
from splunktaucclib.rest_handler import admin_external, util
from splunk_ta_uccexample_delete_checkpoint_rh import CustomRestHandlerDeleteCheckpoint # <----- changed
import logging

util.remove_http_proxy_env_vars()


fields = [
field.RestField(
'interval',
required=True,
encrypted=False,
default=None,
validator=validator.Pattern(
regex=r"""^\-[1-9]\d*$|^\d*$""",
)
),

field.RestField(
'disabled',
required=False,
validator=None
)

]
model = RestModel(fields, name=None)



endpoint = DataInputModel(
'example_input_one',
model,
)


if __name__ == '__main__':
logging.getLogger().addHandler(logging.NullHandler())
admin_external.handle(
endpoint,
handler=CustomRestHandlerDeleteCheckpoint, # <----- changed
)
```
104 changes: 104 additions & 0 deletions docs/components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Components supported by UCC

Components are used by UCC to render the Inputs and Configuration pages. Here is
the list of the supported components.

## `custom`

TBD

## `text`

TBD

## `textarea`

Underlying `@splunk/react-ui` component: [`TextArea`](https://splunkui.splunk.com/Packages/react-ui/TextArea).

`textarea` component is very similar to `text` component, but allows to have a
multi-line input for text.

Example usage below:

```json
{
"type": "textarea",
"label": "Textarea Field",
"field": "textarea_field",
"help": "Help message",
"options": {
"rowsMin": 3,
"rowsMax": 15
},
"required": true
}
```

This is how it looks like in the UI:

![image](images/components/textarea_component_example.png)

## `singleSelect`

TBD

## `checkbox`

TBD

## `multipleSelect`

TBD

## `radio`

TBD

## `placeholder`

TBD

## `oauth`

TBD

## `helpLink`

TBD

## `file`

Underlying `@splunk/react-ui` component: [`File`](https://splunkui.splunk.com/Packages/react-ui/File).

The current implementation of the `file` component only supports `JSON` files
and accepts only 1 file (can be dragged into).

Usage example below:

```json
{
"type": "file",
"label": "SA certificate",
"help": "Upload service account's certificate",
"field": "service_account",
"options": {
"fileSupportMessage": "Support message"
},
"validators": [
{
"type": "file",
"supportedFileTypes": [
"json"
]
}
],
"encrypted": true,
"required": true
}
```

> Note: `validators` field should be present for the file input exactly as it is in the example above.
This is how it looks like in the UI:

![image](images/components/file_component_example.png)
Binary file added docs/images/components/file_component_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion get-ucc-ui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
wget https://github.com/splunk/addonfactory-ucc-base-ui/releases/download/v1.15.1/splunk-ucc-ui.tgz
wget https://github.com/splunk/addonfactory-ucc-base-ui/releases/download/v1.18.0/splunk-ucc-ui.tgz
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ theme:
nav:
- Home: "index.md"
- How to use: "how_to_use.md"
- Components: "components.md"
- Example: "example.md"
- Tabs: "tabs.md"
- Custom UI Extensions:
Expand Down
26 changes: 13 additions & 13 deletions splunk_add_on_ucc_framework/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@
meta_conf,
utils,
)
from splunk_add_on_ucc_framework.commands.rest_builder import global_config
from splunk_add_on_ucc_framework.commands.rest_builder.builder import RestBuilder
from splunk_add_on_ucc_framework.commands.rest_builder.global_config import (
GlobalConfigBuilderSchema,
)
from splunk_add_on_ucc_framework.install_python_libraries import (
SplunktaucclibNotFound,
install_python_libraries,
)
from splunk_add_on_ucc_framework.start_alert_build import alert_build
from splunk_add_on_ucc_framework.uccrestbuilder import build, global_config

logger = logging.getLogger("ucc_gen")

Expand Down Expand Up @@ -129,7 +133,9 @@ def _replace_token(ta_name, outputdir):
f.write(s)


def _generate_rest(ta_name, scheme, import_declare_name, outputdir):
def _generate_rest(
ta_name, scheme: GlobalConfigBuilderSchema, import_declare_name, outputdir
):
"""
Build REST for Add-on.
Expand All @@ -139,17 +145,11 @@ def _generate_rest(ta_name, scheme, import_declare_name, outputdir):
import_declare_name (str): Name of import_declare_* file.
outputdir (str): output directory.
"""
rest_handler_module = "splunktaucclib.rest_handler.admin_external"
rest_handler_class = "AdminExternalHandler"

build(
scheme,
rest_handler_module,
rest_handler_class,
os.path.join(outputdir, ta_name),
post_process=global_config.GlobalConfigPostProcessor(),
import_declare_name=import_declare_name,
)
builder_obj = RestBuilder(scheme, os.path.join(outputdir, ta_name))
builder_obj.build()
post_process = global_config.GlobalConfigPostProcessor()
post_process(builder_obj, scheme, import_declare_name=import_declare_name)
return builder_obj


def _is_oauth_configured(ta_tabs):
Expand Down
15 changes: 15 additions & 0 deletions splunk_add_on_ucc_framework/commands/rest_builder/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Copyright 2021 Splunk Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
Loading

0 comments on commit 312839e

Please sign in to comment.