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 getEndpointUrl() in favor of this |
||
75 | * @return string |
||
76 | */ |
||
77 | public function getPublicUrl() { |
||
80 | |||
81 | /** |
||
82 | * @return string |
||
83 | */ |
||
84 | 9 | public function getEndpointUrl() |
|
92 | |||
93 | /** |
||
94 | * @return string |
||
95 | */ |
||
96 | 9 | public function getTokenId() |
|
104 | |||
105 | /** |
||
106 | * Returns a token to use for the keystone service. Uses cached instance |
||
107 | * whenever possible. |
||
108 | * |
||
109 | * @param bool $forceNew Whether to force creating a new token |
||
110 | * |
||
111 | * @return Token |
||
112 | */ |
||
113 | 10 | public function getToken($forceNew = false) |
|
136 | |||
137 | /** |
||
138 | * @throws TokenException |
||
139 | * |
||
140 | * @return Token |
||
141 | */ |
||
142 | 4 | protected function requestToken() |
|
171 | |||
172 | /** |
||
173 | * @param string $jsonData |
||
174 | * |
||
175 | * @throws TokenException |
||
176 | * |
||
177 | * @return Token |
||
178 | */ |
||
179 | 8 | private function createToken($jsonData) |
|
189 | |||
190 | /** |
||
191 | * @param Token $token |
||
192 | * |
||
193 | * @throws TokenException |
||
194 | * |
||
195 | * @return string |
||
196 | */ |
||
197 | 9 | private function getEndpointUrlFromToken(Token $token) |
|
212 | |||
213 | /** |
||
214 | * @return string |
||
215 | */ |
||
216 | 10 | private function getCacheKey() |
|
220 | } |
||
221 |