Skip to content

Commit d22ce13

Browse files
committed
Updated code review
1 parent e46ffa5 commit d22ce13

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

doc/services/identity/v3/tokens.rst

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,17 @@ Cache authentication token
5050
Use case
5151
~~~~~~~~
5252

53-
Before one can start calling any API, a very first step that this SDK will do is to authenticate with Identity service
54-
using user's credential.
53+
Before the SDK performs an API call, it will first authenticate to the OpenStack Identity service using the provided
54+
credentials.
5555

56-
If the user's credential is valid, Identity service responses with an authentication token embedded in X-Auth-Token
57-
header and services catalog. The SDK will then use this authentication token and services catalog in all subsequent API
58-
calls.
56+
If the user's credential is valid, credentials are valid, the Identity service returns an authentication token. The SDK
57+
will then use this authentication token and service catalog in all subsequent API calls.
5958

60-
This setup typically works well for command line type of applications. However, for web-based applications, performance
59+
This setup typically works well for CLI applications. However, for web-based applications, performance
6160
is undesirable since authentication step adds ~100ms to the response time.
6261

63-
In order to improve performance, SDK allows users to export and store authentication token and re-use it when it is
64-
still valid.
62+
In order to improve performance, the SDK allows users to export and store authentication tokens, and re-use until they
63+
expire.
6564

6665

6766
Generate token and persist to file
@@ -71,7 +70,7 @@ Generate token and persist to file
7170

7271

7372
For scalability, it is recommended that cached tokens are stored in persistent storage such as memcache or redis instead
74-
of local file.
73+
of a local file.
7574

7675
Initialize Open Stack using cached authentication token
7776
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

samples/identity/v3/tokens/export_authentication_token.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@
3030

3131
// Alternatively, one may persist token to memcache or redis
3232
// Redis and memcache then can purge the entry when token expires.
33+
34+
/**@var \Memcached $memcache */
3335
$memcache->set('token', $token->export(), $token->expires->format('U'));

samples/identity/v3/tokens/use_cached_authentication_token.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
require 'vendor/autoload.php';
44

5-
6-
75
$params = [
86
'authUrl' => '{authUrl}',
97
'region' => '{region}',

src/Identity/v3/Models/Token.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ public function create(array $data): Creatable
132132
/**
133133
* Returns a serialized representation of an authentication token.
134134
*
135-
* Initialize OpenStack object using $params['cachedToken'] to reduce HTTP authentication call.
135+
* Initialize OpenStack object using $params['cachedToken'] to reduce the amount of HTTP calls.
136136
*
137-
* This array is a modified version of POST response to `auth/tokens`. Do not manually modify this array.
137+
* This array is a modified version of response from `/auth/tokens`. Do not manually modify this array.
138138
*
139139
* @return array
140140
*/

src/Identity/v3/Service.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function authenticate(array $options): array
3535
$token = $this->generateTokenFromCache($options['cachedToken']);
3636

3737
if ($token->hasExpired()) {
38-
throw new \RuntimeException(sprintf('Cached token has expired. You may need to re-generate a new token.'));
38+
throw new \RuntimeException(sprintf('Cached token has expired on "%s".', $token->expires->format(\DateTime::ISO8601)));
3939
}
4040
} else {
4141
$token = $this->generateToken($authOptions);

0 commit comments

Comments
 (0)