Test Authentification

This commit is contained in:
root 2016-01-31 02:38:05 +01:00
parent 78e6e5787c
commit de1f302047
3 changed files with 55 additions and 35 deletions

69
server/core/LibOverride/Test.php Normal file → Executable file
View file

@ -1,24 +1,56 @@
<?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 $clientHTTP;
private $optionsGlobal;
public function __construct(){
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;
}
/**
@ -33,31 +65,8 @@ class genTokenOptions
$stack->push(GuzzleMiddleware::log($options['logger'], $options['messageFormatter']));
}
}
/**
* @param array $options
* @codeCoverageIgnore
*/
private function stockAuthHandler(array &$options)
{
if (!isset($options['authHandler'])) {
$options['authHandler'] = function () use ($options) {
return $options['identityService']->generateToken($options);
};
}
}
private function getStack(callable $authHandler, Token $token = null)
{
$stack = HandlerStack::create();
$stack->push(Middleware::authHandler($authHandler, $token));
return $stack;
}
private function httpClient($baseUrl, HandlerStack $stack)
{
return new Client([
'base_uri' => Utils::normalizeUrl($baseUrl),
'handler' => $stack,
]);
}
public function getOptions(){
return $this->optionsGlobal;
}
}

7
server/index.php Normal file → Executable file
View file

@ -5,12 +5,13 @@
// $task = $_POST["task"];
// $action = $_POST["action"];
include_once("core/Identity.php");
//$id = new identity($openstack_api, $pluginApi);
// var_dump($id->genToken());
$openstack_api->computeV2(['region'=> 'RegionOne']);
$compute = $openstack_api->computeV2(['region'=> 'RegionOne']);
$servers = $compute->listServers(true);
var_dump($servers);
// var_dump($openstack_api->getBuilderOptions());

14
server/init.php Normal file → Executable file
View file

@ -4,6 +4,8 @@
require "vendor/autoload.php";
include_once("core/LibOverride/Builder.php");
include_once("core/LibOverride/OpenStack.php");
include_once("core/LibOverride/Test.php");
include_once("core/Identity.php");
//traitement requete, recuperation data
if(isset($_POST["key"])){
@ -54,7 +56,15 @@
);
}
$openstack_api = new OpenStack\OpenStack($Args);
$pluginApi = plugin_api::getInstance();
$openstack_api = new OpenStack\OpenStack($Args);
$id = new identity($openstack_api, $pluginApi);
$token = $id->genToken();
$tmp = new genTokenOptions($Args, $token);
$array = $tmp->getOptions();
$openstack_api = new OpenStack\OpenStack($array);
?>