コード例 #1
0
 protected function doNotify($channel, array $events)
 {
     if (!count($events)) {
         return true;
     }
     $response = $this->http->run(array('url' => "{$this->baseUrl}/relayer/api/v1.0/" . rawurlencode($channel), 'method' => 'POST', 'body' => json_encode(array('events' => $events)), 'headers' => array('content-type' => 'application/json')));
     return $response['code'] == 201;
 }
コード例 #2
0
ファイル: RESTBagOStuff.php プロジェクト: paladox/mediawiki
 /**
  * Delete an item.
  *
  * @param string $key
  * @return bool True if the item was deleted or not found, false on failure
  */
 public function delete($key)
 {
     $req = ['method' => 'DELETE', 'url' => $this->url . rawurlencode($key)];
     list($rcode, $rdesc, $rhdrs, $rbody, $rerr) = $this->client->run($req);
     if ($rcode === 200 || $rcode === 204 || $rcode === 205) {
         return true;
     }
     return $this->handleError("Failed to delete {$key}", $rcode, $rerr);
 }
コード例 #3
0
ファイル: SwiftFileBackend.php プロジェクト: OrBin/mediawiki
 /**
  * @return array|null Credential map
  */
 protected function getAuthentication()
 {
     if ($this->authErrorTimestamp !== null) {
         if (time() - $this->authErrorTimestamp < 60) {
             return null;
             // failed last attempt; don't bother
         } else {
             // actually retry this time
             $this->authErrorTimestamp = null;
         }
     }
     // Session keys expire after a while, so we renew them periodically
     $reAuth = time() - $this->authSessionTimestamp > $this->authTTL;
     // Authenticate with proxy and get a session key...
     if (!$this->authCreds || $reAuth) {
         $this->authSessionTimestamp = 0;
         $cacheKey = $this->getCredsCacheKey($this->swiftUser);
         $creds = $this->srvCache->get($cacheKey);
         // credentials
         // Try to use the credential cache
         if (isset($creds['auth_token']) && isset($creds['storage_url'])) {
             $this->authCreds = $creds;
             // Skew the timestamp for worst case to avoid using stale credentials
             $this->authSessionTimestamp = time() - ceil($this->authTTL / 2);
         } else {
             // cache miss
             list($rcode, $rdesc, $rhdrs, $rbody, $rerr) = $this->http->run(array('method' => 'GET', 'url' => "{$this->swiftAuthUrl}/v1.0", 'headers' => array('x-auth-user' => $this->swiftUser, 'x-auth-key' => $this->swiftKey)));
             if ($rcode >= 200 && $rcode <= 299) {
                 // OK
                 $this->authCreds = array('auth_token' => $rhdrs['x-auth-token'], 'storage_url' => $rhdrs['x-storage-url']);
                 $this->srvCache->set($cacheKey, $this->authCreds, ceil($this->authTTL / 2));
                 $this->authSessionTimestamp = time();
             } elseif ($rcode === 401) {
                 $this->onError(null, __METHOD__, array(), "Authentication failed.", $rcode);
                 $this->authErrorTimestamp = time();
                 return null;
             } else {
                 $this->onError(null, __METHOD__, array(), "HTTP return code: {$rcode}", $rcode);
                 $this->authErrorTimestamp = time();
                 return null;
             }
         }
         // Ceph RGW does not use <account> in URLs (OpenStack Swift uses "/v1/<account>")
         if (substr($this->authCreds['storage_url'], -3) === '/v1') {
             $this->isRGW = true;
             // take advantage of strong consistency in Ceph
         }
     }
     return $this->authCreds;
 }