'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
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
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'],
$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);
$this->container->uploadObject($urn, $fileData);
}
+ public function deleteContainer($recursive = false) {
+ $this->container->delete($recursive);
+ }
+
}
\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
if (is_null($this->storage)) {
return;
}
+ $this->storage->deleteContainer(true);
$this->storage->getCache()->clear();
//TODO how do I clear hooks?
}