From 1d42345e07b2ef557de3c5049864e6885632b9e9 Mon Sep 17 00:00:00 2001 From: EoleDev Date: Wed, 27 Apr 2016 14:22:59 +0200 Subject: End of comments --- server/core/LibOverride/genTokenOptions.php | 164 ++++++++++++++++++++++++++-- 1 file changed, 154 insertions(+), 10 deletions(-) (limited to 'server/core/LibOverride/genTokenOptions.php') diff --git a/server/core/LibOverride/genTokenOptions.php b/server/core/LibOverride/genTokenOptions.php index 68a7dbd..f0b3b88 100755 --- a/server/core/LibOverride/genTokenOptions.php +++ b/server/core/LibOverride/genTokenOptions.php @@ -1,4 +1,14 @@ stack = HandlerStack::create(); + $stack = HandlerStack::create(); $httpClient = new Client([ 'base_uri' => Utils::normalizeUrl($options['authUrl']), - 'handler' => $this->stack, + 'handler' => $stack, ]); $this->httpClient = $httpClient; @@ -38,8 +65,13 @@ class genTokenOptions } /** - * @codeCoverageIgnore - */ + * Add a debug for the library + * + * @param array $options Debug options, cf library + * @param HandlerStack $stack pointer to a HandlerStack object + * + * @return void + */ private function addDebugMiddleware(array $options, HandlerStack &$stack) { if (!empty($options['debugLog']) @@ -50,12 +82,20 @@ class genTokenOptions } } + /** + * Check the expiration time of a token + * + * @return boolean if the token is not expired + */ public function checkToken(){ - //error_log(print_r($this->backup['time'], true), 0); return $this->backup['time'] > time(); - //return true; } + /** + * Generate a new token for the Identity service + * + * @return void + */ public function genIdentityToken(){ $options = $this->optionsGlobal['Common']; $options['catalogName'] = 'false'; @@ -81,12 +121,24 @@ class genTokenOptions $this->optionsGlobal['Identity'] = $options; } + /** + * Revoke the token for the Identity Service + * + * @return void + */ public function revokeIdentityToken(){ $token = $this->unserializeToken($this->backup['Identity']['token']); $this->optionsGlobal['Common']['identityService']->revokeToken($token->id); } + /** + * Load a token for the Identity Service + * + * @param String $opt serialized token + * + * @return void + */ public function loadIdentityBackup($opt){ $options = $this->optionsGlobal['Common']; $options['catalogName'] = 'false'; @@ -112,6 +164,11 @@ class genTokenOptions } + /** + * Generate a new token for the Image service + * + * @return void + */ public function genImageToken(){ $options = $this->optionsGlobal['Common']; $options['catalogName'] = 'glance'; @@ -135,12 +192,24 @@ class genTokenOptions $this->optionsGlobal['Image'] = $options; } + /** + * Revoke the token for the Image Service + * + * @return void + */ public function revokeImageToken(){ $token = $this->unserializeToken($this->backup['Image']['token']); $this->optionsGlobal['Common']['identityService']->revokeToken($token->id); } + /** + * Load a token for the Image Service + * + * @param String $opt serialized token + * + * @return void + */ public function loadImageBackup($opt){ $options = $this->optionsGlobal['Common']; $options['catalogName'] = 'glance'; @@ -165,6 +234,11 @@ class genTokenOptions $this->optionsGlobal['Image'] = $options; } + /** + * Generate a new token for the Metwork service + * + * @return void + */ public function genNetworkToken(){ $options = $this->optionsGlobal['Common']; $options['catalogName'] = 'neutron'; @@ -188,12 +262,24 @@ class genTokenOptions $this->optionsGlobal['Network'] = $options; } + /** + * Revoke the token for the Network Service + * + * @return void + */ public function revokeNetworkToken(){ $token = $this->unserializeToken($this->backup['Network']['token']); $this->optionsGlobal['Common']['identityService']->revokeToken($token->id); } + /** + * Load a token for the Network Service + * + * @param String $opt serialized token + * + * @return void + */ public function loadNetworkBackup($opt){ $options = $this->optionsGlobal['Common']; $options['catalogName'] = 'neutron'; @@ -218,6 +304,11 @@ class genTokenOptions $this->optionsGlobal['Network'] = $options; } + /** + * Generate a new token for the Compute service + * + * @return void + */ public function genComputeToken(){ $options = $this->optionsGlobal['Common']; $options['catalogName'] = 'nova'; @@ -241,12 +332,24 @@ class genTokenOptions $this->optionsGlobal['Compute'] = $options; } + /** + * Revoke the token for the Compute Service + * + * @return void + */ public function revokeComputeToken(){ $token = $this->unserializeToken($this->backup['Compute']['token']); $this->optionsGlobal['Common']['identityService']->revokeToken($token->id); } + /** + * Load a token for the Compute Service + * + * @param String $opt serialized token + * + * @return void + */ public function loadComputeBackup($opt){ $options = $this->optionsGlobal['Common']; @@ -272,10 +375,16 @@ class genTokenOptions $this->optionsGlobal['Compute'] = $options; } + /** + * 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 + */ private function saveBackup($name, $data){ $token = $this->serializeToken($data["token"]); - //$path = "core/LibOverride/projectTokenData/".$token['saved']["project"]["name"]; - //error_log("Path a ecrire ".print_r($path, true), 0); file_put_contents("core/LibOverride/projectTokenData/".$token['saved']["project"]["name"], serialize($token['saved'])); $this->backup['time'] = $token['time']; $this->backup["roles"] = $token["roles"]; @@ -284,10 +393,22 @@ class genTokenOptions $this->backup[$name] = array('token' => $token["token"], 'baseUrl' => $data["baseUrl"] ); } + /** + * Retrieve the tokens saved + * + * @return String tokens serialized + */ public function getBackup(){ return serialize($this->backup); } + /** + * Load tokens into the library + * + * @param String $back tokens serialized + * + * @return void + */ public function loadBackup($back){ $backup = unserialize($back); @@ -302,10 +423,24 @@ class genTokenOptions } + /** + * 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 + */ public function getOptions($service){ return $this->optionsGlobal[$service]; } + /** + * Serialize a given token + * + * @param Array $token token to be serialized + * + * @return String token serialized + */ private function serializeToken($token){ global $config; $tokenSerialized = []; @@ -358,6 +493,15 @@ class genTokenOptions return $tokenSerialized; } + /** + * 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 + */ private function unserializeToken($tokenSerialized){ $Saved = file_get_contents("core/LibOverride/projectTokenData/".$this->backup["project"]); $Saved = unserialize($Saved); -- cgit v1.2.3