Test Authentification
This commit is contained in:
parent
78e6e5787c
commit
de1f302047
3 changed files with 55 additions and 35 deletions
69
server/core/LibOverride/Test.php
Normal file → Executable file
69
server/core/LibOverride/Test.php
Normal file → Executable file
|
@ -1,24 +1,56 @@
|
||||||
<?php
|
<?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
|
class genTokenOptions
|
||||||
{
|
{
|
||||||
private $clientHTTP;
|
private $optionsGlobal;
|
||||||
|
|
||||||
public function __construct(){
|
public function __construct($options, $token){
|
||||||
|
echo "test";
|
||||||
|
|
||||||
|
$stack = HandlerStack::create();
|
||||||
//IdentityService?
|
//IdentityService?
|
||||||
// $options['IdentityService'] pas oblige?...
|
// $options['IdentityService'] pas oblige?...
|
||||||
// creer HttpClient authurl HandlerStack::create()
|
// creer HttpClient authurl HandlerStack::create()
|
||||||
// $option['identityService'] = factory httpClient
|
// $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?
|
//AuthHadler?
|
||||||
//
|
//
|
||||||
|
$options['authHandler'] = function () use ($options) {
|
||||||
|
return $options['identityService']->generateToken($options);
|
||||||
|
};
|
||||||
//StockClient?
|
//StockClient?
|
||||||
// creer $options['httpClient'] instance de ClientInterface
|
// creer $options['httpClient'] instance de ClientInterface
|
||||||
// token, baseUrl = identity->authenticate
|
// token, baseUrl = identity->authenticate
|
||||||
// stack = getStack authhandler token
|
// stack = getStack authhandler token
|
||||||
// addDebug??
|
// addDebug??
|
||||||
// $options['httpClient'] = httpCLient baseurl stack
|
// $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']));
|
$stack->push(GuzzleMiddleware::log($options['logger'], $options['messageFormatter']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* @param array $options
|
public function getOptions(){
|
||||||
* @codeCoverageIgnore
|
return $this->optionsGlobal;
|
||||||
*/
|
}
|
||||||
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,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
7
server/index.php
Normal file → Executable file
7
server/index.php
Normal file → Executable file
|
@ -5,12 +5,13 @@
|
||||||
|
|
||||||
// $task = $_POST["task"];
|
// $task = $_POST["task"];
|
||||||
// $action = $_POST["action"];
|
// $action = $_POST["action"];
|
||||||
|
|
||||||
include_once("core/Identity.php");
|
|
||||||
|
|
||||||
//$id = new identity($openstack_api, $pluginApi);
|
//$id = new identity($openstack_api, $pluginApi);
|
||||||
|
|
||||||
// var_dump($id->genToken());
|
// 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());
|
// var_dump($openstack_api->getBuilderOptions());
|
||||||
|
|
14
server/init.php
Normal file → Executable file
14
server/init.php
Normal file → Executable file
|
@ -4,6 +4,8 @@
|
||||||
require "vendor/autoload.php";
|
require "vendor/autoload.php";
|
||||||
include_once("core/LibOverride/Builder.php");
|
include_once("core/LibOverride/Builder.php");
|
||||||
include_once("core/LibOverride/OpenStack.php");
|
include_once("core/LibOverride/OpenStack.php");
|
||||||
|
include_once("core/LibOverride/Test.php");
|
||||||
|
include_once("core/Identity.php");
|
||||||
|
|
||||||
//traitement requete, recuperation data
|
//traitement requete, recuperation data
|
||||||
if(isset($_POST["key"])){
|
if(isset($_POST["key"])){
|
||||||
|
@ -54,7 +56,15 @@
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$openstack_api = new OpenStack\OpenStack($Args);
|
|
||||||
|
|
||||||
$pluginApi = plugin_api::getInstance();
|
$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);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Add table
Reference in a new issue