Ejemplo n.º 1
0
 public function auth($username, $password, $endpoint, $ucID = '')
 {
     $client = clone $this->client;
     //$client->getLogger()->setEnabled(true);
     $this->username = $username;
     $this->password = $password;
     $this->endpoint = $endpoint;
     $this->credentials = array('username' => $this->username, 'password' => $this->password, 'tenantName' => 'demo');
     try {
         $client = new \OpenCloud\OpenStack($this->endpoint, $this->credentials);
         //$client->authenticate();
         $credentials = $client->ExportCredentials();
         $this->store_credentials_in_cache($credentials, $ucID);
     } catch (\Guzzle\Http\Exception\BadResponseException $e) {
         $responseBody = (string) $e->getResponse()->getBody();
         $statusCode = $e->getResponse()->getStatusCode();
         $headers = $e->getResponse()->getHeaderLines();
         echo sprintf("Status: %s\nBody: %s\nHeaders: %s", $statusCode, $responseBody, implode(', ', $headers));
     }
 }
Ejemplo n.º 2
0
 /**
  *
  * @return \OpenCloud\OpenStack
  */
 public function getConnection()
 {
     $res = new \OpenCloud\OpenStack($this->getConfig('openstack_identity_url'), ['username' => $this->getConfig('username'), 'password' => $this->getConfig('password'), 'tenantName' => $this->getConfig('tenant')]);
     //Get credentials from cache if needed
     if ($this->getConfig('cache_credentials')) {
         if (\Cache::has('object-store-credentials')) {
             $res->importCredentials(unserialize(\Cache::get('object-store-credentials')));
         }
         $token = $res->getTokenObject();
         if (!$token || $token->hasExpired()) {
             $res->authenticate();
             Log::info('re-authenticated');
             \Cache::put('object-store-credentials', serialize($res->exportCredentials()), 0);
         }
     } else {
         $res->authenticate();
     }
     return $res;
 }
 /**
  * @param Gaufrette\Adapter\OpenStackCloudFiles\ConnectionFactoryInterface $connectionFactory
  * @param OpenCloud\OpenStack                                              $connection
  * @param OpenCloud\ObjectStore\Service                                    $objectStore
  * @param OpenCloud\ObjectStore\Resource\Container                         $container
  * @param OpenCloud\Common\Collection                                      $objectList
  */
 function it_keys_returns_sorted_array($connectionFactory, $connection, $objectStore, $container, $objectList)
 {
     $inputArray = array('key5', 'key2', 'key1');
     $outputArray = $inputArray;
     sort($outputArray);
     $index = 0;
     $objectList->next()->will(function () use($inputArray, &$index) {
         if ($index < count($inputArray)) {
             $objectItem = new \stdClass();
             $objectItem->name = $inputArray[$index];
             $index++;
             return $objectItem;
         }
     })->shouldBeCalledTimes(count($inputArray) + 1);
     $container->objectList()->willReturn($objectList);
     $objectStore->container("test")->willReturn($container);
     $connection->objectStore()->willReturn($objectStore)->shouldBeCalledTimes(1);
     $connectionFactory->create()->willReturn($connection)->shouldBeCalledTimes(1);
     $this->keys()->shouldReturn($outputArray);
 }