Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 Update: Add No Bucket Check #16496

Open
wants to merge 3 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions core/lexicon/en/source.inc.php
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
25 changes: 18 additions & 7 deletions core/src/Revolution/Sources/modS3MediaSource.php
Expand Up @@ -38,6 +38,7 @@
$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 @@

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)) {
matdave marked this conversation as resolved.
Show resolved Hide resolved
$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 @@
'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',
],

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