Browse Source

add autocreate config option for containers, implement autocreate and delete of containers, use generated container names for tests

tags/v7.0.0RC1
Jörn Friedrich Dreyer 10 years ago
parent
commit
5722e31d1a

+ 1
- 0
config/config.sample.php View File

@@ -320,6 +320,7 @@ $CONFIG = array(
'username' => 'facebook100000123456789', // trystack will user your facebook id as the user name
'password' => 'Secr3tPaSSWoRdt7', // in the trystack dashboard go to user -> settings -> API Password to generate a password
'container' => 'owncloud', // must already exist in the objectstore, name can be different
'autocreate' => true, // create the container if it does not exist. default is false
'region' => 'RegionOne', //required, dev-/trystack defaults to 'RegionOne'
'url' => 'http://8.21.28.222:5000/v2.0', // The Identity / Keystone endpoint
'tenantName' => 'facebook100000123456789', // required on dev-/trystack

+ 28
- 4
lib/private/files/objectstore/swift.php View File

@@ -20,10 +20,15 @@

namespace OC\Files\ObjectStore;

use Guzzle\Http\Exception\ClientErrorResponseException;
use OpenCloud\OpenStack;

class Swift extends AbstractObjectStore {

/**
* @var \OpenCloud\ObjectStore\Service
*/
private $objectStoreService;
/**
* @var \OpenCloud\ObjectStore\Resource\Container
@@ -34,6 +39,13 @@ class Swift extends AbstractObjectStore {
if (!isset($params['username']) || !isset($params['password']) ) {
throw new \Exception("Access Key and Secret have to be configured.");
}
if (!isset($params['container'])) {
$params['container'] = 'owncloud';
}
if (!isset($params['autocreate'])) {
// should only be true for tests
$params['autocreate'] = false;
}

$secret = array(
'username' => $params['username'],
@@ -54,10 +66,18 @@ class Swift extends AbstractObjectStore {

$client = new OpenStack($params['url'], $secret);

/** @var $objectStoreService \OpenCloud\ObjectStore\Service **/
$objectStoreService = $client->objectStoreService($serviceName, $params['region']);

$this->container = $objectStoreService->getContainer($params['container']);
$this->objectStoreService = $client->objectStoreService($serviceName, $params['region']);

try {
$this->container = $this->objectStoreService->getContainer($params['container']);
} catch (ClientErrorResponseException $ex) {
// if the container does not exist and autocreate is true try to create the container on the fly
if (isset($params['autocreate']) && $params['autocreate'] === true) {
$this->container = $this->objectStoreService->createContainer($params['container']);
} else {
throw $ex;
}
}

//set the user via parent constructor, also initializes the root of the filecache
parent::__construct($params);
@@ -105,4 +125,8 @@ class Swift extends AbstractObjectStore {
$this->container->uploadObject($urn, $fileData);
}

public function deleteContainer($recursive = false) {
$this->container->delete($recursive);
}

}

+ 6
- 2
tests/lib/files/objectstore/swift.php View File

@@ -53,11 +53,14 @@ class Swift extends PHPUnit_Framework_TestCase {
\OC_User::setUserId('');
\OC\Files\Filesystem::tearDown();
\OC_User::setUserId('test');

$testContainer = 'oc-test-container-'.substr( md5(rand()), 0, 7);

$params = array(
'username' => 'facebook100000330192569',
'password' => 'Dbdj1sXnRSHxIGc4',
'container' => 'owncloud',
'container' => $testContainer,
'autocreate' => true,
'region' => 'RegionOne', //required, trystack defaults to 'RegionOne'
'url' => 'http://8.21.28.222:5000/v2.0', // The Identity / Keystone endpoint
'tenantName' => 'facebook100000330192569', // required on trystack
@@ -71,6 +74,7 @@ class Swift extends PHPUnit_Framework_TestCase {
if (is_null($this->storage)) {
return;
}
$this->storage->deleteContainer(true);
$this->storage->getCache()->clear();
//TODO how do I clear hooks?
}

Loading…
Cancel
Save