Skip to content

Commit

Permalink
BUGFIX: prevent overwrite of acl setting with default
Browse files Browse the repository at this point in the history
  • Loading branch information
batabana committed Aug 4, 2021
1 parent 1f8e649 commit 87a866d
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions Classes/S3Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -184,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
*
Expand Down Expand Up @@ -236,8 +252,8 @@ public function publishCollection(CollectionInterface $collection, callable $cal
'MetadataDirective' => 'REPLACE',
'Key' => $objectName
];
if ($this->acl !== '') {
$options['ACL'] = $this->acl;
if ($this->getAcl()) {
$options['ACL'] = $this->getAcl();
}
try {
$this->s3Client->copyObject($options);
Expand Down Expand Up @@ -315,8 +331,8 @@ public function publishResource(PersistentResource $resource, CollectionInterfac
'MetadataDirective' => 'REPLACE',
'Key' => $objectName
];
if ($this->acl !== '') {
$options['ACL'] = $this->acl;
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));
Expand Down Expand Up @@ -406,7 +422,7 @@ protected function publishFile($sourceStream, $relativeTargetPathAndFilename, Re
);

try {
$this->s3Client->upload($this->bucketName, $objectName, $sourceStream, $this->acl !== '' ? $this->acl : 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()));
Expand Down

0 comments on commit 87a866d

Please sign in to comment.