Now allow filtering on service catalog.

This commit is contained in:
Matt Butcher 2012-01-25 10:49:27 -06:00
parent 964df86366
commit ff8bed1d56
3 changed files with 52 additions and 5 deletions

View File

@ -413,10 +413,12 @@ class IdentityServices {
}
/**
* Get the service catalog.
* Get the service catalog, optionaly filtering by type.
*
* This returns the service catalog (largely unprocessed) that
* is returned during an authentication request.
* is returned during an authentication request. If a type is passed in,
* only entries of that type are returned. If no type is passed in, the
* entire service catalog is returned.
*
* The service catalog contains information about what services (if any) are
* available for the present user. Object storage (Swift) Compute instances
@ -435,7 +437,7 @@ class IdentityServices {
* array(
* array(
* 'name' : 'Object Storage',
* 'type' => 'object-storage',
* 'type' => 'object-store',
* 'endpoints' => array(
* 'tenantId' => '123456',
* 'adminURL' => 'https://example.hpcloud.net/1.0',
@ -461,16 +463,41 @@ class IdentityServices {
*
* This will not be populated until after authentication has been done.
*
* Types:
*
* While this is by no means an exhaustive list, here are a few types that
* might appear in a service catalog (and upon which you can filter):
*
* - identity: Identity Services (i.e. Keystone)
* - compute: Compute instance (Nova)
* - object-store: Object Storage (Swift)
* - hpext:cdn: HPCloud CDN service (yes, the colon belongs in there)
*
* Other services will be added.
*
* @todo Paging on the service catalog is not yet implemented.
*
* @return array
* An associative array representing
* the service catalog.
*/
public function serviceCatalog() {
public function serviceCatalog($type = NULL) {
// If no type is specified, return the entire
// catalog.
if (empty($type)) {
return $this->serviceCatalog;
}
$list = array();
foreach ($this->serviceCatalog as $entry) {
if ($entry['type'] == $type) {
$list[] = $entry;
}
}
return $list;
}
/**
* Get information about the currently authenticated user.
*

View File

@ -53,6 +53,10 @@ class ObjectStorage {
/**
* Create a new instance after getting an authenitcation token.
*
* THIS METHOD IS DEPRECATED. OpenStack now uses Keyston to authenticate.
* You should use \HPCloud\Services\IdentityServices to authenticate.
* Then use this class's constructor to create an object.
*
* This uses the legacy Swift authentication facility to authenticate
* to swift, get a new token, and then create a new ObjectStorage
* instance with that token.
@ -81,6 +85,9 @@ class ObjectStorage {
* @throws \HPCloud\Transport\FileNotFoundException if the URL is
* wrong.
* @throws \HPCloud\Exception if some other exception occurs.
*
* @deprecated Newer versions of OpenStack use Keystone auth instead
* of Swift auth.
*/
public static function newFromSwiftAuth($account, $key, $url) {
$headers = array(

View File

@ -225,6 +225,19 @@ class IdentityServicesTest extends \HPCloud\Tests\TestCase {
$this->assertEquals('Identity', $idService['name']);
$this->assertNotEmpty($idService['endpoints']);
$this->assertNotEmpty($idService['endpoints'][0]['publicURL']);
// Test filters.
$justID = $service->serviceCatalog('identity');
$this->assertEquals(1, count($justID));
$idService = $justID[0];
$this->assertEquals('Identity', $idService['name']);
$this->assertNotEmpty($idService['endpoints']);
$this->assertNotEmpty($idService['endpoints'][0]['publicURL']);
// Make sure a missed filter returns an empty set.
$expectEmpty = $service->serviceCatalog('no-such-servicename');
$this->assertEmpty($expectEmpty);
}