/
Service.php
54 lines (43 loc) · 1.41 KB
/
Service.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
declare(strict_types=1);
namespace OpenStack\Identity\v2;
use GuzzleHttp\ClientInterface;
use OpenStack\Common\Auth\IdentityService;
use OpenStack\Common\Service\AbstractService;
use OpenStack\Identity\v2\Models\Catalog;
use OpenStack\Identity\v2\Models\Token;
/**
* Represents the OpenStack Identity v2 service.
*
* @property Api $api
*/
class Service extends AbstractService implements IdentityService
{
public static function factory(ClientInterface $client): self
{
return new static($client, new Api());
}
public function authenticate(array $options = []): array
{
$definition = $this->api->postToken();
$response = $this->execute($definition, array_intersect_key($options, $definition['params']));
$token = $this->model(Token::class, $response);
$serviceUrl = $this->model(Catalog::class, $response)->getServiceUrl(
$options['catalogName'],
$options['catalogType'],
$options['region'],
$options['urlType']
);
return [$token, $serviceUrl];
}
/**
* Generates a new authentication token.
*
* @param array $options {@see \OpenStack\Identity\v2\Api::postToken}
*/
public function generateToken(array $options = []): Token
{
$response = $this->execute($this->api->postToken(), $options);
return $this->model(Token::class, $response);
}
}