Customizing with Lifecycle Hooks
Background
Lifecycle HooksWriting a Lifecycle Hooks Script
Write a Python script (e.g. lifecycle_hooks.py)
In this script, define the lifecycle events to hook into
Define what kind of behavior to execute for each of those events
Below is a sample script that prints some strings during two lifecycle events.
Manipulating the context object will affect the behaviour of the request interception.
from stoobly_agent.app.proxy.replay.context import ReplayContext
def handle_before_replay(context: ReplayContext):
print('Before replay!')
After a request gets intercepted, the string "Before replay!"
will be printed.
Enabling Lifecycle Hook Script Use
Pass the path to the lifecycle hooks scripts using the --lifecycle-hooks-path
option:
stoobly-agent run --lifecycle-hooks-path ~/path-to-file/lifecycle_hooks.py
Example
from stoobly_agent.app.proxy.replay.context import ReplayContext
from stoobly_agent.config.constants import record_policy, replay_policy
def handle_before_replay(context: ReplayContext):
intercept_settings = context.intercept_settings
flow = context.flow
headers = flow.request
request = request.headers
is_overwriting = intercept_settings.policy == record_policy.OVERWRITE
if is_overwriting:
# Handle setting credentials here
# e.g. headers['authorization'] = '<TOKEN>'
pass
Last updated
Was this helpful?