Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion globalConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"tabs": [
{
"name": "account",
"restHandlerModule": "example_api_key_verification",
"restHandlerClass": "APIKeyValidator",
"table": {
"actions": [
"edit",
Expand Down Expand Up @@ -176,7 +178,7 @@
"meta": {
"name": "Splunk_TA_Example",
"restRoot": "Splunk_TA_Example",
"version": "0.0.1+97695b3",
"version": "0.0.1+2cf76ae",
"displayName": "Splunk Add-on for Example",
"schemaVersion": "0.0.9",
"supportedThemes": [
Expand Down
35 changes: 35 additions & 0 deletions package/bin/example_api_key_verification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import import_declare_test

from splunktaucclib.rest_handler.admin_external import AdminExternalHandler
from splunktaucclib.rest_handler.error import RestError


def _validate_api_key(api_key: str):
# 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.
if api_key != "super-secret-api-token":
raise RestError(400, "API Key provided is not correct!")


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

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

def handleEdit(self, confInfo):
_validate_api_key(
self.payload.get("api_key"),
)
AdminExternalHandler.handleEdit(self, confInfo)

def handleCreate(self, confInfo):
_validate_api_key(
self.payload.get("api_key"),
)
AdminExternalHandler.handleCreate(self, confInfo)

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