Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #18 from ingalless/master
Browse files Browse the repository at this point in the history
Add support for custom blob endpoint
  • Loading branch information
matthewbdaly authored Sep 22, 2020
2 parents ed93ba6 + c01f1aa commit 889b60a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/AzureStorageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ public function boot()
{
Storage::extend('azure', function ($app, $config) {
$endpoint = sprintf(
'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s',
'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s;',
$config['name'],
$config['key']
);
if ($config['endpoint'] !== null) {
$endpoint .= sprintf("BlobEndpoint=%s;", $config['endpoint']);
}
$client = BlobRestProxy::createBlobService($endpoint);
$adapter = new AzureBlobStorageAdapter(
$client,
Expand Down
27 changes: 24 additions & 3 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace Tests;

use Storage;
use Mockery as m;
use Illuminate\Support\Facades\Storage;

class ServiceProviderTest extends TestCase
{
Expand All @@ -21,8 +20,30 @@ public function it_sets_up_the_config_correctly()
$storage = $this->app['filesystem'];
$settings = $this->app['config']->get('filesystems.disks.azure');

foreach($settings as $key => $value){
foreach ($settings as $key => $value) {
$this->assertEquals($value, $storage->getConfig()->get($key));
}
}

/** @test */
public function it_handles_custom_blob_endpoint()
{
$endpoint = 'http://custom';
$container = $this->app['config']->get('filesystems.disks.azure.container');
$this->app['config']->set('filesystems.disks.azure.endpoint', $endpoint);

$this->assertEquals("$endpoint/$container/a.txt", Storage::url('a.txt'));
}

/** @test */
public function custom_url_overrides_endpoint()
{
$endpoint = 'http://custom';
$customUrl = 'http://cdn.com';
$container = $this->app['config']->get('filesystems.disks.azure.container');
$this->app['config']->set('filesystems.disks.azure.endpoint', $endpoint);
$this->app['config']->set('filesystems.disks.azure.url', $customUrl);

$this->assertEquals("$customUrl/$container/a.txt", Storage::url('a.txt'));
}
}
1 change: 1 addition & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protected function getEnvironmentSetUp($app)
'driver' => 'azure',
'name' => 'MY_AZURE_STORAGE_NAME',
'key' => base64_encode('MY_AZURE_STORAGE_KEY'),
'endpoint' => null,
'container' => 'MY_AZURE_STORAGE_CONTAINER',
'prefix' => null,
]);
Expand Down

0 comments on commit 889b60a

Please sign in to comment.