1 | <?php |
||
16 | class TokenPool |
||
17 | { |
||
18 | const TOKEN_KEY_FORMAT = 'keystone_token_3_%s'; |
||
19 | |||
20 | /** |
||
21 | * @var Tenant |
||
22 | */ |
||
23 | protected $tenant; |
||
24 | |||
25 | /** |
||
26 | * The cache where tokens are stored. |
||
27 | * |
||
28 | * @var CacheInterface |
||
29 | */ |
||
30 | protected $cache; |
||
31 | |||
32 | /** |
||
33 | * Optional logger. |
||
34 | * |
||
35 | * @var LoggerInterface |
||
36 | */ |
||
37 | protected $logger; |
||
38 | |||
39 | /** |
||
40 | * Internal client to request a new token with. |
||
41 | * |
||
42 | * @var ClientInterface |
||
43 | */ |
||
44 | protected $client; |
||
45 | |||
46 | /** |
||
47 | * The endpoint url that was obtained via the token. |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $endpointUrl; |
||
52 | |||
53 | /** |
||
54 | * Cached copy of the token id. |
||
55 | * |
||
56 | * @var string |
||
57 | */ |
||
58 | protected $tokenId; |
||
59 | |||
60 | /** |
||
61 | * @param Tenant $tenant |
||
62 | * @param CacheInterface $cache |
||
63 | * @param LoggerInterface $logger |
||
64 | */ |
||
65 | 14 | public function __construct(Tenant $tenant, CacheInterface $cache, LoggerInterface $logger = null) |
|
72 | |||
73 | /** |
||
74 | * @deprecated Please use {@link getEndpointUrl()} in favor of this |
||
75 | * |
||
76 | * @return string |
||
77 | */ |
||
78 | public function getPublicUrl() |
||
82 | |||
83 | /** |
||
84 | * @return string |
||
85 | */ |
||
86 | 9 | public function getEndpointUrl() |
|
94 | |||
95 | /** |
||
96 | * @return string |
||
97 | */ |
||
98 | 9 | public function getTokenId() |
|
106 | |||
107 | /** |
||
108 | * Returns a token to use for the keystone service. Uses cached instance |
||
109 | * whenever possible. |
||
110 | * |
||
111 | * @param bool $forceNew Whether to force creating a new token |
||
112 | * |
||
113 | * @return Token |
||
114 | */ |
||
115 | 10 | public function getToken($forceNew = false) |
|
138 | |||
139 | /** |
||
140 | * @throws TokenException |
||
141 | * |
||
142 | * @return Token |
||
143 | */ |
||
144 | 4 | protected function requestToken() |
|
173 | |||
174 | /** |
||
175 | * @param string $jsonData |
||
176 | * |
||
177 | * @throws TokenException |
||
178 | * |
||
179 | * @return Token |
||
180 | */ |
||
181 | 8 | private function createToken($jsonData) |
|
191 | |||
192 | /** |
||
193 | * @param Token $token |
||
194 | * |
||
195 | * @throws TokenException |
||
196 | * |
||
197 | * @return string |
||
198 | */ |
||
199 | 9 | private function getEndpointUrlFromToken(Token $token) |
|
214 | |||
215 | /** |
||
216 | * @return string |
||
217 | */ |
||
218 | 10 | private function getCacheKey() |
|
222 | } |
||
223 |