From f0cd2614ca50452fd347ce114f6760c4b8245acb Mon Sep 17 00:00:00 2001 From: matdave Date: Wed, 15 Nov 2023 12:40:45 -0600 Subject: [PATCH] Add a "No Bucket Check" option for users with limited access --- core/lexicon/en/source.inc.php | 1 + .../Revolution/Sources/modS3MediaSource.php | 25 +++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/core/lexicon/en/source.inc.php b/core/lexicon/en/source.inc.php index 6d9c00e7672..5a3db6bb6ef 100644 --- a/core/lexicon/en/source.inc.php +++ b/core/lexicon/en/source.inc.php @@ -84,6 +84,7 @@ $_lang['prop_s3.endpoint_desc'] = 'Alternative S3-compatible endpoint URL, e.g., "https://s3..example.com". Review your S3-compatible provider’s documentation for the endpoint location. Leave empty for Amazon S3'; $_lang['prop_s3.region_desc'] = 'Region of the bucket. Example: us-west-1'; $_lang['prop_s3.prefix_desc'] = 'Optional path/folder prefix'; +$_lang['prop_s3.no_bucket_check_desc'] = 'If set, don\'t attempt to check the bucket exists. It can be needed if the access key you are using does not have bucket creation/list permissions.'; $_lang['s3_no_move_folder'] = 'The S3 driver does not support moving of folders at this time.'; /* ftp source type */ diff --git a/core/src/Revolution/Sources/modS3MediaSource.php b/core/src/Revolution/Sources/modS3MediaSource.php index 7ab7cca326c..44c6a35bca4 100644 --- a/core/src/Revolution/Sources/modS3MediaSource.php +++ b/core/src/Revolution/Sources/modS3MediaSource.php @@ -38,6 +38,7 @@ public function initialize() $bucket = $this->xpdo->getOption('bucket', $properties, ''); $prefix = $this->xpdo->getOption('prefix', $properties, ''); $endpoint = $this->xpdo->getOption('endpoint', $properties, ''); + $noBucketCheck = $this->xpdo->getOption('no_check_bucket', $properties, false); $config = [ 'credentials' => [ @@ -54,13 +55,15 @@ public function initialize() try { $client = new S3Client($config); - if (!$client->doesBucketExist($bucket)) { - $this->xpdo->log( - xPDO::LOG_LEVEL_ERROR, - $this->xpdo->lexicon('source_err_init', ['source' => $this->get('name')]) - ); - - return false; + if (!$noBucketCheck) { + if (!$client->doesBucketExist($bucket)) { + $this->xpdo->log( + xPDO::LOG_LEVEL_ERROR, + $this->xpdo->lexicon('source_err_init', ['source' => $this->get('name')]) + ); + + return false; + } } $adapter = new AwsS3V3Adapter(new S3Client($config), $bucket, $prefix); $this->loadFlySystem($adapter); @@ -158,6 +161,14 @@ public function getDefaultProperties() 'value' => '', 'lexicon' => 'core:source', ], + 'no_bucket_check' => [ + 'name' => 'no_bucket_check', + 'desc' => 'prop_s3.no_bucket_check_desc', + 'type' => 'combo-boolean', + 'options' => '', + 'value' => false, + 'lexicon' => 'core:source', + ], 'imageExtensions' => [ 'name' => 'imageExtensions', 'desc' => 'prop_s3.imageExtensions_desc',