Now allow filtering on service catalog.
This commit is contained in:
parent
964df86366
commit
ff8bed1d56
@ -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
|
* 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
|
* The service catalog contains information about what services (if any) are
|
||||||
* available for the present user. Object storage (Swift) Compute instances
|
* available for the present user. Object storage (Swift) Compute instances
|
||||||
@ -435,7 +437,7 @@ class IdentityServices {
|
|||||||
* array(
|
* array(
|
||||||
* array(
|
* array(
|
||||||
* 'name' : 'Object Storage',
|
* 'name' : 'Object Storage',
|
||||||
* 'type' => 'object-storage',
|
* 'type' => 'object-store',
|
||||||
* 'endpoints' => array(
|
* 'endpoints' => array(
|
||||||
* 'tenantId' => '123456',
|
* 'tenantId' => '123456',
|
||||||
* 'adminURL' => 'https://example.hpcloud.net/1.0',
|
* 'adminURL' => 'https://example.hpcloud.net/1.0',
|
||||||
@ -461,14 +463,39 @@ class IdentityServices {
|
|||||||
*
|
*
|
||||||
* This will not be populated until after authentication has been done.
|
* 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.
|
* @todo Paging on the service catalog is not yet implemented.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* An associative array representing
|
* An associative array representing
|
||||||
* the service catalog.
|
* the service catalog.
|
||||||
*/
|
*/
|
||||||
public function serviceCatalog() {
|
public function serviceCatalog($type = NULL) {
|
||||||
return $this->serviceCatalog;
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,6 +53,10 @@ class ObjectStorage {
|
|||||||
/**
|
/**
|
||||||
* Create a new instance after getting an authenitcation token.
|
* 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
|
* This uses the legacy Swift authentication facility to authenticate
|
||||||
* to swift, get a new token, and then create a new ObjectStorage
|
* to swift, get a new token, and then create a new ObjectStorage
|
||||||
* instance with that token.
|
* instance with that token.
|
||||||
@ -81,6 +85,9 @@ class ObjectStorage {
|
|||||||
* @throws \HPCloud\Transport\FileNotFoundException if the URL is
|
* @throws \HPCloud\Transport\FileNotFoundException if the URL is
|
||||||
* wrong.
|
* wrong.
|
||||||
* @throws \HPCloud\Exception if some other exception occurs.
|
* @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) {
|
public static function newFromSwiftAuth($account, $key, $url) {
|
||||||
$headers = array(
|
$headers = array(
|
||||||
|
@ -225,6 +225,19 @@ class IdentityServicesTest extends \HPCloud\Tests\TestCase {
|
|||||||
$this->assertEquals('Identity', $idService['name']);
|
$this->assertEquals('Identity', $idService['name']);
|
||||||
$this->assertNotEmpty($idService['endpoints']);
|
$this->assertNotEmpty($idService['endpoints']);
|
||||||
$this->assertNotEmpty($idService['endpoints'][0]['publicURL']);
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user