From aee70508f14b2b029ec5ea55b9a69be854cfff93 Mon Sep 17 00:00:00 2001 From: Michael Thomas Date: Tue, 24 Sep 2024 10:18:17 +0200 Subject: [PATCH 1/4] chore: add .idea --- .gitignore | 1 + 1 file changed, 1 insertion(+) 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 From 11ac80687cef24755049fd388c7735b254aa5521 Mon Sep 17 00:00:00 2001 From: Michael Thomas Date: Tue, 24 Sep 2024 10:18:26 +0200 Subject: [PATCH 2/4] feat: added API Token support --- src/F5Purger.php | 6 ++++++ src/templates/settings.twig | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/F5Purger.php b/src/F5Purger.php index a0388c5..d444541 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 @@ -221,6 +226,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..5005382 100644 --- a/src/templates/settings.twig +++ b/src/templates/settings.twig @@ -35,6 +35,18 @@ required: true, }) }} +{{ forms.autosuggestField({ + label: 'API Token'|t('blitz-f5'), + instructions: 'The API token.'|t('blitz-f5'), + placeholder: 'system', + suggestEnvVars: true, + suggestions: craft.cp.getEnvSuggestions(), + name: 'apiToken', + value: purger.apiToken, + errors: purger.getErrors('namespace'), + 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'), From 7b43f20d348dbf2df98ba14d317adbde38a3c8e2 Mon Sep 17 00:00:00 2001 From: Michael Thomas Date: Tue, 24 Sep 2024 10:30:31 +0200 Subject: [PATCH 3/4] fix: added apiToken to env parse behaviors --- src/F5Purger.php | 1 + src/templates/settings.twig | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/F5Purger.php b/src/F5Purger.php index d444541..c6ffe10 100644 --- a/src/F5Purger.php +++ b/src/F5Purger.php @@ -87,6 +87,7 @@ public function behaviors(): array 'baseUrl', 'namespace', 'name', + 'apiToken', ], ]; diff --git a/src/templates/settings.twig b/src/templates/settings.twig index 5005382..637cac1 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', @@ -38,7 +38,7 @@ {{ forms.autosuggestField({ label: 'API Token'|t('blitz-f5'), instructions: 'The API token.'|t('blitz-f5'), - placeholder: 'system', + placeholder: 'API Token', suggestEnvVars: true, suggestions: craft.cp.getEnvSuggestions(), name: 'apiToken', From 07ed2b10821449aafbcb58c89e86daeb3afc7587 Mon Sep 17 00:00:00 2001 From: Michael Thomas Date: Tue, 24 Sep 2024 10:34:58 +0200 Subject: [PATCH 4/4] fix: getting correct errors on apiToken --- src/templates/settings.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates/settings.twig b/src/templates/settings.twig index 637cac1..361074e 100644 --- a/src/templates/settings.twig +++ b/src/templates/settings.twig @@ -43,7 +43,7 @@ suggestions: craft.cp.getEnvSuggestions(), name: 'apiToken', value: purger.apiToken, - errors: purger.getErrors('namespace'), + errors: purger.getErrors('apiToken'), required: true, }) }}