Begin of Identity Implementation, Begin of Token management for Identification
This commit is contained in:
parent
ba8bbc77fb
commit
78e6e5787c
8 changed files with 335 additions and 9 deletions
|
@ -1,7 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
date_default_timezone_set('Europe/Paris');
|
||||||
|
|
||||||
$config = Array();
|
$config = Array();
|
||||||
|
|
||||||
$config["modules_enabled"] = "";
|
$config["modules_enabled"] = "";
|
||||||
|
$config["urlAuth"] = "http://148.60.11.31:5000/v3";
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1 +1,19 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class identity {
|
||||||
|
|
||||||
|
protected $oidentity;
|
||||||
|
|
||||||
|
public function __construct($ostack, $apiP){
|
||||||
|
|
||||||
|
$this->oidentity = $ostack->identityV3();
|
||||||
|
$this->plugins = $apiP;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function genToken(){
|
||||||
|
global $Args;
|
||||||
|
$token = $this->oidentity->generateToken($Args);
|
||||||
|
return $token;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
169
server/core/LibOverride/Builder.php
Normal file
169
server/core/LibOverride/Builder.php
Normal file
|
@ -0,0 +1,169 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OpenStack\Common\Service;
|
||||||
|
|
||||||
|
use GuzzleHttp\Client;
|
||||||
|
use GuzzleHttp\ClientInterface;
|
||||||
|
use GuzzleHttp\Middleware as GuzzleMiddleware;
|
||||||
|
use OpenStack\Common\Auth\ServiceUrlResolver;
|
||||||
|
use OpenStack\Common\Auth\Token;
|
||||||
|
use OpenStack\Common\Transport\HandlerStack;
|
||||||
|
use OpenStack\Common\Transport\Middleware;
|
||||||
|
use OpenStack\Common\Transport\Utils;
|
||||||
|
use OpenStack\Identity\v3\Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Builder for easily creating OpenStack services.
|
||||||
|
*
|
||||||
|
* @package OpenStack\Common\Service
|
||||||
|
*/
|
||||||
|
class Builder_override extends Builder
|
||||||
|
{
|
||||||
|
private $globalOptions = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defaults that will be applied to options if no values are provided by the user.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $defaults = ['urlType' => 'publicURL'];
|
||||||
|
|
||||||
|
public function __construct(array $globalOptions = [])
|
||||||
|
{
|
||||||
|
$this->globalOptions = $globalOptions;
|
||||||
|
parent::__construct($globalOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOptions()
|
||||||
|
{
|
||||||
|
return $this->globalOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setOptions($Options)
|
||||||
|
{
|
||||||
|
$this->globalOptions = $Options;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal method which resolves the API and Service classes for a service.
|
||||||
|
*
|
||||||
|
* @param string $serviceName The name of the service, e.g. Compute
|
||||||
|
* @param int $serviceVersion The major version of the service, e.g. 2
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getClasses($serviceName, $serviceVersion)
|
||||||
|
{
|
||||||
|
$rootNamespace = sprintf("OpenStack\\%s\\v%d", $serviceName, $serviceVersion);
|
||||||
|
|
||||||
|
return [
|
||||||
|
sprintf("%s\\Api", $rootNamespace),
|
||||||
|
sprintf("%s\\Service", $rootNamespace),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
|
||||||
|
$this->stockIdentityService($options);
|
||||||
|
$this->stockAuthHandler($options);
|
||||||
|
$this->stockHttpClient($options, $serviceName);
|
||||||
|
|
||||||
|
list($apiClass, $serviceClass) = $this->getClasses($serviceName, $serviceVersion);
|
||||||
|
|
||||||
|
return new $serviceClass($options['httpClient'], new $apiClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
private function stockHttpClient(array &$options, $serviceName)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->addDebugMiddleware($options, $stack);
|
||||||
|
|
||||||
|
$options['httpClient'] = $this->httpClient($baseUrl, $stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function stockIdentityService(array &$options)
|
||||||
|
{
|
||||||
|
if (!isset($options['identityService'])) {
|
||||||
|
$httpClient = $this->httpClient($options['authUrl'], HandlerStack::create());
|
||||||
|
$options['identityService'] = Service::factory($httpClient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function mergeOptions(array $serviceOptions)
|
||||||
|
{
|
||||||
|
$options = array_merge($this->defaults, $this->globalOptions, $serviceOptions);
|
||||||
|
|
||||||
|
if (!isset($options['authUrl'])) {
|
||||||
|
throw new \InvalidArgumentException('"authUrl" is a required option');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
43
server/core/LibOverride/OpenStack.php
Normal file
43
server/core/LibOverride/OpenStack.php
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
namespace OpenStack;
|
||||||
|
|
||||||
|
#use OpenStack\Common\Service\Builder;
|
||||||
|
use OpenStack\Common\Service\Builder_override;
|
||||||
|
/**
|
||||||
|
* This class is the primary entry point for working with the SDK. It allows for the easy creation
|
||||||
|
* of OpenStack services.
|
||||||
|
*
|
||||||
|
* @package OpenStack
|
||||||
|
*/
|
||||||
|
class OpenStack_override extends OpenStack
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param array $options User-defined options
|
||||||
|
*
|
||||||
|
* $options['username'] = (string) Your OpenStack username [REQUIRED]
|
||||||
|
* ['password'] = (string) Your OpenStack password [REQUIRED]
|
||||||
|
* ['tenantId'] = (string) Your tenant ID [REQUIRED if tenantName omitted]
|
||||||
|
* ['tenantName'] = (string) Your tenant name [REQUIRED if tenantId omitted]
|
||||||
|
* ['authUrl'] = (string) The Keystone URL [REQUIRED]
|
||||||
|
* ['debug'] = (bool) Whether to enable HTTP logging [OPTIONAL]
|
||||||
|
*/
|
||||||
|
public function __construct(array $options = [], Builder $builder = null)
|
||||||
|
{
|
||||||
|
$this->builder = $builder ?: new Builder_override($options);
|
||||||
|
parent::__construct($options, $this->builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBuilderOptions()
|
||||||
|
{
|
||||||
|
|
||||||
|
return $this->builder->getOptions();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBuilderOptions($options)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->builder->setOptions($options);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
63
server/core/LibOverride/Test.php
Normal file
63
server/core/LibOverride/Test.php
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class genTokenOptions
|
||||||
|
{
|
||||||
|
private $clientHTTP;
|
||||||
|
|
||||||
|
public function __construct(){
|
||||||
|
|
||||||
|
//IdentityService?
|
||||||
|
// $options['IdentityService'] pas oblige?...
|
||||||
|
// creer HttpClient authurl HandlerStack::create()
|
||||||
|
// $option['identityService'] = factory httpClient
|
||||||
|
//AuthHadler?
|
||||||
|
//
|
||||||
|
//StockClient?
|
||||||
|
// creer $options['httpClient'] instance de ClientInterface
|
||||||
|
// token, baseUrl = identity->authenticate
|
||||||
|
// stack = getStack authhandler token
|
||||||
|
// addDebug??
|
||||||
|
// $options['httpClient'] = httpCLient baseurl stack
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @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,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
//Init plugin directory
|
//Init plugin directory
|
||||||
if (!defined('PLUGINS_DIR')) {
|
/*if (!defined('PLUGINS_DIR')) {
|
||||||
define('PLUGINS_DIR', INSTALL_PATH . 'plugins/');
|
define('PLUGINS_DIR', INSTALL_PATH . 'plugins/');
|
||||||
}
|
}*/
|
||||||
|
|
||||||
class plugin_api{
|
class plugin_api{
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,14 @@
|
||||||
include_once("config.inc.php");
|
include_once("config.inc.php");
|
||||||
include_once("init.php");
|
include_once("init.php");
|
||||||
|
|
||||||
$task = $_POST["task"];
|
// $task = $_POST["task"];
|
||||||
$action = $_POST["action"];
|
// $action = $_POST["action"];
|
||||||
|
|
||||||
|
|
||||||
|
include_once("core/Identity.php");
|
||||||
|
|
||||||
|
//$id = new identity($openstack_api, $pluginApi);
|
||||||
|
|
||||||
|
// var_dump($id->genToken());
|
||||||
|
$openstack_api->computeV2(['region'=> 'RegionOne']);
|
||||||
|
|
||||||
|
// var_dump($openstack_api->getBuilderOptions());
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
include_once("config.inc.php");
|
include_once("config.inc.php");
|
||||||
include_once("core/Plugin_Api.php");
|
include_once("core/Plugin_Api.php");
|
||||||
require "vendor/autoload.php";
|
require "vendor/autoload.php";
|
||||||
|
include_once("core/LibOverride/Builder.php");
|
||||||
|
include_once("core/LibOverride/OpenStack.php");
|
||||||
|
|
||||||
//traitement requete, recuperation data
|
//traitement requete, recuperation data
|
||||||
if(isset($_POST["key"])){
|
if(isset($_POST["key"])){
|
||||||
//recuperation des donnes sauvegardes
|
//recuperation des donnes sauvegardes
|
||||||
|
@ -27,11 +29,32 @@
|
||||||
"name" => "Default")
|
"name" => "Default")
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
"authUrl" => $urlAuth
|
"authUrl" => $config["urlAuth"]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$user = "admin";
|
||||||
|
$password = "ae5or6cn";
|
||||||
|
$project = "admin";
|
||||||
|
|
||||||
|
$Args = Array(
|
||||||
|
"user" => Array(
|
||||||
|
"name" => $user,
|
||||||
|
"password" => $password,
|
||||||
|
"domain" => Array(
|
||||||
|
"name" => "Default")
|
||||||
|
),
|
||||||
|
"scope" => Array(
|
||||||
|
"project" => Array(
|
||||||
|
"name" => $project,
|
||||||
|
"domain" => Array(
|
||||||
|
"name" => "Default")
|
||||||
|
)
|
||||||
|
),
|
||||||
|
"authUrl" => $config["urlAuth"]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$openstack_api = new OpenStack\OpenStack($Args);
|
$openstack_api = new OpenStack\OpenStack($Args);
|
||||||
|
|
||||||
$pluginApi = plugin_api::getInstance();
|
$pluginApi = plugin_api::getInstance();
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Add table
Reference in a new issue