/** * Cleaning up the test container so we can reuse it for other tests. */ public static function tearDownAfterClass() { // First we get an identity $user = self::conf('hpcloud.identity.username'); $pass = self::conf('hpcloud.identity.password'); $tenantId = self::conf('hpcloud.identity.tenantId'); $url = self::conf('hpcloud.identity.url'); $ident = new \HPCloud\Services\IdentityServices($url); $token = $ident->authenticateAsUser($user, $pass, $tenantId); $region = self::conf('hpcloud.swift.region'); // Then we need to get an instance of storage $store = \HPCloud\Storage\ObjectStorage::newFromIdentity($ident, $region); // Delete the container and all the contents. $cname = self::$settings['hpcloud.swift.container']; try { $container = $store->container($cname); } catch (\HPCloud\Transport\FileNotFoundException $e) { return; } foreach ($container as $object) { try { $container->delete($object->name()); } catch (\Exception $e) { } } $store->deleteContainer($cname); }
protected function authenticate() { $username = $this->cxt('username'); $password = $this->cxt('password'); $account = $this->cxt('account'); $key = $this->cxt('key'); $tenantId = $this->cxt('tenantid'); $authUrl = $this->cxt('endpoint'); $ident = new \HPCloud\Services\IdentityServices($authUrl); // Frustrated? Go burninate. http://www.homestarrunner.com/trogdor.html if (!empty($username) && !empty($password)) { $token = $ident->authenticateAsUser($username, $password, $tenantId); } elseif (!empty($account) && !empty($key)) { $token = $ident->authenticateAsAccount($account, $key, $tenantId); } else { throw new \HPCloud\Exception('Either username/password or account/key must be provided.'); } // Cache the service catalog. self::$serviceCatalogCache[$token] = $ident->serviceCatalog(); return $ident; }
// CDN enabled. Using the one you use for standard // tests is ill advised. define('TEST_CONTAINER', 'mycontainer'); $base = __DIR__ . '/../src'; require_once $base . '/HPCloud/Bootstrap.php'; \HPCloud\Bootstrap::useAutoloader(); $inifile = __DIR__ . '/settings.ini'; if (!is_readable($inifile)) { die('Could not find ' . $inifile); } $ini = parse_ini_file($inifile, FALSE); \HPCloud\Bootstrap::setConfiguration($ini); \HPCloud\Bootstrap::useStreamWrappers(); $id = new \HPCloud\Services\IdentityServices($ini['hpcloud.identity.url']); //$token = $id->authenticateAsAccount($ini['hpcloud.identity.account'], $ini['hpcloud.identity.secret'], $ini['hpcloud.identity.tenantId']); $token = $id->authenticateAsUser($ini['hpcloud.identity.username'], $ini['hpcloud.identity.password'], $ini['hpcloud.identity.tenantId']); $objstore = \HPCloud\Storage\ObjectStorage::newFromServiceCatalog($id->serviceCatalog(), $token); $cdn = \HPCloud\Storage\CDN::newFromServiceCatalog($id->serviceCatalog(), $token); $objstore->useCDN($cdn); //var_dump($cdn->containers()); // Check that the container has CDN. $cname = TEST_CONTAINER; //$ini['hpcloud.swift.container']; $isEnabled = FALSE; $cdnData = $cdn->container($cname); print "***** TESTING CDN ENABLED" . PHP_EOL; if ($cdnData['cdn_enabled'] != 1) { die('Cannot test CDN: You must enable CDN on ' . $cname); } $container = $objstore->container($cname); print "***** TESTING CDN URL" . PHP_EOL;
/** * Get a handle to an IdentityServices object. * * Authentication is performed, and the returned * service has its tenant ID set already. * * @code * <?php * // Get the current token. * $this->identity()->token(); * ?> * @endcode */ protected function identity($reset = FALSE) { if ($reset || empty(self::$ident)) { $user = self::conf('hpcloud.identity.username'); $pass = self::conf('hpcloud.identity.password'); $tenantId = self::conf('hpcloud.identity.tenantId'); $url = self::conf('hpcloud.identity.url'); $is = new \HPCloud\Services\IdentityServices($url); $token = $is->authenticateAsUser($user, $pass, $tenantId); self::$ident = $is; } return self::$ident; }