Skip to content

Commit 82c4826

Browse files
author
brecht.vermeersch
committed
add temporary urls
1 parent 761b64c commit 82c4826

File tree

5 files changed

+38
-70
lines changed

5 files changed

+38
-70
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The connection string can be obtained from the azure portal.
2424
```php
2525
<?php
2626

27-
use AzureOss\FlysystemAzureBlobStorage\AzureBlobStorageAdapter;
27+
use AzureOss\src\AzureBlobStorageAdapter;
2828
use AzureOss\Storage\Blob\BlobServiceClient;
2929
use League\Flysystem\Filesystem;
3030

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"autoload": {
1313
"psr-4": {
14-
"AzureOss\\FlysystemAzureBlobStorage\\": "FlysystemAzureBlobStorage/"
14+
"AzureOss\\FlysystemAzureBlobStorage\\": "src/"
1515
}
1616
},
1717
"autoload-dev": {

pint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"preset": "psr12",
2+
"preset": "per",
33
"rules": {
44
"declare_strict_types": true
55
}

FlysystemAzureBlobStorage/AzureBlobStorageAdapter.php renamed to src/AzureBlobStorageAdapter.php

Lines changed: 27 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44

55
namespace AzureOss\FlysystemAzureBlobStorage;
66

7-
use AzureOss\Storage\Blob\ContainerClient;
7+
use AzureOss\Storage\Blob\Clients\ContainerClient;
88
use AzureOss\Storage\Blob\Options\ListBlobsOptions;
99
use AzureOss\Storage\Blob\Options\UploadBlockBlobOptions;
10-
use AzureOss\Storage\Common\SAS\BlobSASPermission;
11-
use AzureOss\Storage\Common\SAS\BlobSASSignatureValues;
12-
use AzureOss\Storage\Common\SAS\SasIpRange;
13-
use AzureOss\Storage\Common\SAS\SasProtocol;
14-
use AzureOss\Storage\Common\SAS\SharedAccessSignatureHelper;
15-
use DateTimeInterface;
16-
use League\Flysystem\CalculateChecksumFromStream;
17-
use League\Flysystem\ChecksumProvider;
10+
use AzureOss\Storage\Blob\SAS\BlobSASPermissions;
11+
use AzureOss\Storage\Blob\SAS\BlobSASQueryParameters;
12+
use AzureOss\Storage\Blob\SAS\BlobSASSignatureValues;
13+
use AzureOss\Storage\Common\SAS\SASProtocol;
1814
use League\Flysystem\Config;
1915
use League\Flysystem\DirectoryAttributes;
2016
use League\Flysystem\FileAttributes;
@@ -29,15 +25,12 @@
2925
use League\Flysystem\UnableToRetrieveMetadata;
3026
use League\Flysystem\UnableToSetVisibility;
3127
use League\Flysystem\UnableToWriteFile;
32-
use League\Flysystem\UrlGeneration\PublicUrlGenerator;
3328
use League\Flysystem\UrlGeneration\TemporaryUrlGenerator;
3429
use League\MimeTypeDetection\FinfoMimeTypeDetector;
3530
use League\MimeTypeDetection\MimeTypeDetector;
3631

37-
class AzureBlobStorageAdapter implements FilesystemAdapter, ChecksumProvider, PublicUrlGenerator, TemporaryUrlGenerator
32+
class AzureBlobStorageAdapter implements FilesystemAdapter, TemporaryUrlGenerator
3833
{
39-
use CalculateChecksumFromStream;
40-
4134
private readonly MimeTypeDetector $mimeTypeDetector;
4235

4336
public function __construct(
@@ -62,7 +55,7 @@ public function directoryExists(string $path): bool
6255
$options = new ListBlobsOptions(
6356
prefix: $this->getPrefix($path),
6457
maxResults: 1,
65-
delimiter: "/"
58+
delimiter: "/",
6659
);
6760

6861
$response = $this->containerClient->listBlobs($options);
@@ -200,7 +193,7 @@ private function fetchMetadata(string $path): FileAttributes
200193
$path,
201194
fileSize: $response->contentLength,
202195
lastModified: $response->lastModified->getTimestamp(),
203-
mimeType: $response->contentType
196+
mimeType: $response->contentType,
204197
);
205198
}
206199

@@ -262,49 +255,31 @@ private function getPrefix(string $path): ?string
262255
return $path === "" ? null : rtrim($path, "/") . "/";
263256
}
264257

265-
public function checksum(string $path, Config $config): string
266-
{
267-
return $this->calculateChecksumFromStream($path, $config);
268-
}
269-
270-
public function publicUrl(string $path, Config $config): string
258+
public function temporaryUrl(string $path, \DateTimeInterface $expiresAt, Config $config): string
271259
{
272260
$url = $this->containerClient->getBlobClient($path)->getUrl();
273261

274-
$sasValues = new BlobSASSignatureValues(
275-
$path,
276-
$config->get("cache_control"),
277-
$config->get("container_name"),
278-
$config->get("content_disposition"),
279-
$config->get("content_encoding"),
280-
$config->get("content_language"),
281-
$config->get("content_type"),
282-
$config->get("correlation_id"),
283-
$config->get("encryption_scope"),
284-
$config->get("expires_on"),
285-
$config->get("identifier"),
286-
$config->get("ip_range"),
287-
$config->get("permissions", [BlobSASPermission::READ]),
288-
$config->get("preauthorized_agent_object_id"),
289-
$config->get("protocol"),
290-
$config->get("snapshot_time"),
291-
$config->get("starts_on"),
292-
$config->get("version"),
293-
$config->get("version_id"),
262+
$values = new BlobSASSignatureValues(
263+
containerName: $this->containerClient->containerName,
264+
expiresOn: $expiresAt,
265+
blobName: $path,
266+
permissions: $config->get("permissions", (string) new BlobSASPermissions(read: true)),
267+
identifier: $config->get("identifier"),
268+
startsOn: $config->get("starts_on"),
269+
cacheControl: $config->get("cache_control"),
270+
contentDisposition: $config->get("content_disposition"),
271+
contentEncoding: $config->get("content_encoding"),
272+
contentLanguage: $config->get("content_language"),
273+
contentType: $config->get("content_type"),
274+
encryptionScope: $config->get("encryption_scope"),
275+
ipRange: $config->get("ip_range"),
276+
snapshotTime: $config->get("snapshot_time"),
277+
protocol: $config->get("protocol", SASProtocol::HTTPS_AND_HTTP),
278+
version: $config->get("version"),
294279
);
295280

296-
$sas = SharedAccessSignatureHelper::generateBlobSASQueryParameters(
297-
$sasValues,
298-
$this->containerClient->sharedKeyCredentials,
299-
);
281+
$sas = BlobSASQueryParameters::generate($values, $this->containerClient->sharedKeyCredentials);
300282

301283
return sprintf("%s?%s", $url, $sas);
302284
}
303-
304-
public function temporaryUrl(string $path, DateTimeInterface $expiresAt, Config $config): string
305-
{
306-
$config->withSetting("expires_on", $expiresAt);
307-
308-
return $this->publicUrl($path, $config);
309-
}
310285
}

tests/AzureBlobStorageTest.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
namespace AzureOss\FlysystemAzureBlobStorage\Tests;
66

77
use AzureOss\FlysystemAzureBlobStorage\AzureBlobStorageAdapter;
8-
use AzureOss\Storage\Blob\BlobServiceClient;
9-
use AzureOss\Storage\Blob\ContainerClient;
8+
use AzureOss\Storage\Blob\Clients\BlobServiceClient;
9+
use AzureOss\Storage\Blob\Clients\ContainerClient;
1010
use League\Flysystem\AdapterTestUtilities\FilesystemAdapterTestCase as TestCase;
1111
use League\Flysystem\Config;
1212
use League\Flysystem\FilesystemAdapter;
@@ -32,13 +32,6 @@ private static function createContainerClient(): ContainerClient
3232
return BlobServiceClient::fromConnectionString($connectionString)->getContainerClient('flysystem');
3333
}
3434

35-
public function clearStorage(): void
36-
{
37-
$containerClient = self::createContainerClient();
38-
$containerClient->deleteIfExists();
39-
$containerClient->create();
40-
}
41-
4235
public function overwriting_a_file(): void
4336
{
4437
$this->runScenario(
@@ -50,7 +43,7 @@ function () {
5043

5144
$contents = $adapter->read('path.txt');
5245
$this->assertEquals('new contents', $contents);
53-
}
46+
},
5447
);
5548
}
5649

@@ -76,7 +69,7 @@ public function copying_a_file(): void
7669
$adapter->write(
7770
'source.txt',
7871
'contents to be copied',
79-
new Config([Config::OPTION_VISIBILITY => Visibility::PUBLIC])
72+
new Config([Config::OPTION_VISIBILITY => Visibility::PUBLIC]),
8073
);
8174

8275
$adapter->copy('source.txt', 'destination.txt', new Config());
@@ -94,16 +87,16 @@ public function moving_a_file(): void
9487
$adapter->write(
9588
'source.txt',
9689
'contents to be copied',
97-
new Config([Config::OPTION_VISIBILITY => Visibility::PUBLIC])
90+
new Config([Config::OPTION_VISIBILITY => Visibility::PUBLIC]),
9891
);
9992
$adapter->move('source.txt', 'destination.txt', new Config());
10093
$this->assertFalse(
10194
$adapter->fileExists('source.txt'),
102-
'After moving a file should no longer exist in the original location.'
95+
'After moving a file should no longer exist in the original location.',
10396
);
10497
$this->assertTrue(
10598
$adapter->fileExists('destination.txt'),
106-
'After moving, a file should be present at the new location.'
99+
'After moving, a file should be present at the new location.',
107100
);
108101
$this->assertEquals('contents to be copied', $adapter->read('destination.txt'));
109102
});
@@ -116,7 +109,7 @@ public function copying_a_file_again(): void
116109
$adapter->write(
117110
'source.txt',
118111
'contents to be copied',
119-
new Config()
112+
new Config(),
120113
);
121114

122115
$adapter->copy('source.txt', 'destination.txt', new Config());

0 commit comments

Comments
 (0)