summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwn_ <[email protected]>2022-12-03 14:02:59 +0000
committerwn_ <[email protected]>2022-12-03 14:02:59 +0000
commit09b07d59ef5175ac084b39e9d99eed9900813a45 (patch)
tree426c72a65f5da6d3bbd3836e40df7eb876f77b32
parent579cf771e59347a5892f5bfbcb23eedd0d34b529 (diff)
Switch back to plugin-specific access key env vars.
-rw-r--r--README.md5
-rw-r--r--init.php21
2 files changed, 19 insertions, 7 deletions
diff --git a/README.md b/README.md
index b8e68d7..78e4e40 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,6 @@ The following options are required if you're directly providing access keys (i.e
See [Credentials for the AWS SDK for PHP Version 3](https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html) for more information.
```ini
-# Intentionally without the 'TTRSS_' prefix.
-AWS_ACCESS_KEY_ID=xxx
-AWS_SECRET_ACCESS_KEY=yyy
+TTRSS_CACHE_S3_ACCESS_KEY=xxx
+TTRSS_CACHE_S3_SECRET_KEY=yyy
```
diff --git a/init.php b/init.php
index 232a098..1fff42d 100644
--- a/init.php
+++ b/init.php
@@ -13,6 +13,8 @@ class Cache_S3 extends Plugin implements Cache_Adapter {
const CACHE_S3_ENDPOINT = "CACHE_S3_ENDPOINT";
const CACHE_S3_BUCKET = "CACHE_S3_BUCKET";
const CACHE_S3_REGION = "CACHE_S3_REGION";
+ const CACHE_S3_ACCESS_KEY = "CACHE_S3_ACCESS_KEY";
+ const CACHE_S3_SECRET_KEY = "CACHE_S3_SECRET_KEY";
public function remove(string $filename): bool {
return unlink($this->get_full_path($filename));
@@ -29,14 +31,25 @@ class Cache_S3 extends Plugin implements Cache_Adapter {
Config::add(self::CACHE_S3_ENDPOINT, "", Config::T_STRING);
Config::add(self::CACHE_S3_BUCKET, "", Config::T_STRING);
Config::add(self::CACHE_S3_REGION, "", Config::T_STRING);
+ Config::add(self::CACHE_S3_ACCESS_KEY, "", Config::T_STRING);
+ Config::add(self::CACHE_S3_SECRET_KEY, "", Config::T_STRING);
- /** @phpstan-ignore-next-line */
- $this->s3 = new Aws\S3\S3Client([
+ $s3_client_props = [
'version' => 'latest',
'region' => Config::get(self::CACHE_S3_REGION),
'endpoint' => Config::get(self::CACHE_S3_ENDPOINT),
'use_path_style_endpoint' => true,
- ]);
+ ];
+
+ if (Config::get(self::CACHE_S3_ACCESS_KEY) && Config::get(self::CACHE_S3_SECRET_KEY)) {
+ $s3_client_props['credentials'] = [
+ 'key' => Config::get(self::CACHE_S3_ACCESS_KEY),
+ 'secret' => Config::get(self::CACHE_S3_SECRET_KEY),
+ ];
+ }
+
+ /** @phpstan-ignore-next-line */
+ $this->s3 = new Aws\S3\S3Client($s3_client_props);
/** @phpstan-ignore-next-line */
$this->s3->registerStreamWrapper();
@@ -79,7 +92,7 @@ class Cache_S3 extends Plugin implements Cache_Adapter {
}
public function get_full_path(string $filename): string {
- return 's3://' . Config::get(self::CACHE_S3_BUCKET) . '/' . ($this->dir ? $this->dir . '/' : '') . basename(clean($filename));
+ return 's3://' . Config::get(self::CACHE_S3_BUCKET) . '/' . $this->dir . '/' . basename(clean($filename));
}
public function get_mime_type(string $filename) {