Esempio n. 1
0
 /**
  * @deprecated
  */
 protected function swiftAuth()
 {
     $user = self::$settings['hpcloud.swift.account'];
     $key = self::$settings['hpcloud.swift.key'];
     $url = self::$settings['hpcloud.swift.url'];
     //$url = self::$settings['hpcloud.identity.url'];
     return \HPCloud\Storage\ObjectStorage::newFromSwiftAuth($user, $key, $url);
 }
Esempio n. 2
0
 /**
  * Based on the context, initialize the ObjectStorage.
  *
  * The following parameters may be set either in the stream context
  * or through HPCloud::Bootstrap::setConfiguration():
  *
  * - token: An auth token. If this is supplied, authentication is skipped and
  *     this token is used. NOTE: You MUST set swift_endpoint if using this
  *     option.
  * - swift_endpoint: The URL to the swift instance. This is only necessary if
  *     'token' is set. Otherwise it is ignored.
  * - username: A username. MUST be accompanied by 'password' and 'tenantid'.
  * - password: A password. MUST be accompanied by 'username' and 'tenantid'.
  * - account: An account ID. MUST be accompanied by a 'key' and 'tenantid'.
  * - key: A secret key. MUST be accompanied by an 'account' and 'tenantid'.
  * - endpoint: The URL to the authentication endpoint. Necessary if you are not
  *     using a 'token' and 'swift_endpoint'.
  * - use_swift_auth: If this is set to TRUE, it will force the app to use
  *     the deprecated swiftAuth instead of IdentityServices authentication.
  *     In general, you should avoid using this.
  *
  * To find these params, the method first checks the supplied context. If the
  * key is not found there, it checks the Bootstrap::conf().
  *
  * @fixme This should be rewritten to use ObjectStorage::newFromServiceCatalog().
  */
 protected function initializeObjectStorage()
 {
     $token = $this->cxt('token');
     if (empty($token) && isset($_SESSION["HPCLOUD_TOKEN"])) {
         $token = $_SESSION["HPCLOUD_TOKEN"];
     }
     $account = $this->cxt('account');
     $key = $this->cxt('key');
     $tenantId = $this->cxt('tenantid');
     $authUrl = $this->cxt('endpoint');
     $endpoint = $this->cxt('swift_endpoint');
     $serviceCatalog = NULL;
     if (!empty($token) && (isset(self::$serviceCatalogCache[$token]) || isset($_SESSION["HPCLOUD_CATALOG"]))) {
         if (isset($_SESSION["HPCLOUD_CATALOG"])) {
             $serviceCatalog = $_SESSION["HPCLOUD_CATALOG"];
         } else {
             $serviceCatalog = self::$serviceCatalogCache[$token];
         }
         if (empty($endpoint)) {
             for ($i = 0; $i < count($serviceCatalog); $i++) {
                 if ($serviceCatalog[$i]['type'] == "object-store") {
                     $endpoint = $serviceCatalog[$i]['endpoints'][0]['publicURL'];
                     break;
                 }
             }
         }
     }
     // FIXME: If a token is invalidated, we should try to re-authenticate.
     // If context has the info we need, start from there.
     if (!empty($token) && !empty($endpoint)) {
         $this->store = new \HPCloud\Storage\ObjectStorage($token, $endpoint);
     } elseif ($this->cxt('use_swift_auth', FALSE)) {
         if (empty($authUrl) || empty($account) || empty($key)) {
             throw new \HPCloud\Exception('account, endpoint, key are required stream parameters.');
         }
         $this->store = \HPCloud\Storage\ObjectStorage::newFromSwiftAuth($account, $key, $authUrl);
     } elseif (empty($tenantId) || empty($authUrl)) {
         throw new \HPCloud\Exception('Tenant ID (tenantid) and endpoint are required.');
     } else {
         \AJXP_Logger::debug("Authenticating");
         $ident = $this->authenticate();
         // Update token and service catalog. The old pair may be out of date.
         $token = $ident->token();
         $serviceCatalog = $ident->serviceCatalog();
         self::$serviceCatalogCache[$token] = $serviceCatalog;
         $this->store = ObjectStorage::newFromServiceCatalog($serviceCatalog, $token);
         $_SESSION["HPCLOUD_TOKEN"] = $token;
         $_SESSION["HPCLOUD_CATALOG"] = $serviceCatalog;
         /*
               $catalog = $ident->serviceCatalog(ObjectStorage::SERVICE_TYPE);
               if (empty($catalog) || empty($catalog[0]['endpoints'][0]['publicURL'])) {
          //throw new \HPCloud\Exception('No object storage services could be found for this tenant ID.' . print_r($catalog, TRUE));
          throw new \HPCloud\Exception('No object storage services could be found for this tenant ID.');
               }
               $serviceURL = $catalog[0]['endpoints'][0]['publicURL'];
         
               $this->store = new ObjectStorage($token, $serviceURL);
         */
     }
     try {
         $this->initializeCDN($token, $serviceCatalog);
     } catch (\HPCloud\Exception $e) {
         //fwrite(STDOUT, $e);
         throw new \HPCloud\Exception('CDN could not be initialized', 1, $e);
     }
     return !empty($this->store);
 }
