diff --git a/README.md b/README.md index 62fd82d..3633c0d 100644 --- a/README.md +++ b/README.md @@ -22,15 +22,17 @@ php flarum cache:clear The S3 (or compatible) bucket can be configured either by environment variables or via the extension settings. If the environment variables are set, they will override the settings entered in the admin panel, if set. #### Environment variables -- `AWS_ACCESS_KEY_ID` - your access key ID -- `AWS_SECRET_ACCESS_KEY` - your secret -- `AWS_DEFAULT_REGION` - the region -- `AWS_BUCKET` - the bucket name -- `AWS_URL` - the public facing base URL of the bucket -- `AWS_ENDPOINT` - the ARN -- `AWS_ACL` - The ACL, if any, that should be applied to the uploaded object (default: private). For possible values, see [AWS Docs](https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl) +- `FOF_S3_AWS_ACCESS_KEY_ID` - your access key ID * +- `FOF_S3_AWS_SECRET_ACCESS_KEY` - your secret * +- `FOF_S3_AWS_DEFAULT_REGION` - the region * +- `FOF_S3_AWS_BUCKET` - the bucket name * +- `FOF_S3_AWS_URL` - the public facing base URL of the bucket +- `FOF_S3_AWS_ENDPOINT` - the ARN +- `FOF_S3_AWS_ACL` - The ACL, if any, that should be applied to the uploaded object. For possible values, see [AWS Docs](https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl) - `AWS_PATH_STYLE_ENDPOINT` - boolean value +`*` denotes the minimum requirements for using S3 on AWS. S3-compatible services will require more. + If you plan to setup the S3 configuration using the environment variables, please ensure these are set _before_ enabling the extension #### Transferring assets from the existing filesystem to the S3 bucket diff --git a/js/src/admin/components/S3SettingsPage.tsx b/js/src/admin/components/S3SettingsPage.tsx index fbaf953..5ae31e0 100644 --- a/js/src/admin/components/S3SettingsPage.tsx +++ b/js/src/admin/components/S3SettingsPage.tsx @@ -95,7 +95,7 @@ export default class S3SettingsPage extends ExtensionPage { 'awsS3Key', this.buildSettingComponent({ setting: `${this.settingPrefix}awsS3Key`, - type: 'string', + type: 'password', label: app.translator.trans('fof-s3-assets.admin.settings.s3key.label'), help: app.translator.trans('fof-s3-assets.admin.settings.s3key.help'), }) @@ -105,7 +105,7 @@ export default class S3SettingsPage extends ExtensionPage { 'awsS3Secret', this.buildSettingComponent({ setting: `${this.settingPrefix}awsS3Secret`, - type: 'string', + type: 'password', label: app.translator.trans('fof-s3-assets.admin.settings.s3secret.label'), help: app.translator.trans('fof-s3-assets.admin.settings.s3secret.help'), }) diff --git a/src/Content/AdminPayload.php b/src/Content/AdminPayload.php index 6ae81ed..c8851a4 100644 --- a/src/Content/AdminPayload.php +++ b/src/Content/AdminPayload.php @@ -14,6 +14,7 @@ use Flarum\Foundation\Config; use Flarum\Frontend\Document; use Flarum\Settings\SettingsRepositoryInterface; +use FoF\S3Assets\Driver\Config as S3Config; use FoF\S3Assets\Repository\S3Repository; use Illuminate\Support\Arr; @@ -22,13 +23,14 @@ class AdminPayload public function __construct( protected Config $config, protected SettingsRepositoryInterface $settings, - protected S3Repository $s3 + protected S3Repository $s3, + protected S3Config $s3Config ) { } public function __invoke(Document $document) { - $document->payload['s3SetByEnv'] = Arr::get($this->config->offsetGet('filesystems'), 'disks.s3.set_by_environment'); + $document->payload['s3SetByEnv'] = $this->s3Config->shouldUseEnv(); $document->payload['FoFS3Regions'] = $this->s3->getAwsRegions(); $document->payload['FoFS3ShareWithFoFUpload'] = $this->settings->get('fof-s3-assets.share_s3_config_with_fof_upload'); } diff --git a/src/Driver/Config.php b/src/Driver/Config.php index 2d8e85a..e5b8c1c 100644 --- a/src/Driver/Config.php +++ b/src/Driver/Config.php @@ -25,9 +25,9 @@ public function __construct( ) { } - protected function shouldUseEnv(): bool + public function shouldUseEnv(): bool { - return env('AWS_ACCESS_KEY_ID') && env('AWS_SECRET_ACCESS_KEY') && env('AWS_BUCKET'); + return env('FOF_S3_AWS_ACCESS_KEY_ID') && env('FOF_S3_AWS_SECRET_ACCESS_KEY') && env('FOF_S3_AWS_BUCKET') && env('FOF_S3_AWS_REGION'); } public function config(): array @@ -44,7 +44,7 @@ public function config(): array try { $this->validator->assertValid($config); } catch (IlluminateValidationException $e) { - $this->logger->error('[fof-s3-assets] Invalid S3 disk configuration', ['errors' => $e->errors()]); + $this->logger->error('[FOF_S3-assets] Invalid S3 disk configuration', ['errors' => $e->errors()]); return []; } @@ -87,16 +87,16 @@ protected function buildConfigArray(string $key, string $secret, string $region, protected function buildConfigFromEnv(): array { - $bucket = env('AWS_BUCKET'); - $region = env('AWS_DEFAULT_REGION'); - $cdnUrl = env('AWS_URL', $this->createAwsUrlFromBucketAndRegion($bucket, $region)); - $endpoint = env('AWS_ENDPOINT'); - $pathStyle = (bool) env('AWS_PATH_STYLE_ENDPOINT', false); - $acl = env('AWS_ACL'); + $bucket = env('FOF_S3_AWS_BUCKET'); + $region = env('FOF_S3_AWS_REGION'); + $cdnUrl = env('FOF_S3_AWS_URL', $this->createAwsUrlFromBucketAndRegion($bucket, $region)); + $endpoint = env('FOF_S3_AWS_ENDPOINT'); + $pathStyle = (bool) env('FOF_S3_AWS_PATH_STYLE_ENDPOINT', false); + $acl = env('FOF_S3_AWS_ACL'); return $this->buildConfigArray( - key: env('AWS_ACCESS_KEY_ID'), - secret: env('AWS_SECRET_ACCESS_KEY'), + key: env('FOF_S3_AWS_ACCESS_KEY_ID'), + secret: env('FOF_S3_AWS_SECRET_ACCESS_KEY'), region: $region, bucket: $bucket, cdnUrl: $cdnUrl, @@ -148,12 +148,12 @@ protected function createAwsUrlFromBucketAndRegion(?string $bucket, ?string $reg protected function getSettingsPrefix(): string { - $shareWithFoFUpload = (bool) $this->settings->get('fof-s3-assets.share_s3_config_with_fof_upload'); + $shareWithFoFUpload = (bool) $this->settings->get('FOF_S3-assets.share_s3_config_with_fof_upload'); if ($shareWithFoFUpload) { return 'fof-upload'; } - return 'fof-s3-assets'; + return 'FOF_S3-assets'; } }