diff --git a/src/HPCloud/Services/IdentityServices.php b/src/HPCloud/Services/IdentityServices.php index cf1baf5..c1be5ed 100644 --- a/src/HPCloud/Services/IdentityServices.php +++ b/src/HPCloud/Services/IdentityServices.php @@ -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,14 +463,39 @@ 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() { - return $this->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; } /** diff --git a/src/HPCloud/Storage/ObjectStorage.php b/src/HPCloud/Storage/ObjectStorage.php index 32315ab..8558592 100644 --- a/src/HPCloud/Storage/ObjectStorage.php +++ b/src/HPCloud/Storage/ObjectStorage.php @@ -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( diff --git a/test/Tests/IdentityServicesTest.php b/test/Tests/IdentityServicesTest.php index 7e384d2..cac960f 100644 --- a/test/Tests/IdentityServicesTest.php +++ b/test/Tests/IdentityServicesTest.php @@ -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); }