Skip to content

Commit ab686e7

Browse files
author
Jamie Hannaford
committed
Ensure authUrl allows for default identity
1 parent f249bc0 commit ab686e7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/OpenStack.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
namespace OpenStack;
44

5+
use GuzzleHttp\Client;
6+
use GuzzleHttp\HandlerStack;
57
use OpenCloud\Common\Service\Builder;
8+
use OpenCloud\Common\Transport\Utils;
9+
use OpenStack\Identity\v3\Service;
610

711
/**
812
* This class is the primary entry point for working with the SDK. It allows for the easy creation
@@ -27,9 +31,30 @@ class OpenStack
2731
*/
2832
public function __construct(array $options = [], Builder $builder = null)
2933
{
34+
if (!isset($options['identityService'])) {
35+
$options['identityService'] = $this->getDefaultIdentityService($options);
36+
}
37+
3038
$this->builder = $builder ?: new Builder($options, 'OpenStack');
3139
}
3240

41+
/**
42+
* @param array $options
43+
*
44+
* @return Service
45+
*/
46+
private function getDefaultIdentityService(array $options): Service
47+
{
48+
if (!isset($options['authUrl'])) {
49+
throw new \InvalidArgumentException("'authUrl' is a required option");
50+
}
51+
52+
return Service::factory(new Client([
53+
'base_uri' => Utils::normalizeUrl($options['authUrl']),
54+
'handler' => HandlerStack::create(),
55+
]));
56+
}
57+
3358
/**
3459
* Creates a new Compute v2 service.
3560
*

0 commit comments

Comments
 (0)