/** * This method will return an OpenStack service ready fully built and ready for use. There is * some initial setup that may prohibit users from directly instantiating the service class * directly - this setup includes the configuration of the HTTP client's base URL, and the * attachment of an authentication handler. * * @param $serviceName The name of the service as it appears in the OpenStack\* namespace * @param $serviceVersion The major version of the service * @param array $serviceOptions The service-specific options to use * * @return \OpenStack\Common\Service\ServiceInterface * * @throws \Exception */ public function createService($serviceName, $serviceVersion, array $serviceOptions = []) { $options = $this->mergeOptions($serviceOptions); if (!isset($options['identityService'])) { $httpClient = $this->httpClient($options['authUrl'], HandlerStack::create()); $options['identityService'] = Service::factory($httpClient); } if (!isset($options['authHandler'])) { $options['authHandler'] = function () use($options) { return $options['identityService']->generateToken($options); }; } if (!isset($options['httpClient']) || !$options['httpClient'] instanceof ClientInterface) { if (strcasecmp($serviceName, 'identity') === 0) { $baseUrl = $options['authUrl']; $stack = $this->getStack($options['authHandler']); } else { list($token, $baseUrl) = $options['identityService']->authenticate($options); $stack = $this->getStack($options['authHandler'], $token); } if (!empty($options['debugLog'])) { $stack->push(GuzzleMiddleware::log($options['logger'], $options['messageFormatter'])); } $options['httpClient'] = $this->httpClient($baseUrl, $stack); } list($apiClass, $serviceClass) = $this->getClasses($serviceName, $serviceVersion); return new $serviceClass($options['httpClient'], new $apiClass()); }
/** * @param array $options * * @return Service */ private function getDefaultIdentityService(array $options) : Service { if (!isset($options['authUrl'])) { throw new \InvalidArgumentException("'authUrl' is a required option"); } return Service::factory(new Client(['base_uri' => Utils::normalizeUrl($options['authUrl']), 'handler' => HandlerStack::create()])); }
/** * genTokenOptions constructor * * @param Array $options Options to create the objects in the library * AuthUrl is the main options required * * @return genTokenOptions Object */ public function __construct($options) { $stack = HandlerStack::create(); $httpClient = new Client(['base_uri' => Utils::normalizeUrl($options['authUrl']), 'handler' => $stack]); $this->httpClient = $httpClient; $options['identityService'] = Service::factory($httpClient); $options['authHandler'] = function () use($options) { return $options['identityService']->generateToken($options); }; $this->optionsGlobal['Common'] = $options; }
private function stockIdentityService(array &$options) { if (!isset($options['identityService'])) { $httpClient = $this->httpClient($options['authUrl'], HandlerStack::create()); $options['identityService'] = Service::factory($httpClient); } }