Skip to content

Instantly share code, notes, and snippets.

@gbaudoin
Last active January 4, 2017 19:36
Show Gist options
  • Save gbaudoin/4f39ce18c6ee10f20bf36fa18a979216 to your computer and use it in GitHub Desktop.
Save gbaudoin/4f39ce18c6ee10f20bf36fa18a979216 to your computer and use it in GitHub Desktop.
<?php
namespace App\Providers;
use Storage;
use League\Flysystem\Filesystem;
use OpenStack\OpenStack;
use Illuminate\Support\ServiceProvider;
use Nimbusoft\Flysystem\OpenStack\SwiftAdapter;
use OpenStack\Identity\v2\Service;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use OpenStack\Common\Transport\Utils;
class SwiftServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
Storage::extend('swift', function ($app, $config) {
$options = [
'authUrl' => $config['endpoint'],
'region' => $config['region'],
'username' => $config['username'],
'password' => $config['password'],
'tenantName' => $config['tenantName'],
'publicUrl' => $config['publicUrl'],
];
$clientOptions = [
'base_uri' => Utils::normalizeUrl($options['authUrl']),
'handler' => HandlerStack::create(),
];
$options['identityService'] = Service::factory(new Client($clientOptions));
$openstack = new OpenStack($options);
$container = $openstack->objectStoreV1()->getContainer($config['container']);
$adapter = new SwiftAdapter($container);
return new Filesystem($adapter);
});
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
}
@nicolas-t
Copy link

nicolas-t commented Jan 4, 2017

line 27:

-                 'authUrl'    => $config['endpoint'],
+                 'authUrl'    => $config['authUrl'],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment