From d00ea4f7b1317ed5e9fe2743ea61ceb4330aadf6 Mon Sep 17 00:00:00 2001 From: Eole Date: Sun, 31 Jan 2016 12:29:20 +0100 Subject: [PATCH] nettoyage --- server/core/LibOverride/Builder.php | 169 -------------------- server/core/LibOverride/OpenStack.php | 43 ----- server/core/LibOverride/genTokenOptions.php | 5 +- 3 files changed, 2 insertions(+), 215 deletions(-) delete mode 100644 server/core/LibOverride/Builder.php delete mode 100644 server/core/LibOverride/OpenStack.php diff --git a/server/core/LibOverride/Builder.php b/server/core/LibOverride/Builder.php deleted file mode 100644 index 30ea9d3..0000000 --- a/server/core/LibOverride/Builder.php +++ /dev/null @@ -1,169 +0,0 @@ - 'publicURL']; - - public function __construct(array $globalOptions = []) - { - $this->globalOptions = $globalOptions; - parent::__construct($globalOptions); - } - - public function getOptions() - { - return $this->globalOptions; - } - - public function setOptions($Options) - { - $this->globalOptions = $Options; - } - - /** - * Internal method which resolves the API and Service classes for a service. - * - * @param string $serviceName The name of the service, e.g. Compute - * @param int $serviceVersion The major version of the service, e.g. 2 - * - * @return array - */ - private function getClasses($serviceName, $serviceVersion) - { - $rootNamespace = sprintf("OpenStack\\%s\\v%d", $serviceName, $serviceVersion); - - return [ - sprintf("%s\\Api", $rootNamespace), - sprintf("%s\\Service", $rootNamespace), - ]; - } - - /** - * This method will return an OpenStack service ready fully built and ready for use. There is - * some initial setup that may prohibit users from directly instantiating the service class - * directly - this setup includes the configuration of the HTTP client's base URL, and the - * attachment of an authentication handler. - * - * @param $serviceName The name of the service as it appears in the OpenStack\* namespace - * @param $serviceVersion The major version of the service - * @param array $serviceOptions The service-specific options to use - * - * @return \OpenStack\Common\Service\ServiceInterface - * - * @throws \Exception - */ - public function createService($serviceName, $serviceVersion, array $serviceOptions = []) - { - $options = $this->mergeOptions($serviceOptions); - - $this->stockIdentityService($options); - $this->stockAuthHandler($options); - $this->stockHttpClient($options, $serviceName); - - list($apiClass, $serviceClass) = $this->getClasses($serviceName, $serviceVersion); - - return new $serviceClass($options['httpClient'], new $apiClass()); - } - - private function stockHttpClient(array &$options, $serviceName) - { - if (!isset($options['httpClient']) || !($options['httpClient'] instanceof ClientInterface)) { - if (strcasecmp($serviceName, 'identity') === 0) { - $baseUrl = $options['authUrl']; - $stack = $this->getStack($options['authHandler']); - } else { - list($token, $baseUrl) = $options['identityService']->authenticate($options); - $stack = $this->getStack($options['authHandler'], $token); - } - - $this->addDebugMiddleware($options, $stack); - - $options['httpClient'] = $this->httpClient($baseUrl, $stack); - } - } - - /** - * @codeCoverageIgnore - */ - private function addDebugMiddleware(array $options, HandlerStack &$stack) - { - if (!empty($options['debugLog']) - && !empty($options['logger']) - && !empty($options['messageFormatter']) - ) { - $stack->push(GuzzleMiddleware::log($options['logger'], $options['messageFormatter'])); - } - } - - private function stockIdentityService(array &$options) - { - if (!isset($options['identityService'])) { - $httpClient = $this->httpClient($options['authUrl'], HandlerStack::create()); - $options['identityService'] = Service::factory($httpClient); - } - } - - /** - * @param array $options - * @codeCoverageIgnore - */ - private function stockAuthHandler(array &$options) - { - if (!isset($options['authHandler'])) { - $options['authHandler'] = function () use ($options) { - return $options['identityService']->generateToken($options); - }; - } - } - - private function getStack(callable $authHandler, Token $token = null) - { - $stack = HandlerStack::create(); - $stack->push(Middleware::authHandler($authHandler, $token)); - return $stack; - } - - private function httpClient($baseUrl, HandlerStack $stack) - { - return new Client([ - 'base_uri' => Utils::normalizeUrl($baseUrl), - 'handler' => $stack, - ]); - } - - private function mergeOptions(array $serviceOptions) - { - $options = array_merge($this->defaults, $this->globalOptions, $serviceOptions); - - if (!isset($options['authUrl'])) { - throw new \InvalidArgumentException('"authUrl" is a required option'); - } - - return $options; - } -} - diff --git a/server/core/LibOverride/OpenStack.php b/server/core/LibOverride/OpenStack.php deleted file mode 100644 index 2b3897a..0000000 --- a/server/core/LibOverride/OpenStack.php +++ /dev/null @@ -1,43 +0,0 @@ -builder = $builder ?: new Builder_override($options); - parent::__construct($options, $this->builder); - } - - public function getBuilderOptions() - { - - return $this->builder->getOptions(); - - } - - public function setBuilderOptions($options) - { - - $this->builder->setOptions($options); - - } -} diff --git a/server/core/LibOverride/genTokenOptions.php b/server/core/LibOverride/genTokenOptions.php index 0b00163..2e10cac 100755 --- a/server/core/LibOverride/genTokenOptions.php +++ b/server/core/LibOverride/genTokenOptions.php @@ -155,7 +155,7 @@ class genTokenOptions $token = new Models\Token($this->httpClient, $api); $token->methods = unserialize($tokenSerialized["methods"]); $token->roles = []; - $i = 0; + foreach($tokenSerialized["roles"] as $key => $role){ $tmp = new Models\Role($this->httpClient, $api); @@ -164,8 +164,7 @@ class genTokenOptions if(isset($role["name"])) $tmp->name = unserialize($role["name"]); - $token->roles[] = $tmp; - $i++; + $token->roles[] = $tmp } $token->expires = unserialize($tokenSerialized["expires"]);