Webhooks – Pantheon Example
Introduction
AAArdvark’s Webhooks integration allows you to automate accessibility scans, ensuring that your site remains accessible every time new code is deployed. This helps minimize the introduction of new accessibility issues during updates.
Automate Accessibility Scans with Webhooks
Pantheon is a popular host for Drupal and WordPress projects. They provide the ability to execute commands as part of the deployment process using a system called Quicksilver.
The example below will trigger a scan for any Pantheon environment that has a valid site id and token in the /files/private/secrets.json
file.
Step 1
Set up the Pantheon environment you want to scan as a site in AAArdvark. This could be your production, development, staging, or multidev environment.”
Step 2
Add the generic Webhook integration to the site and note down the generated URL for future reference.
Step 3
If your Pantheon environment doesn’t already use a secrets.json
file, create one. If it does, simply add the keys to the existing file. Use the provided example, replacing aaardvark_site_id
and aaardvark_webhook_token
with your actual values.
Upload the file using SFTP to the /files/private
directory.
If you copy the files from this environment to another, you will need to update or remove the secrets.json file in the destination environment.
Step 4
Add the pantheon.yml
and /private/scripts/aaardvark.php
files to your codebase. Push these updates to the Pantheon environment you configured earlier.
From now on, every time you push code to this environment, AAArdvark will automatically perform an accessibility scan, helping you maintain an inclusive and accessible website.
Example Files for Pantheon Quicksilver
/pantheon.yml
This configuration triggers the AAArdvark scan after every code deployment.
# Add configurations that override your default pantheon.upstream.yml settings here.
# For more information, see: https://pantheon.io/docs/pantheon-yml/
api_version: 1
workflows:
sync_code:
after:
- type: webphp
description: Scan for Accessibility Issues on Deploy
script: private/scripts/aaardvark.php
/private/scripts/aaardvark.php
This script posts a request to the AAArdvark webhook URL, initiating the scan.
<?php function loadSecrets() { $secretsFile = $_SERVER['HOME'].'/files/private/secrets.json'; if (!file_exists($secretsFile)) { throw new \Exception("Secrets file not found in the /files/private directory"); } $secretsContents = file_get_contents($secretsFile); $secrets = json_decode($secretsContents, 1); if ($secrets == false) { die('Could not parse json in secrets file.'); } $missing = array_diff(['aaardvark_site_id', 'aaardvark_webhook_token'], array_keys($secrets)); if (!empty($missing)) { throw new \Exception('Missing required keys in json secrets file: '.implode(',', $missing).'.'); } return $secrets; } try { $secrets = loadSecrets(); $url = "https://app.aaardvarkaccessibility.com/webhooks/site/{$secrets['aaardvark_site_id']}/scan/{$secrets['aaardvark_webhook_token']}"; $payload['source'] = 'Pantheon: ' . $_ENV['PANTHEON_ENVIRONMENT']; $payload = http_build_query($payload); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); print("\n==== Posting to Webhook URL ====\n"); $result = curl_exec($ch); print("RESULT: $result"); print("\n===== Post Complete! =====\n"); curl_close($ch); } catch (\Exception $e) { print("\n==== Skipping: " . $e->getMessage() . " ====\n"); }
/files/private/secrets.json
For Webhook url
—–
{ "aaardvark_site_id": "3QdjF5", "aaardvark_webhook_token": "0c16e69038f8d46fdcfb9c832235af199ce9dad14ae625e0401c9daa13c0cef5" }