summaryrefslogtreecommitdiff
path: root/server/core/App.php
diff options
context:
space:
mode:
Diffstat (limited to 'server/core/App.php')
-rwxr-xr-xserver/core/App.php164
1 files changed, 128 insertions, 36 deletions
diff --git a/server/core/App.php b/server/core/App.php
index 114d945..3a027d7 100755
--- a/server/core/App.php
+++ b/server/core/App.php
@@ -1,21 +1,53 @@
<?php
+/**
+* File containing the identity Class.
+*
+* @version 1.0 Initialisation of this file
+* @since 1.0 Core application's file
+*
+* @author Eole 'eoledev at outlook . fr'
+*
+*/
+
+//Library token management override
include_once("core/LibOverride/genTokenOptions.php");
include_once("core/ErrorManagement.php");
+//Library loading
use OpenCloud\Common\Error\BadResponseError;
use OpenCloud\Common\Error\BaseError;
use OpenCloud\Common\Error\NotImplementedError;
use OpenCloud\Common\Error\UserInputError;
+/**
+* App Class of the back-end application
+*
+* This class allow the communication between the front-end application and
+* the library which allow to send requests to an Openstack instance.
+*
+*/
class App{
+ /** @var Openstack $openstack protected, contains the main library object */
protected $openstack;
+ /** @var Array $postParams protected, contains the post parameters */
protected $postParams;
+ /** @var genTokenOptions $tokenClass protected, contains the class object for the authentication override of the library */
protected $tokenClass;
+ /** @var String $tokenPost protected, contains the token given in parameter */
protected $tokenPost;
+ /** @var errorManagement $errorClass protected, contains the errorManagement object */
protected $errorClass;
+ /** @var Array $output protected, contains the result for the API call */
protected $output;
+ /**
+ * App constructor
+ *
+ * @param Array $args Args for the OpenStack Library
+ *
+ * @return App object
+ */
public function __construct($args){
$this->tokenPost = NULL;
@@ -27,6 +59,13 @@ class App{
}
+ /**
+ * Set the class var $tokenPost and load the token
+ * into the genTokenOptions Class
+ *
+ * @param String $token token to be set
+ *
+ */
public function setToken($token){
$this->tokenPost = $token;
@@ -34,42 +73,59 @@ class App{
}
+ /**
+ * Check the expiration of the token
+ *
+ * @return Boolean if the token is not expired
+ */
public function checkToken(){
return $this->tokenClass->checkToken();
}
+ /**
+ * Get the service Class given the name in parameter
+ *
+ * @param String $service Name of the service
+ *
+ * @return Core object
+ */
public function getLibClass($service){
switch($service){
- case "Identity":
- if($this->tokenPost == NULL) $this->tokenClass->genIdentityToken();
- $opt = $this->tokenClass->getOptions($service);
- return $this->openstack->identityV3($opt);
- break;
- case "Image":
- if($this->tokenPost == NULL) $this->tokenClass->genImageToken();
- $opt = $this->tokenClass->getOptions($service);
- return $this->openstack->imagesV2($opt);
- break;
- case "Network":
- if($this->tokenPost == NULL) $this->tokenClass->genNetworkToken();
- $opt = $this->tokenClass->getOptions($service);
- return $this->openstack->networkingV2($opt);
- break;
- case "Compute":
- if($this->tokenPost == NULL) $this->tokenClass->genComputeToken();
- $opt = $this->tokenClass->getOptions($service);
- return $this->openstack->computeV2($opt);
- break;
- case "NetworkLayer3":
- if($this->tokenPost == NULL) $this->tokenClass->genNetworkToken();
- $opt = $this->tokenClass->getOptions('Network');
- return $this->openstack->networkingV2ExtLayer3($opt);
- break;
+ case "Identity":
+ if($this->tokenPost == NULL) $this->tokenClass->genIdentityToken();
+ $opt = $this->tokenClass->getOptions($service);
+ return $this->openstack->identityV3($opt);
+ break;
+ case "Image":
+ if($this->tokenPost == NULL) $this->tokenClass->genImageToken();
+ $opt = $this->tokenClass->getOptions($service);
+ return $this->openstack->imagesV2($opt);
+ break;
+ case "Network":
+ if($this->tokenPost == NULL) $this->tokenClass->genNetworkToken();
+ $opt = $this->tokenClass->getOptions($service);
+ return $this->openstack->networkingV2($opt);
+ break;
+ case "Compute":
+ if($this->tokenPost == NULL) $this->tokenClass->genComputeToken();
+ $opt = $this->tokenClass->getOptions($service);
+ return $this->openstack->computeV2($opt);
+ break;
+ case "NetworkLayer3":
+ if($this->tokenPost == NULL) $this->tokenClass->genNetworkToken();
+ $opt = $this->tokenClass->getOptions('Network');
+ return $this->openstack->networkingV2ExtLayer3($opt);
+ break;
}
}
+ /**
+ * Generate the token for the different services in OpenStack
+ *
+ * @return NULL
+ */
public function authenticate(){
try{
@@ -81,16 +137,21 @@ class App{
$this->setOutput("token", $this->tokenClass->getBackup());
}catch(BadResponseError $e){
$this->errorClass->BadResponseHandler($e);
- }catch(UserInputError $e){
+ }catch(UserInputError $e){
$this->errorClass->UserInputHandler($e);
- }catch(BaseError $e){
+ }catch(BaseError $e){
$this->errorClass->BaseErrorHandler($e);
- }catch(NotImplementedError $e){
+ }catch(NotImplementedError $e){
$this->errorClass->NotImplementedHandler($e);
- }
+ }
}
+ /**
+ * Revoke the openstack services' token
+ *
+ * @return NULL
+ */
public function deauthenticate(){
try{
@@ -103,16 +164,23 @@ class App{
$this->setOutput("deauthenticate", "Ok");
}catch(BadResponseError $e){
$this->errorClass->BadResponseHandler($e);
- }catch(UserInputError $e){
+ }catch(UserInputError $e){
$this->errorClass->UserInputHandler($e);
- }catch(BaseError $e){
+ }catch(BaseError $e){
$this->errorClass->BaseErrorHandler($e);
- }catch(NotImplementedError $e){
+ }catch(NotImplementedError $e){
$this->errorClass->NotImplementedHandler($e);
- }
+ }
}
+ /**
+ * Retrieve a post parameter given its name
+ *
+ * @param String $name Expected post parameter's name
+ *
+ * @return Object Post value
+ */
public function getPostParam($name){
if(isset($this->postParams[$name])){
@@ -123,28 +191,52 @@ class App{
}
-
+ /**
+ * Set a post parameter for automating task
+ *
+ * @param String $param Name for the Post entry
+ * @param Object $value Value for the Post entry
+ *
+ * @return NULL
+ */
public function setPostParam($param, $value){
$this->postParams[$param] = $value;
-
+
}
+ /**
+ * Set a new output message
+ *
+ * @param String $key Array key for the message
+ * @param Array $out Message's value
+ *
+ * @return NULL
+ */
public function setOutput($key, $out){
$this->output[$key] = $out;
}
+ /**
+ * Retrieve the errorManagement instance Object
+ *
+ * @return errorManagement object
+ */
public function getErrorInstance(){
return $this->errorClass;
}
+ /**
+ * Output the messages to be send to the client
+ *
+ * @return NULl
+ */
public function show(){
echo json_encode($this->output);
- //error_log(var_dump(json_encode($this->output), true), 0);
}
}