Each script type has its own
context and actions modules tailored to that
automation scenario.Overview
Request Review scripts run when an access request is assigned to a service user for review. The script can automatically approve, deny, or add comments to the request. This guide details the context and action modules you can use to get started, as well as the best practices and limitations when using OpalScript. For use case specific sample scripts, see our examples.Quick start
The simplest script approves all requests:context Module
Thecontext module provides read-only access to the request being reviewed.
Get the request object
context.get_request() returns the Request object being reviewed.
None
Contains information about the access request
actions Module
Theactions module provides methods to take action on the request.
Approve a request
actions.approve([comment], [duration_minutes]) approves the request.
Optional comment to add to the approval.
Optional override for the access duration. Must be a positive integer. If different from the originally requested duration, a notice is automatically appended to the comment.
Deny a request
actions.deny(comment) denies a request. A comment is required to explain the denial.
Comment explaining the denial.
Comment on a request
actions.comment(comment, [duration_minutes]) adds a comment without changing the request status. Useful for flagging requests or adding context for manual reviewers.
Comment to add.
Optional override for the access duration. Must be a positive integer. If different from the originally requested duration, a notice is automatically appended to the comment.
Pause execution
actions.pause(minutes) pauses script execution and resumes from the same point after the specified time. Any actions already taken before the pause are skipped on replay.
Number of minutes to pause. Must be between 1 and 1440 (24 hours).
Poll a condition
actions.poll(function, minutes, max_iterations) repeatedly calls function at the given interval until it returns True or the maximum iterations are reached. Returns True if the function succeeded, False if it ran out of iterations.
A function that takes no arguments and returns a boolean. Execution resumes when it returns
True or max_iterations is exhausted.Interval between calls in minutes. Must be between 1 and 1440.
Maximum number of times to call the function. Must be between 1 and 50.
Objects
Request object
Returned bycontext.get_request() and contains information about the access request.
RequestedResource object
Represents a resource included in the request. Returned in the Request object.RequestedGroup object
Represents a group included in the request. Returned in the Request object.Custom fields
Thecustom_fields attribute is a dictionary containing values from the request template’s custom fields. The keys are field names, and values depend on the field type:
Constraints & limits
OpalScript enforces limits to ensure safe, predictable execution:Unsupported operations
For security and reliability, OpalScript does not support:- Unrestricted network access: outbound HTTP is only available through the
httpmodule, and only to hosts on the egress allowlist - File I/O: Scripts cannot read or write files
- Direct database access: All data access goes through provided modules
- Import statements: All modules are pre-loaded
- While loops: Use
forloops withrange()instead
Error handling
Scripts can fail due to various errors. Understanding common error types helps you write more robust scripts.Syntax errors
None value errors
Type errors
Best practices
- Check for None before using optional attributes
- Use
.get()with defaults when accessing dictionary values - Keep scripts focused - do one thing well
- Test with edge cases - empty strings, None values, missing fields