stack = HandlerStack::create(); $httpClient = new Client([ 'base_uri' => Utils::normalizeUrl($options['authUrl']), 'handler' => $this->stack, ]); $options['identityService'] = Service::factory($httpClient); $options['authHandler'] = function () use ($options) { return $options['identityService']->generateToken($options); }; $this->optionsGlobal['Common'] = $options; } /** * @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'])); } } public function genComputeToken(){ $options = $this->optionsGlobal['Common']; $options['catalogName'] = 'nova'; $options['catalogType'] = 'compute'; $options['region'] = 'RegionOne'; list($token, $baseUrl) = $options['identityService']->authenticate($options); //var_dump($token); //$stack = HandlerStack::create(); $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); $this->addDebugMiddleware($options, $this->stack); $options['httpClient'] = new Client([ 'base_uri' => Utils::normalizeUrl($baseUrl), 'handler' => $this->stack, ]); $this->backup['Compute'] = array('token' => json_encode($token), 'baseUrl' => $baseUrl ); serialize($token->methods); foreach($token->roles as $role){ serialize($role->name); serialize($role->links); serialize($role->id); } serialize($token->expires); serialize($token->project->domainId); serialize($token->project->parentId); serialize($token->project->enabled); serialize($token->project->description); serialize($token->project->id); serialize($token->project->links); serialize($token->project->name); foreach($token->catalog->services as $service){ serialize($service->id); serialize($service->name); serialize($service->description); serialize($service->type); foreach($service->endpoints as $end){ serialize($end->id); serialize($end->interface); serialize($end->name); serialize($end->serviceId); serialize($end->region); serialize($end->links); serialize($end->url); } serialize($service->links); } serialize($token->extras); serialize($token->user->domainId); serialize($token->user->defaultProjectId); serialize($token->user->id); serialize($token->user->email); serialize($token->user->enabled); serialize($token->user->description); serialize($token->user->links); serialize($token->user->name); serialize($token->issued); serialize($token->id); var_dump($token->id); $this->optionsGlobal['Compute'] = $options; } public function loadComputeBackup($opt){ $options = $this->optionsGlobal['Common']; $options['catalogName'] = 'nova'; $options['catalogType'] = 'compute'; $options['region'] = 'RegionOne'; //list($token, $baseUrl) = $options['identityService']->authenticate($options); $this->backup['Compute'] = json_decode($opt, true); var_dump($this->backup['Compute']); $token = json_decode($this->backup['Compute']['token'], true); $baseUrl = $this->backup['Compute']['baseUrl']; //$stack = HandlerStack::create(); $this->stack->push(Middleware::authHandler($options['authHandler'], $token)); $this->addDebugMiddleware($options, $this->stack); $options['httpClient'] = new Client([ 'base_uri' => Utils::normalizeUrl($baseUrl), 'handler' => $this->stack, ]); $this->backup['Compute'] = array('token' => json_encode($token), 'baseUrl' => $baseUrl ); $this->optionsGlobal['Compute'] = $options; } public function getBackup($service){ return json_encode($this->backup[$service]); } public function getOptionsCompute(){ return $this->optionsGlobal['Compute']; } }