From 3e50d9d02686a851b7e938283248bdb877f352fc Mon Sep 17 00:00:00 2001 From: Patric Eckhart Date: Tue, 13 Aug 2024 13:09:44 +0200 Subject: [PATCH 1/2] If you have private non-public cloud storage buckets, 'predefinedAcl' => 'private' is used instead of 'publicRead' --- Classes/GcsTarget.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Classes/GcsTarget.php b/Classes/GcsTarget.php index 20806bd..563d4ae 100644 --- a/Classes/GcsTarget.php +++ b/Classes/GcsTarget.php @@ -399,7 +399,7 @@ private function publishCollectionFromDifferentGoogleCloudStorage(CollectionInte $this->logger->debug(sprintf('Copy object "%s" to bucket "%s"', $targetObjectName, $this->bucketName), LogEnvironment::fromMethodName(__METHOD__)); $options = [ 'name' => $targetObjectName, - 'predefinedAcl' => 'publicRead', + 'predefinedAcl' => $this->persistentResourceUriEnableSigning ? 'private' : 'publicRead', 'contentType' => $object->getMediaType(), 'cacheControl' => 'public, max-age=1209600', ]; @@ -465,7 +465,7 @@ public function publishResource(PersistentResource $resource, CollectionInterfac $storageBucket = $this->storageClient->bucket($storage->getBucketName()); $storageBucket->object($storage->getKeyPrefix() . $resource->getSha1())->update( [ - 'predefinedAcl' => 'publicRead', + 'predefinedAcl' => $this->persistentResourceUriEnableSigning ? 'private' : 'publicRead', 'contentType' => $resource->getMediaType(), 'cacheControl' => 'public, max-age=1209600' ]); @@ -491,7 +491,7 @@ public function publishResource(PersistentResource $resource, CollectionInterfac try { $storageBucket->object($storage->getKeyPrefix() . $resource->getSha1())->copy($this->getCurrentBucket(), [ 'name' => $targetObjectName, - 'predefinedAcl' => 'publicRead', + 'predefinedAcl' => $this->persistentResourceUriEnableSigning ? 'private' : 'publicRead', 'contentType' => $resource->getMediaType(), 'cacheControl' => 'public, max-age=1209600', ]); @@ -598,7 +598,7 @@ protected function publishFile($sourceStream, string $relativeTargetPathAndFilen $objectName = $this->keyPrefix . $relativeTargetPathAndFilename; $uploadParameters = [ 'name' => $objectName, - 'predefinedAcl' => 'publicRead', + 'predefinedAcl' => $this->persistentResourceUriEnableSigning ? 'private' : 'publicRead', 'contentType' => $metaData->getMediaType(), 'cacheControl' => 'public, max-age=1209600' ]; From 90a5b2b50db543015233b60f729adb6a6bc2deab Mon Sep 17 00:00:00 2001 From: Patric Eckhart Date: Fri, 16 Aug 2024 13:07:30 +0200 Subject: [PATCH 2/2] objectVisibility targetOptions added --- Classes/GcsTarget.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Classes/GcsTarget.php b/Classes/GcsTarget.php index 563d4ae..17b6d3f 100644 --- a/Classes/GcsTarget.php +++ b/Classes/GcsTarget.php @@ -60,6 +60,13 @@ class GcsTarget implements TargetInterface */ protected $keyPrefix = ''; + /** + * Name of the Google Cloud Storage bucket which should be used for publication + * + * @var string + */ + protected $objectVisibility = 'publicRead'; + /** * @var string */ @@ -190,6 +197,9 @@ public function __construct(string $name, array $options = []) case 'keyPrefix': $this->keyPrefix = ltrim($value, '/'); break; + case 'objectVisibility': + $this->objectVisibility = $value; + break; case 'persistentResourceUris': if (!is_array($value)) { throw new Exception(sprintf('The option "%s" which was specified in the configuration of the "%s" resource GcsTarget is not a valid array. Please check your settings.', $key, $name), 1568875196); @@ -399,7 +409,7 @@ private function publishCollectionFromDifferentGoogleCloudStorage(CollectionInte $this->logger->debug(sprintf('Copy object "%s" to bucket "%s"', $targetObjectName, $this->bucketName), LogEnvironment::fromMethodName(__METHOD__)); $options = [ 'name' => $targetObjectName, - 'predefinedAcl' => $this->persistentResourceUriEnableSigning ? 'private' : 'publicRead', + 'predefinedAcl' => $this->objectVisibility, 'contentType' => $object->getMediaType(), 'cacheControl' => 'public, max-age=1209600', ]; @@ -465,7 +475,7 @@ public function publishResource(PersistentResource $resource, CollectionInterfac $storageBucket = $this->storageClient->bucket($storage->getBucketName()); $storageBucket->object($storage->getKeyPrefix() . $resource->getSha1())->update( [ - 'predefinedAcl' => $this->persistentResourceUriEnableSigning ? 'private' : 'publicRead', + 'predefinedAcl' => $this->objectVisibility, 'contentType' => $resource->getMediaType(), 'cacheControl' => 'public, max-age=1209600' ]); @@ -491,7 +501,7 @@ public function publishResource(PersistentResource $resource, CollectionInterfac try { $storageBucket->object($storage->getKeyPrefix() . $resource->getSha1())->copy($this->getCurrentBucket(), [ 'name' => $targetObjectName, - 'predefinedAcl' => $this->persistentResourceUriEnableSigning ? 'private' : 'publicRead', + 'predefinedAcl' => $this->objectVisibility, 'contentType' => $resource->getMediaType(), 'cacheControl' => 'public, max-age=1209600', ]); @@ -598,7 +608,7 @@ protected function publishFile($sourceStream, string $relativeTargetPathAndFilen $objectName = $this->keyPrefix . $relativeTargetPathAndFilename; $uploadParameters = [ 'name' => $objectName, - 'predefinedAcl' => $this->persistentResourceUriEnableSigning ? 'private' : 'publicRead', + 'predefinedAcl' => $this->objectVisibility, 'contentType' => $metaData->getMediaType(), 'cacheControl' => 'public, max-age=1209600' ];