From 78e6e5787ce2df4ae55f5b4d64c792b8f20696d7 Mon Sep 17 00:00:00 2001 From: Eole Date: Sat, 30 Jan 2016 11:41:45 +0100 Subject: Begin of Identity Implementation, Begin of Token management for Identification --- server/config.inc.php | 3 + server/core/Identity.php | 20 +++- server/core/LibOverride/Builder.php | 169 ++++++++++++++++++++++++++++++++++ server/core/LibOverride/OpenStack.php | 43 +++++++++ server/core/LibOverride/Test.php | 63 +++++++++++++ server/core/Plugin_Api.php | 4 +- server/index.php | 13 ++- server/init.php | 29 +++++- 8 files changed, 335 insertions(+), 9 deletions(-) create mode 100644 server/core/LibOverride/Builder.php create mode 100644 server/core/LibOverride/OpenStack.php create mode 100644 server/core/LibOverride/Test.php (limited to 'server') diff --git a/server/config.inc.php b/server/config.inc.php index 07adcbd..9767c72 100644 --- a/server/config.inc.php +++ b/server/config.inc.php @@ -1,7 +1,10 @@ diff --git a/server/core/Identity.php b/server/core/Identity.php index 8d1c8b6..343ed15 100644 --- a/server/core/Identity.php +++ b/server/core/Identity.php @@ -1 +1,19 @@ - +oidentity = $ostack->identityV3(); + $this->plugins = $apiP; + + } + + public function genToken(){ + global $Args; + $token = $this->oidentity->generateToken($Args); + return $token; + } +} diff --git a/server/core/LibOverride/Builder.php b/server/core/LibOverride/Builder.php new file mode 100644 index 0000000..30ea9d3 --- /dev/null +++ b/server/core/LibOverride/Builder.php @@ -0,0 +1,169 @@ + '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; + } +} + diff --git a/server/core/LibOverride/OpenStack.php b/server/core/LibOverride/OpenStack.php new file mode 100644 index 0000000..2b3897a --- /dev/null +++ b/server/core/LibOverride/OpenStack.php @@ -0,0 +1,43 @@ +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); + + } +} diff --git a/server/core/LibOverride/Test.php b/server/core/LibOverride/Test.php new file mode 100644 index 0000000..a1c8023 --- /dev/null +++ b/server/core/LibOverride/Test.php @@ -0,0 +1,63 @@ +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, + ]); + } +} diff --git a/server/core/Plugin_Api.php b/server/core/Plugin_Api.php index c2a9041..20ffd0c 100644 --- a/server/core/Plugin_Api.php +++ b/server/core/Plugin_Api.php @@ -1,9 +1,9 @@ genToken()); + $openstack_api->computeV2(['region'=> 'RegionOne']); + +// var_dump($openstack_api->getBuilderOptions()); diff --git a/server/init.php b/server/init.php index ff7f90b..5b6a6c1 100644 --- a/server/init.php +++ b/server/init.php @@ -2,7 +2,9 @@ include_once("config.inc.php"); include_once("core/Plugin_Api.php"); require "vendor/autoload.php"; - + include_once("core/LibOverride/Builder.php"); + include_once("core/LibOverride/OpenStack.php"); + //traitement requete, recuperation data if(isset($_POST["key"])){ //recuperation des donnes sauvegardes @@ -27,11 +29,32 @@ "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); - + $pluginApi = plugin_api::getInstance(); ?> -- cgit v1.2.3 From de1f3020478a471e0041c1030231bb5462640fd8 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 31 Jan 2016 02:38:05 +0100 Subject: Test Authentification --- server/core/LibOverride/Test.php | 69 +++++++++++++++++++++++----------------- server/index.php | 7 ++-- server/init.php | 12 ++++++- 3 files changed, 54 insertions(+), 34 deletions(-) mode change 100644 => 100755 server/core/LibOverride/Test.php mode change 100644 => 100755 server/index.php mode change 100644 => 100755 server/init.php (limited to 'server') diff --git a/server/core/LibOverride/Test.php b/server/core/LibOverride/Test.php old mode 100644 new mode 100755 index a1c8023..09f08d5 --- a/server/core/LibOverride/Test.php +++ b/server/core/LibOverride/Test.php @@ -1,24 +1,56 @@ 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; + } } diff --git a/server/index.php b/server/index.php old mode 100644 new mode 100755 index ceba59e..5259a69 --- a/server/index.php +++ b/server/index.php @@ -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()); diff --git a/server/init.php b/server/init.php old mode 100644 new mode 100755 index 5b6a6c1..e186667 --- a/server/init.php +++ b/server/init.php @@ -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 @@ ); } + $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); - $pluginApi = plugin_api::getInstance(); ?> -- cgit v1.2.3 From 7276d3f0334785a33ab23ef80db1e2ea77d24922 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 31 Jan 2016 03:24:02 +0100 Subject: Suite Test Token Management --- server/core/LibOverride/Test.php | 60 ++++++++++++++++++++-------------------- server/index.php | 2 +- server/init.php | 13 +++++---- 3 files changed, 38 insertions(+), 37 deletions(-) (limited to 'server') diff --git a/server/core/LibOverride/Test.php b/server/core/LibOverride/Test.php index 09f08d5..4e8e540 100755 --- a/server/core/LibOverride/Test.php +++ b/server/core/LibOverride/Test.php @@ -10,47 +10,26 @@ use OpenStack\Common\Transport\Utils; class genTokenOptions { private $optionsGlobal; + + private $stack; - public function __construct($options, $token){ + public function __construct($options){ 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(), - //]); + $this->stack = HandlerStack::create(); - $httpClient = new Client([ + $httpClient['Common'] = 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; + $this->optionsGlobal['Common'] = $options; } /** @@ -66,7 +45,28 @@ class genTokenOptions } } - public function getOptions(){ - return $this->optionsGlobal; + public genComputeToken(){ + $options = $this->optionsGlobal['Common']; + $options['catalogName'] = 'nova'; + $options['catalogType'] = 'compute'; + $options['region'] = 'RegionOne'; + + list($token, $baseUrl) = $options['identityService']->authenticate($options); + + //$stack = HandlerStack::create(); + $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); + + $this->addDebugMiddleware($options, $this->stack); + + $options['httpClient'] = new Client([ + 'base_uri' => Utils::normalizeUrl($options['authUrl']), + 'handler' => $stack, + ]); + + $this->optionsGlobal['Compute'] = $options; + } + + public function getOptionsCompute(){ + return $this->optionsGlobal['Compute']; } } diff --git a/server/index.php b/server/index.php index 5259a69..23c99a1 100755 --- a/server/index.php +++ b/server/index.php @@ -10,7 +10,7 @@ //$id = new identity($openstack_api, $pluginApi); // var_dump($id->genToken()); - $compute = $openstack_api->computeV2(['region'=> 'RegionOne']); + $compute = $openstack_api->computeV2($array); $servers = $compute->listServers(true); var_dump($servers); diff --git a/server/init.php b/server/init.php index e186667..a7989ce 100755 --- a/server/init.php +++ b/server/init.php @@ -58,13 +58,14 @@ $pluginApi = plugin_api::getInstance(); - $openstack_api = new OpenStack\OpenStack($Args); - $id = new identity($openstack_api, $pluginApi); + //$openstack_api = new OpenStack\OpenStack($Args); + //$id = new identity($openstack_api, $pluginApi); - $token = $id->genToken(); + //$token = $id->genToken(); - $tmp = new genTokenOptions($Args, $token); - $array = $tmp->getOptions(); - $openstack_api = new OpenStack\OpenStack($array); + $tmp = new genTokenOptions($Args); + $tmp->genComputeToken(); + $array = $tmp->getOptionsCompute(); + $openstack_api = new OpenStack\OpenStack(new array()); ?> -- cgit v1.2.3 From 6c4cdf62ac99a56cefb663ad4779dd07f0944a26 Mon Sep 17 00:00:00 2001 From: Eole Date: Sun, 31 Jan 2016 04:00:20 +0100 Subject: Test Serialization Token Debut --- server/core/LibOverride/Test.php | 43 ++++++++++++++++++++++++++++++++++------ server/index.php | 13 ++++++++++++ server/init.php | 7 +++++-- 3 files changed, 55 insertions(+), 8 deletions(-) (limited to 'server') diff --git a/server/core/LibOverride/Test.php b/server/core/LibOverride/Test.php index 4e8e540..5babc35 100755 --- a/server/core/LibOverride/Test.php +++ b/server/core/LibOverride/Test.php @@ -12,15 +12,16 @@ class genTokenOptions private $optionsGlobal; private $stack; + private $backup = []; public function __construct($options){ echo "test"; $this->stack = HandlerStack::create(); - $httpClient['Common'] = new Client([ + $httpClient = new Client([ 'base_uri' => Utils::normalizeUrl($options['authUrl']), - 'handler' => $stack, + 'handler' => $this->stack, ]); $options['identityService'] = Service::factory($httpClient); @@ -45,26 +46,56 @@ class genTokenOptions } } - public genComputeToken(){ + public function genComputeToken(){ $options = $this->optionsGlobal['Common']; $options['catalogName'] = 'nova'; $options['catalogType'] = 'compute'; $options['region'] = 'RegionOne'; list($token, $baseUrl) = $options['identityService']->authenticate($options); - + var_dump($token); //$stack = HandlerStack::create(); $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); $this->addDebugMiddleware($options, $this->stack); $options['httpClient'] = new Client([ - 'base_uri' => Utils::normalizeUrl($options['authUrl']), - 'handler' => $stack, + 'base_uri' => Utils::normalizeUrl($baseUrl), + 'handler' => $this->stack, ]); + $this->backup['Compute'] = array('token' => serialize($token), 'baseUrl' => $baseUrl ); + $this->optionsGlobal['Compute'] = $options; + } + + public function loadComputeBackup($opt){ + + $options = $this->optionsGlobal['Common']; + $options['catalogName'] = 'nova'; + $options['catalogType'] = 'compute'; + $options['region'] = 'RegionOne'; + //list($token, $baseUrl) = $options['identityService']->authenticate($options); + $this->backup['Compute'] = unserialize($opt); + $token = unserialize($this->backup['Compute'] ['token']); + $baseUrl = $this->backup['Compute']['baseUrl']; + + //$stack = HandlerStack::create(); + + $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); + + $this->addDebugMiddleware($options, $this->stack); + + $options['httpClient'] = new Client([ + 'base_uri' => Utils::normalizeUrl($baseUrl), + 'handler' => $this->stack, + ]); + $this->backup['Compute'] = array('token' => serialize($token), 'baseUrl' => $baseUrl ); $this->optionsGlobal['Compute'] = $options; } + + public function getBackup($service){ + return serialize($this->backup[$service]); + } public function getOptionsCompute(){ return $this->optionsGlobal['Compute']; diff --git a/server/index.php b/server/index.php index 23c99a1..b5424da 100755 --- a/server/index.php +++ b/server/index.php @@ -13,5 +13,18 @@ $compute = $openstack_api->computeV2($array); $servers = $compute->listServers(true); var_dump($servers); + foreach($servers as $server){ + echo $server->id." !!!!!!!!! "; + } + $tmp = new genTokenOptions($Args); + $tmp->loadComputeBackup($computBack); + $array = $tmp->getOptionsCompute(); + + $openstackTest = new OpenStack\OpenStack([]); + $computeTest = $openstackTest->computeV2($array); + $serversTest = $computeTest->listServers(true); + foreach($serversTest as $server){ + echo $server->id." %%%%%% "; + } // var_dump($openstack_api->getBuilderOptions()); diff --git a/server/init.php b/server/init.php index a7989ce..3c5f848 100755 --- a/server/init.php +++ b/server/init.php @@ -66,6 +66,9 @@ $tmp = new genTokenOptions($Args); $tmp->genComputeToken(); $array = $tmp->getOptionsCompute(); - $openstack_api = new OpenStack\OpenStack(new array()); - + $openstack_api = new OpenStack\OpenStack([]); + + $computBack = $tmp->getBackup("Compute"); + //file_put_contents("token", serialize($tmp)); + ?> -- cgit v1.2.3 From c796facb137a908b36e5477abfc3ff7828b45c6e Mon Sep 17 00:00:00 2001 From: Eole Date: Sun, 31 Jan 2016 10:47:57 +0100 Subject: Begin Serialization Token --- server/core/LibOverride/Test.php | 55 +++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 6 deletions(-) (limited to 'server') diff --git a/server/core/LibOverride/Test.php b/server/core/LibOverride/Test.php index 5babc35..beb4e70 100755 --- a/server/core/LibOverride/Test.php +++ b/server/core/LibOverride/Test.php @@ -53,7 +53,7 @@ class genTokenOptions $options['region'] = 'RegionOne'; list($token, $baseUrl) = $options['identityService']->authenticate($options); - var_dump($token); + //var_dump($token); //$stack = HandlerStack::create(); $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); @@ -63,7 +63,49 @@ class genTokenOptions 'base_uri' => Utils::normalizeUrl($baseUrl), 'handler' => $this->stack, ]); - $this->backup['Compute'] = array('token' => serialize($token), 'baseUrl' => $baseUrl ); + $this->backup['Compute'] = array('token' => json_encode($token), 'baseUrl' => $baseUrl ); + serialize($token->methods); + foreach($token->roles as $role){ + serialize($role->name); + serialize($role->links); + serialize($role->id); + } + serialize($token->expires); + serialize($token->project->domainId); + serialize($token->project->parentId); + serialize($token->project->enabled); + serialize($token->project->description); + serialize($token->project->id); + serialize($token->project->links); + serialize($token->project->name); + foreach($token->catalog->services as $service){ + serialize($service->id); + serialize($service->name); + serialize($service->description); + serialize($service->type); + foreach($service->endpoints as $end){ + serialize($end->id); + serialize($end->interface); + serialize($end->name); + serialize($end->serviceId); + serialize($end->region); + serialize($end->links); + serialize($end->url); + } + serialize($service->links); + } + serialize($token->extras); + serialize($token->user->domainId); + serialize($token->user->defaultProjectId); + serialize($token->user->id); + serialize($token->user->email); + serialize($token->user->enabled); + serialize($token->user->description); + serialize($token->user->links); + serialize($token->user->name); + serialize($token->issued); + serialize($token->id); + var_dump($token->id); $this->optionsGlobal['Compute'] = $options; } @@ -75,8 +117,9 @@ class genTokenOptions $options['region'] = 'RegionOne'; //list($token, $baseUrl) = $options['identityService']->authenticate($options); - $this->backup['Compute'] = unserialize($opt); - $token = unserialize($this->backup['Compute'] ['token']); + $this->backup['Compute'] = json_decode($opt, true); + var_dump($this->backup['Compute']); + $token = json_decode($this->backup['Compute']['token'], true); $baseUrl = $this->backup['Compute']['baseUrl']; //$stack = HandlerStack::create(); @@ -89,12 +132,12 @@ class genTokenOptions 'base_uri' => Utils::normalizeUrl($baseUrl), 'handler' => $this->stack, ]); - $this->backup['Compute'] = array('token' => serialize($token), 'baseUrl' => $baseUrl ); + $this->backup['Compute'] = array('token' => json_encode($token), 'baseUrl' => $baseUrl ); $this->optionsGlobal['Compute'] = $options; } public function getBackup($service){ - return serialize($this->backup[$service]); + return json_encode($this->backup[$service]); } public function getOptionsCompute(){ -- cgit v1.2.3 From f6c4c90567161fdb73e0fcec5f3d330c3a118a60 Mon Sep 17 00:00:00 2001 From: Eole Date: Sun, 31 Jan 2016 11:54:53 +0100 Subject: Fin test Token Management --- server/core/LibOverride/Test.php | 172 ++++++++++++++++++++++++++++----------- server/index.php | 6 +- 2 files changed, 126 insertions(+), 52 deletions(-) (limited to 'server') diff --git a/server/core/LibOverride/Test.php b/server/core/LibOverride/Test.php index beb4e70..91ea84d 100755 --- a/server/core/LibOverride/Test.php +++ b/server/core/LibOverride/Test.php @@ -4,8 +4,10 @@ use GuzzleHttp\Client; use OpenStack\Common\Transport\HandlerStack; use OpenStack\Common\Transport\Middleware; use OpenStack\Identity\v3\Service; +use OpenStack\Identity\v3\Api; use OpenStack\Common\Auth\Token; use OpenStack\Common\Transport\Utils; +use OpenStack\Identity\v3\Models; class genTokenOptions { @@ -13,9 +15,9 @@ class genTokenOptions private $stack; private $backup = []; + private $httpClient; public function __construct($options){ - echo "test"; $this->stack = HandlerStack::create(); @@ -24,6 +26,8 @@ class genTokenOptions 'handler' => $this->stack, ]); + $this->httpClient = $httpClient; + $options['identityService'] = Service::factory($httpClient); $options['authHandler'] = function () use ($options) { @@ -63,49 +67,8 @@ class genTokenOptions 'base_uri' => Utils::normalizeUrl($baseUrl), 'handler' => $this->stack, ]); - $this->backup['Compute'] = array('token' => json_encode($token), 'baseUrl' => $baseUrl ); - serialize($token->methods); - foreach($token->roles as $role){ - serialize($role->name); - serialize($role->links); - serialize($role->id); - } - serialize($token->expires); - serialize($token->project->domainId); - serialize($token->project->parentId); - serialize($token->project->enabled); - serialize($token->project->description); - serialize($token->project->id); - serialize($token->project->links); - serialize($token->project->name); - foreach($token->catalog->services as $service){ - serialize($service->id); - serialize($service->name); - serialize($service->description); - serialize($service->type); - foreach($service->endpoints as $end){ - serialize($end->id); - serialize($end->interface); - serialize($end->name); - serialize($end->serviceId); - serialize($end->region); - serialize($end->links); - serialize($end->url); - } - serialize($service->links); - } - serialize($token->extras); - serialize($token->user->domainId); - serialize($token->user->defaultProjectId); - serialize($token->user->id); - serialize($token->user->email); - serialize($token->user->enabled); - serialize($token->user->description); - serialize($token->user->links); - serialize($token->user->name); - serialize($token->issued); - serialize($token->id); - var_dump($token->id); + $this->backup['Compute'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); + $this->optionsGlobal['Compute'] = $options; } @@ -117,9 +80,9 @@ class genTokenOptions $options['region'] = 'RegionOne'; //list($token, $baseUrl) = $options['identityService']->authenticate($options); - $this->backup['Compute'] = json_decode($opt, true); - var_dump($this->backup['Compute']); - $token = json_decode($this->backup['Compute']['token'], true); + $this->backup['Compute'] = unserialize($opt); + //var_dump($this->backup['Compute']); + $token = $this->unserializeToken($this->backup['Compute']['token']); $baseUrl = $this->backup['Compute']['baseUrl']; //$stack = HandlerStack::create(); @@ -132,15 +95,126 @@ class genTokenOptions 'base_uri' => Utils::normalizeUrl($baseUrl), 'handler' => $this->stack, ]); - $this->backup['Compute'] = array('token' => json_encode($token), 'baseUrl' => $baseUrl ); + $this->backup['Compute'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); $this->optionsGlobal['Compute'] = $options; } public function getBackup($service){ - return json_encode($this->backup[$service]); + return serialize($this->backup[$service]); } public function getOptionsCompute(){ return $this->optionsGlobal['Compute']; } + + private function serializeToken($token){ + $tokenSerialized = []; + $tokenSerialized["methods"] = serialize($token->methods); + $tokenSerialized["roles"] = []; + //var_dump($token->roles); + foreach($token->roles as $role){ + $tokenSerialized["roles"][serialize($role->name)]["links"] = serialize($role->links); + $tokenSerialized["roles"][serialize($role->name)]["id"] = serialize($role->id); + } + $tokenSerialized["expires"] = serialize($token->expires); + $tokenSerialized["project"]["domainId"] = serialize($token->project->domainId); + $tokenSerialized["project"]["parentId"] = serialize($token->project->parentId); + $tokenSerialized["project"]["enabled"] = serialize($token->project->enabled); + $tokenSerialized["project"]["description"] = serialize($token->project->description); + $tokenSerialized["project"]["id"] = serialize($token->project->id); + $tokenSerialized["project"]["links"] = serialize($token->project->links); + $tokenSerialized["project"]["name"] = serialize($token->project->name); + foreach($token->catalog->services as $service){ + $tokenSerialized["catalog"][serialize($service->id)]["name"] = serialize($service->name); + $tokenSerialized["catalog"][serialize($service->id)]["description"] = serialize($service->description); + $tokenSerialized["catalog"][serialize($service->id)]["type"] = serialize($service->type); + foreach($service->endpoints as $end){ + $tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["interface"] = serialize($end->interface); + $tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["name"] = serialize($end->name); + $tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["serviceId"] = serialize($end->serviceId); + $tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["region"] = serialize($end->region); + $tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["links"] = serialize($end->links); + $tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["url"] = serialize($end->url); + } + $tokenSerialized["roles"][serialize($service->id)]["links"] = serialize($service->links); + } + $tokenSerialized["extras"] = serialize($token->extras); + $tokenSerialized["user"]["domainId"] = serialize($token->user->domainId); + $tokenSerialized["user"]["defaultProjectId"] = serialize($token->user->defaultProjectId); + $tokenSerialized["user"]["id"] = serialize($token->user->id); + $tokenSerialized["user"]["email"] = serialize($token->user->email); + $tokenSerialized["user"]["enabled"] = serialize($token->user->enabled); + $tokenSerialized["user"]["description"] = serialize($token->user->description); + $tokenSerialized["user"]["links"] = serialize($token->user->links); + $tokenSerialized["user"]["name"] = serialize($token->user->name); + $tokenSerialized["issued"] = serialize($token->issued); + $tokenSerialized["id"] = serialize($token->id); + + return $tokenSerialized; + } + + private function unserializeToken($tokenSerialized){ + $api = new Api(); + $token = new Models\Token($this->httpClient, $api); + $token->methods = unserialize($tokenSerialized["methods"]); + $token->roles = []; + foreach($tokenSerialized["roles"] as $key => $role){ + $tmp = new Models\Role($this->httpClient, $api); + + $tmp->name = unserialize($key); + $tmp->links = unserialize($role["links"]); + $tmp->id = unserialize($role["id"]); + + $token->roles[] = $tmp; + } + + $token->expires = unserialize($tokenSerialized["expires"]); + $token->project = new Models\Project($this->httpClient, $api); + $token->project->domainId = unserialize($tokenSerialized["project"]["domainId"]); + $token->project->parentId = unserialize($tokenSerialized["project"]["parentId"]); + $token->project->enabled = unserialize($tokenSerialized["project"]["enabled"]); + $token->project->description = unserialize($tokenSerialized["project"]["description"]); + $token->project->id = unserialize($tokenSerialized["project"]["id"]); + $token->project->links = unserialize($tokenSerialized["project"]["links"]); + $token->project->name = unserialize($tokenSerialized["project"]["name"]); + + $token->catalog = []; + foreach($tokenSerialized["catalog"] as $key => $service){ + $tmp = new Models\Service($this->httpClient, $api); + + $tmp->id = unserialize($key); + $tmp->name = unserialize($service["name"]); + $tmp->description = unserialize($service["description"]); + $tmp->type = unserialize($service["type"]); + $tmp->endpoints = []; + foreach($service["endpoints"] as $key => $end){ + $tmpEnd = new Models\Endpoint($this->httpClient, $api); + $tmpEnd->id = unserialize($key); + $tmpEnd->interface = unserialize($end["interface"]); + $tmpEnd->name = unserialize($end["name"]); + $tmpEnd->serviceId = unserialize($end["serviceId"]); + $tmpEnd->region = unserialize($end["region"]); + $tmpEnd->links = unserialize($end["links"]); + $tmpEnd->url = unserialize($end["url"]); + $tmp->endpoints[] = $tmpEnd; + } + $tmp->links = unserialize($service["links"]); + $token->catalog[] = $tmp; + } + + $token->extras = unserialize($tokenSerialized["extras"]); + $token->user = new Models\User($this->httpClient, $api); + $token->user->domainId = unserialize($tokenSerialized["user"]["domainId"]); + $token->user->defaultProjectId = unserialize($tokenSerialized["user"]["defaultProjectId"]); + $token->user->id = unserialize($tokenSerialized["user"]["id"]); + $token->user->email = unserialize($tokenSerialized["user"]["email"]); + $token->user->enabled = unserialize($tokenSerialized["user"]["enabled"]); + $token->user->links = unserialize($tokenSerialized["user"]["links"]); + $token->user->name = unserialize($tokenSerialized["user"]["name"]); + $token->user->description = unserialize($tokenSerialized["user"]["description"]); + $token->issued = unserialize($tokenSerialized["issued"]); + $token->id = unserialize($tokenSerialized["id"]); + + return $token; + } } diff --git a/server/index.php b/server/index.php index b5424da..c99e8bc 100755 --- a/server/index.php +++ b/server/index.php @@ -12,9 +12,9 @@ // var_dump($id->genToken()); $compute = $openstack_api->computeV2($array); $servers = $compute->listServers(true); - var_dump($servers); + //var_dump($servers); foreach($servers as $server){ - echo $server->id." !!!!!!!!! "; + // echo $server->id." !!!!!!!!! "; } $tmp = new genTokenOptions($Args); @@ -25,6 +25,6 @@ $computeTest = $openstackTest->computeV2($array); $serversTest = $computeTest->listServers(true); foreach($serversTest as $server){ - echo $server->id." %%%%%% "; + // echo $server->id." %%%%%% "; } // var_dump($openstack_api->getBuilderOptions()); -- cgit v1.2.3 From 4c0fb055903b7cc1eaf8d6c65237e362edf4b18d Mon Sep 17 00:00:00 2001 From: Eole Date: Sun, 31 Jan 2016 12:16:31 +0100 Subject: Fin Token --- server/core/LibOverride/Test.php | 25 ++++++++++++++++--------- server/index.php | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) (limited to 'server') diff --git a/server/core/LibOverride/Test.php b/server/core/LibOverride/Test.php index 91ea84d..10a7837 100755 --- a/server/core/LibOverride/Test.php +++ b/server/core/LibOverride/Test.php @@ -111,11 +111,12 @@ class genTokenOptions $tokenSerialized = []; $tokenSerialized["methods"] = serialize($token->methods); $tokenSerialized["roles"] = []; - //var_dump($token->roles); + foreach($token->roles as $role){ - $tokenSerialized["roles"][serialize($role->name)]["links"] = serialize($role->links); - $tokenSerialized["roles"][serialize($role->name)]["id"] = serialize($role->id); - } + $tokenSerialized["roles"][serialize($role->id)]["links"] = serialize($role->links); + $tokenSerialized["roles"][serialize($role->id)]["name"] = serialize($role->name); + } + $tokenSerialized["expires"] = serialize($token->expires); $tokenSerialized["project"]["domainId"] = serialize($token->project->domainId); $tokenSerialized["project"]["parentId"] = serialize($token->project->parentId); @@ -124,6 +125,7 @@ class genTokenOptions $tokenSerialized["project"]["id"] = serialize($token->project->id); $tokenSerialized["project"]["links"] = serialize($token->project->links); $tokenSerialized["project"]["name"] = serialize($token->project->name); + foreach($token->catalog->services as $service){ $tokenSerialized["catalog"][serialize($service->id)]["name"] = serialize($service->name); $tokenSerialized["catalog"][serialize($service->id)]["description"] = serialize($service->description); @@ -158,14 +160,17 @@ class genTokenOptions $token = new Models\Token($this->httpClient, $api); $token->methods = unserialize($tokenSerialized["methods"]); $token->roles = []; + $i = 0; foreach($tokenSerialized["roles"] as $key => $role){ $tmp = new Models\Role($this->httpClient, $api); - $tmp->name = unserialize($key); + $tmp->id = unserialize($key); $tmp->links = unserialize($role["links"]); - $tmp->id = unserialize($role["id"]); + if(isset($role["name"])) + $tmp->name = unserialize($role["name"]); $token->roles[] = $tmp; + $i++; } $token->expires = unserialize($tokenSerialized["expires"]); @@ -178,7 +183,8 @@ class genTokenOptions $token->project->links = unserialize($tokenSerialized["project"]["links"]); $token->project->name = unserialize($tokenSerialized["project"]["name"]); - $token->catalog = []; + $token->catalog = new Models\Catalog($this->httpClient, $api); + $token->catalog->services = []; foreach($tokenSerialized["catalog"] as $key => $service){ $tmp = new Models\Service($this->httpClient, $api); @@ -198,8 +204,9 @@ class genTokenOptions $tmpEnd->url = unserialize($end["url"]); $tmp->endpoints[] = $tmpEnd; } - $tmp->links = unserialize($service["links"]); - $token->catalog[] = $tmp; + if(isset($service["links"])) + $tmp->links = unserialize($service["links"]); + $token->catalog->services[] = $tmp; } $token->extras = unserialize($tokenSerialized["extras"]); diff --git a/server/index.php b/server/index.php index c99e8bc..4d65c59 100755 --- a/server/index.php +++ b/server/index.php @@ -25,6 +25,6 @@ $computeTest = $openstackTest->computeV2($array); $serversTest = $computeTest->listServers(true); foreach($serversTest as $server){ - // echo $server->id." %%%%%% "; + echo $server->id." %%%%%% "; } // var_dump($openstack_api->getBuilderOptions()); -- cgit v1.2.3 From f10df7fee15a15728ca2f2f539c8c1e6b123a5e4 Mon Sep 17 00:00:00 2001 From: Eole Date: Sun, 31 Jan 2016 12:22:51 +0100 Subject: Implementation Token Management End --- server/core/LibOverride/Test.php | 227 ---------------------------- server/core/LibOverride/genTokenOptions.php | 222 +++++++++++++++++++++++++++ 2 files changed, 222 insertions(+), 227 deletions(-) delete mode 100755 server/core/LibOverride/Test.php create mode 100755 server/core/LibOverride/genTokenOptions.php (limited to 'server') diff --git a/server/core/LibOverride/Test.php b/server/core/LibOverride/Test.php deleted file mode 100755 index 10a7837..0000000 --- a/server/core/LibOverride/Test.php +++ /dev/null @@ -1,227 +0,0 @@ -stack = HandlerStack::create(); - - $httpClient = new Client([ - 'base_uri' => Utils::normalizeUrl($options['authUrl']), - 'handler' => $this->stack, - ]); - - $this->httpClient = $httpClient; - - $options['identityService'] = Service::factory($httpClient); - - $options['authHandler'] = function () use ($options) { - return $options['identityService']->generateToken($options); - }; - - $this->optionsGlobal['Common'] = $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 genComputeToken(){ - $options = $this->optionsGlobal['Common']; - $options['catalogName'] = 'nova'; - $options['catalogType'] = 'compute'; - $options['region'] = 'RegionOne'; - - list($token, $baseUrl) = $options['identityService']->authenticate($options); - //var_dump($token); - //$stack = HandlerStack::create(); - $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); - - $this->addDebugMiddleware($options, $this->stack); - - $options['httpClient'] = new Client([ - 'base_uri' => Utils::normalizeUrl($baseUrl), - 'handler' => $this->stack, - ]); - $this->backup['Compute'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); - - $this->optionsGlobal['Compute'] = $options; - } - - public function loadComputeBackup($opt){ - - $options = $this->optionsGlobal['Common']; - $options['catalogName'] = 'nova'; - $options['catalogType'] = 'compute'; - $options['region'] = 'RegionOne'; - - //list($token, $baseUrl) = $options['identityService']->authenticate($options); - $this->backup['Compute'] = unserialize($opt); - //var_dump($this->backup['Compute']); - $token = $this->unserializeToken($this->backup['Compute']['token']); - $baseUrl = $this->backup['Compute']['baseUrl']; - - //$stack = HandlerStack::create(); - - $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); - - $this->addDebugMiddleware($options, $this->stack); - - $options['httpClient'] = new Client([ - 'base_uri' => Utils::normalizeUrl($baseUrl), - 'handler' => $this->stack, - ]); - $this->backup['Compute'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); - $this->optionsGlobal['Compute'] = $options; - } - - public function getBackup($service){ - return serialize($this->backup[$service]); - } - - public function getOptionsCompute(){ - return $this->optionsGlobal['Compute']; - } - - private function serializeToken($token){ - $tokenSerialized = []; - $tokenSerialized["methods"] = serialize($token->methods); - $tokenSerialized["roles"] = []; - - foreach($token->roles as $role){ - $tokenSerialized["roles"][serialize($role->id)]["links"] = serialize($role->links); - $tokenSerialized["roles"][serialize($role->id)]["name"] = serialize($role->name); - } - - $tokenSerialized["expires"] = serialize($token->expires); - $tokenSerialized["project"]["domainId"] = serialize($token->project->domainId); - $tokenSerialized["project"]["parentId"] = serialize($token->project->parentId); - $tokenSerialized["project"]["enabled"] = serialize($token->project->enabled); - $tokenSerialized["project"]["description"] = serialize($token->project->description); - $tokenSerialized["project"]["id"] = serialize($token->project->id); - $tokenSerialized["project"]["links"] = serialize($token->project->links); - $tokenSerialized["project"]["name"] = serialize($token->project->name); - - foreach($token->catalog->services as $service){ - $tokenSerialized["catalog"][serialize($service->id)]["name"] = serialize($service->name); - $tokenSerialized["catalog"][serialize($service->id)]["description"] = serialize($service->description); - $tokenSerialized["catalog"][serialize($service->id)]["type"] = serialize($service->type); - foreach($service->endpoints as $end){ - $tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["interface"] = serialize($end->interface); - $tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["name"] = serialize($end->name); - $tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["serviceId"] = serialize($end->serviceId); - $tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["region"] = serialize($end->region); - $tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["links"] = serialize($end->links); - $tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["url"] = serialize($end->url); - } - $tokenSerialized["roles"][serialize($service->id)]["links"] = serialize($service->links); - } - $tokenSerialized["extras"] = serialize($token->extras); - $tokenSerialized["user"]["domainId"] = serialize($token->user->domainId); - $tokenSerialized["user"]["defaultProjectId"] = serialize($token->user->defaultProjectId); - $tokenSerialized["user"]["id"] = serialize($token->user->id); - $tokenSerialized["user"]["email"] = serialize($token->user->email); - $tokenSerialized["user"]["enabled"] = serialize($token->user->enabled); - $tokenSerialized["user"]["description"] = serialize($token->user->description); - $tokenSerialized["user"]["links"] = serialize($token->user->links); - $tokenSerialized["user"]["name"] = serialize($token->user->name); - $tokenSerialized["issued"] = serialize($token->issued); - $tokenSerialized["id"] = serialize($token->id); - - return $tokenSerialized; - } - - private function unserializeToken($tokenSerialized){ - $api = new Api(); - $token = new Models\Token($this->httpClient, $api); - $token->methods = unserialize($tokenSerialized["methods"]); - $token->roles = []; - $i = 0; - foreach($tokenSerialized["roles"] as $key => $role){ - $tmp = new Models\Role($this->httpClient, $api); - - $tmp->id = unserialize($key); - $tmp->links = unserialize($role["links"]); - if(isset($role["name"])) - $tmp->name = unserialize($role["name"]); - - $token->roles[] = $tmp; - $i++; - } - - $token->expires = unserialize($tokenSerialized["expires"]); - $token->project = new Models\Project($this->httpClient, $api); - $token->project->domainId = unserialize($tokenSerialized["project"]["domainId"]); - $token->project->parentId = unserialize($tokenSerialized["project"]["parentId"]); - $token->project->enabled = unserialize($tokenSerialized["project"]["enabled"]); - $token->project->description = unserialize($tokenSerialized["project"]["description"]); - $token->project->id = unserialize($tokenSerialized["project"]["id"]); - $token->project->links = unserialize($tokenSerialized["project"]["links"]); - $token->project->name = unserialize($tokenSerialized["project"]["name"]); - - $token->catalog = new Models\Catalog($this->httpClient, $api); - $token->catalog->services = []; - foreach($tokenSerialized["catalog"] as $key => $service){ - $tmp = new Models\Service($this->httpClient, $api); - - $tmp->id = unserialize($key); - $tmp->name = unserialize($service["name"]); - $tmp->description = unserialize($service["description"]); - $tmp->type = unserialize($service["type"]); - $tmp->endpoints = []; - foreach($service["endpoints"] as $key => $end){ - $tmpEnd = new Models\Endpoint($this->httpClient, $api); - $tmpEnd->id = unserialize($key); - $tmpEnd->interface = unserialize($end["interface"]); - $tmpEnd->name = unserialize($end["name"]); - $tmpEnd->serviceId = unserialize($end["serviceId"]); - $tmpEnd->region = unserialize($end["region"]); - $tmpEnd->links = unserialize($end["links"]); - $tmpEnd->url = unserialize($end["url"]); - $tmp->endpoints[] = $tmpEnd; - } - if(isset($service["links"])) - $tmp->links = unserialize($service["links"]); - $token->catalog->services[] = $tmp; - } - - $token->extras = unserialize($tokenSerialized["extras"]); - $token->user = new Models\User($this->httpClient, $api); - $token->user->domainId = unserialize($tokenSerialized["user"]["domainId"]); - $token->user->defaultProjectId = unserialize($tokenSerialized["user"]["defaultProjectId"]); - $token->user->id = unserialize($tokenSerialized["user"]["id"]); - $token->user->email = unserialize($tokenSerialized["user"]["email"]); - $token->user->enabled = unserialize($tokenSerialized["user"]["enabled"]); - $token->user->links = unserialize($tokenSerialized["user"]["links"]); - $token->user->name = unserialize($tokenSerialized["user"]["name"]); - $token->user->description = unserialize($tokenSerialized["user"]["description"]); - $token->issued = unserialize($tokenSerialized["issued"]); - $token->id = unserialize($tokenSerialized["id"]); - - return $token; - } -} diff --git a/server/core/LibOverride/genTokenOptions.php b/server/core/LibOverride/genTokenOptions.php new file mode 100755 index 0000000..0b00163 --- /dev/null +++ b/server/core/LibOverride/genTokenOptions.php @@ -0,0 +1,222 @@ +stack = HandlerStack::create(); + + $httpClient = new Client([ + 'base_uri' => Utils::normalizeUrl($options['authUrl']), + 'handler' => $this->stack, + ]); + + $this->httpClient = $httpClient; + + $options['identityService'] = Service::factory($httpClient); + + $options['authHandler'] = function () use ($options) { + return $options['identityService']->generateToken($options); + }; + + $this->optionsGlobal['Common'] = $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 genComputeToken(){ + $options = $this->optionsGlobal['Common']; + $options['catalogName'] = 'nova'; + $options['catalogType'] = 'compute'; + $options['region'] = 'RegionOne'; + + list($token, $baseUrl) = $options['identityService']->authenticate($options); + + $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); + + $this->addDebugMiddleware($options, $this->stack); + + $options['httpClient'] = new Client([ + 'base_uri' => Utils::normalizeUrl($baseUrl), + 'handler' => $this->stack, + ]); + $this->backup['Compute'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); + + $this->optionsGlobal['Compute'] = $options; + } + + public function loadComputeBackup($opt){ + + $options = $this->optionsGlobal['Common']; + $options['catalogName'] = 'nova'; + $options['catalogType'] = 'compute'; + $options['region'] = 'RegionOne'; + + $this->backup['Compute'] = unserialize($opt); + $token = $this->unserializeToken($this->backup['Compute']['token']); + $baseUrl = $this->backup['Compute']['baseUrl']; + + $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); + + $this->addDebugMiddleware($options, $this->stack); + + $options['httpClient'] = new Client([ + 'base_uri' => Utils::normalizeUrl($baseUrl), + 'handler' => $this->stack, + ]); + $this->backup['Compute'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); + $this->optionsGlobal['Compute'] = $options; + } + + public function getBackup($service){ + return serialize($this->backup[$service]); + } + + public function getOptionsCompute(){ + return $this->optionsGlobal['Compute']; + } + + private function serializeToken($token){ + $tokenSerialized = []; + $tokenSerialized["methods"] = serialize($token->methods); + $tokenSerialized["roles"] = []; + + foreach($token->roles as $role){ + $tokenSerialized["roles"][serialize($role->id)]["links"] = serialize($role->links); + $tokenSerialized["roles"][serialize($role->id)]["name"] = serialize($role->name); + } + + $tokenSerialized["expires"] = serialize($token->expires); + $tokenSerialized["project"]["domainId"] = serialize($token->project->domainId); + $tokenSerialized["project"]["parentId"] = serialize($token->project->parentId); + $tokenSerialized["project"]["enabled"] = serialize($token->project->enabled); + $tokenSerialized["project"]["description"] = serialize($token->project->description); + $tokenSerialized["project"]["id"] = serialize($token->project->id); + $tokenSerialized["project"]["links"] = serialize($token->project->links); + $tokenSerialized["project"]["name"] = serialize($token->project->name); + + foreach($token->catalog->services as $service){ + $tokenSerialized["catalog"][serialize($service->id)]["name"] = serialize($service->name); + $tokenSerialized["catalog"][serialize($service->id)]["description"] = serialize($service->description); + $tokenSerialized["catalog"][serialize($service->id)]["type"] = serialize($service->type); + foreach($service->endpoints as $end){ + $tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["interface"] = serialize($end->interface); + $tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["name"] = serialize($end->name); + $tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["serviceId"] = serialize($end->serviceId); + $tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["region"] = serialize($end->region); + $tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["links"] = serialize($end->links); + $tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["url"] = serialize($end->url); + } + $tokenSerialized["roles"][serialize($service->id)]["links"] = serialize($service->links); + } + $tokenSerialized["extras"] = serialize($token->extras); + $tokenSerialized["user"]["domainId"] = serialize($token->user->domainId); + $tokenSerialized["user"]["defaultProjectId"] = serialize($token->user->defaultProjectId); + $tokenSerialized["user"]["id"] = serialize($token->user->id); + $tokenSerialized["user"]["email"] = serialize($token->user->email); + $tokenSerialized["user"]["enabled"] = serialize($token->user->enabled); + $tokenSerialized["user"]["description"] = serialize($token->user->description); + $tokenSerialized["user"]["links"] = serialize($token->user->links); + $tokenSerialized["user"]["name"] = serialize($token->user->name); + $tokenSerialized["issued"] = serialize($token->issued); + $tokenSerialized["id"] = serialize($token->id); + + return $tokenSerialized; + } + + private function unserializeToken($tokenSerialized){ + $api = new Api(); + $token = new Models\Token($this->httpClient, $api); + $token->methods = unserialize($tokenSerialized["methods"]); + $token->roles = []; + $i = 0; + foreach($tokenSerialized["roles"] as $key => $role){ + $tmp = new Models\Role($this->httpClient, $api); + + $tmp->id = unserialize($key); + $tmp->links = unserialize($role["links"]); + if(isset($role["name"])) + $tmp->name = unserialize($role["name"]); + + $token->roles[] = $tmp; + $i++; + } + + $token->expires = unserialize($tokenSerialized["expires"]); + $token->project = new Models\Project($this->httpClient, $api); + $token->project->domainId = unserialize($tokenSerialized["project"]["domainId"]); + $token->project->parentId = unserialize($tokenSerialized["project"]["parentId"]); + $token->project->enabled = unserialize($tokenSerialized["project"]["enabled"]); + $token->project->description = unserialize($tokenSerialized["project"]["description"]); + $token->project->id = unserialize($tokenSerialized["project"]["id"]); + $token->project->links = unserialize($tokenSerialized["project"]["links"]); + $token->project->name = unserialize($tokenSerialized["project"]["name"]); + + $token->catalog = new Models\Catalog($this->httpClient, $api); + $token->catalog->services = []; + foreach($tokenSerialized["catalog"] as $key => $service){ + $tmp = new Models\Service($this->httpClient, $api); + + $tmp->id = unserialize($key); + $tmp->name = unserialize($service["name"]); + $tmp->description = unserialize($service["description"]); + $tmp->type = unserialize($service["type"]); + $tmp->endpoints = []; + foreach($service["endpoints"] as $key => $end){ + $tmpEnd = new Models\Endpoint($this->httpClient, $api); + $tmpEnd->id = unserialize($key); + $tmpEnd->interface = unserialize($end["interface"]); + $tmpEnd->name = unserialize($end["name"]); + $tmpEnd->serviceId = unserialize($end["serviceId"]); + $tmpEnd->region = unserialize($end["region"]); + $tmpEnd->links = unserialize($end["links"]); + $tmpEnd->url = unserialize($end["url"]); + $tmp->endpoints[] = $tmpEnd; + } + if(isset($service["links"])) + $tmp->links = unserialize($service["links"]); + $token->catalog->services[] = $tmp; + } + + $token->extras = unserialize($tokenSerialized["extras"]); + $token->user = new Models\User($this->httpClient, $api); + $token->user->domainId = unserialize($tokenSerialized["user"]["domainId"]); + $token->user->defaultProjectId = unserialize($tokenSerialized["user"]["defaultProjectId"]); + $token->user->id = unserialize($tokenSerialized["user"]["id"]); + $token->user->email = unserialize($tokenSerialized["user"]["email"]); + $token->user->enabled = unserialize($tokenSerialized["user"]["enabled"]); + $token->user->links = unserialize($tokenSerialized["user"]["links"]); + $token->user->name = unserialize($tokenSerialized["user"]["name"]); + $token->user->description = unserialize($tokenSerialized["user"]["description"]); + $token->issued = unserialize($tokenSerialized["issued"]); + $token->id = unserialize($tokenSerialized["id"]); + + return $token; + } +} -- cgit v1.2.3 From d00ea4f7b1317ed5e9fe2743ea61ceb4330aadf6 Mon Sep 17 00:00:00 2001 From: Eole Date: Sun, 31 Jan 2016 12:29:20 +0100 Subject: nettoyage --- server/core/LibOverride/Builder.php | 169 ---------------------------- server/core/LibOverride/OpenStack.php | 43 ------- server/core/LibOverride/genTokenOptions.php | 5 +- 3 files changed, 2 insertions(+), 215 deletions(-) delete mode 100644 server/core/LibOverride/Builder.php delete mode 100644 server/core/LibOverride/OpenStack.php (limited to 'server') diff --git a/server/core/LibOverride/Builder.php b/server/core/LibOverride/Builder.php deleted file mode 100644 index 30ea9d3..0000000 --- a/server/core/LibOverride/Builder.php +++ /dev/null @@ -1,169 +0,0 @@ - '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; - } -} - diff --git a/server/core/LibOverride/OpenStack.php b/server/core/LibOverride/OpenStack.php deleted file mode 100644 index 2b3897a..0000000 --- a/server/core/LibOverride/OpenStack.php +++ /dev/null @@ -1,43 +0,0 @@ -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); - - } -} diff --git a/server/core/LibOverride/genTokenOptions.php b/server/core/LibOverride/genTokenOptions.php index 0b00163..2e10cac 100755 --- a/server/core/LibOverride/genTokenOptions.php +++ b/server/core/LibOverride/genTokenOptions.php @@ -155,7 +155,7 @@ class genTokenOptions $token = new Models\Token($this->httpClient, $api); $token->methods = unserialize($tokenSerialized["methods"]); $token->roles = []; - $i = 0; + foreach($tokenSerialized["roles"] as $key => $role){ $tmp = new Models\Role($this->httpClient, $api); @@ -164,8 +164,7 @@ class genTokenOptions if(isset($role["name"])) $tmp->name = unserialize($role["name"]); - $token->roles[] = $tmp; - $i++; + $token->roles[] = $tmp } $token->expires = unserialize($tokenSerialized["expires"]); -- cgit v1.2.3 From f884e408730be1dcd6b28e5f7a55eee80677db05 Mon Sep 17 00:00:00 2001 From: Eole Date: Sun, 31 Jan 2016 12:49:56 +0100 Subject: Delete deleted class load --- server/init.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'server') diff --git a/server/init.php b/server/init.php index 3c5f848..9e0500b 100755 --- a/server/init.php +++ b/server/init.php @@ -2,9 +2,7 @@ include_once("config.inc.php"); include_once("core/Plugin_Api.php"); 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/LibOverride/genTokenOptions.php"); include_once("core/Identity.php"); //traitement requete, recuperation data -- cgit v1.2.3 From 217c2247567550f320dc2956615824194c20632d Mon Sep 17 00:00:00 2001 From: Eole Date: Sun, 31 Jan 2016 12:54:37 +0100 Subject: Error Correction --- server/core/LibOverride/genTokenOptions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server') diff --git a/server/core/LibOverride/genTokenOptions.php b/server/core/LibOverride/genTokenOptions.php index 2e10cac..ba9e196 100755 --- a/server/core/LibOverride/genTokenOptions.php +++ b/server/core/LibOverride/genTokenOptions.php @@ -164,7 +164,7 @@ class genTokenOptions if(isset($role["name"])) $tmp->name = unserialize($role["name"]); - $token->roles[] = $tmp + $token->roles[] = $tmp; } $token->expires = unserialize($tokenSerialized["expires"]); -- cgit v1.2.3 From 3914858d7a00508bdef2a8caa205b5019ce39274 Mon Sep 17 00:00:00 2001 From: Eole Date: Sun, 31 Jan 2016 14:24:30 +0100 Subject: Different Service Token Implementation --- server/core/LibOverride/genTokenOptions.php | 129 ++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) (limited to 'server') diff --git a/server/core/LibOverride/genTokenOptions.php b/server/core/LibOverride/genTokenOptions.php index ba9e196..3e8414e 100755 --- a/server/core/LibOverride/genTokenOptions.php +++ b/server/core/LibOverride/genTokenOptions.php @@ -50,6 +50,135 @@ class genTokenOptions } } + public function genIdentityToken(){ + $options = $this->optionsGlobal['Common']; + $options['catalogName'] = 'false'; + $options['catalogType'] = 'false'; + $options['region'] = 'RegionOne'; + + list($token, $baseUrl) = $options['identityService']->authenticate($options); + + $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); + + $this->addDebugMiddleware($options, $this->stack); + + $options['httpClient'] = new Client([ + 'base_uri' => Utils::normalizeUrl($baseUrl), + 'handler' => $this->stack, + ]); + $this->backup['Identity'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); + + $this->optionsGlobal['Identity'] = $options; + } + + public function loadIdentityBackup($opt){ + $options = $this->optionsGlobal['Common']; + $options['catalogName'] = 'false'; + $options['catalogType'] = 'false'; + $options['region'] = 'RegionOne'; + + $this->backup['Identity'] = unserialize($opt); + $token = $this->unserializeToken($this->backup['Identity']['token']); + $baseUrl = $this->backup['Identity']['baseUrl']; + + $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); + + $this->addDebugMiddleware($options, $this->stack); + + $options['httpClient'] = new Client([ + 'base_uri' => Utils::normalizeUrl($baseUrl), + 'handler' => $this->stack, + ]); + $this->backup['Identity'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); + $this->optionsGlobal['Identity'] = $options; + } + + public function genImageToken(){ + $options = $this->optionsGlobal['Common']; + $options['catalogName'] = 'glance'; + $options['catalogType'] = 'image'; + $options['region'] = 'RegionOne'; + + list($token, $baseUrl) = $options['identityService']->authenticate($options); + + $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); + + $this->addDebugMiddleware($options, $this->stack); + + $options['httpClient'] = new Client([ + 'base_uri' => Utils::normalizeUrl($baseUrl), + 'handler' => $this->stack, + ]); + $this->backup['Image'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); + + $this->optionsGlobal['Image'] = $options; + } + + public function loadImageBackup($opt){ + $options = $this->optionsGlobal['Common']; + $options['catalogName'] = 'glance'; + $options['catalogType'] = 'image'; + $options['region'] = 'RegionOne'; + + $this->backup['Image'] = unserialize($opt); + $token = $this->unserializeToken($this->backup['Image']['token']); + $baseUrl = $this->backup['Image']['baseUrl']; + + $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); + + $this->addDebugMiddleware($options, $this->stack); + + $options['httpClient'] = new Client([ + 'base_uri' => Utils::normalizeUrl($baseUrl), + 'handler' => $this->stack, + ]); + $this->backup['Image'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); + $this->optionsGlobal['Image'] = $options; + } + + public function genNetworkToken(){ + $options = $this->optionsGlobal['Common']; + $options['catalogName'] = 'neutron'; + $options['catalogType'] = 'network'; + $options['region'] = 'RegionOne'; + + list($token, $baseUrl) = $options['identityService']->authenticate($options); + + $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); + + $this->addDebugMiddleware($options, $this->stack); + + $options['httpClient'] = new Client([ + 'base_uri' => Utils::normalizeUrl($baseUrl), + 'handler' => $this->stack, + ]); + $this->backup['Network'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); + + $this->optionsGlobal['Network'] = $options; + } + + public function loadNetworkBackup($opt){ + $options = $this->optionsGlobal['Common']; + $options['catalogName'] = 'neutron'; + $options['catalogType'] = 'network'; + $options['region'] = 'RegionOne'; + + $this->backup['Network'] = unserialize($opt); + $token = $this->unserializeToken($this->backup['Network']['token']); + $baseUrl = $this->backup['Network']['baseUrl']; + + $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); + + $this->addDebugMiddleware($options, $this->stack); + + $options['httpClient'] = new Client([ + 'base_uri' => Utils::normalizeUrl($baseUrl), + 'handler' => $this->stack, + ]); + $this->backup['Network'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); + $this->optionsGlobal['Network'] = $options; + } + public function genComputeToken(){ $options = $this->optionsGlobal['Common']; $options['catalogName'] = 'nova'; -- cgit v1.2.3 From 4f062230bcfc8209776259af9c21fc34a29668e4 Mon Sep 17 00:00:00 2001 From: Eole Date: Sun, 31 Jan 2016 14:34:43 +0100 Subject: Implementation Token Multi Service ENd --- server/core/LibOverride/genTokenOptions.php | 12 +++++++----- server/index.php | 27 ++++++++++++++++----------- server/init.php | 6 +++--- 3 files changed, 26 insertions(+), 19 deletions(-) (limited to 'server') diff --git a/server/core/LibOverride/genTokenOptions.php b/server/core/LibOverride/genTokenOptions.php index 3e8414e..9cb4100 100755 --- a/server/core/LibOverride/genTokenOptions.php +++ b/server/core/LibOverride/genTokenOptions.php @@ -56,9 +56,11 @@ class genTokenOptions $options['catalogType'] = 'false'; $options['region'] = 'RegionOne'; - list($token, $baseUrl) = $options['identityService']->authenticate($options); - - $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); + //list($token, $baseUrl) = $options['identityService']->authenticate($options); + $baseUrl = $options["authUrl"]; + $token = $options['identityService']->generateToken($options); + + $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); $this->addDebugMiddleware($options, $this->stack); @@ -227,8 +229,8 @@ class genTokenOptions return serialize($this->backup[$service]); } - public function getOptionsCompute(){ - return $this->optionsGlobal['Compute']; + public function getOptions($service){ + return $this->optionsGlobal[$service]; } private function serializeToken($token){ diff --git a/server/index.php b/server/index.php index 4d65c59..b3c061a 100755 --- a/server/index.php +++ b/server/index.php @@ -10,21 +10,26 @@ //$id = new identity($openstack_api, $pluginApi); // var_dump($id->genToken()); - $compute = $openstack_api->computeV2($array); - $servers = $compute->listServers(true); +// $identity = $openstack_api->identityV3($Args); + //$tmp = $identity->listEndpoints(); + //foreach($tmp as $cred){ +// echo $cred->id." %%%%%% "; + //} + //$servers = $compute->listServers(true); //var_dump($servers); - foreach($servers as $server){ + //foreach($servers as $server){ // echo $server->id." !!!!!!!!! "; - } + //} $tmp = new genTokenOptions($Args); - $tmp->loadComputeBackup($computBack); - $array = $tmp->getOptionsCompute(); + $tmp->loadIdentityBackup($identityBack); + $array = $tmp->getOptions("Identity"); $openstackTest = new OpenStack\OpenStack([]); - $computeTest = $openstackTest->computeV2($array); - $serversTest = $computeTest->listServers(true); - foreach($serversTest as $server){ - echo $server->id." %%%%%% "; + $identityTest = $openstackTest->identityV3($array); + $domainsTest = $identityTest->listDomains(); + foreach($domainsTest as $domain){ + echo $domain->id." %%%%%% "; } -// var_dump($openstack_api->getBuilderOptions()); + // var_dump($openstack_api->getBuilderOptions()); + diff --git a/server/init.php b/server/init.php index 9e0500b..2c07947 100755 --- a/server/init.php +++ b/server/init.php @@ -62,11 +62,11 @@ //$token = $id->genToken(); $tmp = new genTokenOptions($Args); - $tmp->genComputeToken(); - $array = $tmp->getOptionsCompute(); + $tmp->genIdentityToken(); + $array = $tmp->getOptions("Identity"); $openstack_api = new OpenStack\OpenStack([]); - $computBack = $tmp->getBackup("Compute"); + $identityBack = $tmp->getBackup("Identity"); //file_put_contents("token", serialize($tmp)); ?> -- cgit v1.2.3 From e11520996ae8a487ca46b00865ffcce4385f1efb Mon Sep 17 00:00:00 2001 From: Eole Date: Sun, 31 Jan 2016 16:19:13 +0100 Subject: Tests Class genTokenOptions --- server/Test/genTokenOptionsTest.php | 86 +++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100755 server/Test/genTokenOptionsTest.php (limited to 'server') diff --git a/server/Test/genTokenOptionsTest.php b/server/Test/genTokenOptionsTest.php new file mode 100755 index 0000000..54c22d2 --- /dev/null +++ b/server/Test/genTokenOptionsTest.php @@ -0,0 +1,86 @@ + Array( + "name" => $user, + "password" => $password, + "domain" => Array( + "name" => "Default") + ), + "scope" => Array( + "project" => Array( + "name" => $project, + "domain" => Array( + "name" => "Default") + ) + ), + "authUrl" => $config["urlAuth"] + ); + + $genOptions = new genTokenOptions($Args); + $genOptions->genIdentityToken(); + $genOptions->genComputeToken(); + $genOptions->genNetworkToken(); + $genOptions->genImageToken(); + + $backCompute = $genOptions->getBackup("Compute"); + $backIdentity = $genOptions->getBackup("Identity"); + $backNetwork = $genOptions->getBackup("Network"); + $backImage = $genOptions->getBackup("Image"); + + $openstack_api = new OpenStack\OpenStack([]); + + $newGenOptions = new genTokenOptions($Args); + $newGenOptions->loadIdentityBackup($backIdentity); + $newGenOptions->loadComputeBackup($backCompute); + $newGenOptions->loadImageBackup($backImage); + $newGenOptions->loadNetworkBackup($backNetwork); + + $optionsCompute = $newGenOptions->getOptions("Compute"); + $optionsIdentity = $newGenOptions->getOptions("Identity"); + $optionsNetwork = $newGenOptions->getOptions("Network"); + $optionsImage = $newGenOptions->getOptions("Image"); + + $identityTest = $openstack_api->identityV3($optionsIdentity); + $computeTest = $openstack_api->computeV2($optionsCompute); + $networkTest = $openstack_api->networkingV2($optionsNetwork); + $imageTest = $openstack_api->imagesV2($optionsImage); + + $domainsTest = $identityTest->listDomains(); + echo "Identity Test, List Domains
"; + foreach($domainsTest as $domain){ + echo $domain->id; + echo "
"; + } + echo "
"; + + $imagesTest = $imageTest->listImages(); + echo "Image Test, List Images
"; + foreach($imagesTest as $image){ + echo $image->id; + echo "
"; + } + echo "
"; + $serversTest = $computeTest->listServers(); + echo "Compute Test, List Servers
"; + foreach($serversTest as $server){ + echo $server->id; + echo "
"; + } + echo "
"; + $networkTest = $networkTest->listNetworks(); + echo "Network Test, List networks
"; + foreach($networkTest as $network){ + echo $network->id; + echo "
"; + } + +?> \ No newline at end of file -- cgit v1.2.3 From 33463352403037ad03877f18bc3bdd17a7478d3c Mon Sep 17 00:00:00 2001 From: Eole Date: Sun, 31 Jan 2016 17:53:27 +0100 Subject: Debug TokenGen --- server/core/LibOverride/genTokenOptions.php | 69 ++++++++++++++++++----------- 1 file changed, 43 insertions(+), 26 deletions(-) (limited to 'server') diff --git a/server/core/LibOverride/genTokenOptions.php b/server/core/LibOverride/genTokenOptions.php index 9cb4100..81ecfc8 100755 --- a/server/core/LibOverride/genTokenOptions.php +++ b/server/core/LibOverride/genTokenOptions.php @@ -33,7 +33,7 @@ class genTokenOptions $options['authHandler'] = function () use ($options) { return $options['identityService']->generateToken($options); }; - + $this->optionsGlobal['Common'] = $options; } @@ -60,13 +60,15 @@ class genTokenOptions $baseUrl = $options["authUrl"]; $token = $options['identityService']->generateToken($options); - $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); + $stack = HandlerStack::create(); + + $stack->push(Middleware::authHandler($options['authHandler'], $token)); - $this->addDebugMiddleware($options, $this->stack); + $this->addDebugMiddleware($options, $stack); $options['httpClient'] = new Client([ 'base_uri' => Utils::normalizeUrl($baseUrl), - 'handler' => $this->stack, + 'handler' => $stack, ]); $this->backup['Identity'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); @@ -82,17 +84,20 @@ class genTokenOptions $this->backup['Identity'] = unserialize($opt); $token = $this->unserializeToken($this->backup['Identity']['token']); $baseUrl = $this->backup['Identity']['baseUrl']; - - $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); - $this->addDebugMiddleware($options, $this->stack); + $stack = HandlerStack::create(); + + $stack->push(Middleware::authHandler($options['authHandler'], $token)); + + $this->addDebugMiddleware($options, $stack); $options['httpClient'] = new Client([ 'base_uri' => Utils::normalizeUrl($baseUrl), - 'handler' => $this->stack, + 'handler' => $stack, ]); $this->backup['Identity'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); $this->optionsGlobal['Identity'] = $options; + } public function genImageToken(){ @@ -103,13 +108,15 @@ class genTokenOptions list($token, $baseUrl) = $options['identityService']->authenticate($options); - $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); + $stack = HandlerStack::create(); - $this->addDebugMiddleware($options, $this->stack); + $stack->push(Middleware::authHandler($options['authHandler'], $token)); + + $this->addDebugMiddleware($options, $stack); $options['httpClient'] = new Client([ 'base_uri' => Utils::normalizeUrl($baseUrl), - 'handler' => $this->stack, + 'handler' => $stack, ]); $this->backup['Image'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); @@ -126,13 +133,15 @@ class genTokenOptions $token = $this->unserializeToken($this->backup['Image']['token']); $baseUrl = $this->backup['Image']['baseUrl']; - $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); + $stack = HandlerStack::create(); - $this->addDebugMiddleware($options, $this->stack); + $stack->push(Middleware::authHandler($options['authHandler'], $token)); + + $this->addDebugMiddleware($options, $stack); $options['httpClient'] = new Client([ 'base_uri' => Utils::normalizeUrl($baseUrl), - 'handler' => $this->stack, + 'handler' => $stack, ]); $this->backup['Image'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); $this->optionsGlobal['Image'] = $options; @@ -146,13 +155,15 @@ class genTokenOptions list($token, $baseUrl) = $options['identityService']->authenticate($options); - $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); + $stack = HandlerStack::create(); + + $stack->push(Middleware::authHandler($options['authHandler'], $token)); - $this->addDebugMiddleware($options, $this->stack); + $this->addDebugMiddleware($options, $stack); $options['httpClient'] = new Client([ 'base_uri' => Utils::normalizeUrl($baseUrl), - 'handler' => $this->stack, + 'handler' => $stack, ]); $this->backup['Network'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); @@ -169,13 +180,15 @@ class genTokenOptions $token = $this->unserializeToken($this->backup['Network']['token']); $baseUrl = $this->backup['Network']['baseUrl']; - $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); + $stack = HandlerStack::create(); + + $stack->push(Middleware::authHandler($options['authHandler'], $token)); - $this->addDebugMiddleware($options, $this->stack); + $this->addDebugMiddleware($options, $stack); $options['httpClient'] = new Client([ 'base_uri' => Utils::normalizeUrl($baseUrl), - 'handler' => $this->stack, + 'handler' => $stack, ]); $this->backup['Network'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); $this->optionsGlobal['Network'] = $options; @@ -189,13 +202,15 @@ class genTokenOptions list($token, $baseUrl) = $options['identityService']->authenticate($options); - $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); + $stack = HandlerStack::create(); + + $stack->push(Middleware::authHandler($options['authHandler'], $token)); - $this->addDebugMiddleware($options, $this->stack); + $this->addDebugMiddleware($options, $stack); $options['httpClient'] = new Client([ 'base_uri' => Utils::normalizeUrl($baseUrl), - 'handler' => $this->stack, + 'handler' => $stack, ]); $this->backup['Compute'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); @@ -213,13 +228,15 @@ class genTokenOptions $token = $this->unserializeToken($this->backup['Compute']['token']); $baseUrl = $this->backup['Compute']['baseUrl']; - $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); + $stack = HandlerStack::create(); + + $stack->push(Middleware::authHandler($options['authHandler'], $token)); - $this->addDebugMiddleware($options, $this->stack); + $this->addDebugMiddleware($options, $stack); $options['httpClient'] = new Client([ 'base_uri' => Utils::normalizeUrl($baseUrl), - 'handler' => $this->stack, + 'handler' => $stack, ]); $this->backup['Compute'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); $this->optionsGlobal['Compute'] = $options; -- cgit v1.2.3 From b39f5c1cd4631be3259b272e1f6cbe9b4915410b Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Thu, 4 Feb 2016 23:48:43 +0100 Subject: Ajout des fonctionnalités de base des images, sans gestion la d'erreurs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/core/Image.php | 195 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 194 insertions(+), 1 deletion(-) (limited to 'server') diff --git a/server/core/Image.php b/server/core/Image.php index 8d1c8b6..d345034 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -1 +1,194 @@ - +oidentity = $ostack->imagesV2($options); + //$this->plugins = $apiP; + } + + + /** + * Details about an image + * + * @param array $opt + * options for the image creation + * + **/ + public function create_image(array $opt){ + // VOIR SI MAUVAIS TYPE + $options = Array(); + if(isset($opt['name'])){ // string, rendre le nom obligatoire + $options['name'] = $opt['name']; + } + if(isset($opt['id'])){ // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn + $options['id'] = $opt['id']; + } + if(isset($opt['visibility'])){ // public, private + $options['visibility'] = $opt['visibility']; + } + if(isset($opt['tags'])){ // list + $options['tags'] = $opt['tags']; + } + if(isset($opt['containerFormat'])){ // string : ami, ari, aki, bare, ovf, ova, docker + $options['containerFormat'] = $opt['containerFormat']; + } + if(isset($opt['diskFormat'])){ // string : ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, iso + $options['diskFormat'] = $opt['diskFormat']; + } + if(isset($opt['minDisk'])){ //int + $options['minDisk'] = $opt['minDisk']; + } + if(isset($opt['minRam'])){ // int + $options['minRam'] = $opt['minRam']; + } + if(isset($opt['protected'])){ // boolean + $options['protected'] = $opt['protected']; + } + if(isset($opt['properties'])){ // type dict ? + $options['properties'] = $opt['properties']; + } + + $image = $this->oidentity->createImage($options); + + return $image; + } + + /* + * List images + */ + public function list_images(){ + $service = $this->oidentity; + $images = $service->listImages(); + return $images; + } + + /** + * Details about an image + * + * @param string $id + * identifier of the image + * + **/ + public function image_details($id){ + $service = $this->oidentity; + $image = $service->getImage($id); + return $image; + } + + /** + * Details about an image + * + * @param string $id + * id of the image + * + * @param array $opt + * options for the image creation + **/ + public function update_image($id, array $opt){ + $service = $this->oidentity; + $image = $service->getImage($id); + $options = Array(); + + // Voir vérification des types + if(isset($opt['name'])){ //string + $options['name'] = $opt['name']; + } + if(isset($opt['minDisk'])){ //int + $options['minDisk'] = $opt['minDisk']; + } + if(isset($opt['minRam'])){ // int + $options['minRam'] = $opt['minRam']; + } + if(isset($opt['protected'])){ // boolean + $options['protected'] = $opt['protected']; + } + if(isset($opt['visibility'])){ // public, private + $options['visibility'] = $opt['visibility']; + } + if(isset($opt['tags'])){ // list + $options['tags'] = $opt['tags']; + } + $image->update($options); + + return $image; + } + + /** + * Delete an image + * + * @param string $id + * identifier of the image + **/ + public function delete_image($id){ + $service = $this->oidentity; + $service->getImage($id)->delete(); + } + + /** + * Resactive an image + * + * @param string $id + * identifier of the image + **/ + public function reactivate_image($id){ + $service = $this->oidentity; + $image = $service->getImage($id); + $image->reactivate(); + } + + /** + * Desactive an image + * + * @param string $id + * identifier of the image + **/ + public function desactivate_image($id){ + $service = $this->oidentity; + $image = $service->getImage($id); + $image->deactivate(); + } + + /** + * Upload an image + * + * @param string $id + * identifier of the image + * + * @param string $file_name + * path of the image + **/ + public function upload_image($id, $file_name){ + $service = $this->oidentity; + $image = $service->getImage($id); + $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR + $image->uploadData($stream); + } + + /** + * Download an image + * + * @param string $id + * identifier of the image + */ + public function download_image($id){ + $service = $this->oidentity; + $image = $service->getImage($id); + $stream = $image->downloadData(); + return $stream; + } +} +?> -- cgit v1.2.3