Skip to content

Commit 61e7f98

Browse files
authored
Merge pull request #195 from rvanlaak/feat/retain-visibility-config
2 parents 8837667 + 81ef411 commit 61e7f98

File tree

6 files changed

+46
-1
lines changed

6 files changed

+46
-1
lines changed

docs/2-cloud-storage-providers.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ flysystem:
161161
## Cloudflare R2
162162
163163
The Cloudflare R2 is compatible with the AWS S3 API, meaning that you can use the same configuration
164-
as for a AWS storage. For example:
164+
as for an AWS storage. Both the regular and the async AWS Client can be used. As example:
165165
166166
```yaml
167167
# config/packages/flysystem.yaml
@@ -184,6 +184,23 @@ flysystem:
184184
bucket: '%env(CLOUDFLARE_R2_BUCKET)%'
185185
```
186186
187+
Cloudflare R2 does not have implemented ACL-related features yet, and thereby making use of Flysystem's `move` and `copy`
188+
methods requires configuring explicit value for `visibility` and setting `retain_visibility` to `false` to prevent the
189+
S3 adapter to call the `GetObjectAcl` command to retrieve an object's current ACL visibility, then resulting in an exception.
190+
191+
```yaml
192+
flysystem:
193+
storages:
194+
cdn.storage:
195+
# ...
196+
visibility: private # or public
197+
198+
# to use the visibility as defined above instead of retaining the object's visibility, and not having to run
199+
# the unsupported `GetObjectAcl` command to get the object's current visibility.
200+
retain_visibility: false
201+
# ...
202+
```
203+
187204
## Next
188205

189206
[Interacting with FTP and SFTP servers](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/3-interacting-with-ftp-and-sftp-servers.md)

docs/B-configuration-reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ flysystem:
5252
private: 0o700
5353
visibility: ~ # default null. Possible values are 'public' or 'private'
5454
directory_visibility: ~ # default null. Possible values are 'public' or 'private'
55+
retain_visibility: ~ # default null. When set to `true` or `null`, it will lead to adapters performing visibility checks (e.g. GetObjectAcl command for S3 adapters) on copy and move actions, hence `false` prevents retrieving an object's current visibility and use the value as set in `visibility` instead
5556
case_sensitive: true
5657
disable_asserts: false
5758

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function getConfigTreeBuilder(): TreeBuilder
4242
->end()
4343
->scalarNode('visibility')->defaultNull()->end()
4444
->scalarNode('directory_visibility')->defaultNull()->end()
45+
->booleanNode('retain_visibility')->defaultNull()->end()
4546
->booleanNode('case_sensitive')->defaultTrue()->end()
4647
->booleanNode('disable_asserts')->defaultFalse()->end()
4748
->arrayNode('public_url')

src/DependencyInjection/FlysystemExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ private function createStorageDefinition(string $storageName, Reference $adapter
124124
$definition->setArgument(1, [
125125
'visibility' => $config['visibility'],
126126
'directory_visibility' => $config['directory_visibility'],
127+
'retain_visibility' => $config['retain_visibility'],
127128
'case_sensitive' => $config['case_sensitive'],
128129
'disable_asserts' => $config['disable_asserts'],
129130
'public_url' => $publicUrl,

tests/DependencyInjection/FlysystemExtensionTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Aws\S3\S3Client;
1616
use Google\Cloud\Storage\Bucket;
1717
use Google\Cloud\Storage\StorageClient;
18+
use League\Flysystem\Filesystem;
1819
use League\Flysystem\FilesystemOperator;
1920
use League\Flysystem\UnableToWriteFile;
2021
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
@@ -118,6 +119,28 @@ public function testReadOnly(): void
118119
$fs->write('/path/to/file', 'Unable to write in read only');
119120
}
120121

122+
public function testNotRetainingVisibilityPreventsAclCommandInvocation(): void
123+
{
124+
$kernel = $this->createFlysystemKernel();
125+
$container = $kernel->getContainer()->get('test.service_container');
126+
127+
$calledGetObjectAcl = false;
128+
129+
/** @var S3Client $mock */
130+
$mock = $container->get('aws_client_service');
131+
$mock->method('getCommand')->with($this->callback(function ($name) use (&$calledGetObjectAcl) {
132+
if ('GetObjectAcl' === $name) {
133+
$calledGetObjectAcl = true;
134+
}
135+
}));
136+
137+
/** @var Filesystem $fs */
138+
$fs = $container->get('flysystem.test.fs_aws');
139+
$fs->copy('test.txt', 'test2.txt');
140+
141+
self::assertFalse($calledGetObjectAcl, 'The ACL command should not be called when `retain_visibility` is set to `false`.');
142+
}
143+
121144
private function createFlysystemKernel(): FlysystemAppKernel
122145
{
123146
(new Dotenv())->populate([

tests/Kernel/config/flysystem.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
],
1616
'fs_aws' => [
1717
'adapter' => 'aws',
18+
'visibility' => 'private',
19+
'retain_visibility' => false,
1820
'options' => [
1921
'client' => 'aws_client_service',
2022
'bucket' => '%env(AWS_BUCKET)%',

0 commit comments

Comments
 (0)