|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace OpenStack\Identity\v3; |
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp\ClientInterface; |
|
6
|
|
|
use OpenStack\Common\Auth\IdentityService; |
|
7
|
|
|
use OpenStack\Common\Error\BadResponseError; |
|
8
|
|
|
use OpenStack\Common\Service\AbstractService; |
|
9
|
|
|
use OpenStack\Identity\v3\Models; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Represents the Keystone v3 service. |
|
13
|
|
|
* |
|
14
|
|
|
* @property \OpenStack\Identity\v3\Api $api |
|
15
|
|
|
*/ |
|
16
|
|
|
class Service extends AbstractService implements IdentityService |
|
17
|
|
|
{ |
|
18
|
5 |
|
public static function factory(ClientInterface $client): self |
|
19
|
|
|
{ |
|
20
|
5 |
|
return new static($client, new Api()); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Authenticates credentials, giving back a token and a base URL for the service. |
|
25
|
|
|
* |
|
26
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::postTokens} |
|
27
|
|
|
* |
|
28
|
|
|
* @return array Returns a {@see Models\Token} as the first element, a string base URL as the second |
|
29
|
|
|
*/ |
|
30
|
6 |
|
public function authenticate(array $options): array |
|
31
|
|
|
{ |
|
32
|
6 |
|
$authOptions = array_intersect_key($options, $this->api->postTokens()['params']); |
|
33
|
|
|
|
|
34
|
6 |
|
if (!empty($options['cachedToken'])) { |
|
35
|
|
|
$token = $this->generateTokenFromCache($options['cachedToken']); |
|
36
|
2 |
|
|
|
37
|
2 |
|
if ($token->hasExpired()) { |
|
38
|
2 |
|
throw new \RuntimeException(sprintf('Cached token has expired on "%s".', $token->expires->format(\DateTime::ISO8601))); |
|
39
|
2 |
|
} |
|
40
|
|
|
} else { |
|
41
|
2 |
|
$token = $this->generateToken($authOptions); |
|
42
|
1 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
$name = $options['catalogName']; |
|
45
|
1 |
|
$type = $options['catalogType']; |
|
46
|
1 |
|
$region = $options['region']; |
|
47
|
|
|
$interface = isset($options['interface']) ? $options['interface'] : Enum::INTERFACE_PUBLIC; |
|
48
|
|
|
|
|
49
|
|
|
if ($baseUrl = $token->catalog->getServiceUrl($name, $type, $region, $interface)) { |
|
50
|
|
|
return [$token, $baseUrl]; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
throw new \RuntimeException(sprintf("No service found with type [%s] name [%s] region [%s] interface [%s]", |
|
54
|
|
|
$type, $name, $region, $interface)); |
|
55
|
|
|
} |
|
56
|
8 |
|
|
|
57
|
|
|
/** |
|
58
|
8 |
|
* Generates authentication token from cached token using `$token->export()` |
|
59
|
|
|
* |
|
60
|
|
|
* @param array $cachedToken {@see \OpenStack\Identity\v3\Models\Token::export} |
|
61
|
|
|
* |
|
62
|
|
|
* @return Models\Token |
|
63
|
|
|
*/ |
|
64
|
|
|
public function generateTokenFromCache(array $cachedToken): Models\Token |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->model(Models\Token::class)->populateFromArray($cachedToken); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
1 |
|
/** |
|
70
|
|
|
* Generates a new authentication token |
|
71
|
1 |
|
* |
|
72
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::postTokens} |
|
73
|
|
|
* |
|
74
|
|
|
* @return Models\Token |
|
75
|
|
|
*/ |
|
76
|
|
|
public function generateToken(array $options): Models\Token |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->model(Models\Token::class)->create($options); |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
2 |
|
/** |
|
82
|
|
|
* Retrieves a token object and populates its unique identifier object. This operation will not perform a GET or |
|
83
|
|
|
* HEAD request by default; you will need to call retrieve() if you want to pull in remote state from the API. |
|
84
|
2 |
|
* |
|
85
|
1 |
|
* @param string $id The unique ID of the token to retrieve |
|
86
|
1 |
|
* |
|
87
|
1 |
|
* @return Models\Token |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getToken(string $id): Models\Token |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->model(Models\Token::class, ['id' => $id]); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Validates a token, identified by its ID, and returns TRUE if its valid, FALSE if not. |
|
96
|
|
|
* |
|
97
|
|
|
* @param string $id The unique ID of the token |
|
98
|
|
|
* |
|
99
|
1 |
|
* @return bool |
|
100
|
1 |
|
*/ |
|
101
|
1 |
|
public function validateToken(string $id): bool |
|
102
|
1 |
|
{ |
|
103
|
|
|
try { |
|
104
|
|
|
$this->execute($this->api->headTokens(), ['tokenId' => $id]); |
|
105
|
|
|
return true; |
|
106
|
|
|
} catch (BadResponseError $e) { |
|
107
|
|
|
return false; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
1 |
|
/** |
|
112
|
|
|
* Revokes a token, identified by its ID. After this operation completes, users will not be able to use this token |
|
113
|
1 |
|
* again for authentication. |
|
114
|
|
|
* |
|
115
|
|
|
* @param string $id The unique ID of the token |
|
116
|
|
|
*/ |
|
117
|
|
|
public function revokeToken(string $id) |
|
118
|
|
|
{ |
|
119
|
|
|
$this->execute($this->api->deleteTokens(), ['tokenId' => $id]); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Creates a new service according to the provided options. |
|
124
|
|
|
* |
|
125
|
1 |
|
* @param array $options {@see \OpenStack\Identity\v3\Api::postServices} |
|
126
|
|
|
* |
|
127
|
1 |
|
* @return Models\Service |
|
128
|
|
|
*/ |
|
129
|
|
|
public function createService(array $options): Models\Service |
|
130
|
|
|
{ |
|
131
|
|
|
return $this->model(Models\Service::class)->create($options); |
|
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Returns a generator which will yield a collection of service objects. The elements which generators yield can be |
|
136
|
|
|
* accessed using a foreach loop. Often the API will not return the full state of the resource in collections; you |
|
137
|
|
|
* will need to use retrieve() to pull in the full state of the remote resource from the API. |
|
138
|
1 |
|
* |
|
139
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::getServices} |
|
140
|
1 |
|
* |
|
141
|
|
|
* @return \Generator |
|
142
|
|
|
*/ |
|
143
|
|
|
public function listServices(array $options = []): \Generator |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->model(Models\Service::class)->enumerate($this->api->getServices(), $options); |
|
|
|
|
|
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Retrieves a service object and populates its unique identifier object. This operation will not perform a GET or |
|
150
|
2 |
|
* HEAD request by default; you will need to call retrieve() if you want to pull in remote state from the API. |
|
151
|
|
|
* |
|
152
|
2 |
|
* @param string $id The unique ID of the service |
|
153
|
|
|
* |
|
154
|
|
|
* @return Models\Service |
|
155
|
|
|
*/ |
|
156
|
|
|
public function getService(string $id): Models\Service |
|
157
|
|
|
{ |
|
158
|
|
|
return $this->model(Models\Service::class, ['id' => $id]); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Creates a new endpoint according to the provided options. |
|
163
|
1 |
|
* |
|
164
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::postEndpoints} |
|
165
|
1 |
|
* |
|
166
|
|
|
* @return Models\Endpoint |
|
167
|
|
|
*/ |
|
168
|
|
|
public function createEndpoint(array $options): Models\Endpoint |
|
169
|
|
|
{ |
|
170
|
|
|
return $this->model(Models\Endpoint::class)->create($options); |
|
|
|
|
|
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Retrieves an endpoint object and populates its unique identifier object. This operation will not perform a GET or |
|
175
|
|
|
* HEAD request by default; you will need to call retrieve() if you want to pull in remote state from the API. |
|
176
|
|
|
* |
|
177
|
1 |
|
* @param string $id The unique ID of the service |
|
178
|
|
|
* |
|
179
|
1 |
|
* @return Models\Endpoint |
|
180
|
|
|
*/ |
|
181
|
|
|
public function getEndpoint(string $id): Models\Endpoint |
|
182
|
|
|
{ |
|
183
|
|
|
return $this->model(Models\Endpoint::class, ['id' => $id]); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Returns a generator which will yield a collection of endpoint objects. The elements which generators yield can be |
|
188
|
|
|
* accessed using a foreach loop. Often the API will not return the full state of the resource in collections; you |
|
189
|
1 |
|
* will need to use retrieve() to pull in the full state of the remote resource from the API. |
|
190
|
|
|
* |
|
191
|
1 |
|
* @param array $options {@see \OpenStack\Identity\v3\Api::getEndpoints} |
|
192
|
|
|
* |
|
193
|
|
|
* @return \Generator |
|
194
|
|
|
*/ |
|
195
|
|
|
public function listEndpoints(array $options = []): \Generator |
|
196
|
|
|
{ |
|
197
|
|
|
return $this->model(Models\Endpoint::class)->enumerate($this->api->getEndpoints(), $options); |
|
|
|
|
|
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* Creates a new domain according to the provided options. |
|
202
|
|
|
* |
|
203
|
1 |
|
* @param array $options {@see \OpenStack\Identity\v3\Api::postDomains} |
|
204
|
|
|
* |
|
205
|
1 |
|
* @return Models\Domain |
|
206
|
|
|
*/ |
|
207
|
|
|
public function createDomain(array $options): Models\Domain |
|
208
|
|
|
{ |
|
209
|
|
|
return $this->model(Models\Domain::class)->create($options); |
|
|
|
|
|
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* Returns a generator which will yield a collection of domain objects. The elements which generators yield can be |
|
214
|
|
|
* accessed using a foreach loop. Often the API will not return the full state of the resource in collections; you |
|
215
|
|
|
* will need to use retrieve() to pull in the full state of the remote resource from the API. |
|
216
|
1 |
|
* |
|
217
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::getDomains} |
|
218
|
1 |
|
* |
|
219
|
|
|
* @return \Generator |
|
220
|
|
|
*/ |
|
221
|
|
|
public function listDomains(array $options = []): \Generator |
|
222
|
|
|
{ |
|
223
|
|
|
return $this->model(Models\Domain::class)->enumerate($this->api->getDomains(), $options); |
|
|
|
|
|
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* Retrieves a domain object and populates its unique identifier object. This operation will not perform a GET or |
|
228
|
1 |
|
* HEAD request by default; you will need to call retrieve() if you want to pull in remote state from the API. |
|
229
|
|
|
* |
|
230
|
1 |
|
* @param string $id The unique ID of the domain |
|
231
|
|
|
* |
|
232
|
|
|
* @return Models\Domain |
|
233
|
|
|
*/ |
|
234
|
|
|
public function getDomain(string $id): Models\Domain |
|
235
|
|
|
{ |
|
236
|
|
|
return $this->model(Models\Domain::class, ['id' => $id]); |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* Creates a new project according to the provided options. |
|
241
|
|
|
* |
|
242
|
1 |
|
* @param array $options {@see \OpenStack\Identity\v3\Api::postProjects} |
|
243
|
|
|
* |
|
244
|
1 |
|
* @return Models\Project |
|
245
|
|
|
*/ |
|
246
|
|
|
public function createProject(array $options): Models\Project |
|
247
|
|
|
{ |
|
248
|
|
|
return $this->model(Models\Project::class)->create($options); |
|
|
|
|
|
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* Returns a generator which will yield a collection of project objects. The elements which generators yield can be |
|
253
|
|
|
* accessed using a foreach loop. Often the API will not return the full state of the resource in collections; you |
|
254
|
|
|
* will need to use retrieve() to pull in the full state of the remote resource from the API. |
|
255
|
1 |
|
* |
|
256
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::getProjects} |
|
257
|
1 |
|
* |
|
258
|
|
|
* @return \Generator |
|
259
|
|
|
*/ |
|
260
|
|
|
public function listProjects(array $options = []): \Generator |
|
261
|
|
|
{ |
|
262
|
|
|
return $this->model(Models\Project::class)->enumerate($this->api->getProjects(), $options); |
|
|
|
|
|
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
/** |
|
266
|
|
|
* Retrieves a project object and populates its unique identifier object. This operation will not perform a GET or |
|
267
|
1 |
|
* HEAD request by default; you will need to call retrieve() if you want to pull in remote state from the API. |
|
268
|
|
|
* |
|
269
|
1 |
|
* @param string $id The unique ID of the project |
|
270
|
|
|
* |
|
271
|
|
|
* @return Models\Project |
|
272
|
|
|
*/ |
|
273
|
|
|
public function getProject(string $id): Models\Project |
|
274
|
|
|
{ |
|
275
|
|
|
return $this->model(Models\Project::class, ['id' => $id]); |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* Creates a new user according to the provided options. |
|
280
|
|
|
* |
|
281
|
1 |
|
* @param array $options {@see \OpenStack\Identity\v3\Api::postUsers} |
|
282
|
|
|
* |
|
283
|
1 |
|
* @return Models\User |
|
284
|
|
|
*/ |
|
285
|
|
|
public function createUser(array $options): Models\User |
|
286
|
|
|
{ |
|
287
|
|
|
return $this->model(Models\User::class)->create($options); |
|
|
|
|
|
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* Returns a generator which will yield a collection of user objects. The elements which generators yield can be |
|
292
|
|
|
* accessed using a foreach loop. Often the API will not return the full state of the resource in collections; you |
|
293
|
|
|
* will need to use retrieve() to pull in the full state of the remote resource from the API. |
|
294
|
1 |
|
* |
|
295
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::getUsers} |
|
296
|
1 |
|
* |
|
297
|
|
|
* @return \Generator |
|
298
|
|
|
*/ |
|
299
|
|
|
public function listUsers(array $options = []): \Generator |
|
300
|
|
|
{ |
|
301
|
|
|
return $this->model(Models\User::class)->enumerate($this->api->getUsers(), $options); |
|
|
|
|
|
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
/** |
|
305
|
|
|
* Retrieves a user object and populates its unique identifier object. This operation will not perform a GET or |
|
306
|
1 |
|
* HEAD request by default; you will need to call retrieve() if you want to pull in remote state from the API. |
|
307
|
|
|
* |
|
308
|
1 |
|
* @param string $id The unique ID of the user |
|
309
|
|
|
* |
|
310
|
|
|
* @return Models\User |
|
311
|
|
|
*/ |
|
312
|
|
|
public function getUser(string $id): Models\User |
|
313
|
|
|
{ |
|
314
|
|
|
return $this->model(Models\User::class, ['id' => $id]); |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
/** |
|
318
|
|
|
* Creates a new group according to the provided options. |
|
319
|
|
|
* |
|
320
|
1 |
|
* @param array $options {@see \OpenStack\Identity\v3\Api::postGroups} |
|
321
|
|
|
* |
|
322
|
1 |
|
* @return Models\Group |
|
323
|
|
|
*/ |
|
324
|
|
|
public function createGroup(array $options): Models\Group |
|
325
|
|
|
{ |
|
326
|
|
|
return $this->model(Models\Group::class)->create($options); |
|
|
|
|
|
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
/** |
|
330
|
|
|
* Returns a generator which will yield a collection of group objects. The elements which generators yield can be |
|
331
|
|
|
* accessed using a foreach loop. Often the API will not return the full state of the resource in collections; you |
|
332
|
|
|
* will need to use retrieve() to pull in the full state of the remote resource from the API. |
|
333
|
1 |
|
* |
|
334
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::getGroups} |
|
335
|
1 |
|
* |
|
336
|
|
|
* @return \Generator |
|
337
|
|
|
*/ |
|
338
|
|
|
public function listGroups(array $options = []): \Generator |
|
339
|
|
|
{ |
|
340
|
|
|
return $this->model(Models\Group::class)->enumerate($this->api->getGroups(), $options); |
|
|
|
|
|
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
/** |
|
344
|
|
|
* Retrieves a group object and populates its unique identifier object. This operation will not perform a GET or |
|
345
|
1 |
|
* HEAD request by default; you will need to call retrieve() if you want to pull in remote state from the API. |
|
346
|
|
|
* |
|
347
|
1 |
|
* @param string $id The unique ID of the group |
|
348
|
|
|
* |
|
349
|
|
|
* @return Models\Group |
|
350
|
|
|
*/ |
|
351
|
|
|
public function getGroup($id): Models\Group |
|
352
|
|
|
{ |
|
353
|
|
|
return $this->model(Models\Group::class, ['id' => $id]); |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
|
|
/** |
|
357
|
1 |
|
* Creates a new credential according to the provided options. |
|
358
|
|
|
* |
|
359
|
1 |
|
* @param array $options {@see \OpenStack\Identity\v3\Api::postCredentials} |
|
360
|
|
|
* |
|
361
|
|
|
* @return Models\Credential |
|
362
|
|
|
*/ |
|
363
|
|
|
public function createCredential(array $options): Models\Credential |
|
364
|
|
|
{ |
|
365
|
|
|
return $this->model(Models\Credential::class)->create($options); |
|
|
|
|
|
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
/** |
|
369
|
|
|
* Returns a generator which will yield a collection of credential objects. The elements which generators yield can |
|
370
|
1 |
|
* be accessed using a foreach loop. Often the API will not return the full state of the resource in collections; |
|
371
|
|
|
* you will need to use retrieve() to pull in the full state of the remote resource from the API. |
|
372
|
1 |
|
* |
|
373
|
|
|
* @return \Generator |
|
374
|
|
|
*/ |
|
375
|
|
|
public function listCredentials(): \Generator |
|
376
|
|
|
{ |
|
377
|
|
|
return $this->model(Models\Credential::class)->enumerate($this->api->getCredentials()); |
|
|
|
|
|
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
|
|
/** |
|
381
|
|
|
* Retrieves a credential object and populates its unique identifier object. This operation will not perform a GET |
|
382
|
1 |
|
* or HEAD request by default; you will need to call retrieve() if you want to pull in remote state from the API. |
|
383
|
|
|
* |
|
384
|
1 |
|
* @param string $id The unique ID of the credential |
|
385
|
|
|
* |
|
386
|
|
|
* @return Models\Credential |
|
387
|
|
|
*/ |
|
388
|
|
|
public function getCredential(string $id): Models\Credential |
|
389
|
|
|
{ |
|
390
|
|
|
return $this->model(Models\Credential::class, ['id' => $id]); |
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
|
|
/** |
|
394
|
|
|
* Creates a new role according to the provided options. |
|
395
|
|
|
* |
|
396
|
1 |
|
* @param array $options {@see \OpenStack\Identity\v3\Api::postRoles} |
|
397
|
|
|
* |
|
398
|
1 |
|
* @return Models\Role |
|
399
|
|
|
*/ |
|
400
|
|
|
public function createRole(array $options): Models\Role |
|
401
|
|
|
{ |
|
402
|
|
|
return $this->model(Models\Role::class)->create($options); |
|
|
|
|
|
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
|
|
/** |
|
406
|
|
|
* Returns a generator which will yield a collection of role objects. The elements which generators yield can be |
|
407
|
|
|
* accessed using a foreach loop. Often the API will not return the full state of the resource in collections; you |
|
408
|
|
|
* will need to use retrieve() to pull in the full state of the remote resource from the API. |
|
409
|
|
|
* |
|
410
|
1 |
|
* @param array $options {@see \OpenStack\Identity\v3\Api::getRoles} |
|
411
|
|
|
* |
|
412
|
1 |
|
* @return \Generator |
|
413
|
|
|
*/ |
|
414
|
|
|
public function listRoles(array $options = []): \Generator |
|
415
|
|
|
{ |
|
416
|
|
|
return $this->model(Models\Role::class)->enumerate($this->api->getRoles(), $options); |
|
|
|
|
|
|
417
|
|
|
} |
|
418
|
|
|
|
|
419
|
|
|
/** |
|
420
|
|
|
* Returns a generator which will yield a collection of role assignment objects. The elements which generators |
|
421
|
|
|
* yield can be accessed using a foreach loop. Often the API will not return the full state of the resource in |
|
422
|
1 |
|
* collections; you will need to use retrieve() to pull in the full state of the remote resource from the API. |
|
423
|
|
|
* |
|
424
|
1 |
|
* @param array $options {@see \OpenStack\Identity\v3\Api::getRoleAssignments} |
|
425
|
|
|
* |
|
426
|
|
|
* @return \Generator |
|
427
|
|
|
*/ |
|
428
|
|
|
public function listRoleAssignments(array $options = []): \Generator |
|
429
|
|
|
{ |
|
430
|
|
|
return $this->model(Models\Assignment::class)->enumerate($this->api->getRoleAssignments(), $options); |
|
|
|
|
|
|
431
|
|
|
} |
|
432
|
|
|
|
|
433
|
|
|
/** |
|
434
|
|
|
* Creates a new policy according to the provided options. |
|
435
|
|
|
* |
|
436
|
1 |
|
* @param array $options {@see \OpenStack\Identity\v3\Api::postPolicies} |
|
437
|
|
|
* |
|
438
|
1 |
|
* @return Models\Policy |
|
439
|
|
|
*/ |
|
440
|
|
|
public function createPolicy(array $options): Models\Policy |
|
441
|
|
|
{ |
|
442
|
|
|
return $this->model(Models\Policy::class)->create($options); |
|
|
|
|
|
|
443
|
|
|
} |
|
444
|
|
|
|
|
445
|
|
|
/** |
|
446
|
|
|
* Returns a generator which will yield a collection of policy objects. The elements which generators yield can be |
|
447
|
|
|
* accessed using a foreach loop. Often the API will not return the full state of the resource in collections; you |
|
448
|
|
|
* will need to use retrieve() to pull in the full state of the remote resource from the API. |
|
449
|
1 |
|
* |
|
450
|
|
|
* @param array $options {@see \OpenStack\Identity\v3\Api::getPolicies} |
|
451
|
1 |
|
* |
|
452
|
|
|
* @return \Generator |
|
453
|
|
|
*/ |
|
454
|
|
|
public function listPolicies(array $options = []): \Generator |
|
455
|
|
|
{ |
|
456
|
|
|
return $this->model(Models\Policy::class)->enumerate($this->api->getPolicies(), $options); |
|
|
|
|
|
|
457
|
|
|
} |
|
458
|
|
|
|
|
459
|
|
|
/** |
|
460
|
|
|
* Retrieves a policy object and populates its unique identifier object. This operation will not perform a GET or |
|
461
|
|
|
* HEAD request by default; you will need to call retrieve() if you want to pull in remote state from the API. |
|
462
|
|
|
* |
|
463
|
|
|
* @param string $id The unique ID of the policy |
|
464
|
|
|
* |
|
465
|
|
|
* @return Models\Policy |
|
466
|
|
|
*/ |
|
467
|
|
|
public function getPolicy(string $id): Models\Policy |
|
468
|
|
|
{ |
|
469
|
|
|
return $this->model(Models\Policy::class, ['id' => $id]); |
|
470
|
|
|
} |
|
471
|
|
|
} |
|
472
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: