diff options
Diffstat (limited to 'server/core')
| -rw-r--r-- | server/core/App.php | 100 | ||||
| -rw-r--r-- | server/core/CoreInterface.php | 7 | ||||
| -rwxr-xr-x | server/core/ErrorManagement.php | 39 | ||||
| -rwxr-xr-x[-rw-r--r--] | server/core/Identity.php | 2572 | ||||
| -rw-r--r-- | server/core/Image.php | 321 | ||||
| -rw-r--r--[-rwxr-xr-x] | server/core/LibOverride/genTokenOptions.php | 137 | ||||
| -rw-r--r-- | server/core/LibOverride/projectTokenData/demo | 1 |
7 files changed, 3110 insertions, 67 deletions
diff --git a/server/core/App.php b/server/core/App.php new file mode 100644 index 0000000..babb3d9 --- /dev/null +++ b/server/core/App.php @@ -0,0 +1,100 @@ +<?php
+include_once("core/Plugin_Api.php");
+include_once("core/LibOverride/genTokenOptions.php");
+include_once("core/ErrorManagement.php");
+
+use OpenStack\Common\Error\BadResponseError;
+use OpenStack\Common\Error\BaseError;
+use OpenStack\Common\Error\NotImplementedError;
+use OpenStack\Common\Error\UserInputError;
+
+class App{
+
+ protected $openstack;
+ protected $pluginsApi;
+ protected $postParams;
+ protected $tokenClass;
+ protected $tokenPost;
+ protected $errorClass;
+ protected $output;
+
+ public function __construct($args){
+
+ $this->tokenPost = NULL;
+ $this->tokenClass = new genTokenOptions($args);
+ $this->openstack = new OpenStack\OpenStack([]);
+ $this->pluginsApi = plugin_api::getInstance();
+ $this->errorClass = new errorManagement($this);
+ $this->output = array();
+ $this->postParams = $_POST;
+
+ }
+
+ public function setToken($token){
+
+ $this->tokenPost = $token;
+ $this->tokenClass->loadBackup($his->tokenPost);
+
+ }
+
+ 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;
+ }
+
+ }
+
+ 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);
+ }
+
+ }
+
+ public function getPostParam($name){
+
+ return $this->postParams[$name];
+
+ }
+
+ public function setOutput($key, $out){
+
+ $this->output[$key] = $out;
+
+ }
+
+ public function getErrorInstance(){
+
+ return $this->errorClass;
+
+ }
+
+ public function show(){
+ echo json_encode($this->output);
+ }
+
+}
\ No newline at end of file diff --git a/server/core/CoreInterface.php b/server/core/CoreInterface.php new file mode 100644 index 0000000..ed0d959 --- /dev/null +++ b/server/core/CoreInterface.php @@ -0,0 +1,7 @@ +<?php
+
+interface Core{
+
+ public function action($action);
+
+}
\ No newline at end of file diff --git a/server/core/ErrorManagement.php b/server/core/ErrorManagement.php new file mode 100755 index 0000000..6bff61f --- /dev/null +++ b/server/core/ErrorManagement.php @@ -0,0 +1,39 @@ +<?php
+
+use OpenStack\Common\Error\BadResponseError;
+use OpenStack\Common\Error\BaseError;
+use OpenStack\Common\Error\NotImplementedError;
+use OpenStack\Common\Error\UserInputError;
+
+
+Class errorManagement{
+
+ protected $app;
+
+
+ public function __construct($args){
+
+ $this->app = $args;
+
+ }
+
+ public function BaseErrorHandler($error){
+
+ }
+
+ public function BadResponseHandler($error){
+ $this->app->setOutput("Error", "Erreur Interne, Merci de contacter un administrateur!");
+ }
+
+ public function NotImplementedHandler($error){
+ $this->app->setOutput("Error", "Erreur Interne, Merci de contacter un administrateur!");
+ }
+
+ public function UserInputHandler($error){
+
+ }
+
+
+}
+
+?>
\ No newline at end of file diff --git a/server/core/Identity.php b/server/core/Identity.php index 343ed15..2638985 100644..100755 --- a/server/core/Identity.php +++ b/server/core/Identity.php @@ -1,19 +1,2571 @@ <?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' +* +* @todo Complete the functions and finish the descriptions +*/ +use OpenStack\Common\Error; + +/** +* Identity 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 identity implements Core{ + + /** @var App $app protected, contains the main app object */ + protected $app; -class identity { + /** @var OpenStack\Identity $libClass protected, contains the library Identity object */ + protected $libClass; + + /** + * identity constructor + * + * @param App $app the main app object + * + * @throws [Type] [<description>] + * + * @return identity + */ + public function __construct($app){ - protected $oidentity; + $this->app = $app; + $this->libClass = $app->getLibClass("Identity"); - public function __construct($ostack, $apiP){ + } + + /** + * Execute an action + * + * @param String $action name of another function of this class + * + * @return void + */ + public function action($action){ + + $this->{$action.""}(); + + } + /** + * Add a credential for the given user/project. + * + * Create a secret/access pair for use with ec2 style auth. + * This operation will generates a new set of credentials that map the user/project pair. + * + * @param JsonString $blob Required credentials information with this structure for ec2: "{\"access\":\"181920\",\"secret\":\"secretKey\"}" + * @param String $projectId Required project's UUID + * @param String $type Required Type of credential : ec2, cert... + * @param String $userId Required Id of the user which own the credential + * + * @return void + */ + private function addCredential(){ + + $blob = $this->app->getPostParam("blob"); + $projectId = $this->app->getPostParam("projectId"); + $type = $this->app->getPostParam("type"); + $userId = $this->app->getPostParam("userId"); + + if(!isset($blob) || !isset($projectId) || !isset($type) || !isset($userId)){ + $this->app->setOutput("Error", "Parameters Incorrect"); + return; + } + + try{ + + $opt = array('blob' => $blob, 'projectId' => $projectId, 'type' => $type, 'userId' => $userId); + $res = $this->libClass->createCredential($opt); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + + } + + /** + * List the credentials for a given user. + * + * @return void + */ + private function listCredentials(){ + try{ + + $this->libClass->listCredentials() + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + + } + + /** + * Retrieve a user’s access/secret pair by the access key. + * + * @param String $credentialId Required credential id for which it retrieve the details + * + * @return void + */ + private function showCredential(){ + $credentId = $this->app->getPostParam("credentialId"); + + if(!isset($credentId)){ + $this->app->setOutput("Error", "Parameters Incorrect"); + } + + try{ + + $cred = $this->libClass->getCredential($credentId); + $cred->retrieve(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + + } + + /** + * Update a user’s access/secret pair. + * + * @param String $credentialId Required credential id to update + * @param JsonString $blob Required credentials information with this structure for ec2: "{\"access\":\"181920\",\"secret\":\"secretKey\"}" + * @param String $type Required Type of credential : ec2, cert... + * + * @return void + */ + private function updateCredential(){ + + $credentId = $this->app->getPostParam("credentialId"); + $blob = $this->app->getPostParam("blob"); + $type = $this->app->getPostParam("type"); + + if(!isset($blob) || !isset($credentId) || !isset($type)){ + $this->app->setOutput("Error", "Parameters Incorrect"); + } + + + try{ + + $credential = $this->libClass->getCredential($credentId); - $this->oidentity = $ostack->identityV3(); - $this->plugins = $apiP; + $credential->type = $type; + $credential->blob = $blob; + $credential->update(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Delete a user’s access/secret pair. + * + * @param String $credentialId Required credential id to delete + * + * @return void + */ + private function deleteCredential(){ + + $credentId = $this->app->getPostParam("credentialId"); + + if(!isset($credentId)){ + $this->app->setOutput("Error", "Parameters Incorrect"); + } + + try{ + + $credential = $this->libClass->getCredential($credentId); + $credential->delete(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + }- + + /** + * Add a domain to an OpenStack instance. + * + * @param String $desc Optional Domain Description + * @param String $enabled Optional Domain enabled or not : value true or false + * @param String $name Required Domain Name + * + * @return void + */ + private function addDomain(){ + + $description = $this->app->getPostParam("desc"); + $enabled = $this->app->getPostParam("enabled"); + $name = $this->app->getPostParam("name"); + + if(!isset($name)){ + $this->app->setOutput("Error", "Parameters Incorrect"); + return; + } + + if(isset($enabled) && isset($description)) + $opt = array('description' => $description, 'enabled' => $enabled, 'name' => $name); + elseif(isset($enabled)) + $opt = array('enabled' => $enabled, 'name' => $name); + elseif(isset($description)) + $opt = array('description' => $description, 'name' => $name); + else + $opt = array('name' => $name); + + try{ + + $res = $this->libClass->createCredential($opt); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + + } + + /** + * Retrieve the different domain's list. + * + * @return void + */ + private function listDomains(){ + + try{ + + $this->libClass->listDomains() + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + + } + + /** + * Retrieve the details of a given domain. + * + * @param String $domainId Required Domain id for which it retrieve the details + * + * @return void + */ + private function showDomain(){ + + $domId = $this->app->getPostParam("domainId"); + + if(!isset($domId)){ + $this->app->setOutput("Error", "Parameters Incorrect"); + } + + try{ + + $domain = $this->libClass->getDomain($domId); + $domain->retrieve(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } + + /** + * Update the given domain. + * + * @param String $domainId Required domain id to update + * @param String $desc Optional Domain Description + * @param String $enabled Optional Domain enabled or not : value true or false + * @param String $name Required Domain Name + * + * @return void + */ + private function updateDomain(){ + + $domId = $this->app->getPostParam("domainId"); + $description = $this->app->getPostParam("desc"); + $enabled = $this->app->getPostParam("enabled"); + $name = $this->app->getPostParam("name"); + + if(!isset($domId)){ + $this->app->setOutput("Error", "Parameters Incorrect"); + return; + } + + + try{ + + $domain = $this->libClass->getDomain($domId); - public function genToken(){ - global $Args; - $token = $this->oidentity->generateToken($Args); - return $token; - } + if(isset($name)) + $domain->name = $name; + if(isset($enabled)) + $domain->enabled = $enabled; + if(isset($description)) + $domain->description = $description; + + $domain->update(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Delete the given domain. + * + * @param String $domainId Required Domain id to delete + * + * @return void + */ + private function deleteDomain(){ + + $domId = $this->app->getPostParam("domainId"); + + if(!isset($domId)){ + $this->app->setOutput("Error", "Parameters Incorrect"); + } + + try{ + + $domain = $this->libClass->getDomain($domId); + $domain->delete(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Retrieve the different roles of a given user in a domain. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function listRolesDomainUser(){ + + $domId = $this->app->getPostParam("domainId"); + $userId = $this->app->getPostParam("userId"); + + if(!isset($domId) || !isset($userId)){ + + } + + try{ + + $domain = $this->libClass->getDomain($domId); + + $domain->listUserRoles(['userId' => $userId]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Grant a role to a given user in a domain. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function grantRoleDomainUser(){ + $domId = $this->app->getPostParam("domainId"); + $roleId = $this->app->getPostParam("roleId"); + $userId = $this->app->getPostParam("userId"); + + if(!isset($domId) || !isset($roleId) || !isset($userId)){ + + } + + try{ + + $domain = $this->libClass->getDomain($domId); + + $domain->grantUserRole([ + 'userId' => $userId, + 'roleId' => $roleId, + ]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Verify that a user has a given role in a domain. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function checkRoleDomainUser(){ + $domId = $this->app->getPostParam("domainId"); + $roleId = $this->app->getPostParam("roleId"); + $userId = $this->app->getPostParam("userId"); + + if(!isset($domId) || !isset($roleId) || !isset($userId)){ + + } + + try{ + + $domain = $this->libClass->getDomain($domId); + + $result = $domain->checkUserRole(['userId' => $userId, 'roleId' => $roleId]); + + /*if (true === $result) { + // It exists! + }*/ + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Delete a role for a given user in a domain. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function revokeRoleDomainUser(){ + $domId = $this->app->getPostParam("domainId"); + $roleId = $this->app->getPostParam("roleId"); + $userId = $this->app->getPostParam("userId"); + + if(!isset($domId) || !isset($roleId) || !isset($userId)){ + + } + + try{ + + $domain = $this->libClass->getDomain($domId); + + $domain->revokeUserRole([ + 'userId' => $userId, + 'roleId' => $roleId, + ]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Retrieve the roles of a given group in a domain. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function listRolesDomainGroup(){ + $domId = $this->app->getPostParam("domainId"); + $groupId = $this->app->getPostParam("groupId"); + + if(!isset($domId) || !isset($groupId)){ + + } + + + try{ + + $domain = $this->libClass->getDomain($domId); + + $domain->listGroupRoles(['groupId' => $groupId]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Add a role to a given group in a domain. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function grantRoleDomainGroup(){ + $domId = $this->app->getPostParam("domainId"); + $groupId = $this->app->getPostParam("groupId"); + $roleId = $this->app->getPostParam("roleId"); + + if(!isset($domId) || !isset($groupId) || !isset($roleId)){ + + } + + try{ + + $domain = $this->libClass->getDomain($domId); + + $domain->grantGroupRole([ + 'groupId' => $groupId, + 'roleId' => $roleId, + ]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Verify that a role is associated with a given group in a domain. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function checkRoleDomainGroup(){ + $domId = $this->app->getPostParam("domainId"); + $groupId = $this->app->getPostParam("groupId"); + $roleId = $this->app->getPostParam("roleId"); + + if(!isset($domId) || !isset($groupId) || !isset($roleId)){ + + } + + try{ + + $domain = $this->libClass->getDomain($domId); + + $result = $domain->checkGroupRole(['groupId' => $groupId, 'roleId' => $roleId]); + + /*if (true === $result) { + // It exists! + }*/ + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Delete a role for a given group in a domain. + * + * A *description*, that can span multiple lines, to go _in-depth_ into the details of this element + * and to provide some background information or textual references. + * + * @param string $myArgument With a *description* of this argument, these may also + * span multiple lines. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function revokeRoleDomainGroup(){ + $domId = $this->app->getPostParam("domainId"); + $groupId = $this->app->getPostParam("groupId"); + $roleId = $this->app->getPostParam("roleId"); + + if(!isset($domId) || !isset($groupId) || !isset($roleId)){ + + } + + try{ + + $domain = $this->libClass->getDomain($roleId); + + $domain->revokeGroupRole([ + 'groupId' => $groupId, + 'roleId' => $roleId, + ]); + + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Add an endpoint to the Openstack instance + * + * @throws [Type] [<description>] + * + * @return void + */ + private function addEndpoint(){ + $servId = $this->app->getPostParam("serviceId"); + $name = $this->app->getPostParam("name"); + $region = $this->app->getPostParam("region"); + $url = $this->app->getPostParam("url"); + + if(!isset($servId) || !isset($name) || !isset($region) || !isset($url)){ + + } + + try{ + + $endpoint = $this->libClass->createEndpoint([ + 'interface' => \OpenStack\Identity\v3\Enum::INTERFACE_INTERNAL, + 'name' => $name, + 'region' => $region, + 'url' => $url, + 'serviceId' => $servId + ]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Retrieve the endpoint for the given id + * + * @throws [Type] [<description>] + * + * @return void + */ + private function getEndpoint(){ + + $endId = $this->app->getPostParam("endpointId"); + + if(!isset($endId)){ + + } + + try{ + + $endpoint = $this->libClass->getEndpoint($endId); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Retrieve the list of the different endpoints + * + * @return void + */ + private function listEndpoints(){ + + try{ + + $res = $this->libClass->listEndpoints(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Update a given endpoint + * + * @throws [Type] [<description>] + * + * @return void + */ + private function updateEndpoint(){ + //Not Implemented Yet + + /*$domId = $this->app->getPostParam("domainId"); + $groupId = $this->app->getPostParam("groupId"); + + if(!isset($domId) || !isset($groupId)){ + + } + + //TODO PARAMETERS + try{ + + $endpoint = $this->libClass->getEndpoint('{endpointId}'); + + $endpoint->interface = \OpenStack\Identity\v3\Enum::INTERFACE_PUBLIC; + + $endpoint->update(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + }*/ + } + + /** + * Delete a given endpoint + * + * @throws [Type] [<description>] + * + * @return void + */ + private function deleteEndpoint(){ + $endId = $this->app->getPostParam("endpointId"); + + if(!isset($endId)){ + + } + + try{ + + $endpoint = $this->libClass->getEndpoint($endId); + $endpoint->delete(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Add a group. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function addGroup(){ + //Not Implemented Yet + + /*$domId = $this->app->getPostParam("domainId"); + $groupId = $this->app->getPostParam("groupId"); + + if(!isset($domId) || !isset($groupId)){ + + } + try{ + + $this->libClass->listCredentials() + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + }*/ + } + + /** + * Retrieve the group's list. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function listGroups(){ + //Not Implemented Yet + /* + $domId = $this->app->getPostParam("domainId"); + $groupId = $this->app->getPostParam("groupId"); + + if(!isset($domId) || !isset($groupId)){ + + } + try{ + + $this->libClass->listCredentials() + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + }*/ + } + + /** + * Retrieve the details of a given group. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function showGroup(){ + //Not Implemented Yet + + /* + $domId = $this->app->getPostParam("domainId"); + $groupId = $this->app->getPostParam("groupId"); + + if(!isset($domId) || !isset($groupId)){ + + } + try{ + + $this->libClass->listCredentials() + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + }*/ + } + + /** + * Update a given group. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function updateGroup(){ + //Todo Argument Optional + $groupId = $this->app->getPostParam("groupId"); + $description = $this->app->getPostParam("description"); + $name = $this->app->getPostParam("name"); + + if(!isset($groupId)){ + + } + + try{ + + $group = $this->libClass->getGroup($groupId); + + if(isset($description)) + $group->description = 'foo'; + if(isset($name)) + $group->name = 'bar'; + + $group->update(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Delete the given group. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function deleteGroup(){ + + $groupId = $this->app->getPostParam("groupId"); + + if(!isset($groupId)){ + + } + + try{ + + $group = $this->libClass->getGroup($groupId); + + $group->delete(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Retrieve the users of a given group. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function listGroupUsers(){ + + $groupId = $this->app->getPostParam("groupId"); + + if(!isset($groupId)){ + + } + + try{ + + $group = $this->libClass->getGroup($groupId); + + $users = $group->listUsers(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Add a user to a group. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function addGroupUser(){ + + $userId = $this->app->getPostParam("userId"); + $groupId = $this->app->getPostParam("groupId"); + + if(!isset($userId) || !isset($groupId)){ + + } + + try{ + + $group = $this->libClass->getGroup($groupId); + + $group->addUser(['userId' => $userId]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Remove a user from a given group. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function removeGroupUser(){ + + $userId = $this->app->getPostParam("userId"); + $groupId = $this->app->getPostParam("groupId"); + + if(!isset($userId) || !isset($groupId)){ + + } + + try{ + + $group = $this->libClass->getGroup($groupId); + + $group->removeUser(['userId' => $userId]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Check if a group contains a given user. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function checkGroupUser(){ + + $userId = $this->app->getPostParam("userId"); + $groupId = $this->app->getPostParam("groupId"); + + if(!isset($userId) || !isset($groupId)){ + + } + + try{ + + $group = $this->libClass->getGroup($groupId); + + $result = $group->checkMembership(['userId' => $userId]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * @todo + * + * @throws [Type] [<description>] + * + * @return void + */ + private function addPolicies(){ + //Not Implemented Yet + /* + $domId = $this->app->getPostParam("domainId"); + $groupId = $this->app->getPostParam("groupId"); + + if(!isset($domId) || !isset($groupId)){ + + } + try{ + + $this->libClass->listCredentials() + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + }*/ + } + + /** + * @todo + * + * @throws [Type] [<description>] + * + * @return void + */ + private function listPolicies(){ + //Not Implemented Yet + /* + $domId = $this->app->getPostParam("domainId"); + $groupId = $this->app->getPostParam("groupId"); + + if(!isset($domId) || !isset($groupId)){ + + } + try{ + + $this->libClass->listCredentials() + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + }*/ + } + + /** + * @todo + * + * @throws [Type] [<description>] + * + * @return void + */ + private function showPolicie(){ + //Not Implemented Yet + /* + $domId = $this->app->getPostParam("domainId"); + $groupId = $this->app->getPostParam("groupId"); + + if(!isset($domId) || !isset($groupId)){ + + } + try{ + + $this->libClass->listCredentials() + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + }*/ + + } + + /** + * @todo + * + * @throws [Type] [<description>] + * + * @return void + */ + private function updatePolicies(){ + //Not Implemented Yet + /* + $domId = $this->app->getPostParam("domainId"); + $groupId = $this->app->getPostParam("groupId"); + + if(!isset($domId) || !isset($groupId)){ + + } + try{ + + $this->libClass->listCredentials() + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + }*/ + } + + /** + * @todo + * + * @throws [Type] [<description>] + * + * @return void + */ + private function deletePolicies(){ + //Not Implemented Yet + /* + $domId = $this->app->getPostParam("domainId"); + $groupId = $this->app->getPostParam("groupId"); + + if(!isset($domId) || !isset($groupId)){ + + } + try{ + + $this->libClass->listCredentials() + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + }*/ + } + + /** + * Add a project. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function addProject(){ + //Todo Parameters Optional + $description = $this->app->getPostParam("description"); + $name = $this->app->getPostParam("name"); + + if(!isset($name) || !isset($description)){ + + } + + try{ + + $project = $this->libClass->createProject([ + 'description' => $description, + 'enabled' => true, + 'name' => $name + ]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Retrieve the different projects. + * + * @return void + */ + private function listProjects(){ + + try{ + + $projects = $this->libClass->listProjects(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Retrieve the details of a given project. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function showProject(){ + + $projId = $this->app->getPostParam("projetId"); + + if(!isset($projId)){ + + } + + try{ + + $project = $this->libClass->getProject($projId); + $project->retrieve(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Update a given project. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function updateProject(){ + //Todo Parameters Optionnal + $description = $this->app->getPostParam("description"); + $name = $this->app->getPostParam("name"); + $projId = $this->app->getPostParam("projetId"); + + if(!isset($projId) || !isset($name) || !isset($description)){ + + } + + try{ + + $project = $this->libClass->getProject($projId); + + $project->enabled = false; + $project->description = $description; + $project->name = $name; + + $project->update(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Delete a given project. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function deleteProject(){ + $projId = $this->app->getPostParam("projId"); + + if(!isset($projId)){ + + } + + try{ + + $project = $this->libClass->getProject($projId); + + $project->delete(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * List the roles of a given user in a project. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function listRolesProjectUser(){ + + $projId = $this->app->getPostParam("projetId"); + $userId = $this->app->getPostParam("userId"); + + if(!isset($projId) || !isset($userId)){ + + } + + try{ + + $project = $this->libClass->getProject($projId); + + $project->listUserRoles(['userId' => $userId]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Grant a role to an user in a project. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function grantRoleProjectUser(){ + + $projId = $this->app->getPostParam("projId"); + $userId = $this->app->getPostParam("userId"); + $roleId = $this->app->getPostParam("roleId"); + + if(!isset($projId) || !isset($userId) || !isset($roleId)){ + + } + + try{ + + $project = $this->libClass->getProject($projId); + + $project->grantUserRole([ + 'userId' => $userId, + 'roleId' => $roleId, + ]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Check if a given user has a role in a project. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function checkRoleProjectUser(){ + $projId = $this->app->getPostParam("projetId"); + $userId = $this->app->getPostParam("userId"); + $roleId = $this->app->getPostParam("roleId"); + + if(!isset($projId) || !isset($userId) || !isset($roleId)){ + + } + + try{ + + $project = $this->libClass->getProject($projId); + + $result = $project->checkUserRole([ + 'userId' => $userId, + 'roleId' => $roleId, + ]); + + /*if (true === $result) { + }*/ + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Delete a role for a given user in a project. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function revokeRoleProjectUser(){ + + $projId = $this->app->getPostParam("projetId"); + $userId = $this->app->getPostParam("userId"); + $roleId = $this->app->getPostParam("roleId"); + + if(!isset($projId) || !isset($userId) || !isset($roleId)){ + + } + + try{ + + $project = $this->libClass->getProject($projId); + + $project->revokeUserRole([ + 'userId' => $userId, + 'roleId' => $roleId, + ]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * List the roles of a group in a project. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function listRolesProjectGroup(){ + + $projId = $this->app->getPostParam("projetId"); + $groupId = $this->app->getPostParam("groupId"); + + + if(!isset($projId) || !isset($groupId)){ + + } + + try{ + + $project = $this->libClass->getProject($projId); + + $project->listGroupRoles(['groupId' => $groupId]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Add a role to a group in a project. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function grantRoleProjectGroup(){ + + $projId = $this->app->getPostParam("projetId"); + $userId = $this->app->getPostParam("userId"); + $roleId = $this->app->getPostParam("roleId"); + + if(!isset($projId) || !isset($userId) || !isset($roleId)){ + + } + + try{ + + $project = $this->libClass->getProject($projId); + + $project->grantUserRole([ + 'userId' => $userId, + 'roleId' => $roleId, + ]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Check if a group has a given role in a project. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function checkRoleProjectGroup(){ + + $projId = $this->app->getPostParam("projetId"); + $userId = $this->app->getPostParam("userId"); + $roleId = $this->app->getPostParam("roleId"); + + if(!isset($projId) || !isset($userId) || !isset($roleId)){ + + } + + try{ + + $project = $this->libClass->getProject($projId); + + $result = $project->checkGroupRole([ + 'groupId' => $groupId, + 'roleId' => $roleId, + ]); + + /*if (true === $result) { + }*/ + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Delete a role for a group in a project. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function revokeRoleProjectGroup(){ + + $projId = $this->app->getPostParam("projetId"); + $userId = $this->app->getPostParam("userId"); + $roleId = $this->app->getPostParam("roleId"); + + if(!isset($projId) || !isset($userId) || !isset($roleId)){ + + } + + try{ + + $project = $this->libClass->getProject($projId); + + $project->revokeGroupRole([ + 'groupId' => $groupId, + 'roleId' => $roleId, + ]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Add a role. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function addRole(){ + + $name = $this->app->getPostParam("name"); + + if(!isset($name)){ + + } + + try{ + + $role = $this->libClass->createRole([ + 'name' => $name, + ]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * List the different roles + * + * @return void + */ + private function listRoles(){ + + try{ + + $roles = $this->libClass->listRoles(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * @todo + * + * @return void + */ + private function listRoleAssignements(){ + + try{ + + $assignements = $this->libClass->listRoleAssignments(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Add a service. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function addService(){ + $name = $this->app->getPostParam("name"); + $type = $this->app->getPostParam("type"); + + if(!isset($name) || !isset($type)){ + + } + + try{ + + $service = $this->libClass->createService([ + 'name' => $name, + 'type' => $type, + ]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Retrieve the different services. + * + * @return void + */ + private function listServices(){ + + try{ + + $services = $this->libClass->listServices(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Retrieve the details for a given service. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function showService(){ + $servId = $this->app->getPostParam("serviceId"); + + if(!isset($servId)){ + + } + + try{ + + $service = $this->libClass->getService($servId); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Delete a given service. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function deleteService(){ + + $servId = $this->app->getPostParam("serviceId"); + $groupId = $this->app->getPostParam("groupId"); + + if(!isset($servId) || !isset($groupId)){ + + } + + try{ + + $service = $this->libClass->getService($servId); + $service->delete(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Generate a new token for a given user id. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function genTokenUserID(){ + + $userId = $this->app->getPostParam("userId"); + $userPass = $this->app->getPostParam("userPassword"); + + if(!isset($userId) || !isset($userPass)){ + + } + + try{ + + $token = $this->libClass->generateToken([ + 'user' => [ + 'id' => $userId, + 'password' => $userPass + ] + ]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Generate a new token for a given user name. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function genTokenUserName(){ + $username = $this->app->getPostParam("username"); + $userPass = $this->app->getPostParam("userPassword"); + $domId = $this->app->getPostParam("domainId"); + + + if(!isset($userId) || !isset($userPass) || !isset($domId)){ + + } + + try{ + + $token = $this->libClass->generateToken([ + 'user' => [ + 'name' => $username, + 'password' => $userPass, + 'domain' => [ + 'id' => $domId + ] + ] + ]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Generate a new token from another token ID. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function genTokenID(){ + + $tokenId = $this->app->getPostParam("tokenId"); + $projectId = $this->app->getPostParam("projectId"); + + if(!isset($tokenId) || !isset($projectId)){ + + } + + try{ + + $token = $this->libClass->generateToken([ + 'tokenId' => $tokenId, + 'scope' => ['project' => ['id' => $projectId]] + ]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Generate a new token scoped by a project ID. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function genTokenScopedProjectID(){ + + $userId = $this->app->getPostParam("userId"); + $userPass = $this->app->getPostParam("userPass"); + $projId = $this->app->getPostParam("projetId"); + + if(!isset($userId) || !isset($projId) || !isset($userPass)){ + + } + + try{ + + $token = $this->libClass->generateToken([ + 'user' => [ + 'id' => $userId, + 'password' => $userPass + ], + 'scope' => [ + 'project' => ['id' => $projId] + ] + ]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Generate a new token scoped by a project name. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function genTokenScopedProjectName(){ + + $userId = $this->app->getPostParam("userId"); + $userPass = $this->app->getPostParam("userPass"); + $projName = $this->app->getPostParam("projetName"); + $domId = $this->app->getPostParam("domId"); + + if(!isset($userId) || !isset($projName) || !isset($userPass) || !isset($domId)){ + + } + + try{ + + $token = $this->libClass->generateToken([ + 'user' => [ + 'id' => $userId, + 'password' => $userPass + ], + 'scope' => [ + 'project' => [ + 'name' => $projName, + 'domain' => [ + 'id' => $domId + ] + ] + ] + ]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Check if a token is validate. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function validateToken(){ + + $tokenId = $this->app->getPostParam("tokenId"); + + if(!isset($tokenId)){ + + } + + try{ + + $result = $this->libClass->validateToken($tokenId); + + /*if (true === $result) { + // It's valid! + }*/ + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Delete a given token. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function revokeToken(){ + + $tokenId = $this->app->getPostParam("tokenId"); + + if(!isset($tokenId)){ + + } + + try{ + + $this->libClass->revokeToken($tokenId); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Add a new user. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function addUser(){ + //Todo Optionnal Parameter + $projId = $this->app->getPostParam("projId"); + $desc = $this->app->getPostParam("description"); + $email = $this->app->getPostParam("email"); + $name = $this->app->getPostParam("name"); + $pass = $this->app->getPostParam("pass"); + $domId = $this->app->getPostParam("domId"); + + if(!isset($domId) || !isset($groupId)){ + + } + + try{ + + $user = $this->libClass->createUser([ + 'defaultProjectId' => $projId, + 'description' => $desc, + 'domainId' => $domId, + 'email' => $email, + 'enabled' => true, + 'name' => $name, + 'password' => $pass + ]); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Retrieve the different users. + * + * @return void + */ + private function listUsers(){ + + try{ + + $users = $this->libClass->listUsers(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Retrieve the details of a given user. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function showUser(){ + + $userId = $this->app->getPostParam("userId"); + + if(!isset($userId)){ + + } + + try{ + + $user = $this->libClass->getUser($userId); + $user->retrieve(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Update a given user. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function updateUser(){ + + $userId = $this->app->getPostParam("userId"); + $desc = $this->app->getPostParam("description"); + $name = $this->app->getPostParam("name"); + + if(!isset($userId) || !isset($desc) || !isset($name)){ + + } + + try{ + + $user = $this->libClass->getUser($userId); + + $user->description = $desc; + $user->name = $name; + + $user->update(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Delete a given user. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function deleteUser(){ + + $userId = $this->app->getPostParam("userId"); + + if(!isset($userId)){ + + } + + try{ + + $user = $this->libClass->getUser($userId); + $user->delete(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Retrieve the groups which contains a given user. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function listUserGroups(){ + + $userId = $this->app->getPostParam("userId"); + + if(!isset($userId)){ + + } + + try{ + + $user = $this->libClass->getUser($userId); + + $groups = $user->listGroups(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } + + /** + * Retrieve the projects which contains a given user. + * + * @throws [Type] [<description>] + * + * @return void + */ + private function listUserProjects(){ + + $userId = $this->app->getPostParam("userId"); + + if(!isset($userId)){ + + } + + try{ + + $user = $this->libClass->getUser($userId); + + $projects = $user->listProjects(); + + //TODO parse answer + + }catch(BadResponseError $e){ + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } } diff --git a/server/core/Image.php b/server/core/Image.php index 8d1c8b6..3001eea 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -1 +1,322 @@ +<?php + +//require 'CoreInterface.php'; + +/** +* File containing the Image Class. +* +* @version 1.0 Initialisation of this file +* @since 1.0 Core application's file +* +* @author Yogg 'yogg at epsina . com' +* +* @todo Complete the functions with errors detection and finish the descriptions +*/ + +/** +* Image Class of the back-end application +* +* ADD CLASS DESCRIPTION +* +*/ +class image{ + //implements Core + + /** @var App $app protected, contains the main app object */ + protected $app; + + /** @var OpenStack\Identity $libClass protected, contains the library Identity object */ + protected $libClass; + + /** @var array $actions protected, contains the functions which can be call by the front-end */ + protected $actions = array(); + + + /** + * Image constructor + * + * @param App $app the main app object + * + * @throws [Type] [<description>] + * + * @return Image + */ + public function __construct($app){ + $this->app = $app; + $this->libClass = $app->getLibClass("Image"); + } + + + + + /** + * 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, vérifier nom pas déjà pris + } + else{ + //ERROR + } + 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(){ + // vérifier si au moins une image + $service = $this->oidentity; + $images = $service->listImages(); + return $images; + } + + /** + * Details about an image + * + * @param string $id + * identifier of the image + * + **/ + public function image_details($id){ + //vérifier existence image + $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){ + //vérifier existence image + $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){ + // si protected = true, demander de le mettre a false + // vérifier existence image + $service = $this->oidentity; + $service->getImage($id)->delete(); + } + + /** + * Resactive an image + * + * @param string $id + * identifier of the image + **/ + public function reactivate_image($id){ + // vérifier existence image + $service = $this->oidentity; + $image = $service->getImage($id); + $image->reactivate(); + } + + /** + * Desactive an image + * + * @param string $id + * identifier of the image + **/ + public function desactivate_image($id){ + // vérifier existence image + $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){ + // vérifier existence image + $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){ + // vérifier existence image + $service = $this->oidentity; + $image = $service->getImage($id); + $stream = $image->downloadData(); + return $stream; + } + + /** + * Add a member to image + * + * @param string $image_id + * identifier of the image + * + * @param string $member_id + * identifier of the member + **/ + public function add_member($image_id, $member_id){ + // vérifier existence image + // on doit être le proprio de l'image + // vérifier membre existe + $service = $this->oidentity; + $member_id = $service>getImage($image_id)->addMember($member_id); + } + + + /** + * List members of an image + * + * @param string $image_id + * identifier of the image + **/ + public function list_member($image_id, $member_id){ + // vérifier existence image + $service = $this->oidentity; + $image = $service->getImage($image_id); + $members = $image->listMembers(); + return $members; + } + + /** + * Show details of a member of an image + * + * @param string $image_id + * identifier of the image + * + * @param string $member_id + * identifier of the member + **/ + public function detail_member($image_id, $member_id){ + // vérifier existence image + // on doit être le proprio de l'image + // vérifier membre existe + $service = $this->oidentity; + $member = $service>getImage($image_id)->getMember($member_id); + return $member; + } + + /** + * Remove a member of an image + * + * @param string $image_id + * identifier of the image + * + * @param string $member_id + * identifier of the member + **/ + public function remove_member($image_id, $member_id){ + // vérifier existence image + // on doit être le proprio de l'image + // vérifier membre existe + $service = $this->oidentity; + $service>getImage($image_id)->getMember($member_id)->delete(); + } + + /** + * Update a member of an image + * + * @param string $image_id + * identifier of the image + * + * @param string $member_id + * identifier of the member + * + * @param string $status + * new status for the member + **/ + public function update_member($image_id, $member_id, $status){ + // vérifier existence image + // on doit être le proprio de l'image + // vérifier membre existe + $service = $this->oidentity; + $member = $service>getImage($image_id)->getMember($member_id)->updateStatus($status); + } + +} +?> diff --git a/server/core/LibOverride/genTokenOptions.php b/server/core/LibOverride/genTokenOptions.php index 81ecfc8..b71defa 100755..100644 --- a/server/core/LibOverride/genTokenOptions.php +++ b/server/core/LibOverride/genTokenOptions.php @@ -70,7 +70,7 @@ class genTokenOptions 'base_uri' => Utils::normalizeUrl($baseUrl), 'handler' => $stack, ]); - $this->backup['Identity'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); + $this->saveBackup('Identity', array('token' => $token, 'baseUrl' => $baseUrl )); $this->optionsGlobal['Identity'] = $options; } @@ -81,7 +81,7 @@ class genTokenOptions $options['catalogType'] = 'false'; $options['region'] = 'RegionOne'; - $this->backup['Identity'] = unserialize($opt); + $this->backup['Identity'] = $opt; $token = $this->unserializeToken($this->backup['Identity']['token']); $baseUrl = $this->backup['Identity']['baseUrl']; @@ -95,7 +95,7 @@ class genTokenOptions 'base_uri' => Utils::normalizeUrl($baseUrl), 'handler' => $stack, ]); - $this->backup['Identity'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); + $this->saveBackup('Identity', array('token' => $token, 'baseUrl' => $baseUrl )); $this->optionsGlobal['Identity'] = $options; } @@ -118,7 +118,7 @@ class genTokenOptions 'base_uri' => Utils::normalizeUrl($baseUrl), 'handler' => $stack, ]); - $this->backup['Image'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); + $this->saveBackup('Image', array('token' => $token, 'baseUrl' => $baseUrl )); $this->optionsGlobal['Image'] = $options; } @@ -129,7 +129,7 @@ class genTokenOptions $options['catalogType'] = 'image'; $options['region'] = 'RegionOne'; - $this->backup['Image'] = unserialize($opt); + $this->backup['Image'] = $opt; $token = $this->unserializeToken($this->backup['Image']['token']); $baseUrl = $this->backup['Image']['baseUrl']; @@ -143,7 +143,7 @@ class genTokenOptions 'base_uri' => Utils::normalizeUrl($baseUrl), 'handler' => $stack, ]); - $this->backup['Image'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); + $this->saveBackup('Image', array('token' => $token, 'baseUrl' => $baseUrl )); $this->optionsGlobal['Image'] = $options; } @@ -165,7 +165,7 @@ class genTokenOptions 'base_uri' => Utils::normalizeUrl($baseUrl), 'handler' => $stack, ]); - $this->backup['Network'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); + $this->saveBackup('Network', array('token' => $token, 'baseUrl' => $baseUrl )); $this->optionsGlobal['Network'] = $options; } @@ -176,7 +176,7 @@ class genTokenOptions $options['catalogType'] = 'network'; $options['region'] = 'RegionOne'; - $this->backup['Network'] = unserialize($opt); + $this->backup['Network'] = $opt; $token = $this->unserializeToken($this->backup['Network']['token']); $baseUrl = $this->backup['Network']['baseUrl']; @@ -190,7 +190,7 @@ class genTokenOptions 'base_uri' => Utils::normalizeUrl($baseUrl), 'handler' => $stack, ]); - $this->backup['Network'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); + $this->saveBackup('Network', array('token' => $token, 'baseUrl' => $baseUrl )); $this->optionsGlobal['Network'] = $options; } @@ -212,7 +212,7 @@ class genTokenOptions 'base_uri' => Utils::normalizeUrl($baseUrl), 'handler' => $stack, ]); - $this->backup['Compute'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); + $this->saveBackup('Compute', array('token' => $token, 'baseUrl' => $baseUrl )); $this->optionsGlobal['Compute'] = $options; } @@ -224,7 +224,7 @@ class genTokenOptions $options['catalogType'] = 'compute'; $options['region'] = 'RegionOne'; - $this->backup['Compute'] = unserialize($opt); + $this->backup['Compute'] = $opt; $token = $this->unserializeToken($this->backup['Compute']['token']); $baseUrl = $this->backup['Compute']['baseUrl']; @@ -238,12 +238,36 @@ class genTokenOptions 'base_uri' => Utils::normalizeUrl($baseUrl), 'handler' => $stack, ]); - $this->backup['Compute'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl ); + $this->saveBackup('Compute', array('token' => $token, 'baseUrl' => $baseUrl )); $this->optionsGlobal['Compute'] = $options; } - public function getBackup($service){ - return serialize($this->backup[$service]); + private function saveBackup($name, $data){ + $token = $this->serializeToken($data["token"]); + $path = "core/LibOverride/projectTokenData/".$token['saved']["project"]["name"]; + error_log(print_r($path, true), 0); + file_put_contents("core/LibOverride/projectTokenData/".$token['saved']["project"]["name"], serialize($token['saved'])); + $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"] ); + } + + public function getBackup(){ + return serialize($this->backup); + } + + public function loadBackup($back){ + + $backup = unserialize($back); + $this->backup["roles"] = $backup["roles"]; + $this->backup["project"] = $backup["project"]; + $this->backup["user"] = $backup["user"]; + loadComputeBackup($backup["Compute"]); + loadIdentityBackup($backup["Identity"]); + loadImageBackup($backup["Image"]); + loadNetworkBackup($backup["Network"]); + } public function getOptions($service){ @@ -252,7 +276,7 @@ class genTokenOptions private function serializeToken($token){ $tokenSerialized = []; - $tokenSerialized["methods"] = serialize($token->methods); + $tokenSerialized["token"]["methods"] = serialize($token->methods); $tokenSerialized["roles"] = []; foreach($token->roles as $role){ @@ -260,30 +284,30 @@ class genTokenOptions $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); + $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; 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); + $tokenSerialized['saved']["catalog"][serialize($service->id)]["name"] = serialize($service->name); + $tokenSerialized['saved']["catalog"][serialize($service->id)]["description"] = serialize($service->description); + $tokenSerialized['saved']["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['saved']["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["interface"] = serialize($end->interface); + $tokenSerialized['saved']["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["name"] = serialize($end->name); + $tokenSerialized['saved']["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["serviceId"] = serialize($end->serviceId); + $tokenSerialized['saved']["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["region"] = serialize($end->region); + $tokenSerialized['saved']["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["links"] = serialize($end->links); + $tokenSerialized['saved']["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["url"] = serialize($end->url); } - $tokenSerialized["roles"][serialize($service->id)]["links"] = serialize($service->links); + $tokenSerialized['saved']["catalog"][serialize($service->id)]["links"] = serialize($service->links); } - $tokenSerialized["extras"] = serialize($token->extras); + $tokenSerialized["token"]["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); @@ -292,42 +316,42 @@ class genTokenOptions $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); + $tokenSerialized["token"]["issued"] = serialize($token->issued); + $tokenSerialized["token"]["id"] = serialize($token->id); return $tokenSerialized; } private function unserializeToken($tokenSerialized){ + $Saved = file_get_contents("core/LibOverride/projectTokenData/".$this->backup["project"]); $api = new Api(); $token = new Models\Token($this->httpClient, $api); $token->methods = unserialize($tokenSerialized["methods"]); $token->roles = []; - foreach($tokenSerialized["roles"] as $key => $role){ + foreach($this->backup["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"]); + $tmp->name = unserialize($role["name"]); $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->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"]; $token->catalog = new Models\Catalog($this->httpClient, $api); $token->catalog->services = []; - foreach($tokenSerialized["catalog"] as $key => $service){ + foreach($Saved["catalog"] as $key => $service){ $tmp = new Models\Service($this->httpClient, $api); $tmp->id = unserialize($key); @@ -346,21 +370,20 @@ class genTokenOptions $tmpEnd->url = unserialize($end["url"]); $tmp->endpoints[] = $tmpEnd; } - if(isset($service["links"])) - $tmp->links = unserialize($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->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"]); $token->issued = unserialize($tokenSerialized["issued"]); $token->id = unserialize($tokenSerialized["id"]); diff --git a/server/core/LibOverride/projectTokenData/demo b/server/core/LibOverride/projectTokenData/demo new file mode 100644 index 0000000..95d1e10 --- /dev/null +++ b/server/core/LibOverride/projectTokenData/demo @@ -0,0 +1 @@ +a:2:{s:7:"project";a:7:{s:8:"domainId";s:2:"N;";s:8:"parentId";s:2:"N;";s:7:"enabled";s:2:"N;";s:11:"description";s:2:"N;";s:2:"id";s:40:"s:32:"bdb42ccd0a074d15a9808ed0d2f09ce7";";s:5:"links";s:2:"N;";s:4:"name";s:4:"demo";}s:7:"catalog";a:4:{s:40:"s:32:"52c1f2e9782b47a697df38185d72a3f9";";a:5:{s:4:"name";s:14:"s:7:"neutron";";s:11:"description";s:2:"N;";s:4:"type";s:14:"s:7:"network";";s:9:"endpoints";a:3:{s:40:"s:32:"2c765b2eb502467fba360a1188174f6a";";a:6:{s:9:"interface";s:15:"s:8:"internal";";s:4:"name";s:2:"N;";s:9:"serviceId";s:2:"N;";s:6:"region";s:16:"s:9:"RegionOne";";s:5:"links";s:2:"N;";s:3:"url";s:30:"s:22:"http://controller:9696";";}s:40:"s:32:"499dc9aeb1c3438fb23b0168d75bbef1";";a:6:{s:9:"interface";s:13:"s:6:"public";";s:4:"name";s:2:"N;";s:9:"serviceId";s:2:"N;";s:6:"region";s:16:"s:9:"RegionOne";";s:5:"links";s:2:"N;";s:3:"url";s:32:"s:24:"http://148.60.11.31:9696";";}s:40:"s:32:"d0672225fe1a4fce89794f3825deec2b";";a:6:{s:9:"interface";s:12:"s:5:"admin";";s:4:"name";s:2:"N;";s:9:"serviceId";s:2:"N;";s:6:"region";s:16:"s:9:"RegionOne";";s:5:"links";s:2:"N;";s:3:"url";s:30:"s:22:"http://controller:9696";";}}s:5:"links";s:2:"N;";}s:40:"s:32:"5d48cf5c41b9412a8bfcf87e4b6b4bb4";";a:5:{s:4:"name";s:13:"s:6:"glance";";s:11:"description";s:2:"N;";s:4:"type";s:12:"s:5:"image";";s:9:"endpoints";a:3:{s:40:"s:32:"03aed8cd676d4b1b8b6ed69ba7750d72";";a:6:{s:9:"interface";s:15:"s:8:"internal";";s:4:"name";s:2:"N;";s:9:"serviceId";s:2:"N;";s:6:"region";s:16:"s:9:"RegionOne";";s:5:"links";s:2:"N;";s:3:"url";s:30:"s:22:"http://controller:9292";";}s:40:"s:32:"06ba5f2c1cb24eaebe3ef3b258ff0841";";a:6:{s:9:"interface";s:13:"s:6:"public";";s:4:"name";s:2:"N;";s:9:"serviceId";s:2:"N;";s:6:"region";s:16:"s:9:"RegionOne";";s:5:"links";s:2:"N;";s:3:"url";s:32:"s:24:"http://148.60.11.31:9292";";}s:40:"s:32:"32dd6e5e7acd44d88c1e89a4d805a355";";a:6:{s:9:"interface";s:12:"s:5:"admin";";s:4:"name";s:2:"N;";s:9:"serviceId";s:2:"N;";s:6:"region";s:16:"s:9:"RegionOne";";s:5:"links";s:2:"N;";s:3:"url";s:30:"s:22:"http://controller:9292";";}}s:5:"links";s:2:"N;";}s:40:"s:32:"be984e9e4da645449c645a3dad056d6b";";a:5:{s:4:"name";s:15:"s:8:"keystone";";s:11:"description";s:2:"N;";s:4:"type";s:15:"s:8:"identity";";s:9:"endpoints";a:3:{s:40:"s:32:"0f292b615b544869841c349dbbfead32";";a:6:{s:9:"interface";s:13:"s:6:"public";";s:4:"name";s:2:"N;";s:9:"serviceId";s:2:"N;";s:6:"region";s:16:"s:9:"RegionOne";";s:5:"links";s:2:"N;";s:3:"url";s:36:"s:28:"http://148.60.11.31:5000/2.0";";}s:40:"s:32:"6a01f770c4014bec933cccc28d378c78";";a:6:{s:9:"interface";s:12:"s:5:"admin";";s:4:"name";s:2:"N;";s:9:"serviceId";s:2:"N;";s:6:"region";s:16:"s:9:"RegionOne";";s:5:"links";s:2:"N;";s:3:"url";s:36:"s:28:"http://controller:35357/v2.0";";}s:40:"s:32:"d94955c39c784602a1ab49003056a4a4";";a:6:{s:9:"interface";s:15:"s:8:"internal";";s:4:"name";s:2:"N;";s:9:"serviceId";s:2:"N;";s:6:"region";s:16:"s:9:"RegionOne";";s:5:"links";s:2:"N;";s:3:"url";s:35:"s:27:"http://controller:5000/v2.0";";}}s:5:"links";s:2:"N;";}s:40:"s:32:"edc16c0a3e4042b7b396727fa8e57e7e";";a:5:{s:4:"name";s:11:"s:4:"nova";";s:11:"description";s:2:"N;";s:4:"type";s:14:"s:7:"compute";";s:9:"endpoints";a:3:{s:40:"s:32:"0d61ec232f3b4975b3e3d32f2b7a6122";";a:6:{s:9:"interface";s:13:"s:6:"public";";s:4:"name";s:2:"N;";s:9:"serviceId";s:2:"N;";s:6:"region";s:16:"s:9:"RegionOne";";s:5:"links";s:2:"N;";s:3:"url";s:68:"s:60:"http://148.60.11.31:8774/v2/bdb42ccd0a074d15a9808ed0d2f09ce7";";}s:40:"s:32:"20ac63e325274a5bbde914f3bb582c45";";a:6:{s:9:"interface";s:12:"s:5:"admin";";s:4:"name";s:2:"N;";s:9:"serviceId";s:2:"N;";s:6:"region";s:16:"s:9:"RegionOne";";s:5:"links";s:2:"N;";s:3:"url";s:66:"s:58:"http://controller:8774/v2/bdb42ccd0a074d15a9808ed0d2f09ce7";";}s:40:"s:32:"749e7483b9b04dceb1838095dd877aa8";";a:6:{s:9:"interface";s:15:"s:8:"internal";";s:4:"name";s:2:"N;";s:9:"serviceId";s:2:"N;";s:6:"region";s:16:"s:9:"RegionOne";";s:5:"links";s:2:"N;";s:3:"url";s:66:"s:58:"http://controller:8774/v2/bdb42ccd0a074d15a9808ed0d2f09ce7";";}}s:5:"links";s:2:"N;";}}}
\ No newline at end of file |
