summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfox <[email protected]>2022-12-03 17:19:28 +0300
committerfox <[email protected]>2022-12-03 17:19:28 +0300
commitbf4c92f945e8b4cf32e74e9def538a4b46fa11cf (patch)
tree77c9c093f70599ee1c65a6ce8a3dc17b40abaa15
parent64b4b9a3d4aba85e86fc32dbc2319bba04499074 (diff)
parente0df88bd1a4cb8f3ae8d75d05c5978c45a482cad (diff)
Merge pull request 'Use the AWS PHP SDK's default credential provider chain' (#2) from wn/ttrss-cache-s3:feature/use-default-cred-provider-chain into master
Reviewed-on: https://dev.tt-rss.org/tt-rss/ttrss-cache-s3/pulls/2
-rw-r--r--README.md8
-rw-r--r--init.php17
2 files changed, 18 insertions, 7 deletions
diff --git a/README.md b/README.md
index 2a1a54d..78e4e40 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# Cache S3
-File cache backend using S3 protocol (e.g. Minio)
+File cache backend using S3 protocol (e.g. Minio, AWS S3).
## Installation
@@ -14,6 +14,12 @@ The following options are required:
TTRSS_CACHE_S3_ENDPOINT=http://example.com:9000
TTRSS_CACHE_S3_BUCKET=bucket-name
TTRSS_CACHE_S3_REGION=us-east-1
+```
+
+The following options are required if you're directly providing access keys (i.e. not using an IAM role or alternative approach).
+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
TTRSS_CACHE_S3_ACCESS_KEY=xxx
TTRSS_CACHE_S3_SECRET_KEY=yyy
```
diff --git a/init.php b/init.php
index 10946c9..d8b42ab 100644
--- a/init.php
+++ b/init.php
@@ -34,17 +34,22 @@ class Cache_S3 extends Plugin implements Cache_Adapter {
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,
- 'credentials' => [
+ ];
+
+ 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)
- ],
- ]);
+ '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();