[touch: 33] Added support for uploading files to Rackspace. Split out the OpenStack options into a separate template to match the Amazon one. Added validation to the Amazon options.

This commit is contained in:
Andy Heathershaw 2016-11-05 09:41:07 +00:00
parent 35758d338a
commit 9ed9626e9d
11 changed files with 269 additions and 208 deletions

View File

@ -140,12 +140,12 @@ class OpenStackSource extends AlbumSourceBase implements IAlbumSource
); );
} }
private function getOriginalsFolder() protected function getOriginalsFolder()
{ {
return '_originals'; return '_originals';
} }
private function getPathToPhoto(Photo $photo, $thumbnail = null) protected function getPathToPhoto(Photo $photo, $thumbnail = null)
{ {
return sprintf( return sprintf(
'%s/%s/%s', '%s/%s/%s',

View File

@ -0,0 +1,63 @@
<?php
namespace App\AlbumSources;
use App\Photo;
use App\Storage;
use OpenCloud\Rackspace;
class RackspaceSource extends OpenStackSource
{
protected function getClient()
{
$endpoint = Rackspace::US_IDENTITY_ENDPOINT;
if ($this->configuration->service_region == 'LON')
{
$endpoint = Rackspace::UK_IDENTITY_ENDPOINT;
}
return new Rackspace($endpoint, [
'username' => $this->configuration->username,
'apiKey' => decrypt($this->configuration->password)
]);
}
/**
* Gets the name of this album source.
* @return string
*/
public function getName()
{
return 'global.album_sources.rackspace';
}
/**
* Gets the absolute URL to the given photo file.
* @param Photo $photo Photo to get the URL to.
* @param string $thumbnail Thumbnail to get the image to.
* @return string
*/
public function getUrlToPhoto(Photo $photo, $thumbnail = null)
{
$isCdnEnabled = false;
$cdnService = $this->getStorageService()->getCdnService();
$thisCdnContainer = null;
foreach ($cdnService->listContainers() as $cdnContainer)
{
if ($cdnContainer->name == $this->configuration->container_name)
{
$isCdnEnabled = true;
$thisCdnContainer = $cdnContainer;
}
}
if ($isCdnEnabled)
{
return sprintf('%s/%s', $thisCdnContainer->getCdnSslUri(), $this->getPathToPhoto($photo, $thumbnail));
}
return parent::getPathToPhoto($photo, $thumbnail);
}
}

View File

@ -8,6 +8,7 @@ use App\AlbumSources\IAlbumSource;
use App\AlbumSources\LocalFilesystemSource; use App\AlbumSources\LocalFilesystemSource;
use App\AlbumSources\OpenStackSource; use App\AlbumSources\OpenStackSource;
use App\AlbumSources\OpenStackV1Source; use App\AlbumSources\OpenStackV1Source;
use App\AlbumSources\RackspaceSource;
use App\Configuration; use App\Configuration;
class ConfigHelper class ConfigHelper
@ -34,7 +35,8 @@ class ConfigHelper
$classes = [ $classes = [
LocalFilesystemSource::class, LocalFilesystemSource::class,
AmazonS3Source::class, AmazonS3Source::class,
OpenStackSource::class OpenStackSource::class,
RackspaceSource::class
]; ];
foreach ($classes as $class) foreach ($classes as $class)
{ {

View File

@ -36,6 +36,14 @@ class StoreStorageRequest extends FormRequest
switch ($this->get('source')) switch ($this->get('source'))
{ {
case 'AmazonS3Source':
$result['auth_url'] = 'sometimes|url';
$result['access_key'] = 'sometimes|required';
$result['secret_key'] = 'sometimes|required';
$result['service_region'] = 'sometimes|required';
$result['container_name'] = 'sometimes|required';
break;
case 'LocalFilesystemSource': case 'LocalFilesystemSource':
$result['location'] = 'sometimes|required|is_dir|dir_empty|is_writeable'; $result['location'] = 'sometimes|required|is_dir|dir_empty|is_writeable';
break; break;
@ -50,6 +58,13 @@ class StoreStorageRequest extends FormRequest
$result['container_name'] = 'sometimes|required'; $result['container_name'] = 'sometimes|required';
$result['cdn_url'] = 'sometimes|url'; $result['cdn_url'] = 'sometimes|url';
break; break;
case 'RackspaceSource':
$result['username'] = 'sometimes|required';
$result['password'] = 'sometimes|required';
$result['service_region'] = 'sometimes|required';
$result['container_name'] = 'sometimes|required';
break;
} }
break; break;
@ -63,6 +78,14 @@ class StoreStorageRequest extends FormRequest
switch ($storage->source) switch ($storage->source)
{ {
case 'AmazonS3Source':
$result['auth_url'] = 'sometimes|url';
$result['access_key'] = 'sometimes|required';
$result['secret_key'] = 'sometimes|required';
$result['service_region'] = 'sometimes|required';
$result['container_name'] = 'sometimes|required';
break;
case 'OpenStackSource': case 'OpenStackSource':
$result['auth_url'] = 'sometimes|required'; $result['auth_url'] = 'sometimes|required';
$result['tenant_name'] = 'sometimes|required'; $result['tenant_name'] = 'sometimes|required';
@ -73,6 +96,13 @@ class StoreStorageRequest extends FormRequest
$result['container_name'] = 'sometimes|required'; $result['container_name'] = 'sometimes|required';
$result['cdn_url'] = 'sometimes|url'; $result['cdn_url'] = 'sometimes|url';
break; break;
case 'RackspaceSource':
$result['username'] = 'sometimes|required';
$result['password'] = 'sometimes|required';
$result['service_region'] = 'sometimes|required';
$result['container_name'] = 'sometimes|required';
break;
} }
break; break;
} }

View File

@ -31,6 +31,7 @@ return [
'settings_restrict_originals_download_help' => 'With this option enabled, only the photo\'s owner can download the original high-resolution images.', 'settings_restrict_originals_download_help' => 'With this option enabled, only the photo\'s owner can download the original high-resolution images.',
'storage_access_key_label' => 'Access key:', 'storage_access_key_label' => 'Access key:',
'storage_active_label' => 'Location is active. Uncheck to prevent creating new albums in this location.', 'storage_active_label' => 'Location is active. Uncheck to prevent creating new albums in this location.',
'storage_api_key_label' => 'API key:',
'storage_auth_url_label' => 'Authentication URL:', 'storage_auth_url_label' => 'Authentication URL:',
'storage_bucket_name_label' => 'Bucket name:', 'storage_bucket_name_label' => 'Bucket name:',
'storage_cdn_url_label' => 'Public CDN URL (if supported and enabled):', 'storage_cdn_url_label' => 'Public CDN URL (if supported and enabled):',

View File

@ -3,7 +3,8 @@ return [
'album_sources' => [ 'album_sources' => [
'amazon_s3' => 'Amazon S3 (or S3-compatible)', 'amazon_s3' => 'Amazon S3 (or S3-compatible)',
'filesystem' => 'Local filesystem', 'filesystem' => 'Local filesystem',
'openstack' => 'OpenStack cloud storage' 'openstack' => 'OpenStack cloud storage',
'rackspace' => 'Rackspace cloud storage'
], ],
'app_name' => 'Blue Twilight', 'app_name' => 'Blue Twilight',
'copyright' => '© :years :link_startAndy Heathershaw:link_end', 'copyright' => '© :years :link_startAndy Heathershaw:link_end',

View File

@ -159,113 +159,16 @@
</div> </div>
<div data-bind="visible: selectedLocation() == 'OpenStackSource'"> <div data-bind="visible: selectedLocation() == 'OpenStackSource'">
<div class="row"> @include(Theme::viewName('partials.admin_storages_openstack_options'))
<div class="col-md-6">
<div class="form-group{{ $errors->has('auth_url') ? ' has-error' : '' }}">
{!! Form::label('auth_url', trans('forms.storage_auth_url_label'), ['class' => 'control-label']) !!}
{!! Form::text('auth_url', old('auth_url'), ['class' => 'form-control']) !!}
@if ($errors->has('auth_url'))
<span class="help-block">
<strong>{{ $errors->first('auth_url') }}</strong>
</span>
@endif
</div>
</div>
<div class="col-md-6">
<div class="form-group{{ $errors->has('tenant_name') ? ' has-error' : '' }}">
{!! Form::label('tenant_name', trans('forms.storage_tenant_name_label'), ['class' => 'control-label']) !!}
{!! Form::text('tenant_name', old('tenant_name'), ['class' => 'form-control']) !!}
@if ($errors->has('tenant_name'))
<span class="help-block">
<strong>{{ $errors->first('tenant_name') }}</strong>
</span>
@endif
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}">
{!! Form::label('username', trans('forms.username_label'), ['class' => 'control-label']) !!}
{!! Form::text('username', old('username'), ['class' => 'form-control']) !!}
@if ($errors->has('username'))
<span class="help-block">
<strong>{{ $errors->first('username') }}</strong>
</span>
@endif
</div>
</div>
<div class="col-md-6">
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
{!! Form::label('password', trans('forms.password_label'), ['class' => 'control-label']) !!}
{!! Form::text('password', old('password'), ['class' => 'form-control']) !!}
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group{{ $errors->has('service_name') ? ' has-error' : '' }}">
{!! Form::label('service_name', trans('forms.storage_service_name_label'), ['class' => 'control-label']) !!}
{!! Form::text('service_name', old('service_name'), ['class' => 'form-control']) !!}
@if ($errors->has('service_name'))
<span class="help-block">
<strong>{{ $errors->first('service_name') }}</strong>
</span>
@endif
</div>
</div>
<div class="col-md-6">
<div class="form-group{{ $errors->has('service_region') ? ' has-error' : '' }}">
{!! Form::label('service_region', trans('forms.storage_service_region_label'), ['class' => 'control-label']) !!}
{!! Form::text('service_region', old('service_region'), ['class' => 'form-control']) !!}
@if ($errors->has('service_region'))
<span class="help-block">
<strong>{{ $errors->first('service_region') }}</strong>
</span>
@endif
</div>
</div>
</div>
<div class="form-group{{ $errors->has('container_name') ? ' has-error' : '' }}">
{!! Form::label('container_name', trans('forms.storage_container_name_label'), ['class' => 'control-label']) !!}
{!! Form::text('container_name', old('container_name'), ['class' => 'form-control']) !!}
@if ($errors->has('container_name'))
<span class="help-block">
<strong>{{ $errors->first('container_name') }}</strong>
</span>
@endif
</div>
<div class="form-group{{ $errors->has('cdn_url') ? ' has-error' : '' }}">
{!! Form::label('cdn_url', trans('forms.storage_cdn_url_label'), ['class' => 'control-label']) !!}
{!! Form::text('cdn_url', old('cdn_url'), ['class' => 'form-control']) !!}
@if ($errors->has('cdn_url'))
<span class="help-block">
<strong>{{ $errors->first('cdn_url') }}</strong>
</span>
@endif
</div>
</div> </div>
<div data-bind="visible: selectedLocation() == 'AmazonS3Source'"> <div data-bind="visible: selectedLocation() == 'AmazonS3Source'">
@include(Theme::viewName('partials.admin_storages_amazon_s3_options')) @include(Theme::viewName('partials.admin_storages_amazon_s3_options'))
</div> </div>
<div data-bind="visible: selectedLocation() == 'RackspaceSource'">
@include(Theme::viewName('partials.admin_storages_rackspace_options'))
</div>
</div> </div>
<div class="checkbox"> <div class="checkbox">

View File

@ -50,114 +50,19 @@
@if ($storage->source == 'OpenStackSource') @if ($storage->source == 'OpenStackSource')
<hr/> <hr/>
<div class="row"> @include(Theme::viewName('partials.admin_storages_openstack_options'))
<div class="col-md-6">
<div class="form-group{{ $errors->has('auth_url') ? ' has-error' : '' }}">
{!! Form::label('auth_url', trans('forms.storage_auth_url_label'), ['class' => 'control-label']) !!}
{!! Form::text('auth_url', old('auth_url'), ['class' => 'form-control']) !!}
@if ($errors->has('auth_url'))
<span class="help-block">
<strong>{{ $errors->first('auth_url') }}</strong>
</span>
@endif
</div>
</div>
<div class="col-md-6">
<div class="form-group{{ $errors->has('tenant_name') ? ' has-error' : '' }}">
{!! Form::label('tenant_name', trans('forms.storage_tenant_name_label'), ['class' => 'control-label']) !!}
{!! Form::text('tenant_name', old('tenant_name'), ['class' => 'form-control']) !!}
@if ($errors->has('tenant_name'))
<span class="help-block">
<strong>{{ $errors->first('tenant_name') }}</strong>
</span>
@endif
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}">
{!! Form::label('username', trans('forms.username_label'), ['class' => 'control-label']) !!}
{!! Form::text('username', old('username'), ['class' => 'form-control']) !!}
@if ($errors->has('username'))
<span class="help-block">
<strong>{{ $errors->first('username') }}</strong>
</span>
@endif
</div>
</div>
<div class="col-md-6">
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
{!! Form::label('password', trans('forms.password_label'), ['class' => 'control-label']) !!}
{!! Form::text('password', old('password'), ['class' => 'form-control']) !!}
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group{{ $errors->has('service_name') ? ' has-error' : '' }}">
{!! Form::label('service_name', trans('forms.storage_service_name_label'), ['class' => 'control-label']) !!}
{!! Form::text('service_name', old('service_name'), ['class' => 'form-control']) !!}
@if ($errors->has('service_name'))
<span class="help-block">
<strong>{{ $errors->first('service_name') }}</strong>
</span>
@endif
</div>
</div>
<div class="col-md-6">
<div class="form-group{{ $errors->has('service_region') ? ' has-error' : '' }}">
{!! Form::label('service_region', trans('forms.storage_service_region_label'), ['class' => 'control-label']) !!}
{!! Form::text('service_region', old('service_region'), ['class' => 'form-control']) !!}
@if ($errors->has('service_region'))
<span class="help-block">
<strong>{{ $errors->first('service_region') }}</strong>
</span>
@endif
</div>
</div>
</div>
<div class="form-group{{ $errors->has('container_name') ? ' has-error' : '' }}">
{!! Form::label('container_name', trans('forms.storage_container_name_label'), ['class' => 'control-label']) !!}
{!! Form::text('container_name', old('container_name'), ['class' => 'form-control']) !!}
@if ($errors->has('container_name'))
<span class="help-block">
<strong>{{ $errors->first('container_name') }}</strong>
</span>
@endif
</div>
<div class="form-group{{ $errors->has('cdn_url') ? ' has-error' : '' }}">
{!! Form::label('cdn_url', trans('forms.storage_cdn_url_label'), ['class' => 'control-label']) !!}
{!! Form::text('cdn_url', old('cdn_url'), ['class' => 'form-control']) !!}
@if ($errors->has('cdn_url'))
<span class="help-block">
<strong>{{ $errors->first('cdn_url') }}</strong>
</span>
@endif
</div>
@endif @endif
@if ($storage->source == 'AmazonS3Source') @if ($storage->source == 'AmazonS3Source')
<hr/>
@include(Theme::viewName('partials.admin_storages_amazon_s3_options')) @include(Theme::viewName('partials.admin_storages_amazon_s3_options'))
@endif @endif
@if ($storage->source == 'RackspaceSource')
<hr/>
@include(Theme::viewName('partials.admin_storages_rackspace_options'))
@endif
<div class="form-actions"> <div class="form-actions">
<a href="{{ route('storage.index') }}" class="btn btn-default">@lang('forms.cancel_action')</a> <a href="{{ route('storage.index') }}" class="btn btn-default">@lang('forms.cancel_action')</a>
{!! Form::submit(trans('forms.save_action'), ['class' => 'btn btn-success']) !!} {!! Form::submit(trans('forms.save_action'), ['class' => 'btn btn-success']) !!}

View File

@ -41,6 +41,7 @@
@if ($storage->source == 'LocalFilesystemSource'){{ $storage->location }}@endif @if ($storage->source == 'LocalFilesystemSource'){{ $storage->location }}@endif
@if ($storage->source == 'OpenStackSource'){{ $storage->container_name }} - {{ $storage->service_name }}, {{ $storage->service_region }}@endif @if ($storage->source == 'OpenStackSource'){{ $storage->container_name }} - {{ $storage->service_name }}, {{ $storage->service_region }}@endif
@if ($storage->source == 'AmazonS3Source'){{ $storage->container_name }} - {{ $storage->service_region }}@endif @if ($storage->source == 'AmazonS3Source'){{ $storage->container_name }} - {{ $storage->service_region }}@endif
@if ($storage->source == 'RackspaceSource'){{ $storage->container_name }} - {{ $storage->service_region }}@endif
</span> </span>
</td> </td>
<td class="text-right"> <td class="text-right">

View File

@ -0,0 +1,102 @@
<div class="row">
<div class="col-md-6">
<div class="form-group{{ $errors->has('auth_url') ? ' has-error' : '' }}">
{!! Form::label('auth_url', trans('forms.storage_auth_url_label'), ['class' => 'control-label']) !!}
{!! Form::text('auth_url', old('auth_url'), ['class' => 'form-control']) !!}
@if ($errors->has('auth_url'))
<span class="help-block">
<strong>{{ $errors->first('auth_url') }}</strong>
</span>
@endif
</div>
</div>
<div class="col-md-6">
<div class="form-group{{ $errors->has('tenant_name') ? ' has-error' : '' }}">
{!! Form::label('tenant_name', trans('forms.storage_tenant_name_label'), ['class' => 'control-label']) !!}
{!! Form::text('tenant_name', old('tenant_name'), ['class' => 'form-control']) !!}
@if ($errors->has('tenant_name'))
<span class="help-block">
<strong>{{ $errors->first('tenant_name') }}</strong>
</span>
@endif
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}">
{!! Form::label('username', trans('forms.username_label'), ['class' => 'control-label']) !!}
{!! Form::text('username', old('username'), ['class' => 'form-control']) !!}
@if ($errors->has('username'))
<span class="help-block">
<strong>{{ $errors->first('username') }}</strong>
</span>
@endif
</div>
</div>
<div class="col-md-6">
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
{!! Form::label('password', trans('forms.password_label'), ['class' => 'control-label']) !!}
{!! Form::text('password', old('password'), ['class' => 'form-control']) !!}
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group{{ $errors->has('service_name') ? ' has-error' : '' }}">
{!! Form::label('service_name', trans('forms.storage_service_name_label'), ['class' => 'control-label']) !!}
{!! Form::text('service_name', old('service_name'), ['class' => 'form-control']) !!}
@if ($errors->has('service_name'))
<span class="help-block">
<strong>{{ $errors->first('service_name') }}</strong>
</span>
@endif
</div>
</div>
<div class="col-md-6">
<div class="form-group{{ $errors->has('service_region') ? ' has-error' : '' }}">
{!! Form::label('service_region', trans('forms.storage_service_region_label'), ['class' => 'control-label']) !!}
{!! Form::text('service_region', old('service_region'), ['class' => 'form-control']) !!}
@if ($errors->has('service_region'))
<span class="help-block">
<strong>{{ $errors->first('service_region') }}</strong>
</span>
@endif
</div>
</div>
</div>
<div class="form-group{{ $errors->has('container_name') ? ' has-error' : '' }}">
{!! Form::label('container_name', trans('forms.storage_container_name_label'), ['class' => 'control-label']) !!}
{!! Form::text('container_name', old('container_name'), ['class' => 'form-control']) !!}
@if ($errors->has('container_name'))
<span class="help-block">
<strong>{{ $errors->first('container_name') }}</strong>
</span>
@endif
</div>
<div class="form-group{{ $errors->has('cdn_url') ? ' has-error' : '' }}">
{!! Form::label('cdn_url', trans('forms.storage_cdn_url_label'), ['class' => 'control-label']) !!}
{!! Form::text('cdn_url', old('cdn_url'), ['class' => 'form-control']) !!}
@if ($errors->has('cdn_url'))
<span class="help-block">
<strong>{{ $errors->first('cdn_url') }}</strong>
</span>
@endif
</div>

View File

@ -0,0 +1,53 @@
<div class="row">
<div class="col-md-6">
<div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}">
{!! Form::label('username', trans('forms.username_label'), ['class' => 'control-label']) !!}
{!! Form::text('username', old('username'), ['class' => 'form-control']) !!}
@if ($errors->has('username'))
<span class="help-block">
<strong>{{ $errors->first('username') }}</strong>
</span>
@endif
</div>
</div>
<div class="col-md-6">
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
{!! Form::label('password', trans('forms.storage_api_key_label'), ['class' => 'control-label']) !!}
{!! Form::text('password', old('password'), ['class' => 'form-control']) !!}
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group{{ $errors->has('service_region') ? ' has-error' : '' }}">
{!! Form::label('service_region', trans('forms.storage_service_region_label'), ['class' => 'control-label']) !!}
{!! Form::text('service_region', old('service_region'), ['class' => 'form-control']) !!}
@if ($errors->has('service_region'))
<span class="help-block">
<strong>{{ $errors->first('service_region') }}</strong>
</span>
@endif
</div>
</div>
<div class="col-md-6">
<div class="form-group{{ $errors->has('container_name') ? ' has-error' : '' }}">
{!! Form::label('container_name', trans('forms.storage_container_name_label'), ['class' => 'control-label']) !!}
{!! Form::text('container_name', old('container_name'), ['class' => 'form-control']) !!}
@if ($errors->has('container_name'))
<span class="help-block">
<strong>{{ $errors->first('container_name') }}</strong>
</span>
@endif
</div>
</div>
</div>