Skip to content

Commit

Permalink
Merge pull request #1 from putyourlightson/feature/api-token
Browse files Browse the repository at this point in the history
Feature/api token
  • Loading branch information
bencroker authored Sep 24, 2024
2 parents 5563365 + 07ed2b1 commit 46b4eb9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.idea
7 changes: 7 additions & 0 deletions src/F5Purger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -82,6 +87,7 @@ public function behaviors(): array
'baseUrl',
'namespace',
'name',
'apiToken',
],
];

Expand Down Expand Up @@ -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,
]);
Expand Down
14 changes: 13 additions & 1 deletion src/templates/settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'),
Expand Down

0 comments on commit 46b4eb9

Please sign in to comment.