Skip to content

Commit

Permalink
BUGFIX: clear mixed up acl target settings
Browse files Browse the repository at this point in the history
  • Loading branch information
batabana committed Aug 4, 2021
1 parent 68188f7 commit 1f8e649
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions Classes/S3Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ class S3Target implements TargetInterface
*/
protected $unpublishResources = true;

/**
* If `true` (default) the S3 ACL is set to `public-read`. If `false` no ACL option will be set.
*
* @var boolean
*/
protected $accessPolicyEnabled = true;

/**
* Internal cache for known storages, indexed by storage name
*
Expand Down Expand Up @@ -147,9 +140,6 @@ public function __construct($name, array $options = array())
case 'unpublishResources':
$this->unpublishResources = (bool)$value;
break;
case 'accessPolicyEnabled':
$this->accessPolicyEnabled = (bool)$value;
break;
case 'acl':
$this->acl = (string)$value;
break;
Expand Down Expand Up @@ -240,13 +230,15 @@ public function publishCollection(CollectionInterface $collection, callable $cal
$potentiallyObsoleteObjects[$objectName] = false;
} else {
$options = [
'ACL' => $this->acl,
'Bucket' => $this->bucketName,
'CopySource' => urlencode($storageBucketName . '/' . $storage->getKeyPrefix() . $object->getSha1()),
'ContentType' => $object->getMediaType(),
'MetadataDirective' => 'REPLACE',
'Key' => $objectName
];
if ($this->acl !== '') {
$options['ACL'] = $this->acl;
}
try {
$this->s3Client->copyObject($options);
$this->systemLogger->debug(sprintf('Successfully copied resource as object "%s" (SHA1: %s) from bucket "%s" to bucket "%s"', $objectName, $object->getSha1() ?: 'unknown', $storageBucketName, $this->bucketName));
Expand Down Expand Up @@ -317,13 +309,15 @@ public function publishResource(PersistentResource $resource, CollectionInterfac
$sourceObjectArn = $storage->getBucketName() . '/' . $storage->getKeyPrefix() . $resource->getSha1();
$objectName = $this->keyPrefix . $this->getRelativePublicationPathAndFilename($resource);
$options = [
'ACL' => $this->acl,
'Bucket' => $this->bucketName,
'CopySource' => urlencode($sourceObjectArn),
'ContentType'=> $resource->getMediaType(),
'MetadataDirective' => 'REPLACE',
'Key' => $objectName
];
if ($this->acl !== '') {
$options['ACL'] = $this->acl;
}
$this->s3Client->copyObject($options);
$this->systemLogger->debug(sprintf('Successfully published resource as object "%s" (SHA1: %s) by copying from bucket "%s" to bucket "%s"', $objectName, $resource->getSha1() ?: 'unknown', $storage->getBucketName(), $this->bucketName));
} catch (S3Exception $e) {
Expand Down Expand Up @@ -412,7 +406,7 @@ protected function publishFile($sourceStream, $relativeTargetPathAndFilename, Re
);

try {
$this->s3Client->upload($this->bucketName, $objectName, $sourceStream, $this->accessPolicyEnabled !== false ? 'public-read' : null, $options);
$this->s3Client->upload($this->bucketName, $objectName, $sourceStream, $this->acl !== '' ? $this->acl : null, $options);
$this->systemLogger->debug(sprintf('Successfully published resource as object "%s" in bucket "%s" with SHA1 hash "%s"', $objectName, $this->bucketName, $metaData->getSha1() ?: 'unknown'));
} catch (\Exception $e) {
$this->systemLogger->debug(sprintf('Failed publishing resource as object "%s" in bucket "%s" with SHA1 hash "%s": %s', $objectName, $this->bucketName, $metaData->getSha1() ?: 'unknown', $e->getMessage()));
Expand Down

0 comments on commit 1f8e649

Please sign in to comment.