Removing HP key/secret auth as this should only cover OpenStack
functionality. Change-Id: I24a10eeb55fc6d4eee56c71b5e06dcb59b034f8c Closes-Bug: 1298413
This commit is contained in:
@@ -116,16 +116,15 @@
|
||||
* // go to authenticate. This URL can be found in your console.
|
||||
* $identity = new IdentityService('http://get.url.from.hpcloud.com');
|
||||
*
|
||||
* // You can authenticate either with username/password (IdentityService::authenticateAsUser())
|
||||
* // or as an account/secret key (IdentityService::authenticateAsAccount()). In either
|
||||
* // case you can get the info you need from the console.
|
||||
* $account = '123456789098765';
|
||||
* $secret = 'dgasgasd';
|
||||
* // You can authenticate with a username/password (IdentityService::authenticateAsUser()).
|
||||
* // In either case you can get the info you need from the console.
|
||||
* $username = 'foobar';
|
||||
* $password = 'dgasgasd';
|
||||
* $tenantId = '56545654';
|
||||
*
|
||||
* // $token will be your authorization key when you connect to other
|
||||
* // services. You can also get it from $identity->token().
|
||||
* $token = $identity->authenticateAsAccount($account, $secret, $tenantId);
|
||||
* $token = $identity->authenticateAsUser($username, $password, $tenantId);
|
||||
*
|
||||
* // Get a listing of all of the services you currently have configured in
|
||||
* // OpenStack.
|
||||
@@ -145,8 +144,6 @@
|
||||
* - OpenStack::Services::IdentityService::__construct() tells the object where to connect.
|
||||
* - OpenStack::Services::IdentityService::authenticateAsUser() lets you log
|
||||
* in with username and password.
|
||||
* - OpenStack::Services::IdentityService::authenticateAsAccount() lets you log
|
||||
* in with account number and secret key.
|
||||
* - OpenStack::Services::IdentityService::serviceCatalog() tells you about
|
||||
* the services you have activated on this account.
|
||||
*
|
||||
|
||||
@@ -11,13 +11,13 @@ Autoloader::useAutoloader();
|
||||
|
||||
// Load these from an ini file.
|
||||
$ini = parse_ini_file(getenv('HOME') . '/.OpenStack.ini');
|
||||
$account = $ini['account'];
|
||||
$key = $ini['secret'];
|
||||
$username = $ini['username'];
|
||||
$password = $ini['password'];
|
||||
$tenantId = $ini['tenantId'];
|
||||
$endpoint = $ini['url'];
|
||||
|
||||
$idService = new IdentityService($endpoint);
|
||||
$token = $idService->authenticateAsAccount($account, $key, $tenantId);
|
||||
$token = $idService->authenticateAsUser($username, $password, $tenantId);
|
||||
|
||||
$catalog = $idService->serviceCatalog();
|
||||
|
||||
|
||||
@@ -110,8 +110,8 @@ class Bootstrap {
|
||||
* // Create a context resource.
|
||||
* $cxt = stream_context_create(array(
|
||||
* 'tenantid' => '12de21',
|
||||
* 'account' => '123454321',
|
||||
* 'secret' => 'f78saf7hhlll',
|
||||
* 'username' => 'foobar',
|
||||
* 'password' => 'f78saf7hhlll',
|
||||
* 'endpoint' => 'https://identity.hpcloud.com' // <-- not real URL!
|
||||
* ));
|
||||
*
|
||||
@@ -155,7 +155,6 @@ class Bootstrap {
|
||||
* - 'transport.ssl.verify': Set this to FALSE to turn off SSL certificate
|
||||
* verification. This is NOT recommended, but is sometimes necessary for
|
||||
* certain proxy configurations.
|
||||
* - 'account' and 'secret'
|
||||
* - 'username' and 'password'
|
||||
* - 'tenantid'
|
||||
* - 'endpoint': The full URL to identity services. This is used by stream
|
||||
@@ -244,11 +243,10 @@ class Bootstrap {
|
||||
throw new Exception('Unable to authenticate. No endpoint supplied.');
|
||||
}
|
||||
|
||||
// Neither user nor account can be an empty string, so we need
|
||||
// User cannot be an empty string, so we need
|
||||
// to do more checking than self::hasConfig(), which returns TRUE
|
||||
// if an item exists and is an empty string.
|
||||
$user = self::config('username', NULL);
|
||||
$account = self::config('account', NULL);
|
||||
|
||||
// Check if we have a username/password
|
||||
if (!empty($user) && self::hasConfig('password')) {
|
||||
@@ -257,15 +255,8 @@ class Bootstrap {
|
||||
self::$identity = $is;
|
||||
}
|
||||
|
||||
// Otherwise we go with access/secret keys
|
||||
elseif (!empty($account) && self::hasConfig('secret')) {
|
||||
$is = new IdentityService(self::config('endpoint'));
|
||||
$is->authenticateAsAccount($account, self::config('secret'), self::config('tenantid', NULL), self::config('tenantname', NULL));
|
||||
self::$identity = $is;
|
||||
}
|
||||
|
||||
else {
|
||||
throw new Exception('Unable to authenticate. No account credentials supplied.');
|
||||
throw new Exception('Unable to authenticate. No user credentials supplied.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace OpenStack\Services;
|
||||
*
|
||||
* The authentication process consists of a single transaction during which the
|
||||
* client (us) submits credentials and the server verifies those credentials,
|
||||
* returning a token (for subsequent requests), account information, and the
|
||||
* returning a token (for subsequent requests), user information, and the
|
||||
* service catalog.
|
||||
*
|
||||
* Authentication credentials:
|
||||
@@ -67,11 +67,11 @@ namespace OpenStack\Services;
|
||||
*
|
||||
* There are two notable places to get this information:
|
||||
*
|
||||
* A list of tenants associated with this account can be obtain programatically
|
||||
* A list of tenants associated with this user can be obtain programatically
|
||||
* using the tenants() method on this object.
|
||||
*
|
||||
* OpenStack users can find their tenant ID in the console along with their
|
||||
* account ID and secret key.
|
||||
* username and password.
|
||||
*
|
||||
* @b EXAMPLE
|
||||
*
|
||||
@@ -113,7 +113,6 @@ namespace OpenStack\Services;
|
||||
*
|
||||
* - authenticate()
|
||||
* - authenticateAsUser()
|
||||
* - authenticateAsAccount()
|
||||
* - tenants()
|
||||
* - rescope()
|
||||
*
|
||||
@@ -146,8 +145,8 @@ class IdentityService /*implements Serializable*/ {
|
||||
*
|
||||
* The exact details of this array will differ depending on what type of
|
||||
* authentication is used. For example, authenticating by username and
|
||||
* password will set tenant information. Authenticating by account ID and
|
||||
* secret, however, will leave the tenant section empty.
|
||||
* password will set tenant information. Authenticating by username and
|
||||
* password, however, will leave the tenant section empty.
|
||||
*
|
||||
* This is an associative array looking like this:
|
||||
*
|
||||
@@ -190,7 +189,7 @@ class IdentityService /*implements Serializable*/ {
|
||||
* @code
|
||||
* <?php
|
||||
* $cs = new \OpenStack\Services\IdentityService('http://example.com');
|
||||
* $token = $cs->authenticateAsAccount($accountId, $accessKey);
|
||||
* $token = $cs->authenticateAsUser($username, $password);
|
||||
* ?>
|
||||
* @endcode
|
||||
*
|
||||
@@ -229,8 +228,8 @@ class IdentityService /*implements Serializable*/ {
|
||||
* Send an authentication request.
|
||||
*
|
||||
* @remark EXPERT: This allows authentication requests at a low level. For simple
|
||||
* authentication requests using account number or username, see the
|
||||
* authenticateAsUser() and authenticateAsAccount() methods.
|
||||
* authentication requests using a username, see the
|
||||
* authenticateAsUser() method.
|
||||
*
|
||||
* Here is an example of username/password-based authentication done with
|
||||
* the authenticate() method:
|
||||
@@ -307,8 +306,6 @@ class IdentityService /*implements Serializable*/ {
|
||||
* rescope() the request (See also tenants()).
|
||||
*
|
||||
* Other authentication methods:
|
||||
*
|
||||
* - authenticateAsAccount()
|
||||
* - authenticate()
|
||||
*
|
||||
* @param string $username
|
||||
@@ -316,10 +313,10 @@ class IdentityService /*implements Serializable*/ {
|
||||
* @param string $password
|
||||
* A password string.
|
||||
* @param string $tenantId
|
||||
* The tenant ID for this account. This can be obtained through the
|
||||
* The tenant ID. This can be obtained through the
|
||||
* OpenStack console.
|
||||
* @param string $tenantName
|
||||
* The tenant Name for this account. This can be obtained through the
|
||||
* The tenant Name. This can be obtained through the
|
||||
* OpenStack console.
|
||||
* @throws OpenStack::Transport::AuthorizationException
|
||||
* If authentication failed.
|
||||
@@ -346,66 +343,6 @@ class IdentityService /*implements Serializable*/ {
|
||||
|
||||
return $this->authenticate($ops);
|
||||
}
|
||||
/**
|
||||
* Authenticate to OpenStack using your account ID and access key.
|
||||
*
|
||||
* Given an account ID and and access key (secret key), authenticate
|
||||
* to Identity Services. Identity Services will then issue a token that can be
|
||||
* used with other OpenStack services, such as Object Storage (aka Swift).
|
||||
*
|
||||
* The account ID and access key information can be found in the account
|
||||
* section of the console.
|
||||
*
|
||||
* The third and fourth paramaters allow you to specify a tenant ID or
|
||||
* tenantName. In order to access services, this object will need a tenant ID
|
||||
* or tenant name. If none is specified, it can be set later using rescope().
|
||||
* The tenants() method can be used to get a list of all available tenant IDs
|
||||
* for this token.
|
||||
*
|
||||
* Other authentication methods:
|
||||
*
|
||||
* - authenticateAsUser()
|
||||
* - authenticate()
|
||||
*
|
||||
* @param string $account
|
||||
* The account ID. It should look something like this:
|
||||
* 1234567890:abcdef123456.
|
||||
* @param string $key
|
||||
* The access key (i.e. secret key), which should be a series of
|
||||
* ASCII letters and digits.
|
||||
* @param string $tenantId
|
||||
* A valid tenant ID. This will be used to associate a tenant's services
|
||||
* with this token.
|
||||
* @param string $tenantName
|
||||
* The tenant Name for this account. This can be obtained through the
|
||||
* OpenStack console.
|
||||
* @retval string
|
||||
* @return string
|
||||
* The auth token.
|
||||
* @throws OpenStack::Transport::AuthorizationException
|
||||
* If authentication failed.
|
||||
* @throws OpenStack::Exception
|
||||
* For abnormal network conditions. The message will give an indication as
|
||||
* to the underlying problem.
|
||||
*/
|
||||
public function authenticateAsAccount($account, $key, $tenantId = NULL, $tenantName = NULL) {
|
||||
$ops = array(
|
||||
'apiAccessKeyCredentials' => array(
|
||||
'accessKey' => $account,
|
||||
'secretKey' => $key,
|
||||
),
|
||||
);
|
||||
|
||||
if (!empty($tenantId)) {
|
||||
$ops['tenantId'] = $tenantId;
|
||||
}
|
||||
elseif (!empty($tenantName)) {
|
||||
$ops['tenantName'] = $tenantName;
|
||||
}
|
||||
|
||||
return $this->authenticate($ops);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the token.
|
||||
@@ -529,9 +466,10 @@ class IdentityService /*implements Serializable*/ {
|
||||
* The service catalog contains information about what services (if any) are
|
||||
* available for the present user. Object storage (Swift) Compute instances
|
||||
* (Nova) and other services will each be listed here if they are enabled
|
||||
* on your account. Only services that have been turned on for the account
|
||||
* will be available. (That is, even if you *can* create a compute instance,
|
||||
* until you have actually created one, it will not show up in this list.)
|
||||
* for your user in the current tenant. Only services that have been turned on
|
||||
* for the user on the tenant will be available. (That is, even if you *can*
|
||||
* create a compute instance, until you have actually created one, it will not
|
||||
* show up in this list.)
|
||||
*
|
||||
* One of the authentication methods MUST be run before obtaining the service
|
||||
* catalog.
|
||||
|
||||
@@ -163,7 +163,7 @@ class ObjectStorage {
|
||||
* Given a service catalog and an token, create an ObjectStorage instance.
|
||||
*
|
||||
* The IdentityServices object contains a service catalog listing all of the
|
||||
* services to which the present account has access.
|
||||
* services to which the present user has access.
|
||||
*
|
||||
* This builder can scan the catalog and generate a new ObjectStorage
|
||||
* instance pointed to the first object storage endpoint in the catalog.
|
||||
@@ -226,10 +226,10 @@ class ObjectStorage {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a list of containers for this account.
|
||||
* Fetch a list of containers for this user.
|
||||
*
|
||||
* By default, this fetches the entire list of containers for the
|
||||
* given account. If you have more than 10,000 containers (who
|
||||
* given user. If you have more than 10,000 containers (who
|
||||
* wouldn't?), you will need to use $marker for paging.
|
||||
*
|
||||
* If you want more controlled paging, you can use $limit to indicate
|
||||
@@ -352,7 +352,7 @@ class ObjectStorage {
|
||||
* cases.
|
||||
*
|
||||
* - Make the resource private: This grants read and write access to
|
||||
* ONLY the creating account. This is the default; it can also be
|
||||
* ONLY the creating user tenant. This is the default; it can also be
|
||||
* specified with ACL::makeNonPublic().
|
||||
* - Make the resource public: This grants READ permission to any
|
||||
* requesting host, yet only allows the creator to WRITE to the
|
||||
|
||||
@@ -99,8 +99,8 @@ use \OpenStack\Storage\ObjectStorage;
|
||||
* // Set up the context.
|
||||
* $context = stream_context_create(
|
||||
* array('swift' => array(
|
||||
* 'account' => ACCOUNT_NUMBER,
|
||||
* 'secret' => SECRET_KEY,
|
||||
* 'username' => USERNAME,
|
||||
* 'password' => PASSWORD,
|
||||
* 'tenantid' => TENANT_ID,
|
||||
* 'tenantname' => TENANT_NAME, // Optional instead of tenantid.
|
||||
* 'endpoint' => AUTH_ENDPOINT_URL,
|
||||
@@ -151,8 +151,8 @@ use \OpenStack\Storage\ObjectStorage;
|
||||
* - You must use Bootstrap::setConfiguration() to pass in all of the values you
|
||||
* would normally pass into a stream context:
|
||||
* * endpoint
|
||||
* * account
|
||||
* * secret
|
||||
* * username
|
||||
* * password
|
||||
* - Most of the information from this family of calls can also be obtained using
|
||||
* fstat(). If you were going to open a stream anyway, you might as well use
|
||||
* fopen()/fstat().
|
||||
@@ -205,7 +205,6 @@ use \OpenStack\Storage\ObjectStorage;
|
||||
* You are required to pass in authentication information. This
|
||||
* comes in one of three forms:
|
||||
*
|
||||
* -# API keys: acccount, secret, tenantid, endpoint
|
||||
* -# User login: username, password, tenantid, endpoint
|
||||
* -# Existing (valid) token: token, swift_endpoint
|
||||
*
|
||||
@@ -213,7 +212,7 @@ use \OpenStack\Storage\ObjectStorage;
|
||||
*
|
||||
* The third method (token) can be used when the application has already
|
||||
* authenticated. In this case, a token has been generated and assigned
|
||||
* to an account and tenant.
|
||||
* to an user and tenant.
|
||||
*
|
||||
* The following parameters may be set either in the stream context
|
||||
* or through OpenStack\Bootstrap::setConfiguration():
|
||||
@@ -225,8 +224,6 @@ use \OpenStack\Storage\ObjectStorage;
|
||||
* 'token' is set. Otherwise it is ignored.
|
||||
* - username: A username. MUST be accompanied by 'password' and 'tenantid' (or 'tenantname').
|
||||
* - password: A password. MUST be accompanied by 'username' and 'tenantid' (or 'tenantname').
|
||||
* - account: An account ID. MUST be accompanied by a 'secret' and 'tenantid' (or 'tenantname').
|
||||
* - secret: A secret key. MUST be accompanied by an 'account' and 'tenantid' (or 'tenantname').
|
||||
* - endpoint: The URL to the authentication endpoint. Necessary if you are not
|
||||
* using a 'token' and 'swift_endpoint'.
|
||||
* - use_swift_auth: If this is set to TRUE, it will force the app to use
|
||||
@@ -234,7 +231,7 @@ use \OpenStack\Storage\ObjectStorage;
|
||||
* In general, you should avoid using this.
|
||||
* - content_type: This is effective only when writing files. It will
|
||||
* set the Content-Type of the file during upload.
|
||||
* - tenantid: The tenant ID for the services you will use. (An account may
|
||||
* - tenantid: The tenant ID for the services you will use. (A user may
|
||||
* have multiple tenancies associated.)
|
||||
* - tenantname: The tenant name for the services you will use. You may use
|
||||
* this in lieu of tenant ID.
|
||||
@@ -506,8 +503,8 @@ class StreamWrapper {
|
||||
* Bootstrap::setConfiguration(array(
|
||||
* 'tenantname' => 'foo@example.com',
|
||||
* // 'tenantid' => '1234', // You can use this instead of tenantname
|
||||
* 'account' => '1234',
|
||||
* 'secret' => '4321',
|
||||
* 'username' => 'foobar',
|
||||
* 'password' => 'baz',
|
||||
* 'endpoint' => 'https://auth.example.com',
|
||||
* ));
|
||||
*
|
||||
@@ -690,9 +687,9 @@ class StreamWrapper {
|
||||
*
|
||||
* <?php
|
||||
* $cxt = stream_context_create(array(
|
||||
* 'account' => '1bc123456',
|
||||
* 'username' => 'foobar',
|
||||
* 'tenantid' => '987654321',
|
||||
* 'secret' => 'eieio',
|
||||
* 'password' => 'eieio',
|
||||
* 'endpoint' => 'https://auth.example.com',
|
||||
* ));
|
||||
* ?>
|
||||
@@ -953,7 +950,7 @@ class StreamWrapper {
|
||||
* ?>
|
||||
*
|
||||
* To use standard `stat()` on a Swift stream, you will
|
||||
* need to set account information (tenant ID, account ID, secret,
|
||||
* need to set account information (tenant ID, username, password,
|
||||
* etc.) through \OpenStack\Bootstrap::setConfiguration().
|
||||
*
|
||||
* @return array The stats array.
|
||||
@@ -1400,8 +1397,6 @@ class StreamWrapper {
|
||||
* 'token' is set. Otherwise it is ignored.
|
||||
* - username: A username. MUST be accompanied by 'password' and 'tenantname'.
|
||||
* - password: A password. MUST be accompanied by 'username' and 'tenantname'.
|
||||
* - account: An account ID. MUST be accompanied by a 'secret' and 'tenantname'.
|
||||
* - secret: A secret key. MUST be accompanied by an 'account' and 'tenantname'.
|
||||
* - endpoint: The URL to the authentication endpoint. Necessary if you are not
|
||||
* using a 'token' and 'swift_endpoint'.
|
||||
* - use_swift_auth: If this is set to TRUE, it will force the app to use
|
||||
@@ -1417,10 +1412,6 @@ class StreamWrapper {
|
||||
|
||||
$token = $this->cxt('token');
|
||||
|
||||
$account = $this->cxt('account');
|
||||
// Legacy support for old 'key' param.
|
||||
$key = $this->cxt('key', $this->cxt('secret'));
|
||||
|
||||
$tenantId = $this->cxt('tenantid');
|
||||
$tenantName = $this->cxt('tenantname');
|
||||
$authUrl = $this->cxt('endpoint');
|
||||
@@ -1437,15 +1428,6 @@ class StreamWrapper {
|
||||
if (!empty($token) && !empty($endpoint)) {
|
||||
$this->store = new \OpenStack\Storage\ObjectStorage($token, $endpoint);
|
||||
}
|
||||
// DEPRECATED: For old swift auth.
|
||||
elseif ($this->cxt('use_swift_auth', FALSE)) {
|
||||
|
||||
if (empty($authUrl) || empty($account) || empty($key)) {
|
||||
throw new \OpenStack\Exception('account, endpoint, key are required stream parameters.');
|
||||
}
|
||||
$this->store = \OpenStack\Storage\ObjectStorage::newFromSwiftAuth($account, $key, $authUrl);
|
||||
|
||||
}
|
||||
// If we get here and tenant ID is not set, we can't get a container.
|
||||
elseif (empty($tenantId) && empty($tenantName)) {
|
||||
throw new \OpenStack\Exception('Either Tenant ID (tenantid) or Tenant Name (tenantname) is required.');
|
||||
@@ -1484,10 +1466,6 @@ class StreamWrapper {
|
||||
$username = $this->cxt('username');
|
||||
$password = $this->cxt('password');
|
||||
|
||||
$account = $this->cxt('account');
|
||||
// Legacy support for old 'key' param.
|
||||
$key = $this->cxt('key', $this->cxt('secret'));
|
||||
|
||||
$tenantId = $this->cxt('tenantid');
|
||||
$tenantName = $this->cxt('tenantname');
|
||||
$authUrl = $this->cxt('endpoint');
|
||||
@@ -1499,11 +1477,8 @@ class StreamWrapper {
|
||||
if (!empty($username) && !empty($password)) {
|
||||
$token = $ident->authenticateAsUser($username, $password, $tenantId, $tenantName);
|
||||
}
|
||||
elseif (!empty($account) && !empty($key)) {
|
||||
$token = $ident->authenticateAsAccount($account, $key, $tenantId, $tenantName);
|
||||
}
|
||||
else {
|
||||
throw new \OpenStack\Exception('Either username/password or account/key must be provided.');
|
||||
throw new \OpenStack\Exception('Username/password must be provided.');
|
||||
}
|
||||
// Cache the service catalog.
|
||||
self::$serviceCatalogCache[$token] = $ident->serviceCatalog();
|
||||
|
||||
@@ -21,32 +21,31 @@
|
||||
*/
|
||||
|
||||
$base = dirname(__DIR__);
|
||||
require_once $base . '/src/OpenStack/Bootstrap.php';
|
||||
require_once $base . '/src/OpenStack/Autoloader.php';
|
||||
|
||||
use \OpenStack\Storage\ObjectStorage;
|
||||
use \OpenStack\Services\IdentityService;
|
||||
|
||||
$config = array(
|
||||
'transport' => '\OpenStack\Transport\CURLTransport',
|
||||
'transport' => '\OpenStack\Transport\PHPStreamTransport',
|
||||
'transport.timeout' => 240,
|
||||
//'transport.debug' => 1,
|
||||
'transport.ssl.verify' => 0,
|
||||
);
|
||||
|
||||
\OpenStack\Bootstrap::useAutoloader();
|
||||
\OpenStack\Autoloader::useAutoloader();
|
||||
\OpenStack\Bootstrap::setConfiguration($config);
|
||||
|
||||
$help = "Authenticate against OpenStack Identity Service.
|
||||
|
||||
You can authenticate either by account number and access key, or (by using the
|
||||
-u flag) by username, password.
|
||||
You can authenticate using a username and password.
|
||||
|
||||
While Tenant ID is optional, it is recommended.
|
||||
|
||||
In both cases, you must supply a URL to the Identity Services endpoint.
|
||||
";
|
||||
|
||||
$usage = "php {$argv[0]} [-u] ID SECRET URL [TENANT_ID]";
|
||||
$usage = "php {$argv[0]} USERNAME PASSWORD URL [TENANT_ID]";
|
||||
|
||||
if ($argc > 1 && $argv[1] == '--help') {
|
||||
print PHP_EOL . "\t" . $usage . PHP_EOL;
|
||||
@@ -54,20 +53,15 @@ if ($argc > 1 && $argv[1] == '--help') {
|
||||
exit(1);
|
||||
}
|
||||
elseif ($argc < 4) {
|
||||
print 'ID, Key, and URL are all required.' . PHP_EOL;
|
||||
print 'USERNAME, PASSWORD, and URL are all required.' . PHP_EOL;
|
||||
print $usage . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$asUser = FALSE;
|
||||
$offset = 0;
|
||||
if ($argv[1] == '-u') {
|
||||
$asUser = TRUE;
|
||||
++$offset;
|
||||
}
|
||||
|
||||
$user = $argv[1 + $offset];
|
||||
$key = $argv[2 + $offset];
|
||||
$password = $argv[2 + $offset];
|
||||
$uri = $argv[3 + $offset];
|
||||
|
||||
$tenantId = NULL;
|
||||
@@ -82,12 +76,7 @@ $token = $store->token();
|
||||
*/
|
||||
$cs = new IdentityService($uri);
|
||||
|
||||
if ($asUser) {
|
||||
$token = $cs->authenticateAsUser($user, $key, $tenantId);
|
||||
}
|
||||
else {
|
||||
$token = $cs->authenticateAsAccount($user, $key, $tenantId);
|
||||
}
|
||||
$token = $cs->authenticateAsUser($user, $password, $tenantId);
|
||||
|
||||
if (empty($token)) {
|
||||
print "Authentication seemed to succeed, but no token was returned." . PHP_EOL;
|
||||
@@ -100,7 +89,7 @@ $user = $cs->user();
|
||||
|
||||
printf($t, $user['name'], $cs->token(), $tokenDetails['expires']);
|
||||
|
||||
print "The following services are available on this account:" . PHP_EOL;
|
||||
print "The following services are available on this user:" . PHP_EOL;
|
||||
|
||||
$services = $cs->serviceCatalog();
|
||||
foreach ($services as $service) {
|
||||
|
||||
@@ -32,16 +32,16 @@ $ php test/AuthTest.php
|
||||
This will instruct you to use a more complete version of the command,
|
||||
including:
|
||||
|
||||
* ID: The ID given to you.
|
||||
* KEY: Your account's key.
|
||||
* TENANT ID: Your account's tenant ID.
|
||||
* USERNAME: The username given to you.
|
||||
* PASSWORD: The password associated with the username.
|
||||
* URL: The Endpoint URL.
|
||||
* TENANT ID: Your users's tenant ID.
|
||||
|
||||
All four pieces of information can be found by logging into the
|
||||
console. From there, you can execute a command like this:
|
||||
|
||||
```
|
||||
$ php test/AuthTest.php 123made-up-key 456made-up-secret https://region-a.geo-1.objects.hpcloudsvc.com/auth/v1.0/ 1234567
|
||||
$ php test/AuthTest.php myusername apassword https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/ 1234567
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -62,8 +62,6 @@ class IdentityServiceTest extends \OpenStack\Tests\TestCase {
|
||||
'openstack.identity.username',
|
||||
'openstack.identity.password',
|
||||
'openstack.identity.tenantId',
|
||||
'openstack.identity.access',
|
||||
'openstack.identity.secret',
|
||||
);
|
||||
foreach ($settings as $setting) {
|
||||
$this->assertNotEmpty(self::conf($setting), "Required param: " . $setting);
|
||||
@@ -95,20 +93,6 @@ class IdentityServiceTest extends \OpenStack\Tests\TestCase {
|
||||
);
|
||||
$tok = $service->authenticate($auth);
|
||||
$this->assertNotEmpty($tok);
|
||||
|
||||
|
||||
// Test account ID/secret key auth.
|
||||
$auth = array(
|
||||
'apiAccessKeyCredentials' => array(
|
||||
'accessKey' => self::conf('openstack.identity.access'),
|
||||
'secretKey' => self::conf('openstack.identity.secret'),
|
||||
),
|
||||
);
|
||||
$service = new IdentityService(self::conf('openstack.identity.url'));
|
||||
$tok3 = $service->authenticate($auth);
|
||||
|
||||
$this->assertNotEmpty($tok3);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,41 +115,19 @@ class IdentityServiceTest extends \OpenStack\Tests\TestCase {
|
||||
|
||||
$details = $service->tokenDetails();
|
||||
$this->assertFalse(isset($details['tenant']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testAuthenticate
|
||||
*/
|
||||
public function testAuthenticateAsAccount() {
|
||||
$service = new IdentityService(self::conf('openstack.identity.url'));
|
||||
|
||||
$account = self::conf('openstack.identity.access');
|
||||
$secret = self::conf('openstack.identity.secret');
|
||||
$tenantId = self::conf('openstack.identity.tenantId');
|
||||
|
||||
// No tenant ID.
|
||||
$tok = $service->authenticateAsAccount($account, $secret);
|
||||
$this->assertNotEmpty($tok);
|
||||
$this->assertEmpty($service->tenantId());
|
||||
|
||||
// No tenant ID.
|
||||
$service = new IdentityService(self::conf('openstack.identity.url'));
|
||||
$tok = $service->authenticateAsAccount($account, $secret, $tenantId);
|
||||
$this->assertNotEmpty($tok);
|
||||
$this->assertEquals($tenantId, $service->tenantId());
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testAuthenticateAsAccount
|
||||
* @depends testAuthenticateAsUser
|
||||
*/
|
||||
public function testToken($service) {
|
||||
$this->assertNotEmpty($service->token());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testAuthenticateAsAccount
|
||||
* @depends testAuthenticateAsUser
|
||||
*/
|
||||
public function testIsExpired($service) {
|
||||
$this->assertFalse($service->isExpired());
|
||||
@@ -175,11 +137,9 @@ class IdentityServiceTest extends \OpenStack\Tests\TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testAuthenticateAsAccount
|
||||
* @depends testAuthenticateAsUser
|
||||
*/
|
||||
public function testTenantName() {
|
||||
$account = self::conf('openstack.identity.access');
|
||||
$secret = self::conf('openstack.identity.secret');
|
||||
$user = self::conf('openstack.identity.username');
|
||||
$pass = self::conf('openstack.identity.password');
|
||||
$tenantName = self::conf('openstack.identity.tenantName');
|
||||
@@ -196,18 +156,10 @@ class IdentityServiceTest extends \OpenStack\Tests\TestCase {
|
||||
|
||||
$service = new IdentityService(self::conf('openstack.identity.url'));
|
||||
$this->assertNull($service->tenantName());
|
||||
|
||||
$service->authenticateAsAccount($account, $secret);
|
||||
$this->assertEmpty($service->tenantName());
|
||||
|
||||
$service = new IdentityService(self::conf('openstack.identity.url'));
|
||||
$ret = $service->authenticateAsAccount($account, $secret, NULL, $tenantName);
|
||||
$this->assertNotEmpty($service->tenantName());
|
||||
$this->assertEquals($tenantName, $service->tenantName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testAuthenticateAsAccount
|
||||
* @depends testAuthenticateAsUser
|
||||
*/
|
||||
public function testTenantId() {
|
||||
$user = self::conf('openstack.identity.username');
|
||||
@@ -226,7 +178,7 @@ class IdentityServiceTest extends \OpenStack\Tests\TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testAuthenticateAsAccount
|
||||
* @depends testAuthenticateAsUser
|
||||
*/
|
||||
public function testTokenDetails() {
|
||||
$now = time();
|
||||
@@ -237,7 +189,7 @@ class IdentityServiceTest extends \OpenStack\Tests\TestCase {
|
||||
$service = new IdentityService(self::conf('openstack.identity.url'));
|
||||
$service->authenticateAsUser($user, $pass);
|
||||
|
||||
// Details for account auth.
|
||||
// Details for user auth.
|
||||
$details = $service->tokenDetails();
|
||||
$this->assertNotEmpty($details['id']);
|
||||
$this->assertFalse(isset($details['tenant']));
|
||||
@@ -265,7 +217,7 @@ class IdentityServiceTest extends \OpenStack\Tests\TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testAuthenticateAsAccount
|
||||
* @depends testAuthenticateAsUser
|
||||
*/
|
||||
public function testServiceCatalog($service) {
|
||||
$catalog = $service->serviceCatalog();
|
||||
@@ -299,7 +251,7 @@ class IdentityServiceTest extends \OpenStack\Tests\TestCase {
|
||||
|
||||
|
||||
/**
|
||||
* @depends testAuthenticateAsAccount
|
||||
* @depends testAuthenticateAsUser
|
||||
*/
|
||||
public function testUser($service) {
|
||||
$user = $service->user();
|
||||
@@ -309,7 +261,7 @@ class IdentityServiceTest extends \OpenStack\Tests\TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testAuthenticateAsAccount
|
||||
* @depends testAuthenticateAsUser
|
||||
* @group serialize
|
||||
*/
|
||||
public function testSerialization($service) {
|
||||
@@ -420,7 +372,6 @@ class IdentityServiceTest extends \OpenStack\Tests\TestCase {
|
||||
|
||||
/**
|
||||
* Test the bootstrap identity factory.
|
||||
* @depends testAuthenticateAsAccount
|
||||
* @depends testAuthenticateAsUser
|
||||
*/
|
||||
function testBootstrap() {
|
||||
@@ -443,20 +394,6 @@ class IdentityServiceTest extends \OpenStack\Tests\TestCase {
|
||||
$is = Bootstrap::identity(TRUE);
|
||||
$this->assertInstanceOf('\OpenStack\Services\IdentityService', $is);
|
||||
|
||||
Bootstrap::$config = $reset;
|
||||
|
||||
// Test authenticating as an account.
|
||||
$settings = array(
|
||||
'account' => self::conf('openstack.identity.access'),
|
||||
'secret' => self::conf('openstack.identity.secret'),
|
||||
'endpoint' => self::conf('openstack.identity.url'),
|
||||
'tenantid' => self::conf('openstack.identity.tenantId'),
|
||||
);
|
||||
Bootstrap::setConfiguration($settings);
|
||||
|
||||
$is = Bootstrap::identity(TRUE);
|
||||
$this->assertInstanceOf('\OpenStack\Services\IdentityService', $is);
|
||||
|
||||
// Test getting a second instance from the cache.
|
||||
$is2 = Bootstrap::identity();
|
||||
$this->assertEquals($is, $is2);
|
||||
@@ -468,17 +405,6 @@ class IdentityServiceTest extends \OpenStack\Tests\TestCase {
|
||||
Bootstrap::$config = $reset;
|
||||
|
||||
// Test with tenant name
|
||||
$settings = array(
|
||||
'account' => self::conf('openstack.identity.access'),
|
||||
'secret' => self::conf('openstack.identity.secret'),
|
||||
'endpoint' => self::conf('openstack.identity.url'),
|
||||
'tenantname' => self::conf('openstack.identity.tenantName'),
|
||||
);
|
||||
Bootstrap::setConfiguration($settings);
|
||||
|
||||
$is = Bootstrap::identity(TRUE);
|
||||
$this->assertInstanceOf('\OpenStack\Services\IdentityService', $is);
|
||||
|
||||
$settings = array(
|
||||
'username' => self::conf('openstack.identity.username'),
|
||||
'password' => self::conf('openstack.identity.password'),
|
||||
|
||||
@@ -124,19 +124,19 @@ class StreamWrapperFSTest extends \OpenStack\Tests\TestCase {
|
||||
* swauth.
|
||||
*/
|
||||
protected function authSwiftContext($add = array(), $scheme = NULL) {
|
||||
$cname = self::$settings['openstack.swift.container'];
|
||||
$account = self::$settings['openstack.identity.access'];
|
||||
$key = self::$settings['openstack.identity.secret'];
|
||||
$tenant = self::$settings['openstack.identity.tenantId'];
|
||||
$baseURL = self::$settings['openstack.identity.url'];
|
||||
$cname = self::$settings['openstack.swift.container'];
|
||||
$username = self::$settings['openstack.identity.username'];
|
||||
$password = self::$settings['openstack.identity.password'];
|
||||
$tenant = self::$settings['openstack.identity.tenantId'];
|
||||
$baseURL = self::$settings['openstack.identity.url'];
|
||||
|
||||
if (empty($scheme)) {
|
||||
$scheme = StreamWrapperFS::DEFAULT_SCHEME;
|
||||
}
|
||||
|
||||
$params = $add + array(
|
||||
'account' => $account,
|
||||
'key' => $key,
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
'endpoint' => $baseURL,
|
||||
'tenantid' => $tenant,
|
||||
'content_type' => self::FTYPE,
|
||||
@@ -158,8 +158,8 @@ class StreamWrapperFSTest extends \OpenStack\Tests\TestCase {
|
||||
*/
|
||||
protected function addBootstrapConfig() {
|
||||
$opts = array(
|
||||
'account' => self::$settings['openstack.identity.access'],
|
||||
'key' => self::$settings['openstack.identity.secret'],
|
||||
'username' => self::$settings['openstack.identity.username'],
|
||||
'password' => self::$settings['openstack.identity.password'],
|
||||
'endpoint' => self::$settings['openstack.identity.url'],
|
||||
'tenantid' => self::$settings['openstack.identity.tenantId'],
|
||||
'token' => $this->objectStore()->token(),
|
||||
|
||||
@@ -121,19 +121,19 @@ class StreamWrapperTest extends \OpenStack\Tests\TestCase {
|
||||
* swauth.
|
||||
*/
|
||||
protected function authSwiftContext($add = array(), $scheme = NULL) {
|
||||
$cname = self::$settings['openstack.swift.container'];
|
||||
$account = self::$settings['openstack.identity.access'];
|
||||
$key = self::$settings['openstack.identity.secret'];
|
||||
$tenant = self::$settings['openstack.identity.tenantId'];
|
||||
$baseURL = self::$settings['openstack.identity.url'];
|
||||
$cname = self::$settings['openstack.swift.container'];
|
||||
$username = self::$settings['openstack.identity.username'];
|
||||
$password = self::$settings['openstack.identity.password'];
|
||||
$tenant = self::$settings['openstack.identity.tenantId'];
|
||||
$baseURL = self::$settings['openstack.identity.url'];
|
||||
|
||||
if (empty($scheme)) {
|
||||
$scheme = StreamWrapper::DEFAULT_SCHEME;
|
||||
}
|
||||
|
||||
$params = $add + array(
|
||||
'account' => $account,
|
||||
'key' => $key,
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
'endpoint' => $baseURL,
|
||||
'tenantid' => $tenant,
|
||||
'content_type' => self::FTYPE,
|
||||
@@ -155,8 +155,8 @@ class StreamWrapperTest extends \OpenStack\Tests\TestCase {
|
||||
*/
|
||||
protected function addBootstrapConfig() {
|
||||
$opts = array(
|
||||
'account' => self::$settings['openstack.identity.access'],
|
||||
'key' => self::$settings['openstack.identity.secret'],
|
||||
'username' => self::$settings['openstack.identity.username'],
|
||||
'password' => self::$settings['openstack.identity.password'],
|
||||
'endpoint' => self::$settings['openstack.identity.url'],
|
||||
'tenantid' => self::$settings['openstack.identity.tenantId'],
|
||||
'token' => $this->objectStore()->token(),
|
||||
|
||||
@@ -13,10 +13,6 @@ openstack.identity.tenantName =
|
||||
openstack.identity.username =
|
||||
openstack.identity.password =
|
||||
|
||||
; For authentication by account ID.
|
||||
openstack.identity.access =
|
||||
openstack.identity.secret =
|
||||
|
||||
;;;;;;;;;;;;;;;;;;
|
||||
; Object Storage ;
|
||||
;;;;;;;;;;;;;;;;;;
|
||||
|
||||
Reference in New Issue
Block a user