Skip to content

Commit

Permalink
Support bucket endpoint (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
zingimmick authored Aug 2, 2021
1 parent fcd590e commit 7d4c278
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ObsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public function boot(): void
Arr::only($config, ['url', 'temporary_url', 'bucket_endpoint']),
$config['options'] ?? []
);
if (! isset($config['is_cname']) && isset($config['bucket_endpoint'])) {
$config['is_cname'] = $config['bucket_endpoint'];
}
if (isset($config['is_cname']) && ! isset($config['bucket_endpoint'])) {
$config['bucket_endpoint'] = $config['is_cname'];
}
$obsAdapter = new ObsAdapter(
new ObsClient($config),
$config['endpoint'],
Expand Down
21 changes: 21 additions & 0 deletions tests/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Storage;
use Obs\ObsClient;
use Zing\Flysystem\Obs\ObsAdapter;

class DriverTest extends TestCase
Expand All @@ -32,4 +33,24 @@ public function testBucketEndpoint(): void
{
self::assertStringStartsWith('https://your-endpoint', Storage::disk('obs-bucket-endpoint')->url('test'));
}

private function supportIsCname(): bool
{
return version_compare(ObsClient::SDK_VERSION, '3.21.6', '>=');
}

public function testIsCname(): void
{
if (! $this->supportIsCname()) {
self::markTestSkipped('Option `is_cname` not supported.');
}
self::assertStringStartsWith(
'https://your-endpoint',
Storage::disk('obs-bucket-endpoint')->temporaryUrl('test', Carbon::now()->addMinutes())
);
self::assertStringStartsWith(
'https://your-endpoint',
Storage::disk('obs-is-cname')->temporaryUrl('test', Carbon::now()->addMinutes())
);
}
}
8 changes: 8 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,13 @@ protected function getEnvironmentSetUp($app): void
'endpoint' => 'your-endpoint',
'bucket_endpoint' => true,
]);
Config::set('filesystems.disks.obs-is-cname', [
'driver' => 'obs',
'key' => '',
'secret' => '',
'bucket' => 'your-bucket',
'endpoint' => 'your-endpoint',
'is_cname' => true,
]);
}
}

0 comments on commit 7d4c278

Please sign in to comment.