Esempio n. 1
0
 /**
  * @see FileBackendStore::getFileHttpUrl()
  * @return string|null
  */
 public function getFileHttpUrl(array $params)
 {
     if ($this->swiftTempUrlKey != '' || $this->rgwS3AccessKey != '' && $this->rgwS3SecretKey != '') {
         list($srcCont, $srcRel) = $this->resolveStoragePathReal($params['src']);
         if ($srcRel === null) {
             return null;
             // invalid path
         }
         try {
             $ttl = isset($params['ttl']) ? $params['ttl'] : 86400;
             $sContObj = $this->getContainer($srcCont);
             $obj = new CF_Object($sContObj, $srcRel, false, false);
             // skip HEAD
             if ($this->swiftTempUrlKey != '') {
                 return $obj->get_temp_url($this->swiftTempUrlKey, $ttl, "GET");
             } else {
                 // give S3 API URL for rgw
                 $expires = time() + $ttl;
                 // Path for signature starts with the bucket
                 $spath = '/' . rawurlencode($srcCont) . '/' . str_replace('%2F', '/', rawurlencode($srcRel));
                 // Calculate the hash
                 $signature = base64_encode(hash_hmac('sha1', "GET\n\n\n{$expires}\n{$spath}", $this->rgwS3SecretKey, true));
                 // See http://s3.amazonaws.com/doc/s3-developer-guide/RESTAuthentication.html.
                 // Note: adding a newline for empty CanonicalizedAmzHeaders does not work.
                 return wfAppendQuery(str_replace('/swift/v1', '', $sContObj->cfs_http->getStorageUrl() . $spath), array('Signature' => $signature, 'Expires' => $expires, 'AWSAccessKeyId' => $this->rgwS3AccessKey));
             }
         } catch (NoSuchContainerException $e) {
         } catch (CloudFilesException $e) {
             // some other exception?
             $this->handleException($e, null, __METHOD__, $params);
         }
     }
     return null;
 }
 /**
  * @see FileBackendStore::getFileHttpUrl()
  * @return string|null
  */
 public function getFileHttpUrl(array $params)
 {
     if ($this->swiftTempUrlKey != '') {
         // temp urls enabled
         list($srcCont, $srcRel) = $this->resolveStoragePathReal($params['src']);
         if ($srcRel === null) {
             return null;
             // invalid path
         }
         try {
             $sContObj = $this->getContainer($srcCont);
             $obj = new CF_Object($sContObj, $srcRel, false, false);
             // skip HEAD
             return $obj->get_temp_url($this->swiftTempUrlKey, 86400, "GET");
         } catch (NoSuchContainerException $e) {
         } catch (CloudFilesException $e) {
             // some other exception?
             $this->handleException($e, null, __METHOD__, $params);
         }
     }
     return null;
 }