Decorators are Splunk utility macros that support code reuse, using the Python decorator idiom.
The Python decorator idiom is a function returning another function, which is usually applied as a function transformation using the @wrapper syntax. Common examples for decorators are classmethod() and staticmethod().
The decorator syntax is syntactic sugar, and you can see that the following function definitions are semantically equivalent, where the @staticmethod syntax is a decorator:
def f(... elided ...):
... elided ...
f = staticmethod(f)
@staticmethod
def f(... elided ...):
... elided ...
The Splunk App Framework provides the following decorators for routing and exposing page functions that depend on authentication and HTTP verbs:
Python
from splunk.appserver.mrsparkle.lib.decorators import <decorator> from splunk.appserver.mrsparkle.lib.routes import route
| expose_page() | Provides authentication, SSO verification, and CSRF protection. |
| lock_session() | Acquires an exclusive lock on a CherryPy session. |
| set_cache_level() | Permits consumers to set specific cache headers within responses. |
| route() | Permits URI targets to be routed to specific controller methods. |