diff options
| author | root <root@serverpc.home> | 2016-05-04 19:46:53 +0200 |
|---|---|---|
| committer | root <root@serverpc.home> | 2016-05-04 19:46:53 +0200 |
| commit | 4b978d4584994536f05b016fb65de9a8667bcb2d (patch) | |
| tree | 5f45e5b0cfcd74058c7de57afe0646cd253672f3 /server/doc/files/core/App.php.txt | |
| parent | 0266c16ffc97042853916c390aaaccecc72e69a1 (diff) | |
| parent | a0056da90605f2fb4c2479cae310f12a81a9a3e7 (diff) | |
Merge branch 'master' into loic
Diffstat (limited to 'server/doc/files/core/App.php.txt')
| -rw-r--r-- | server/doc/files/core/App.php.txt | 245 |
1 files changed, 245 insertions, 0 deletions
diff --git a/server/doc/files/core/App.php.txt b/server/doc/files/core/App.php.txt new file mode 100644 index 0000000..fc6c01d --- /dev/null +++ b/server/doc/files/core/App.php.txt @@ -0,0 +1,245 @@ +<?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 $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;
+ $this->tokenClass = new genTokenOptions($args);
+ $this->openstack = new OpenStack\OpenStack(['authUrl' => $args["authUrl"]]);
+ $this->errorClass = new errorManagement($this);
+ $this->output = array();
+ $this->postParams = $_POST;
+
+ }
+
+ /**
+ * 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;
+ $this->tokenClass->loadBackup($this->tokenPost);
+
+ }
+
+ /**
+ * 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;
+ }
+
+ }
+
+ /**
+ * Generate the token for the different services in OpenStack
+ *
+ * @return void
+ */
+ public function authenticate(){
+
+ try{
+ $this->tokenClass->genIdentityToken();
+ $this->tokenClass->genComputeToken();
+ $this->tokenClass->genImageToken();
+ $this->tokenClass->genNetworkToken();
+
+ $this->setOutput("token", $this->tokenClass->getBackup());
+ }catch(BadResponseError $e){
+ $this->errorClass->BadResponseHandler($e);
+ }catch(UserInputError $e){
+ $this->errorClass->UserInputHandler($e);
+ }catch(BaseError $e){
+ $this->errorClass->BaseErrorHandler($e);
+ }catch(NotImplementedError $e){
+ $this->errorClass->NotImplementedHandler($e);
+ }
+
+ }
+
+ /**
+ * Revoke the openstack services' token
+ *
+ * @return void
+ */
+ public function deauthenticate(){
+
+ try{
+
+ $this->tokenClass->revokeComputeToken();
+ $this->tokenClass->revokeImageToken();
+ $this->tokenClass->revokeNetworkToken();
+ $this->tokenClass->revokeIdentityToken();
+
+ $this->setOutput("deauthenticate", "Ok");
+ }catch(BadResponseError $e){
+ $this->errorClass->BadResponseHandler($e);
+ }catch(UserInputError $e){
+ $this->errorClass->UserInputHandler($e);
+ }catch(BaseError $e){
+ $this->errorClass->BaseErrorHandler($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])){
+ return $this->postParams[$name];
+ }else{
+ $this->setOutput("Error", "Missing parameter ".$name);
+ }
+
+ }
+
+ /**
+ * Set a post parameter for automating task
+ *
+ * @param String $param Name for the Post entry
+ * @param Object $value Value for the Post entry
+ *
+ * @return void
+ */
+ 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 void
+ */
+ 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 void
+ */
+ public function show(){
+ echo json_encode($this->output);
+ }
+
+}
+ |
