Exemplo n.º 1
0
// 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;
$cdnSsl = $objstore->cdnUrl($cname);
Exemplo n.º 2
0
 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;
 }