2016-09-24 09:34:08 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
2016-09-28 20:13:18 +01:00
|
|
|
use App\Storage;
|
2016-09-24 09:34:08 +01:00
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
|
|
|
class StoreStorageRequest extends FormRequest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
2016-10-28 12:59:36 +01:00
|
|
|
$result = [];
|
|
|
|
|
2016-09-28 20:13:18 +01:00
|
|
|
switch ($this->method())
|
|
|
|
{
|
|
|
|
case 'POST':
|
2016-10-27 11:36:37 +01:00
|
|
|
$result = [
|
2016-09-28 20:13:18 +01:00
|
|
|
'name' => 'required|unique:storages|max:255',
|
|
|
|
'source' => 'required|max:255',
|
|
|
|
];
|
|
|
|
|
2016-10-28 04:54:38 +01:00
|
|
|
switch ($this->get('source'))
|
2016-10-27 11:36:37 +01:00
|
|
|
{
|
2016-11-05 09:41:07 +00:00
|
|
|
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;
|
|
|
|
|
2016-10-28 04:54:38 +01:00
|
|
|
case 'LocalFilesystemSource':
|
|
|
|
$result['location'] = 'sometimes|required|is_dir|dir_empty|is_writeable';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'OpenStackSource':
|
|
|
|
$result['auth_url'] = 'sometimes|required';
|
|
|
|
$result['tenant_name'] = 'sometimes|required';
|
|
|
|
$result['username'] = 'sometimes|required';
|
|
|
|
$result['password'] = 'sometimes|required';
|
|
|
|
$result['service_name'] = 'sometimes|required';
|
|
|
|
$result['service_region'] = 'sometimes|required';
|
|
|
|
$result['container_name'] = 'sometimes|required';
|
2016-10-28 12:59:36 +01:00
|
|
|
$result['cdn_url'] = 'sometimes|url';
|
2016-10-28 04:54:38 +01:00
|
|
|
break;
|
2016-11-05 09:41:07 +00:00
|
|
|
|
|
|
|
case 'RackspaceSource':
|
|
|
|
$result['username'] = 'sometimes|required';
|
|
|
|
$result['password'] = 'sometimes|required';
|
|
|
|
$result['service_region'] = 'sometimes|required';
|
|
|
|
$result['container_name'] = 'sometimes|required';
|
|
|
|
break;
|
2016-10-27 11:36:37 +01:00
|
|
|
}
|
2016-10-28 12:59:36 +01:00
|
|
|
break;
|
2016-10-27 11:36:37 +01:00
|
|
|
|
2016-09-28 20:13:18 +01:00
|
|
|
case 'PATCH':
|
|
|
|
case 'PUT':
|
|
|
|
$storageId = intval($this->segment(3));
|
2016-10-28 12:59:36 +01:00
|
|
|
$storage = Storage::find($storageId);
|
|
|
|
$result = [
|
2016-09-28 20:13:18 +01:00
|
|
|
'name' => 'required|max:255|unique:storages,name,' . $storageId
|
|
|
|
];
|
2016-10-28 12:59:36 +01:00
|
|
|
|
|
|
|
switch ($storage->source)
|
|
|
|
{
|
2016-11-05 09:41:07 +00:00
|
|
|
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;
|
|
|
|
|
2016-10-28 12:59:36 +01:00
|
|
|
case 'OpenStackSource':
|
|
|
|
$result['auth_url'] = 'sometimes|required';
|
|
|
|
$result['tenant_name'] = 'sometimes|required';
|
|
|
|
$result['username'] = 'sometimes|required';
|
|
|
|
$result['password'] = 'sometimes|required';
|
|
|
|
$result['service_name'] = 'sometimes|required';
|
|
|
|
$result['service_region'] = 'sometimes|required';
|
|
|
|
$result['container_name'] = 'sometimes|required';
|
|
|
|
$result['cdn_url'] = 'sometimes|url';
|
|
|
|
break;
|
2016-11-05 09:41:07 +00:00
|
|
|
|
|
|
|
case 'RackspaceSource':
|
|
|
|
$result['username'] = 'sometimes|required';
|
|
|
|
$result['password'] = 'sometimes|required';
|
|
|
|
$result['service_region'] = 'sometimes|required';
|
|
|
|
$result['container_name'] = 'sometimes|required';
|
|
|
|
break;
|
2016-10-28 12:59:36 +01:00
|
|
|
}
|
|
|
|
break;
|
2016-09-28 20:13:18 +01:00
|
|
|
}
|
|
|
|
|
2016-10-28 12:59:36 +01:00
|
|
|
return $result;
|
2016-09-24 09:34:08 +01:00
|
|
|
}
|
|
|
|
}
|