istic-openstack/server/core/LibOverride/genTokenOptions.php

583 lines
18 KiB
PHP
Raw Normal View History

<?php
2016-04-27 14:22:59 +02:00
/**
* File containing the override of the authentication for the Library.
*
* @version 1.0 Initialisation of this file
* @since 1.0 Core application's file
*
* @author Eole 'eoledev at outlook . fr'
*
* @todo Check with the API, the condition and test the revoke token implementation
*/
2016-01-31 02:38:05 +01:00
use GuzzleHttp\Client;
2016-03-09 15:21:46 +01:00
use OpenCloud\Common\Transport\HandlerStack;
use OpenCloud\Common\Transport\Middleware;
2016-01-31 02:38:05 +01:00
use OpenStack\Identity\v3\Service;
2016-01-31 11:54:53 +01:00
use OpenStack\Identity\v3\Api;
2016-03-09 15:21:46 +01:00
use OpenCloud\Common\Auth\Token;
use OpenCloud\Common\Transport\Utils;
2016-01-31 11:54:53 +01:00
use OpenStack\Identity\v3\Models;
2016-01-31 02:38:05 +01:00
2016-04-27 14:22:59 +02:00
/**
* genTokenOptions Class
*
* This class allow the generation of tokens for openstack, and to inject
* those tokens into the library. Which allow to do a proper login only once
* and not for each request
*
*/
class genTokenOptions
{
2016-04-27 14:22:59 +02:00
/** @var Array $optionsGlobal private, contains the options common for the different tokens */
2016-01-31 02:38:05 +01:00
private $optionsGlobal;
2016-04-27 14:22:59 +02:00
/** @var Array $backup private, contains all the informations about the different tokens. It contains the information send to the clients */
2016-01-31 04:00:20 +01:00
private $backup = [];
2016-04-27 14:22:59 +02:00
/** @var GuzzleHttp\Client $httpClient private, contains a default Client to construct some OpenStack library object */
2016-01-31 11:54:53 +01:00
private $httpClient;
2016-05-05 19:16:10 +02:00
private $directory = __DIR__;
2016-04-27 14:22:59 +02:00
/**
* genTokenOptions constructor
*
* @param Array $options Options to create the objects in the library
* AuthUrl is the main options required
*
* @return genTokenOptions Object
*/
2016-01-31 03:24:02 +01:00
public function __construct($options){
2016-04-27 14:22:59 +02:00
$stack = HandlerStack::create();
2016-01-31 02:38:05 +01:00
2016-01-31 04:00:20 +01:00
$httpClient = new Client([
2016-04-26 20:42:31 +02:00
'base_uri' => Utils::normalizeUrl($options['authUrl']),
2016-04-27 14:22:59 +02:00
'handler' => $stack,
2016-04-26 20:42:31 +02:00
]);
2016-01-31 02:38:05 +01:00
2016-01-31 11:54:53 +01:00
$this->httpClient = $httpClient;
2016-04-26 20:42:31 +02:00
$options['identityService'] = Service::factory($httpClient);
2016-01-31 03:24:02 +01:00
2016-01-31 02:38:05 +01:00
$options['authHandler'] = function () use ($options) {
return $options['identityService']->generateToken($options);
2016-04-26 20:42:31 +02:00
};
2016-01-31 17:53:27 +01:00
2016-01-31 03:24:02 +01:00
$this->optionsGlobal['Common'] = $options;
}
2016-04-26 20:42:31 +02:00
/**
2016-04-27 14:22:59 +02:00
* Add a debug for the library
*
* @param array $options Debug options, cf library
* @param HandlerStack $stack pointer to a HandlerStack object
*
* @return void
*/
2016-04-26 20:42:31 +02:00
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']));
}
}
2016-03-19 12:49:07 +01:00
2016-04-27 14:22:59 +02:00
/**
* Check the expiration time of a token
*
* @return boolean if the token is not expired
*/
2016-03-19 12:49:07 +01:00
public function checkToken(){
2016-03-30 12:40:30 +02:00
return $this->backup['time'] > time();
2016-03-19 12:49:07 +01:00
}
2016-01-31 02:38:05 +01:00
2016-04-27 14:22:59 +02:00
/**
* Generate a new token for the Identity service
*
* @return void
*/
2016-01-31 14:24:30 +01:00
public function genIdentityToken(){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'false';
$options['catalogType'] = 'false';
$options['region'] = 'RegionOne';
2016-01-31 14:34:43 +01:00
//list($token, $baseUrl) = $options['identityService']->authenticate($options);
$baseUrl = $options["authUrl"];
$token = $options['identityService']->generateToken($options);
2016-01-31 17:53:27 +01:00
$stack = HandlerStack::create();
$stack->push(Middleware::authHandler($options['authHandler'], $token));
2016-01-31 14:24:30 +01:00
2016-01-31 17:53:27 +01:00
$this->addDebugMiddleware($options, $stack);
2016-01-31 14:24:30 +01:00
$options['httpClient'] = new Client([
2016-04-26 20:42:31 +02:00
'base_uri' => Utils::normalizeUrl($baseUrl),
'handler' => $stack,
]);
2016-02-17 16:53:06 +01:00
$this->saveBackup('Identity', array('token' => $token, 'baseUrl' => $baseUrl ));
2016-01-31 14:24:30 +01:00
$this->optionsGlobal['Identity'] = $options;
}
2016-04-27 14:22:59 +02:00
/**
* Revoke the token for the Identity Service
*
* @return void
*/
2016-03-09 14:53:48 +01:00
public function revokeIdentityToken(){
$token = $this->unserializeToken($this->backup['Identity']['token']);
$this->optionsGlobal['Common']['identityService']->revokeToken($token->id);
}
2016-04-27 14:22:59 +02:00
/**
* Load a token for the Identity Service
*
* @param String $opt serialized token
*
* @return void
*/
2016-01-31 14:24:30 +01:00
public function loadIdentityBackup($opt){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'false';
$options['catalogType'] = 'false';
$options['region'] = 'RegionOne';
$this->backup['Identity'] = $opt;
2016-01-31 14:24:30 +01:00
$token = $this->unserializeToken($this->backup['Identity']['token']);
$baseUrl = $this->backup['Identity']['baseUrl'];
2016-01-31 17:53:27 +01:00
$stack = HandlerStack::create();
2016-04-26 20:42:31 +02:00
2016-01-31 17:53:27 +01:00
$stack->push(Middleware::authHandler($options['authHandler'], $token));
$this->addDebugMiddleware($options, $stack);
2016-01-31 14:24:30 +01:00
$options['httpClient'] = new Client([
2016-04-26 20:42:31 +02:00
'base_uri' => Utils::normalizeUrl($baseUrl),
'handler' => $stack,
]);
2016-02-17 16:53:06 +01:00
$this->saveBackup('Identity', array('token' => $token, 'baseUrl' => $baseUrl ));
2016-01-31 14:24:30 +01:00
$this->optionsGlobal['Identity'] = $options;
2016-01-31 17:53:27 +01:00
2016-01-31 14:24:30 +01:00
}
2016-04-27 14:22:59 +02:00
/**
* Generate a new token for the Image service
*
* @return void
*/
2016-01-31 14:24:30 +01:00
public function genImageToken(){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'glance';
$options['catalogType'] = 'image';
$options['region'] = 'RegionOne';
list($token, $baseUrl) = $options['identityService']->authenticate($options);
2016-01-31 17:53:27 +01:00
$stack = HandlerStack::create();
2016-01-31 14:24:30 +01:00
2016-04-26 20:42:31 +02:00
$stack->push(Middleware::authHandler($options['authHandler'], $token));
2016-01-31 17:53:27 +01:00
$this->addDebugMiddleware($options, $stack);
2016-01-31 14:24:30 +01:00
$options['httpClient'] = new Client([
2016-04-26 20:42:31 +02:00
'base_uri' => Utils::normalizeUrl($baseUrl),
'handler' => $stack,
]);
2016-02-17 16:53:06 +01:00
$this->saveBackup('Image', array('token' => $token, 'baseUrl' => $baseUrl ));
2016-01-31 14:24:30 +01:00
$this->optionsGlobal['Image'] = $options;
}
2016-04-27 14:22:59 +02:00
/**
* Revoke the token for the Image Service
*
* @return void
*/
2016-03-09 14:53:48 +01:00
public function revokeImageToken(){
$token = $this->unserializeToken($this->backup['Image']['token']);
$this->optionsGlobal['Common']['identityService']->revokeToken($token->id);
}
2016-04-27 14:22:59 +02:00
/**
* Load a token for the Image Service
*
* @param String $opt serialized token
*
* @return void
*/
2016-01-31 14:24:30 +01:00
public function loadImageBackup($opt){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'glance';
$options['catalogType'] = 'image';
$options['region'] = 'RegionOne';
$this->backup['Image'] = $opt;
2016-01-31 14:24:30 +01:00
$token = $this->unserializeToken($this->backup['Image']['token']);
$baseUrl = $this->backup['Image']['baseUrl'];
2016-04-26 20:42:31 +02:00
2016-01-31 17:53:27 +01:00
$stack = HandlerStack::create();
2016-01-31 14:24:30 +01:00
2016-01-31 17:53:27 +01:00
$stack->push(Middleware::authHandler($options['authHandler'], $token));
$this->addDebugMiddleware($options, $stack);
2016-01-31 14:24:30 +01:00
$options['httpClient'] = new Client([
2016-04-26 20:42:31 +02:00
'base_uri' => Utils::normalizeUrl($baseUrl),
'handler' => $stack,
]);
2016-02-17 16:53:06 +01:00
$this->saveBackup('Image', array('token' => $token, 'baseUrl' => $baseUrl ));
2016-01-31 14:24:30 +01:00
$this->optionsGlobal['Image'] = $options;
}
2016-04-27 14:22:59 +02:00
/**
* Generate a new token for the Metwork service
*
* @return void
*/
2016-01-31 14:24:30 +01:00
public function genNetworkToken(){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'neutron';
$options['catalogType'] = 'network';
$options['region'] = 'RegionOne';
list($token, $baseUrl) = $options['identityService']->authenticate($options);
2016-01-31 17:53:27 +01:00
$stack = HandlerStack::create();
2016-04-26 20:42:31 +02:00
$stack->push(Middleware::authHandler($options['authHandler'], $token));
2016-01-31 14:24:30 +01:00
2016-01-31 17:53:27 +01:00
$this->addDebugMiddleware($options, $stack);
2016-01-31 14:24:30 +01:00
$options['httpClient'] = new Client([
2016-04-26 20:42:31 +02:00
'base_uri' => Utils::normalizeUrl($baseUrl),
'handler' => $stack,
]);
2016-02-17 16:53:06 +01:00
$this->saveBackup('Network', array('token' => $token, 'baseUrl' => $baseUrl ));
2016-01-31 14:24:30 +01:00
$this->optionsGlobal['Network'] = $options;
}
2016-04-27 14:22:59 +02:00
/**
* Revoke the token for the Network Service
*
* @return void
*/
2016-03-09 14:53:48 +01:00
public function revokeNetworkToken(){
$token = $this->unserializeToken($this->backup['Network']['token']);
$this->optionsGlobal['Common']['identityService']->revokeToken($token->id);
}
2016-04-27 14:22:59 +02:00
/**
* Load a token for the Network Service
*
* @param String $opt serialized token
*
* @return void
*/
2016-01-31 14:24:30 +01:00
public function loadNetworkBackup($opt){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'neutron';
$options['catalogType'] = 'network';
$options['region'] = 'RegionOne';
$this->backup['Network'] = $opt;
2016-01-31 14:24:30 +01:00
$token = $this->unserializeToken($this->backup['Network']['token']);
$baseUrl = $this->backup['Network']['baseUrl'];
2016-04-26 20:42:31 +02:00
2016-01-31 17:53:27 +01:00
$stack = HandlerStack::create();
2016-04-26 20:42:31 +02:00
2016-01-31 17:53:27 +01:00
$stack->push(Middleware::authHandler($options['authHandler'], $token));
2016-01-31 14:24:30 +01:00
2016-01-31 17:53:27 +01:00
$this->addDebugMiddleware($options, $stack);
2016-01-31 14:24:30 +01:00
$options['httpClient'] = new Client([
2016-04-26 20:42:31 +02:00
'base_uri' => Utils::normalizeUrl($baseUrl),
'handler' => $stack,
]);
2016-02-17 16:53:06 +01:00
$this->saveBackup('Network', array('token' => $token, 'baseUrl' => $baseUrl ));
2016-01-31 14:24:30 +01:00
$this->optionsGlobal['Network'] = $options;
}
2016-04-27 14:22:59 +02:00
/**
* Generate a new token for the Compute service
*
* @return void
*/
2016-01-31 04:00:20 +01:00
public function genComputeToken(){
2016-01-31 03:24:02 +01:00
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'nova';
$options['catalogType'] = 'compute';
$options['region'] = 'RegionOne';
list($token, $baseUrl) = $options['identityService']->authenticate($options);
2016-01-31 12:22:51 +01:00
2016-01-31 17:53:27 +01:00
$stack = HandlerStack::create();
2016-04-26 20:42:31 +02:00
$stack->push(Middleware::authHandler($options['authHandler'], $token));
2016-01-31 03:24:02 +01:00
2016-01-31 17:53:27 +01:00
$this->addDebugMiddleware($options, $stack);
2016-01-31 03:24:02 +01:00
$options['httpClient'] = new Client([
2016-04-26 20:42:31 +02:00
'base_uri' => Utils::normalizeUrl($baseUrl),
'handler' => $stack,
]);
2016-02-17 16:53:06 +01:00
$this->saveBackup('Compute', array('token' => $token, 'baseUrl' => $baseUrl ));
2016-01-31 11:54:53 +01:00
2016-01-31 04:00:20 +01:00
$this->optionsGlobal['Compute'] = $options;
}
2016-04-27 14:22:59 +02:00
/**
* Revoke the token for the Compute Service
*
* @return void
*/
2016-03-09 14:53:48 +01:00
public function revokeComputeToken(){
$token = $this->unserializeToken($this->backup['Compute']['token']);
$this->optionsGlobal['Common']['identityService']->revokeToken($token->id);
}
2016-04-27 14:22:59 +02:00
/**
* Load a token for the Compute Service
*
* @param String $opt serialized token
*
* @return void
*/
2016-01-31 04:00:20 +01:00
public function loadComputeBackup($opt){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'nova';
$options['catalogType'] = 'compute';
$options['region'] = 'RegionOne';
2016-01-31 03:24:02 +01:00
$this->backup['Compute'] = $opt;
2016-01-31 11:54:53 +01:00
$token = $this->unserializeToken($this->backup['Compute']['token']);
2016-01-31 04:00:20 +01:00
$baseUrl = $this->backup['Compute']['baseUrl'];
2016-04-26 20:42:31 +02:00
2016-01-31 17:53:27 +01:00
$stack = HandlerStack::create();
2016-04-26 20:42:31 +02:00
2016-01-31 17:53:27 +01:00
$stack->push(Middleware::authHandler($options['authHandler'], $token));
2016-01-31 04:00:20 +01:00
2016-01-31 17:53:27 +01:00
$this->addDebugMiddleware($options, $stack);
2016-01-31 04:00:20 +01:00
$options['httpClient'] = new Client([
2016-04-26 20:42:31 +02:00
'base_uri' => Utils::normalizeUrl($baseUrl),
'handler' => $stack,
]);
2016-02-17 16:53:06 +01:00
$this->saveBackup('Compute', array('token' => $token, 'baseUrl' => $baseUrl ));
2016-01-31 03:24:02 +01:00
$this->optionsGlobal['Compute'] = $options;
}
2016-01-31 04:00:20 +01:00
2016-04-27 14:22:59 +02:00
/**
* Save the token given a service name
*
* @param String $name name of the service to save
* @param Array $data token and baseUrl for the service
*
* @return void
*/
2016-02-17 16:53:06 +01:00
private function saveBackup($name, $data){
$token = $this->serializeToken($data["token"]);
2016-05-05 19:16:10 +02:00
$ret = file_put_contents($this->directory."/projectTokenData/".$token['saved']["project"]["name"], serialize($token['saved']));
2016-04-27 15:51:38 +02:00
if($ret === FALSE)
die("Internal Server Error : File Rights");
2016-03-19 12:49:07 +01:00
$this->backup['time'] = $token['time'];
2016-02-17 16:53:06 +01:00
$this->backup["roles"] = $token["roles"];
$this->backup["project"] = $token['saved']["project"]["name"];
$this->backup["user"] = $token["user"];
$this->backup[$name] = array('token' => $token["token"], 'baseUrl' => $data["baseUrl"] );
}
2016-04-27 14:22:59 +02:00
/**
* Retrieve the tokens saved
*
* @return String tokens serialized
*/
public function getBackup(){
return serialize($this->backup);
}
2016-04-27 14:22:59 +02:00
/**
* Load tokens into the library
*
* @param String $back tokens serialized
*
* @return void
*/
public function loadBackup($back){
$backup = unserialize($back);
2016-03-19 12:49:07 +01:00
$this->backup['time'] = $backup['time'];
2016-02-17 16:53:06 +01:00
$this->backup["roles"] = $backup["roles"];
$this->backup["project"] = $backup["project"];
$this->backup["user"] = $backup["user"];
2016-02-28 20:44:17 +01:00
$this->loadComputeBackup($backup["Compute"]);
$this->loadIdentityBackup($backup["Identity"]);
$this->loadImageBackup($backup["Image"]);
$this->loadNetworkBackup($backup["Network"]);
2016-01-31 04:00:20 +01:00
}
2016-01-31 03:24:02 +01:00
2016-04-27 14:22:59 +02:00
/**
* Retrieve the common options for a service
*
* @param String $service name of the service
*
* @return array Options to create the library class corresponding to this service
*/
2016-01-31 14:34:43 +01:00
public function getOptions($service){
return $this->optionsGlobal[$service];
2016-01-31 02:38:05 +01:00
}
2016-01-31 11:54:53 +01:00
2016-04-27 14:22:59 +02:00
/**
* Serialize a given token
*
* @param Array $token token to be serialized
*
* @return String token serialized
*/
2016-01-31 11:54:53 +01:00
private function serializeToken($token){
2016-03-23 15:13:42 +01:00
global $config;
2016-01-31 11:54:53 +01:00
$tokenSerialized = [];
2016-02-17 16:53:06 +01:00
$tokenSerialized["token"]["methods"] = serialize($token->methods);
2016-01-31 11:54:53 +01:00
$tokenSerialized["roles"] = [];
2016-04-14 16:26:09 +02:00
2016-01-31 11:54:53 +01:00
foreach($token->roles as $role){
2016-04-14 16:26:09 +02:00
$tokenSerialized["roles"][$role->id]["links"] = serialize($role->links);
$tokenSerialized["roles"][$role->id]["name"] = serialize($role->name);
2016-01-31 12:16:31 +01:00
}
2016-02-17 16:53:06 +01:00
$tokenSerialized["token"]["expires"] = serialize($token->expires);
$tokenSerialized['saved']["project"]["domainId"] = serialize($token->project->domainId);
$tokenSerialized['saved']["project"]["parentId"] = serialize($token->project->parentId);
$tokenSerialized['saved']["project"]["enabled"] = serialize($token->project->enabled);
$tokenSerialized['saved']["project"]["description"] = serialize($token->project->description);
$tokenSerialized['saved']["project"]["id"] = serialize($token->project->id);
$tokenSerialized['saved']["project"]["links"] = serialize($token->project->links);
$tokenSerialized['saved']["project"]["name"] = $token->project->name;
2016-01-31 12:16:31 +01:00
2016-04-14 16:26:09 +02:00
$tokenSerialized['saved']["catalog"] = array();
2016-01-31 11:54:53 +01:00
foreach($token->catalog->services as $service){
2016-04-14 16:26:09 +02:00
$tokenSerialized['saved']["catalog"][$service->id]["name"] = serialize($service->name);
$tokenSerialized['saved']["catalog"][$service->id]["description"] = serialize($service->description);
$tokenSerialized['saved']["catalog"][$service->id]["type"] = serialize($service->type);
2016-01-31 11:54:53 +01:00
foreach($service->endpoints as $end){
2016-04-14 16:26:09 +02:00
$tokenSerialized['saved']["catalog"][$service->id]["endpoints"][$end->id]["interface"] = serialize($end->interface);
$tokenSerialized['saved']["catalog"][$service->id]["endpoints"][$end->id]["name"] = serialize($end->name);
$tokenSerialized['saved']["catalog"][$service->id]["endpoints"][$end->id]["serviceId"] = serialize($end->serviceId);
$tokenSerialized['saved']["catalog"][$service->id]["endpoints"][$end->id]["region"] = serialize($end->region);
$tokenSerialized['saved']["catalog"][$service->id]["endpoints"][$end->id]["links"] = serialize($end->links);
$tokenSerialized['saved']["catalog"][$service->id]["endpoints"][$end->id]["url"] = serialize($end->url);
2016-01-31 11:54:53 +01:00
}
2016-04-14 16:26:09 +02:00
$tokenSerialized['saved']["catalog"][$service->id]["links"] = serialize($service->links);
2016-01-31 11:54:53 +01:00
}
2016-02-17 16:53:06 +01:00
$tokenSerialized["token"]["extras"] = serialize($token->extras);
2016-01-31 11:54:53 +01:00
$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);
2016-02-17 16:53:06 +01:00
$tokenSerialized["token"]["issued"] = serialize($token->issued);
$tokenSerialized["token"]["id"] = serialize($token->id);
2016-03-19 12:49:07 +01:00
$tokenSerialized['time'] = time()+$config['tokenTime']*60;
2016-01-31 11:54:53 +01:00
return $tokenSerialized;
}
2016-04-27 14:22:59 +02:00
/**
* Unserialize a token
*
* Unserialize a token and recreate the architecture of the library token
*
* @param String $tokenSerialized the token to be unserialized
*
* @return OpenCloud\Common\Auth\Token the token unserialized
*/
2016-01-31 11:54:53 +01:00
private function unserializeToken($tokenSerialized){
2016-05-05 19:16:10 +02:00
$Saved = file_get_contents($this->directory."/projectTokenData/".$this->backup["project"]);
2016-04-27 15:51:38 +02:00
if($Saved === FALSE)
die("Internal Server Error : File Access");
2016-02-28 22:54:51 +01:00
$Saved = unserialize($Saved);
2016-04-14 16:26:09 +02:00
2016-01-31 11:54:53 +01:00
$api = new Api();
$token = new Models\Token($this->httpClient, $api);
$token->methods = unserialize($tokenSerialized["methods"]);
$token->roles = [];
2016-04-14 16:26:09 +02:00
2016-02-17 16:53:06 +01:00
foreach($this->backup["roles"] as $key => $role){
2016-01-31 11:54:53 +01:00
$tmp = new Models\Role($this->httpClient, $api);
2016-04-14 16:26:09 +02:00
$tmp->id = $key;
2016-01-31 11:54:53 +01:00
$tmp->links = unserialize($role["links"]);
2016-02-17 16:53:06 +01:00
$tmp->name = unserialize($role["name"]);
2016-01-31 11:54:53 +01:00
2016-01-31 12:54:37 +01:00
$token->roles[] = $tmp;
2016-01-31 11:54:53 +01:00
}
$token->expires = unserialize($tokenSerialized["expires"]);
$token->project = new Models\Project($this->httpClient, $api);
2016-02-17 16:53:06 +01:00
$token->project->domainId = unserialize($Saved["project"]["domainId"]);
$token->project->parentId = unserialize($Saved["project"]["parentId"]);
$token->project->enabled = unserialize($Saved["project"]["enabled"]);
$token->project->description = unserialize($Saved["project"]["description"]);
$token->project->id = unserialize($Saved["project"]["id"]);
$token->project->links = unserialize($Saved["project"]["links"]);
$token->project->name = $Saved["project"]["name"];
2016-01-31 11:54:53 +01:00
2016-01-31 12:16:31 +01:00
$token->catalog = new Models\Catalog($this->httpClient, $api);
$token->catalog->services = [];
2016-02-17 16:53:06 +01:00
foreach($Saved["catalog"] as $key => $service){
2016-01-31 11:54:53 +01:00
$tmp = new Models\Service($this->httpClient, $api);
2016-04-14 16:26:09 +02:00
$tmp->id = $key;
2016-01-31 11:54:53 +01:00
$tmp->name = unserialize($service["name"]);
$tmp->description = unserialize($service["description"]);
$tmp->type = unserialize($service["type"]);
$tmp->endpoints = [];
2016-04-14 16:26:09 +02:00
2016-01-31 11:54:53 +01:00
foreach($service["endpoints"] as $key => $end){
$tmpEnd = new Models\Endpoint($this->httpClient, $api);
2016-04-14 16:26:09 +02:00
$tmpEnd->id = $key;
2016-01-31 11:54:53 +01:00
$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;
}
2016-02-17 16:53:06 +01:00
$tmp->links = unserialize($service["links"]);
2016-01-31 12:16:31 +01:00
$token->catalog->services[] = $tmp;
2016-01-31 11:54:53 +01:00
}
$token->extras = unserialize($tokenSerialized["extras"]);
$token->user = new Models\User($this->httpClient, $api);
2016-02-17 16:53:06 +01:00
$token->user->domainId = unserialize($this->backup["user"]["domainId"]);
$token->user->defaultProjectId = unserialize($this->backup["user"]["defaultProjectId"]);
$token->user->id = unserialize($this->backup["user"]["id"]);
$token->user->email = unserialize($this->backup["user"]["email"]);
$token->user->enabled = unserialize($this->backup["user"]["enabled"]);
$token->user->links = unserialize($this->backup["user"]["links"]);
$token->user->name = unserialize($this->backup["user"]["name"]);
$token->user->description = unserialize($this->backup["user"]["description"]);
2016-01-31 11:54:53 +01:00
$token->issued = unserialize($tokenSerialized["issued"]);
$token->id = unserialize($tokenSerialized["id"]);
2016-04-26 20:42:31 +02:00
2016-01-31 11:54:53 +01:00
return $token;
}
}