diff --git a/Classes/S3Target.php b/Classes/S3Target.php index bfb2192..ea74e29 100644 --- a/Classes/S3Target.php +++ b/Classes/S3Target.php @@ -26,11 +26,17 @@ class S3Target implements TargetInterface { /** * The ACL when uploading a file - * @Flow\InjectConfiguration(package="Flownative.Aws.S3", path="profiles.default.acl") * @var string */ protected $acl; + /** + * The default ACL + * @Flow\InjectConfiguration(package="Flownative.Aws.S3", path="profiles.default.acl") + * @var string + */ + protected $defaultAcl; + /** * Name which identifies this resource target * @@ -72,13 +78,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 * @@ -147,9 +146,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; @@ -194,6 +190,16 @@ public function getKeyPrefix() return $this->keyPrefix; } + /** + * Returns the ACL when uploading a file + * + * @return string + */ + public function getAcl() + { + return isset($this->acl) ? $this->acl : $this->defaultAcl; + } + /** * Publishes the whole collection to this target * @@ -240,13 +246,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->getAcl()) { + $options['ACL'] = $this->getAcl(); + } 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)); @@ -317,13 +325,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->getAcl()) { + $options['ACL'] = $this->getAcl(); + } $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) { @@ -412,7 +422,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->getAcl() ? $this->getAcl() : 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()));