diff --git a/.gitignore b/.gitignore index e43b0f9..3d72576 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .DS_Store +.idea \ No newline at end of file diff --git a/src/F5Purger.php b/src/F5Purger.php index a0388c5..c6ffe10 100644 --- a/src/F5Purger.php +++ b/src/F5Purger.php @@ -44,6 +44,11 @@ class F5Purger extends BaseCachePurger */ public string $name = ''; + /** + * @var string + */ + public string $apiToken = ''; + /** * Whether to remove the content from the distribution, forcing the next request to retrieve the content from the origin server. With this off, the content will be replaced on the next request if the content is stale. * https://docs.cloud.f5.com/docs-v2/content-delivery-network/how-to/configure-cdn-distribution @@ -82,6 +87,7 @@ public function behaviors(): array 'baseUrl', 'namespace', 'name', + 'apiToken', ], ]; @@ -221,6 +227,7 @@ private function sendRequest(string $pattern): bool 'base_uri' => $this->baseUrl, 'headers' => [ 'Content-Type' => 'application/json', + 'Authorization' => 'APIToken ' . $this->apiToken, ], 'timeout' => self::API_REQUEST_TIMEOUT, ]); diff --git a/src/templates/settings.twig b/src/templates/settings.twig index c0d81b3..361074e 100644 --- a/src/templates/settings.twig +++ b/src/templates/settings.twig @@ -15,7 +15,7 @@ {{ forms.autosuggestField({ label: 'Namespace'|t('blitz-f5'), instructions: 'The CDN namespace.'|t('blitz-f5'), - placeholder: 'system', + placeholder: 'namespace', suggestEnvVars: true, suggestions: craft.cp.getEnvSuggestions(), name: 'namespace', @@ -35,6 +35,18 @@ required: true, }) }} +{{ forms.autosuggestField({ + label: 'API Token'|t('blitz-f5'), + instructions: 'The API token.'|t('blitz-f5'), + placeholder: 'API Token', + suggestEnvVars: true, + suggestions: craft.cp.getEnvSuggestions(), + name: 'apiToken', + value: purger.apiToken, + errors: purger.getErrors('apiToken'), + required: true, +}) }} + {{ forms.lightswitchField({ label: 'Hard Purge'|t('blitz-f5'), instructions: 'Whether to remove the content from the distribution, forcing the next request to retrieve the content from the origin server. With this off, the content will be replaced on the next request if the content is stale.'|t('blitz-f5'),