Installing the Enforcer
Communicate with the HUMAN Backend
For the enforcer to communicate with HUMAN Collector server, a specific “backend” server must be added and configured in the Fastly UI (or using the contrib/pxbackend.sh
script).
Backend parameters (replace ${APP_ID}
with your HUMAN Application ID):
- Name:
PX_BACKEND_${APP_ID}
- Hostname:
sapi-${APP_ID}.perimeterx.net
- Override host:
sapi-${APP_ID}.perimeterx.net
- Use SSL/TLS: Yes
Module installation
Include perimeterx-fastly-enforcer dependency to Cargo.toml:
Module integration
To integrate HUMAN Rust module into an existing Rust code, the following base snippet could be used:
PXEnforcer Setup
Initialize PXEnforcer structure, it takes a name of Fastly “ConfigStore” (it’s possible to use the default name: perimeterx_fastly_enforcer::DEFAULT_CONFIGSTORE_NAME
)
This function takes a request and returns a result which basically contains a response (for “blocked” or “first party” requests):
At the end of request processing, the following function must be called to finalize HUMAN enforcer code:
It is possible to access HUMANContext structure with various Enforcer variables via px.ctx
member:
To set “custom_parameters” variables, the following callback function could be used:
where:
req
: fastly::Request
conf
: HUMANConfig
params
: modifiable structure with custom_param1 .. custom_param10 fields
To set custom parameters callback function, use the following setter:
Sample code
This is the simplest example on how to use HUMAN Rust module: