Skip to content

Commit

Permalink
Add a "No Bucket Check" option for users with limited access
Browse files Browse the repository at this point in the history
  • Loading branch information
matdave committed Nov 15, 2023
1 parent 73bfd27 commit f0cd261
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
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_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 */
Expand Down
25 changes: 18 additions & 7 deletions 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);

Check warning on line 41 in core/src/Revolution/Sources/modS3MediaSource.php

View check run for this annotation

Codecov / codecov/patch

core/src/Revolution/Sources/modS3MediaSource.php#L41

Added line #L41 was not covered by tests

$config = [
'credentials' => [
Expand All @@ -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')])
);

Check warning on line 63 in core/src/Revolution/Sources/modS3MediaSource.php

View check run for this annotation

Codecov / codecov/patch

core/src/Revolution/Sources/modS3MediaSource.php#L58-L63

Added lines #L58 - L63 were not covered by tests

return false;

Check warning on line 65 in core/src/Revolution/Sources/modS3MediaSource.php

View check run for this annotation

Codecov / codecov/patch

core/src/Revolution/Sources/modS3MediaSource.php#L65

Added line #L65 was not covered by tests
}
}
$adapter = new AwsS3V3Adapter(new S3Client($config), $bucket, $prefix);
$this->loadFlySystem($adapter);
Expand Down Expand Up @@ -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',
],

Check warning on line 171 in core/src/Revolution/Sources/modS3MediaSource.php

View check run for this annotation

Codecov / codecov/patch

core/src/Revolution/Sources/modS3MediaSource.php#L164-L171

Added lines #L164 - L171 were not covered by tests
'imageExtensions' => [
'name' => 'imageExtensions',
'desc' => 'prop_s3.imageExtensions_desc',
Expand Down

0 comments on commit f0cd261

Please sign in to comment.