72 lines
2 KiB
PHP
Executable file
72 lines
2 KiB
PHP
Executable file
<?php
|
|
|
|
use GuzzleHttp\Client;
|
|
use OpenStack\Common\Transport\HandlerStack;
|
|
use OpenStack\Common\Transport\Middleware;
|
|
use OpenStack\Identity\v3\Service;
|
|
use OpenStack\Common\Auth\Token;
|
|
use OpenStack\Common\Transport\Utils;
|
|
|
|
class genTokenOptions
|
|
{
|
|
private $optionsGlobal;
|
|
|
|
public function __construct($options, $token){
|
|
echo "test";
|
|
|
|
$stack = HandlerStack::create();
|
|
//IdentityService?
|
|
// $options['IdentityService'] pas oblige?...
|
|
// creer HttpClient authurl HandlerStack::create()
|
|
// $option['identityService'] = factory httpClient
|
|
//$httpClient = new Client([
|
|
// 'base_uri' => Utils::normalizeUrl($options['authUrl']),
|
|
// 'handler' => HandlerStack::create(),
|
|
//]);
|
|
|
|
$httpClient = new Client([
|
|
'base_uri' => Utils::normalizeUrl($options['authUrl']),
|
|
'handler' => $stack,
|
|
]);
|
|
|
|
$options['identityService'] = Service::factory($httpClient);
|
|
//AuthHadler?
|
|
//
|
|
$options['authHandler'] = function () use ($options) {
|
|
return $options['identityService']->generateToken($options);
|
|
};
|
|
//StockClient?
|
|
// creer $options['httpClient'] instance de ClientInterface
|
|
// token, baseUrl = identity->authenticate
|
|
// stack = getStack authhandler token
|
|
// addDebug??
|
|
// $options['httpClient'] = httpCLient baseurl stack
|
|
$baseUrl = $options['authUrl'];
|
|
|
|
//$stack = HandlerStack::create();
|
|
$stack->push(Middleware::authHandler($options['authHandler'], $token));
|
|
|
|
$this->addDebugMiddleware($options, $stack);
|
|
|
|
$options['httpClient'] = $httpClient;
|
|
|
|
$this->optionsGlobal = $options;
|
|
}
|
|
|
|
/**
|
|
* @codeCoverageIgnore
|
|
*/
|
|
private function addDebugMiddleware(array $options, HandlerStack &$stack)
|
|
{
|
|
if (!empty($options['debugLog'])
|
|
&& !empty($options['logger'])
|
|
&& !empty($options['messageFormatter'])
|
|
) {
|
|
$stack->push(GuzzleMiddleware::log($options['logger'], $options['messageFormatter']));
|
|
}
|
|
}
|
|
|
|
public function getOptions(){
|
|
return $this->optionsGlobal;
|
|
}
|
|
}
|