View source
<?php
namespace Drupal\fastly;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Messenger\Messenger;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\fastly\Services\Webhook;
use Drupal\fastly\Utility\FastlyEdgeModulesHelper;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class VclHandler {
use StringTranslationTrait;
const ERROR_PAGE_RESPONSE_OBJECT = 'drupalmodule_error_page_response_object';
const IMAGE_OPTIMIZER_BASIC_IMAGE_SETTINGS = 'drupalmodule_image_optimizer';
protected $api;
protected $vclData;
protected $conditionData;
protected $settingData;
protected $hostname;
protected $apiKey;
protected $serviceId;
protected $versionBaseUrl;
protected $headersGet;
protected $headersPost;
protected $lastVersionData;
public $nextClonedVersionNum = NULL;
public $lastActiveVersionNum = NULL;
protected $lastClonedVersion;
protected $errors = [];
protected $logger;
protected $webhook;
protected $baseUrl;
protected $messenger;
protected $moduleHandler;
public function __construct(ConfigFactoryInterface $config_factory, $host, Api $api, LoggerInterface $logger, Webhook $webhook, RequestStack $requestStack, Messenger $messenger, ModuleHandlerInterface $module_handler) {
$this->moduleHandler = $module_handler;
$vcl_dir = drupal_get_path('module', 'fastly') . '/vcl_snippets';
$data = [
'vcl' => [
[
'vcl_dir' => $vcl_dir,
'type' => 'recv',
],
[
'vcl_dir' => $vcl_dir,
'type' => 'deliver',
],
[
'vcl_dir' => $vcl_dir,
'type' => 'error',
],
[
'vcl_dir' => $vcl_dir,
'type' => 'fetch',
],
],
'condition' => [
[
'name' => 'drupalmodule_request',
'statement' => 'req.http.x-pass == "1"',
'type' => 'REQUEST',
'priority' => 90,
],
],
'setting' => [
[
'name' => 'drupalmodule_setting',
'action' => 'pass',
'request_condition' => 'drupalmodule_request',
],
],
];
$this->moduleHandler
->alter('vcl_handler_data', $data);
$this->api = $api;
$this->webhook = $webhook;
$config = $config_factory
->get('fastly.settings');
$this->vclData = !empty($data['vcl']) ? $data['vcl'] : FALSE;
$this->conditionData = !empty($data['condition']) ? $data['condition'] : FALSE;
$this->settingData = !empty($data['setting']) ? $data['setting'] : FALSE;
$this->hostname = $host;
$this->serviceId = getenv('FASTLY_API_SERVICE') ?: $config
->get('service_id');
$this->apiKey = getenv('FASTLY_API_TOKEN') ?: $config
->get('api_key');
$this->logger = $logger;
$this->baseUrl = $requestStack
->getCurrentRequest()
->getHost();
$connection = $this->api
->testFastlyApiConnection();
if (!$connection['status']) {
$this
->addError($connection['message']);
return;
}
$this->versionBaseUrl = '/service/' . $this->serviceId . '/version';
$this->headersGet = [
'Fastly-Key' => $this->apiKey,
'Accept' => 'application/json',
];
$this->headersPost = [
'Fastly-Key' => $this->apiKey,
'Accept' => 'application/json',
'Content-Type' => 'application/x-www-form-urlencoded',
];
$this->lastVersionData = $this
->getLastVersion();
if ($this->lastVersionData) {
$this->lastActiveVersionNum = $this->lastVersionData->number;
}
$this->messenger = $messenger;
}
public function createResponse($version, array $responseToCreate) {
$responseObject = $this
->getResponse($version, $responseToCreate['name']);
$url = $this->versionBaseUrl . '/' . $version . '/response_object/';
if ($responseObject
->getStatusCode() != "404") {
$headers = $this->headersPost;
$type = "PUT";
$url = $url . $responseToCreate['name'];
}
else {
$headers = $this->headersPost;
$type = "POST";
}
$result = $this
->vclRequestWrapper($url, $headers, $responseToCreate, $type);
return $result;
}
public function getResponse($version, $name) {
if (empty($this->lastVersionData)) {
return FALSE;
}
$url = $this->versionBaseUrl . '/' . $version . '/response_object/' . $name;
return $this
->vclRequestWrapper($url);
}
public function prepareSingleVcl(array $single_vcl_data, $prefix = "drupalmodule") {
if (!empty($single_vcl_data['type'])) {
$single_vcl_data['name'] = $single_vcl_data['name'] ? $single_vcl_data['name'] : $prefix . '_' . $single_vcl_data['type'];
$single_vcl_data['dynamic'] = 0;
$single_vcl_data['priority'] = isset($single_vcl_data['priority']) ? $single_vcl_data['priority'] : 50;
if (isset($single_vcl_data['vcl_dir']) && file_exists($single_vcl_data['vcl_dir'] . '/' . $single_vcl_data['type'] . '.vcl')) {
$single_vcl_data['content'] = file_get_contents($single_vcl_data['vcl_dir'] . '/' . $single_vcl_data['type'] . '.vcl');
unset($single_vcl_data['vcl_dir']);
}
elseif (!$single_vcl_data['content']) {
$message = $this
->t('VCL file does not exist.');
$this
->addError($message);
$this->logger
->info($message);
return FALSE;
}
if ($this
->checkIfVclExists($single_vcl_data['name'])) {
$requests[] = $this
->prepareUpdateVcl($single_vcl_data);
}
else {
$requests[] = $this
->prepareInsertVcl($single_vcl_data);
}
}
else {
$message = $this
->t('VCL type not set.');
$this
->addError($message);
$this->logger
->info($message);
return FALSE;
}
return $requests;
}
public function uploadMaintenancePage($html) {
try {
$clone = $this
->cloneLastActiveVersion();
if (FALSE === $clone) {
$this
->addError($this
->t('Unable to clone last version'));
return FALSE;
}
$condition = [
'name' => 'drupalmodule_error_page_condition',
'statement' => 'req.http.ResponseObject == "970"',
'type' => 'REQUEST',
];
$_condition = $this
->getCondition($condition["name"]);
if ($_condition
->getStatusCode() == "404") {
$this
->insertCondition($condition);
}
$response = [
'name' => self::ERROR_PAGE_RESPONSE_OBJECT,
'request_condition' => $condition["name"],
'content' => $html,
'status' => "503",
'response' => "Service Temporarily Unavailable",
];
$createResponse = $this
->createResponse($this->lastClonedVersion, $response);
if (!$createResponse) {
$this
->addError($this
->t('Failed to create a RESPONSE object.'));
return FALSE;
}
$validate = $this
->validateVersion($this->lastClonedVersion);
if (!$validate) {
$this
->addError($this
->t('Failed to validate service version: @last_cloned_version', [
'@last_cloned_version' => $this->lastClonedVersion,
]));
return FALSE;
}
$vcl_dir = drupal_get_path('module', 'fastly') . '/vcl_snippets/errors';
$singleVclData['vcl_dir'] = $vcl_dir;
$singleVclData['type'] = 'deliver';
$requests = [];
if (!empty($singleVclData)) {
$requests = array_merge($requests, $this
->prepareSingleVcl($singleVclData, "drupalmodule_error_page"));
}
$responses = [];
foreach ($requests as $value) {
if (!isset($value['type'])) {
continue;
}
$url = $value['url'];
$data = $value['data'];
$type = $value['type'];
$headers = [];
$response = $this
->vclRequestWrapper($url, $headers, $data, $type);
$responses[] = $response;
}
unset($responses);
$request = $this
->prepareActivateVersion();
$response = $this
->vclRequestWrapper($request['url'], $request['headers'], [], $request['type']);
if ($response
->getStatusCode() != "200") {
return FALSE;
}
$this->webhook
->sendWebHook($this
->t('*New Error/Maintenance page has updated and activated under config version @last_cloned_version', [
'@last_cloned_version' => $this->lastClonedVersion,
]), "maintenance_page");
return TRUE;
} catch (\Exception $e) {
$this
->addError($this
->t('@message', [
'@message' => $e
->getMessage(),
]));
return FALSE;
}
}
public function execute($activate = FALSE) {
$errors = $this
->getErrors();
if (!empty($errors)) {
foreach ($errors as $error) {
$this->messenger
->addError($error);
}
return FALSE;
}
if ($this->lastVersionData === FALSE) {
$this
->addError($this
->t('Last version does not exist'));
return FALSE;
}
if (empty($this->vclData) && empty($this->conditionData) && empty($this->settingData)) {
$this
->addError($this
->t('No update data set, please specify, vcl, condition or setting data'));
return FALSE;
}
try {
if (FALSE === $this
->cloneLastActiveVersion()) {
$this
->addError($this
->t('Unable to clone last version'));
return FALSE;
}
$requests = [];
if (!empty($this->vclData)) {
$requests = array_merge($requests, $this
->prepareVcl());
}
if (!empty($this->conditionData)) {
$conditions = $this
->prepareCondition();
if (FALSE === $conditions) {
$this
->addError($this
->t('Unable to insert new condition'));
return FALSE;
}
$requests = array_merge($requests, $conditions);
}
if (!empty($this->settingData)) {
$requests = array_merge($requests, $this
->prepareSetting());
}
if (!$this
->validateVersion()) {
$this
->addError($this
->t('Version not validated'));
return FALSE;
}
foreach ($requests as $key => $request) {
if (in_array($request['type'], [
"POST",
"PUT",
])) {
$requests[$key]['headers'] = $this->headersPost;
}
else {
$requests[$key]['headers'] = $this->headersGet;
}
}
$responses = [];
foreach ($requests as $key => $value) {
if (!isset($value['type'])) {
continue;
}
$url = $value['url'];
$data = $value['data'];
$type = $value['type'];
$headers = $value['headers'];
$response = $this
->vclRequestWrapper($url, $headers, $data, $type);
$responses[] = $response;
}
$pass = TRUE;
foreach ($responses as $response) {
if ($response
->getStatusCode() != "200") {
$pass = FALSE;
$this
->addError($this
->t('Some of the API requests failed, enable debugging and check logs for more information.'));
$this->logger
->critical('VCL update failed : @body', [
'@body' => json_decode($response
->getBody()),
]);
}
}
if ($pass && $activate) {
$request = $this
->prepareActivateVersion();
$response = $this
->vclRequestWrapper($request['url'], $request['headers'], [], $request['type']);
if ($response
->getStatusCode() != "200") {
$this
->addError($this
->t('Some of the API requests failed, enable debugging and check logs for more information.'));
$this->logger
->critical('Activation of new version failed : @body', [
'@body' => $response
->getBody(),
]);
}
else {
$this->logger
->info('VCL updated, version activated : ', [
'@last_cloned_version' => $this->lastClonedVersion,
]);
}
}
elseif ($pass && !$activate) {
$message = $this
->t('VCL updated, but not activated.');
$this->logger
->info($message);
return $message;
}
$this->webhook
->sendWebHook($this
->t('VCL updated, but not activated on %base_url', [
'%base_url' => $this->baseUrl,
]), "vcl_update");
} catch (Exception $e) {
$this
->addError($this
->t('Some of the API requests failed, enable debugging and check logs for more information.'));
$this->logger
->critical('VCL update failed : @message', [
'@message' => $e
->getMessage(),
]);
foreach ($this
->getErrors() as $error) {
$this->messenger
->addError($error);
}
return FALSE;
}
return TRUE;
}
public function prepareVcl() {
$requests = [];
foreach ($this->vclData as $single_vcl_data) {
if (!empty($single_vcl_data['type'])) {
$single_vcl_data['name'] = 'drupalmodule_' . $single_vcl_data['type'];
$single_vcl_data['dynamic'] = 0;
$single_vcl_data['priority'] = 50;
if (file_exists($single_vcl_data['vcl_dir'] . '/' . $single_vcl_data['type'] . '.vcl')) {
$single_vcl_data['content'] = file_get_contents($single_vcl_data['vcl_dir'] . '/' . $single_vcl_data['type'] . '.vcl');
unset($single_vcl_data['vcl_dir']);
}
else {
$message = $this
->t('VCL file does not exist.');
$this
->addError($message);
$this->logger
->info($message);
return FALSE;
}
if ($this
->checkIfVclExists($single_vcl_data['name'])) {
$requests[] = $this
->prepareUpdateVcl($single_vcl_data);
}
else {
$requests[] = $this
->prepareInsertVcl($single_vcl_data);
}
}
else {
$message = $this
->t('VCL type not set.');
$this
->addError($message);
$this->logger
->info($message);
return FALSE;
}
}
return $requests;
}
public function checkIfVclExists($name) {
if (empty($this->lastVersionData)) {
return FALSE;
}
$url = $this->versionBaseUrl . '/' . $this->lastClonedVersion . '/snippet/' . $name;
$response = $this
->vclGetWrapper($url);
$responseBody = (string) $response
->getBody();
if (empty($responseBody)) {
return FALSE;
}
$_responseBody = json_decode($response
->getBody());
if (!empty($_responseBody->content)) {
return TRUE;
}
return FALSE;
}
public function getSnippetId($data) {
$url = $this->versionBaseUrl . '/' . $this->lastClonedVersion . '/snippet/' . $data['name'];
$response = $this
->vclGetWrapper($url);
$responseData = json_decode($response
->getBody());
return $responseData->id;
}
public function prepareUpdateVcl($data) {
$url = $this->versionBaseUrl . '/' . $this->lastClonedVersion . '/snippet/' . $data["name"];
$data['form_params'] = [
'content' => $data['content'],
'type' => $data['type'],
'name' => $data['name'],
'dynamic' => $data['dynamic'],
'priority' => $data['priority'],
];
$request = [
'url' => $url,
'data' => $data,
'type' => "PUT",
];
return $request;
}
public function prepareInsertVcl($data) {
$url = $this->versionBaseUrl . '/' . $this->lastClonedVersion . '/snippet';
$request = [
'url' => $url,
'data' => $data,
'type' => 'POST',
];
return $request;
}
public function getLastVersion() {
$url = $this->versionBaseUrl;
$response = $this
->vclGetWrapper($url, $this->headersGet);
$response_data = json_decode($response
->getBody());
$this->nextClonedVersionNum = count($response_data) + 1;
foreach ($response_data as $version_data) {
if ($version_data->active) {
return $version_data;
}
}
return FALSE;
}
public function cloneLastActiveVersion() {
if (empty($this->lastVersionData)) {
return FALSE;
}
$version_number = $this->lastVersionData->number;
$url = $this->versionBaseUrl . '/' . $version_number . '/clone';
$response = $this
->vclPutWrapper($url, $this->headersPost);
$response_data = json_decode($response
->getBody());
$cloned_version_number = isset($response_data->number) ? $response_data->number : FALSE;
$this->lastClonedVersion = $cloned_version_number;
return $cloned_version_number;
}
public function prepareCondition() {
$requests = [];
foreach ($this->conditionData as $single_condition_data) {
if (empty($single_condition_data['name']) || empty($single_condition_data['statement']) || empty($single_condition_data['type']) || empty($single_condition_data['priority'])) {
$message = $this
->t('Condition data not properly set.');
$this
->addError($message);
$this->logger
->critical($message);
return FALSE;
}
else {
if ($this
->checkCondition($single_condition_data['name'])) {
$requests[] = $this
->prepareUpdateCondition($single_condition_data);
}
else {
return $this
->insertCondition($single_condition_data);
}
}
}
return $requests;
}
public function checkCondition($name) {
$url = $this->versionBaseUrl . '/' . $this->lastClonedVersion . '/condition/' . $name;
$response = $this
->vclGetWrapper($url, $this->headersGet);
$responseBody = (string) $response
->getBody();
$_responseBody = json_decode($responseBody);
if (empty($_responseBody)) {
return FALSE;
}
if ($_responseBody->version) {
return TRUE;
}
return FALSE;
}
public function getCondition($name) {
$url = $this->versionBaseUrl . '/' . $this->lastClonedVersion . '/condition/' . $name;
return $this
->vclGetWrapper($url, $this->headersGet);
}
public function prepareUpdateCondition($data) {
$url = $this->versionBaseUrl . '/' . $this->lastClonedVersion . '/condition/' . $data['name'];
$request = [
'url' => $url,
'data' => $data,
'type' => "PUT",
];
return $request;
}
public function insertCondition($data) {
$url = $this->versionBaseUrl . '/' . $this->lastClonedVersion . '/condition';
$request = [
'url' => $url,
'data' => $data,
'type' => 'POST',
];
$response = $this
->vclRequestWrapper($request['url'], $this->headersPost, $request['data'], $request['type']);
$responseData = json_decode($response
->getBody());
if ($responseData) {
return $responseData;
}
else {
return [];
}
}
public function prepareSetting() {
$requests = [];
foreach ($this->settingData as $single_setting_data) {
if (empty($single_setting_data['name']) || empty($single_setting_data['action']) || empty($single_setting_data['request_condition'])) {
$message = $this
->t('Setting data not properly set.');
$this
->addError($message);
$this->logger
->critical($message);
return FALSE;
}
else {
if ($this
->getSetting($single_setting_data['name'])) {
$requests[] = $this
->prepareUpdateSetting($single_setting_data);
}
else {
$requests[] = $this
->prepareInsertSetting($single_setting_data);
}
}
}
return $requests;
}
public function getSetting($name) {
$url = $this->versionBaseUrl . '/' . $this->lastClonedVersion . '/request_settings/' . $name;
$response = $this
->vclGetWrapper($url, $this->headersGet);
$responseBody = (string) $response
->getBody();
$_responseBody = json_decode($responseBody);
if (empty($_responseBody)) {
return FALSE;
}
if (!$_responseBody->version) {
return FALSE;
}
return TRUE;
}
public function prepareUpdateSetting($data) {
$url = $this->versionBaseUrl . '/' . $this->lastClonedVersion . '/request_settings/' . $data['name'];
$request = [
'url' => $url,
'data' => $data,
'type' => 'PUT',
];
return $request;
}
public function prepareInsertSetting($data) {
$url = $this->versionBaseUrl . '/' . $this->lastClonedVersion . '/request_settings';
$request = [
'url' => $url,
'data' => $data,
'type' => 'POST',
];
return $request;
}
public function validateVersion() {
$url = $this->versionBaseUrl . '/' . $this->lastClonedVersion . '/validate';
$response = $this
->vclGetWrapper($url, $this->headersGet);
$responseData = json_decode($response
->getBody());
if (!empty($responseData->errors)) {
return FALSE;
}
return TRUE;
}
public function prepareActivateVersion() {
$url = $this->versionBaseUrl . '/' . $this->lastClonedVersion . '/activate';
$request = [
'url' => $url,
'type' => 'PUT',
'headers' => $this->headersGet,
];
return $request;
}
public function addError($message) {
$this->errors[] = $message;
}
public function getErrors() {
return $this->errors;
}
public function vclRequestWrapper($url, array $headers = [], array $data = [], $type = "GET") {
return $this->api
->vclQuery($url, $data, $type, $headers);
}
public function vclGetWrapper($url, array $headers = [], array $data = []) {
return $this
->vclRequestWrapper($url, $headers, $data, "GET");
}
public function vclPutWrapper($url, array $headers = [], array $data = []) {
return $this
->vclRequestWrapper($url, $headers, $data, "PUT");
}
public function setImageOptimization($params = []) {
try {
$this
->cloneLastActiveVersion();
$data['vcl_dir'] = drupal_get_path('module', 'fastly') . '/vcl_snippets_image_optimizations/' . $params['optimize'];
$data['type'] = 'recv';
if ($this
->checkIfVclExists(self::IMAGE_OPTIMIZER_BASIC_IMAGE_SETTINGS)) {
$data['name'] = self::IMAGE_OPTIMIZER_BASIC_IMAGE_SETTINGS;
$requests = $this
->prepareUpdateVcl($data);
}
else {
$requests = $this
->prepareSingleVcl($data, self::IMAGE_OPTIMIZER_BASIC_IMAGE_SETTINGS);
}
$request = reset($requests);
$response = $this
->vclRequestWrapper($request['url'], [], $request['data'], $request['type']);
if ($response
->getStatusCode() != "200") {
$this->messenger
->addError($response
->getBody());
return FALSE;
}
$id = $this->serviceId . '-' . $this->lastClonedVersion . '-imageopto';
$imageParams = [
'data' => [
'id' => $id,
'type' => 'io_settings',
'attributes' => $params,
],
];
$params['body'] = json_encode($imageParams);
$this
->configureImageOptimizationDefaultConfigOptions($params, $this->lastClonedVersion);
unset($responses);
$this
->prepareActivateVersion();
$request = $this
->prepareActivateVersion();
$response = $this
->vclRequestWrapper($request['url'], $request['headers'], [], $request['type']);
if ($response
->getStatusCode() != "200") {
$this->messenger
->addError($response
->getBody());
return FALSE;
}
} catch (\Exception $e) {
$this->logger
->error($e
->getMessage());
return FALSE;
}
return TRUE;
}
public function configureImageOptimizationDefaultConfigOptions($params, $version) {
$url = '/service/' . $this->serviceId . '/version/' . $version . '/io_settings';
return $this
->vclRequestWrapper($url, [], $params, 'PATCH');
}
public function checkImageOptimizerStatus() {
$url = '/service/' . $this->serviceId . '/dynamic_io_settings';
$req = $this
->vclGetWrapper($url);
return $req ? TRUE : FALSE;
}
public function removeImageOptimization() {
$this
->cloneLastActiveVersion();
$data['name'] = self::IMAGE_OPTIMIZER_BASIC_IMAGE_SETTINGS . '_recv';
if ($this
->getSnippetId($data)) {
$this
->removeSnippet($this->lastClonedVersion, $data['name']);
}
$this
->prepareActivateVersion();
$request = $this
->prepareActivateVersion();
$response = $this
->vclRequestWrapper($request['url'], $request['headers'], [], $request['type']);
if ($response
->getStatusCode() != "200") {
$this->messenger
->addError($response
->getBody());
return FALSE;
}
}
public function removeSnippet($version, $name) {
$url = '/service/' . $this->serviceId . '/version/' . $version . '/snippet/' . $name;
return $this
->vclRequestWrapper($url, [], [], 'DELETE');
}
public function getAllSnippets($version = null) {
$v = is_null($version) ? $this
->getLastVersion()->number : $version;
$url = $this->versionBaseUrl . "/" . $v . "/snippet";
$response = $this
->vclGetWrapper($url, $this->headersGet);
$responseBody = (string) $response
->getBody();
return json_decode($responseBody);
}
public function removeEdgeModule($name, $version = NULL) {
$this
->cloneLastActiveVersion();
$version = is_null($version) ? $this->lastClonedVersion : $version;
$snippets = $this
->getAllSnippets($version);
foreach ($snippets as $snippet) {
if (substr($snippet->name, 0, strlen(FastlyEdgeModulesHelper::FASTLY_EDGE_MODULE_PREFIX . $name)) === FastlyEdgeModulesHelper::FASTLY_EDGE_MODULE_PREFIX . $name) {
$this
->removeSnippet($version, $snippet->name);
}
}
$request = $this
->prepareActivateVersion();
$response = $this
->vclRequestWrapper($request['url'], $request['headers'], [], $request['type']);
if ($response
->getStatusCode() != "200") {
$this->messenger
->addError($response
->getBody());
return FALSE;
}
return TRUE;
}
public function uploadEdgeModule($name, $values) {
$this
->cloneLastActiveVersion();
switch ($name) {
case 'blackfire_integration':
case 'cors_headers':
case 'countryblock':
case 'datadome_integration':
case 'force_cache_miss_on_hard_reload_for_admins':
case 'increase_timeouts_long_jobs':
case 'mobile_device_detection':
case 'netacea_integration':
case 'disable_cache':
case 'other_cms_integration':
case 'redirect_hosts':
case 'url_rewrites':
$moduleConfig = FastlyEdgeModulesHelper::getModules();
$moduleConfig = $moduleConfig[$name];
foreach ($moduleConfig['vcl'] as $vcl) {
if (isset($vcl['priority'])) {
$data['priority'] = $vcl['priority'];
}
$data['name'] = FastlyEdgeModulesHelper::FASTLY_EDGE_MODULE_PREFIX . $name . '_' . $vcl['type'];
$path = drupal_get_path('module', 'fastly') . '/fastly_edge_modules/templates/';
$loader = new \Twig\Loader\ArrayLoader([
'template' => file_get_contents($path . $vcl['template'] . '.html.twig', TRUE),
]);
$twig = new \Twig\Environment($loader);
$data['content'] = $twig
->render('template', $values);
if (empty($data['content'])) {
continue;
}
$data['type'] = $vcl['type'];
$requests = $this
->prepareSingleVcl($data, FastlyEdgeModulesHelper::FASTLY_EDGE_MODULE_PREFIX);
foreach ($requests as $request) {
$request['headers'] = is_null($request['headers']) ? [] : $request['headers'];
$response = $this
->vclRequestWrapper($request['url'], $request['headers'], $request['data'], $request['type']);
if ($response
->getStatusCode() != "200") {
return FALSE;
}
}
}
break;
}
$request = $this
->prepareActivateVersion();
$response = $this
->vclRequestWrapper($request['url'], $request['headers'], [], $request['type']);
if ($response
->getStatusCode() != "200") {
$this->messenger
->addError($response
->getBody());
return FALSE;
}
return TRUE;
}
public function getAllAcls() {
$url = '/service/' . $this->serviceId . '/version/' . $this
->getLastVersion()->number . '/acl';
$response = $this
->vclRequestWrapper($url, [], [], 'GET');
return Json::decode($response
->getBody());
}
public function getAllDictionaries() {
$url = '/service/' . $this->serviceId . '/version/' . $this
->getLastVersion()->number . '/dictionary';
$response = $this
->vclRequestWrapper($url, [], [], 'GET');
return Json::decode($response
->getBody());
}
}