Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ composer require craftcms/google-cloud

## Setup

Your Google Cloud bucket must use Google's `Fine grained` (per object) permissions, not `Uniform` (per bucket).

In case your Google Cloud bucket uses Google's `Fine grained` (per object) permissions:
On the permissions table for the new bucket, grant `Storage Object Viewer` to `allUsers`. The `Storage Admin` role should be granted to the service account the credentials are tied to.

To create a new asset volume for your Google Cloud Storage bucket, go to Settings → Assets, create a new volume, and set the Volume Type setting to “Google Cloud Storage”.

> **Tip:** The Project ID, Bucket, and Subfolder settings can be set to environment variables. See [Environmental Configuration](https://docs.craftcms.com/v3/config/environments.html) in the Craft docs to learn more about that.

In case your Google Cloud bucket uses Uniform bucket-level access, just make sure to set the `Visibility` in your volume settings to `Uniform Bucket-Level Access`.
14 changes: 13 additions & 1 deletion src/Fs.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use League\Flysystem\FilesystemAdapter;
use League\Flysystem\GoogleCloudStorage\GoogleCloudStorageAdapter;
use League\Flysystem\GoogleCloudStorage\PortableVisibilityHandler;
use League\Flysystem\GoogleCloudStorage\UniformBucketLevelAccessVisibility;
use League\Flysystem\Visibility;

/**
Expand All @@ -36,6 +37,9 @@
*/
class Fs extends FlysystemFs
{

public const UNIFORM_BUCKET_LEVEL_ACCESS = 'uniformBucketLevelAccess';

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -135,6 +139,7 @@ public function getVisibilityOptions(): array
['value' => '', 'label' => Craft::t('google-cloud', 'Automatic')],
['value' => Visibility::PUBLIC, 'label' => Craft::t('google-cloud', 'Public')],
['value' => Visibility::PRIVATE, 'label' => Craft::t('google-cloud', 'Private')],
['value' => self::UNIFORM_BUCKET_LEVEL_ACCESS, 'label' => Craft::t('google-cloud', 'Uniform Bucket-Level Access')],
];
}

Expand Down Expand Up @@ -253,7 +258,14 @@ protected function createAdapter(): FilesystemAdapter
$client = static::client($config);
$bucket = $client->bucket(Craft::parseEnv($this->bucket));

return new GoogleCloudStorageAdapter($bucket, $this->_subfolder(), new PortableVisibilityHandler('allUsers'));
$visibilityHandler = null;
if ($this->visibility === self::UNIFORM_BUCKET_LEVEL_ACCESS) {
$visibilityHandler = new UniformBucketLevelAccessVisibility();
} else {
$visibilityHandler = new PortableVisibilityHandler('allUsers');
}

return new GoogleCloudStorageAdapter($bucket, $this->_subfolder(), $visibilityHandler);
}

/**
Expand Down