Esempio n. 3
0
 /**
  * Based on the context, initialize the ObjectStorage.
  *
  * The following parameters may be set either in the stream context
  * or through HPCloud::Bootstrap::setConfiguration():
  *
  * - token: An auth token. If this is supplied, authentication is skipped and
  *     this token is used. NOTE: You MUST set swift_endpoint if using this
  *     option.
  * - swift_endpoint: The URL to the swift instance. This is only necessary if
  *     'token' is set. Otherwise it is ignored.
  * - username: A username. MUST be accompanied by 'password' and 'tenantname'.
  * - password: A password. MUST be accompanied by 'username' and 'tenantname'.
  * - account: An account ID. MUST be accompanied by a 'secret' and 'tenantname'.
  * - secret: A secret key. MUST be accompanied by an 'account' and 'tenantname'.
  * - endpoint: The URL to the authentication endpoint. Necessary if you are not
  *     using a 'token' and 'swift_endpoint'.
  * - use_swift_auth: If this is set to TRUE, it will force the app to use
  *     the deprecated swiftAuth instead of IdentityServices authentication.
  *     In general, you should avoid using this.
  *
  * To find these params, the method first checks the supplied context. If the
  * key is not found there, it checks the Bootstrap::conf().
  *
  * @param string $region
  *   The region being used for this service.
  *
  * @fixme This should be rewritten to use ObjectStorage::newFromServiceCatalog().
  */
 protected function initializeObjectStorage()
 {
     $token = $this->cxt('token');
     $account = $this->cxt('account');
     // Legacy support for old 'key' param.
     $key = $this->cxt('key', $this->cxt('secret'));
     $tenantId = $this->cxt('tenantid');
     $tenantName = $this->cxt('tenantname');
     $authUrl = $this->cxt('endpoint');
     $endpoint = $this->cxt('swift_endpoint');
     $region = $this->cxt('region');
     $serviceCatalog = NULL;
     if (!empty($token) && isset(self::$serviceCatalogCache[$token])) {
         $serviceCatalog = self::$serviceCatalogCache[$token];
     }
     // FIXME: If a token is invalidated, we should try to re-authenticate.
     // If context has the info we need, start from there.
     if (!empty($token) && !empty($endpoint)) {
         $this->store = new \HPCloud\Storage\ObjectStorage($token, $endpoint);
     } elseif ($this->cxt('use_swift_auth', FALSE)) {
         if (empty($authUrl) || empty($account) || empty($key)) {
             throw new \HPCloud\Exception('account, endpoint, key are required stream parameters.');
         }
         $this->store = \HPCloud\Storage\ObjectStorage::newFromSwiftAuth($account, $key, $authUrl);
     } elseif (empty($tenantId) && empty($tenantName)) {
         throw new \HPCloud\Exception('Either Tenant ID (tenantid) or Tenant Name (tenantname) is required.');
     } elseif (empty($authUrl)) {
         throw new \HPCloud\Exception('An Identity Service Endpoint (endpoint) is required.');
     } else {
         $ident = $this->authenticate();
         // Update token and service catalog. The old pair may be out of date.
         $token = $ident->token();
         $serviceCatalog = $ident->serviceCatalog();
         self::$serviceCatalogCache[$token] = $serviceCatalog;
         $this->store = ObjectStorage::newFromServiceCatalog($serviceCatalog, $token, $region);
         /*
               $catalog = $ident->serviceCatalog(ObjectStorage::SERVICE_TYPE);
               if (empty($catalog) || empty($catalog[0]['endpoints'][0]['publicURL'])) {
          //throw new \HPCloud\Exception('No object storage services could be found for this tenant ID.' . print_r($catalog, TRUE));
          throw new \HPCloud\Exception('No object storage services could be found for this tenant ID.');
               }
               $serviceURL = $catalog[0]['endpoints'][0]['publicURL'];
         
               $this->store = new ObjectStorage($token, $serviceURL);
         */
     }
     try {
         $this->initializeCDN($token, $serviceCatalog);
     } catch (\HPCloud\Exception $e) {
         //fwrite(STDOUT, $e);
         throw new \HPCloud\Exception('CDN could not be initialized', 1, $e);
     }
     return !empty($this->store);
 }