Skip to content

Commit

Permalink
Add No Bucket Check for S3 Media Sources (#16496)
Browse files Browse the repository at this point in the history
### What does it do?
Add a "No Bucket Check" option for users with limited access.

### Why is it needed?
Some access keys aren't authorized to list buckets, so will fail to
initialize the S3 source when it checks if the bucket exists.

### How to test
This would take some set up. Primarily, this is addressing an issue we
are facing with updating our internal S3 provider. However, it is a
common feature and the logic was ported from rclone
https://rclone.org/s3/#s3-no-check-bucket
  • Loading branch information
matdave committed May 29, 2024
1 parent 28b4032 commit e1e45ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/lexicon/en/source.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
$_lang['prop_s3.endpoint_desc'] = 'Alternative S3-compatible endpoint URL, e.g., "https://s3.<region>.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_check_bucket_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 */
Expand Down
11 changes: 10 additions & 1 deletion core/src/Revolution/Sources/modS3MediaSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand All @@ -54,7 +55,7 @@ public function initialize()

try {
$client = new S3Client($config);
if (!$client->doesBucketExist($bucket)) {
if (!$noBucketCheck && !$client->doesBucketExist($bucket)) {
$this->xpdo->log(
xPDO::LOG_LEVEL_ERROR,
$this->xpdo->lexicon('source_err_init', ['source' => $this->get('name')])
Expand Down Expand Up @@ -158,6 +159,14 @@ public function getDefaultProperties()
'value' => '',
'lexicon' => 'core:source',
],
'no_check_bucket' => [
'name' => 'no_check_bucket',
'desc' => 'prop_s3.no_check_bucket_desc',
'type' => 'combo-boolean',
'options' => '',
'value' => false,
'lexicon' => 'core:source',
],
'imageExtensions' => [
'name' => 'imageExtensions',
'desc' => 'prop_s3.imageExtensions_desc',
Expand Down

0 comments on commit e1e45ff

Please sign in to comment.