Updated CDN and OS to use newFromIdentity().
This commit is contained in:
parent
7451d92e29
commit
3299840a14
@ -171,12 +171,16 @@
|
||||
*
|
||||
* @code
|
||||
* <?php
|
||||
* // The explicit way:
|
||||
* // Find out where our ObjectStorage instance lives:
|
||||
* $storageList = $identity->serviceCatalog('object-storage');
|
||||
* $objectStorageUrl = storageList[0]['endpoints'][0]['publicURL'];
|
||||
* // $storageList = $identity->serviceCatalog('object-storage');
|
||||
* // $objectStorageUrl = storageList[0]['endpoints'][0]['publicURL'];
|
||||
*
|
||||
* // Create a new ObjectStorage instance:
|
||||
* $objectStore = new \HPCloud\Storage\ObjectStorage($token, $objectStorageUrl);
|
||||
* // $objectStore = new \HPCloud\Storage\ObjectStorage($token, $objectStorageUrl);
|
||||
*
|
||||
* // Or let ObjectStorage figure out which instance to use:
|
||||
* $objectStore = \HPCloud\Storage\ObjectStorage::newFromIdentity($identity);
|
||||
*
|
||||
* // List containers:
|
||||
* print_r($objectStore->containers());
|
||||
|
@ -269,6 +269,9 @@ Now we can get a new HPCloud::Storage::ObjectStorage instance:
|
||||
$catalog = $idService->serviceCatalog();
|
||||
|
||||
$store = ObjectStorage::newFromServiceCatalog($catalog, $token);
|
||||
|
||||
// UPDATE: As of Beta 6, you can use newFromIdentity():
|
||||
// $store = ObjectStorage::newFromIdentity($idService);
|
||||
?>
|
||||
~~~
|
||||
|
||||
|
@ -138,6 +138,28 @@ class CDN {
|
||||
*/
|
||||
protected $token;
|
||||
|
||||
/**
|
||||
* Create a new instance from an IdentityServices object.
|
||||
*
|
||||
* This builds a new CDN instance form an authenticated
|
||||
* IdentityServices object.
|
||||
*
|
||||
* In the service catalog, this selects the first service entry
|
||||
* for CDN. At this time, that is sufficient.
|
||||
*
|
||||
* @param HPCloud::Services::IdentityServices $identity
|
||||
* The identity to use.
|
||||
* @retval object
|
||||
* A CDN object or FALSE if no CDN services could be found
|
||||
* in the catalog.
|
||||
*/
|
||||
public static function newFromIdentity($identity) {
|
||||
$tok = $identity->token();
|
||||
$cat = $identity->serviceCatalog();
|
||||
|
||||
return self::newFromServiceCatalog($cat, $tok);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new CDN object based on a service catalog.
|
||||
*
|
||||
|
@ -163,6 +163,24 @@ class ObjectStorage {
|
||||
return $store;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an IdentityServices instance, create an ObjectStorage instance.
|
||||
*
|
||||
* This constructs a new ObjectStorage from an authenticated instance
|
||||
* of an HPCloud::Services::IdentityServices object.
|
||||
*
|
||||
* @param HPCloud::Services::IdentityServices $identity
|
||||
* An identity services object that already has a valid token and a
|
||||
* service catalog.
|
||||
* @retval object ObjectStorage
|
||||
* A new ObjectStorage instance.
|
||||
*/
|
||||
public static function newFromIdentity($identity) {
|
||||
$cat = $identity->serviceCatalog();
|
||||
$tok = $identity->token();
|
||||
return self::newFromServiceCatalog($cat, $tok);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a service catalog and an token, create an ObjectStorage instance.
|
||||
*
|
||||
|
@ -145,19 +145,7 @@ class TestCase extends \PHPUnit_Framework_TestCase {
|
||||
if ($reset || empty(self::$ostore)) {
|
||||
$ident = $this->identity($reset);
|
||||
|
||||
$services = $ident->serviceCatalog(\HPCloud\Storage\ObjectStorage::SERVICE_TYPE);
|
||||
|
||||
if (empty($services)) {
|
||||
throw new \Exception('No object-store service found.');
|
||||
}
|
||||
|
||||
/*
|
||||
//$serviceURL = $services[0]['endpoints'][0]['adminURL'];
|
||||
$serviceURL = $services[0]['endpoints'][0]['publicURL'];
|
||||
|
||||
$objStore = new \HPCloud\Storage\ObjectStorage($ident->token(), $serviceURL);
|
||||
*/
|
||||
$objStore = \HPCloud\Storage\ObjectStorage::newFromServiceCatalog($services, $ident->token());
|
||||
$objStore = \HPCloud\Storage\ObjectStorage::newFromIdentity($ident);
|
||||
|
||||
self::$ostore = $objStore;
|
||||
|
||||
|
@ -80,6 +80,18 @@ class CDNTest extends \HPCloud\Tests\TestCase {
|
||||
return $cdn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testConstructor
|
||||
*/
|
||||
public function testNewFromIdentity() {
|
||||
$ident = $this->identity();
|
||||
$cdn = CDN::newFromIdentity($ident);
|
||||
|
||||
$this->assertInstanceOf('\HPCloud\Storage\CDN', $cdn);
|
||||
|
||||
return $cdn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testNewFromServiceCatalog
|
||||
*/
|
||||
|
@ -77,7 +77,17 @@ class ObjectStorageTest extends \HPCloud\Tests\TestCase {
|
||||
}
|
||||
|
||||
public function testNewFromServiceCatalog() {
|
||||
$ostore = $this->objectStore();
|
||||
$ident = $this->identity();
|
||||
$tok = $ident->token();
|
||||
$cat = $ident->serviceCatalog();
|
||||
$ostore = \HPCloud\Storage\ObjectStorage::newFromServiceCatalog($cat, $tok);
|
||||
$this->assertInstanceOf('\HPCloud\Storage\ObjectStorage', $ostore);
|
||||
$this->assertTrue(strlen($ostore->token()) > 0);
|
||||
}
|
||||
|
||||
public function testNewFromIdnetity() {
|
||||
$ident = $this->identity();
|
||||
$ostore = \HPCloud\Storage\ObjectStorage::newFromIdentity($ident);
|
||||
$this->assertInstanceOf('\HPCloud\Storage\ObjectStorage', $ostore);
|
||||
$this->assertTrue(strlen($ostore->token()) > 0);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user